Compile Programs on your PC (cross compiling)
From NAS-2000.org
There are several ways how to cross compile software on your machine. Here is a collection of howtos:
- http://people.debian.org/~debacle/cross/ (Cross compiling on a debian based host system)
- http://www.scratchbox.org/ (Cros compiling with scratchbox)
- http://gentoo-wiki.com/HOWTO_Cross_Compile (Cross compiling on a gentoo based host system)
[edit] Compiling programs for your NAS-1000/2000
We are about to create a HowTo for cross compiling especially for the nas-1000/2000. Here is a rough start:
OK here is a very short version ... :)
get the source.rar and kernel.rar from the raidsonic site. (NAS1000 or NAS 2000 sources???)
Unpack the source.rar and cd to chroot there unpack all the dirs. Make sure the 920xxx is the last you extract.
tar -xvzf zoneinfo.tgz for example...
now create a dir called source and copy all the files which are at the same level as chroot(kernel, kernelbase directory) to the source-dir.
Also some programs need the kernel sources unpacked in the source/kernel directory, specifically programs that need access to the linux kernel headers.
go back to the chroot level and run
chroot . /bin/bash
Hint: the developers tried to clean up but there are still some infos in the /root/.bash_history :-)
Now you can start compiling programs with arm_920t_le-gcc compiler. To test if everthing works like expected write and compile a hello-world-program and run it on your icybox.
But what if when I need to compile a program with the ./configure make commands?
Create a script that you exec after you enter the chroot enviroment.
This works for some programs, however some of the newer GNU stuff for instance needs further methods below.
#!/bin/bash
export LINUX="/usr/local/arm-linux-toolchain/armv4tl-hardhat-linux/include"
export CROSS=arm_920t_le
export CROSS_PREFIX=$CROSS
export CC=$CROSS_PREFIX-gcc
export CPP=$CROSS_PREFIX-g++
export AS=$CROSS_PREFIX-as
export AR=$CROSS_PREFIX-ar
export NM=$CROSS_PREFIX-nm
export RANLIB=$CROSS_PREFIX-ranlib
export STRIP=$CROSS_PREFIX-strip
export GCC=$CROSS_PREFIX-gcc
export LD=$CROSS_PREFIX-ld
export LDD=$CROSS_PREFIX-ldd
#export CXX="/usr/local/arm-linux-toolchain/bin/arm_920t_le-g++"
#export STRIP="/usr/local/arm-linux-toolchain/bin/arm_920t_le-strip"
#export RANLIB="/usr/local/arm-linux-toolchain/bin/arm_920t_le-ranlib"
export
LDFLAGS="-I/usr/local/arm-linux-toolchain/armv4tl-hardhat-linux/include \
-Wl --gc-sections"
export CFLAGS="-I$LINUX -ffunction-sections -fdata-sections"
Further Methods (1).
The above method does not work for some of the newer gnu compile scripts, for these you need to do the following :-
add the following to the root .bashrc (within the chrooted environment) :
PATH=$PATH:/usr/local/arm-linux-toolchain/bin
This is so that configure can find the cross-compiler that has the standard format naming.
once this is done configure can be ran as follows :
./configure --build=i686-pc-linux-gnu --host=armv4tl-hardhat-linux
This tells configure that you are building on a linux pc and compiling for the arm/linux system. Note some programs also need additional options passed to configure, you should always read the installation instructions that come with the package that you are installing, you may need to experement to get the correct options.
Once your packages is compiled, you may want to create a tempory directory to install it into, so that you can then tar it up and transfer it to the NAS more easily, this can often be done by passing the DESTDIR variable when doing a make install e.g.
make install DESTDIR=`pwd`/NASBin
This will create an install tree under NASBin, you can then cd to NASBin, and tar the package up, and then transfer it to the nasbox, and untar it in the root dir.
Further Methods (2).
Some packages don't come with a configure script, and you will have to edit the Makefile by hand, or over-ride defaults, to say specify the compiler to use, e.g. something like :-
make CC=armv4tl-hardhat-linux-gcc
[edit] Things usefull to build/import into your chrooted environment
The following make building packages within the chrooted environment much easier to use without having to switch backwards and forwards between chrooted and non chrooted.
1) A text editor, this can either be pre-built or built from source, note that if building form source you should not have to use any --build and --host, as you will be running it on the same environment that you are building on.
2) An ssh/scp client, it is reasonably easy to build dropbear for this purpose, and makes transfering compiled packages to your nas much easier.