# cross compile iperf



## alxjns (Sep 28, 2010)

How do we cross-compile any external ports (that are not part of the build world) for my ARM board on FreeBSD? For example I want to cross-compile "iperf" now. How should I go about it? 

How do we give the compiler while configurin? If I am not wrong the architecture is given to the "cc" compiler as option for cross-compiling normal world tools. Any help on this please?


----------



## alxjns (Sep 29, 2010)

Has no one ever tried it? How about cross-compiling a small 'hello world' program?


----------



## Lainoox (Jan 9, 2011)

You should take a look at OpenWRT (http://www.openwrt.org) for help with cross-compilation.  They have a wicked toolchain, and a great build system for cross-compilation to many embedded devices running different architectures.


----------



## loos (Jan 28, 2011)

Cross building ports can be a pain depending on the dependencies list. E.g. if the port requires libtool or something like that the tool itself needs to support cross building (which isn't the case for libtool).

You also need to prevent scripts like 'configure' from generating the 'try' program (which is used to check if the system compiler works). This is done passing the arguments '--host=' and '--build=', but this (at least in my tests) break some ports in a very obscure way...

Cross building simple programs (like a 'hello world') can be easily accomplished by use the 'make buildenv':

(this is a sample for a MIPS cross build environment)


```
**************** buildenv.csh begin **************
#!/bin/csh

setenv SRCROOT /usr/src
setenv TARGET mips
setenv TARGET_ARCH mipseb
setenv TARGET_CPUTYPE mips32
setenv KERNCONF RSPRO
setenv MAKEOBJDIRPREFIX /usr/obj
set NFSROOT=/data/rspro/nfsroot
set TFTPBOOT=/data/tftpboot/rspro

set MAKEFLAGS=(-DWITHOUT_CDDL		\
		-DWITHOUT_GAMES		\
		-DWITHOUT_DOCS		\
		-DWITHOUT_ACPI		\
		-DWITHOUT_KERBEROS	\
		-DWITHOUT_RESCUE	\
		-DWITHOUT_PROFILE	\
		-DWITHOUT_BSNMP		\
		-DWITHOUT_NIS		\
		-DWITHOUT_IPX		\
		-DWITHOUT_ATM		\
		-DWITH_GPIO)

cd ${SRCROOT}
make ${MAKEFLAGS} kernel-toolchain
make ${MAKEFLAGS} buildenv

**************** buildenv.csh end **************
```

The 'make kernel-toolchain' builds the cross tools for FreeBSD and then the 'make buildenv' sets all the PATHs for the cross building tools:


```
# ./buildenv.csh
(lots of compiling happens here - and then)
Entering world for mipseb:mips
# cc -v
Using built-in specs.
Target: mipseb-undermydesk-freebsd
Configured with: FreeBSD/mipseb system compiler
Thread model: posix
gcc version 4.2.1 20070719  [FreeBSD]
#
```

Done! You can now cross build your programs 

Good luck!


----------

