четверг, 22 сентября 2011 г.

How incorrectly cross build FreeBSD ports

Q: Why incorrectly?
A: Because configure script will thought what software will be built for host system, not for target. (for i386 instead of armeb)

Since we still can't cross compile FreeBSD ports, everyone use own workaround for that. So I decide to write my own notes to help some folks who don't yet have own workaround for that.

1. Toolchain
At first we need cross toolchain for building, there is many ways to do it, but I use this:
TARGET=arm
TARGET_ARCH=armeb
SRC_TREE=/usr/src

cd ${SRC_TREE}
make TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} TARGET_CPUARCH=${TARGET} toolchain

When toolchain build done you will have toolchain binary (cc,cpp,gcc etc.) in directory:
/usr/obj/${TARGET}.${TARGET_ARCH}/${SRC_TREE}/tmp/usr/bin

2. Port dependency
Change dir to desire port, and get two lists of dependencies:

> cd /usr/ports/security/openvpn

> make run-depends-list
/usr/ports/archivers/lzo2
> make build-depends-list
/usr/ports/archivers/lzo2
/usr/ports/archivers/xz





Remove ports that exist in run-depends-list from build-depends-list, and you will get:
  1. run-depends-list - list of ports that must be also cross-compiled.
  2. build-depends-list - list of ports that must be installed on build host to be able to build your desired port.
3. Building
Install ports from build-depends-list. Then for every ports in run-depends-list run:
  1. make configure
  2. PATH=/usr/obj/${TARGET}.${TARGET_ARCH}/${SRC_TREE}/tmp/usr/bin:${PATH} make DESTDIR=${PATH_TO_TARGET_DEVICE_ROOTFS} install
Some ports require to manual fixing for cross-building. Example:
lzo2 which is dependency for openvpn have test target in port Makefile, so we need to comment out that requirement, because we can't run those binary's (you remember, we do compilation for system with different CPU). To do so we need remove target post-build from Makefile:

post-build:
	@${ECHO_MSG} "===>  Running self-tests for ${PKGNAME} (can take a few minutes)"
	@#: override MALLOC_OPTIONS, else tests take excessively long
	cd ${WRKSRC} && ${SETENV} MALLOC_OPTIONS=jz ${MAKE} check test SHELL="${SH} -x"

That for example only, because last commit add checking of variable WITHOUT_CHECKS. So we need only define WITHOUT_CHECKS to avoid those tests.
 
  1. make configure
  2. PATH=/usr/obj/${TARGET}.${TARGET_ARCH}/${SRC_TREE}/tmp/usr/bin:${PATH} make WITHOUT_CHECKS=yes DESTDIR=${PATH_TO_TARGET_DEVICE_ROOTFS} install
Hope this will help somebody to do great work :)

Комментариев нет:

Отправить комментарий