Hello Hugo.
I'm back again with good news and mini howto about crosscompile under openwrt toolchain:
1. D*ownload and extract toolchain for your target platform. This includes basic gcc, linker including minimal set of libraries (uclibc, crypt etc). I'll use OpenWrt Barrier Breaker 10.03.1 toolchain, extracted in /tmp/openwrt-toolchain, compiler used is mipsel-openwrt-linux-uclibc-gcc.
If you use this toolchain, please note that toolchain script usr/bin/mipsel-openwrt-linux-uclibc-wrapper.sh has a bug inside, GCC_SYSROOT_FLAGS content needs to start with "-Wl,", in toolchain -Wl is somewhere further in contente which prevents it from correct work.
2. Add toolchain binary directories (/bin, /usr/bin etc) to your build host PATH variable. Any standard Linux system can be used as build host. I used Tiny Core Linux with minimal packages, just for building. This includes gcc (not generally necessary), make, cmake etc.
3. Do*wnload and extract hiawatha sources - I used /tmp/hiawatha
4. Make build directory and cd to it (as build instructions of hiawatha says).
5. For building using cross compiler, create configuration file of cmake (my is mipsel-openwrt-linux-uclibc.cmake) with this content:
INCLUDE(CMakeForceCompiler)
SET(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR brcm47xx)
SET(CMAKE_SYSTEM_VERSION 1)
# compiler binary names
SET(CMAKE_C_COMPILER mipsel-openwrt-linux-uclibc-gcc)
SET(CMAKE_CXX_COMPILER mipsel-openwrt-linux-uclibx-g++)
# toolchain root directory
SET(CMAKE_FIND_ROOT_PATH /tmp/openwrt-toolchain)
# target location for compiled binaries install to prevent mixing with build host system
SET(CMAKE_STAGING_PREFIX /tmp/openwrt-toolchain)
# search for programs, libraries and includes in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
- for more details see cmake documentation
6. configure hiawatha using cmake:
cmake -DCMAKE_TOOLCHAIN_FILE=../mipsel-openwrt-linux-uclibc.cmake -DENABLE_CACHE=off -DENABLE_IPV6=off -DENABLE_RPROXY=off -DENABLE_XSLT=off -DCMAKE_INSTALL_PREFIX= ..
options for hiawatha configuration according to needs, for example TLS can be ommited etc ...
7. You'll probably encounter problems with missing zlib.h header files and zlib.so library in toolchain library folder. You can fix it by downloading the header file and binary from the openwrt repository. The zlib.so binary can be aither downloaded from your server (it's necessary to have it there for running hiawatha binary later), or you can extract the coresponding zlib package and find the library there. The header should be put in toolchain directory under
usr/include
directory, the library in
usr/lib
under toolchain.
8. After sucesfull configuration, make the binary using
make
command
9. You can use either
make install
to include the compiled binaries in your toolchain and copy them from there, or you can manually take all the necesarry binaries (at least hiawatha binary) and copy them to your target system (using eg. scp) or make a openwrt package and install them using opkg tool
I encountered problem arounf 86% of build during hiawatha linking: [quite]Implicit definition of gzdopen() ... undefined reference to gzdopen, gzwrite ... [/quite]. It seems to me that zlib binary in default build is somewhow stripped down with some code ommited in favour of size. This can be fixed by custom build of zlib library by downloading its sources (at least in version according the one used in openwrt build):
1. Download the sources, extract them somewhere (/tmp/zlib) and cd to it
2. Run configure WITHOUT selecting toolchain compiler (some issue with shared library compilation):
./configure --shared
3. Now open generated makefile of zlib and replace all occurences of gcc compiler with the toolchain one (mipsel-openwrt-linux-uclibc-gcc)
4. Run make, check if toolchain compiler was used.
5. After compilation, zlib.so should be present in the zlib sources directory. Grab them and put it in
usr/lib
folder of your toolchain, ang header files zlib.h and zconf.h put in
usr/include
. Then run cmake (see above) again, everything should be fine then.
After fresh build of hiawatha I noticed that it simply doesn't woth and freezes, so in detached mode Ctrl+C doesn't work. The interface port was bought altough. I tracked this down to challenge module initialization. It seems that at least my router doesn't have anough entropy for
/dev/random
to generate the server secret. You can fix this by using /dev/urandom (yes, not recommended generally, but this is the only solution in that case I think) in
get_random()
function in source
challenge.c
.
I wish you good luck with your cross compilations and sorry in case that this post isn't perfectly formated
Tomas