Cross compiling thttpd-2.21b + php-5.2.1: Howto

Written by Dennis on Thursday 23/08/07


Download source code


thttpd

php


Decompress files



$ cd ~/packages/php/
$ tar xjvf php-5.2.1.tar.bz2
$ cd ~/packages/thttpd/
$ tar xzvf thttpd-2.21b.tar.gz


Configure and compile PHP making it aware of thttpd



$ cd ~/packages/php/php-5.2.1/
$ mkdir install-arm
$ export CC=/usr/arm/bin/arm-linux-gcc
$ export CXX=/usr/arm/bin/arm-linux-cpp
$ ./configure --host=i386-linux-gnu --target=arm --prefix=install-arm \\\\
--disable-short-tags --without-mysql \\\\
--without-pear --disable-all --disable-short-tags \\\\
--with-thttpd=../../thttpd/thttpd-2.21b
$ make
$ make install


Success!



Build complete.
(It is safe to ignore warnings about tempnam and tmpnam).

dennis@dens-linux:~/packages/php/php-5.2.1$ make install
Installing PHP SAPI module: thttpd
patching file Makefile.in
patching file config.h
patching file configure
patching file configure.in
patching file fdwatch.c
patching file libhttpd.c
patching file libhttpd.h
patching file mime_encodings.txt
patching file mime_types.txt
patching file mmc.c
patching file mmc.h
patching file thttpd.c
patching file version.h
Installing PHP CLI binary: install-arm/bin/
Installing PHP CLI man page: install-arm/man/man1/
Installing build environment: install-arm/lib/php/build/
Installing header files: install-arm/include/php/
Installing helper programs: install-arm/bin/
program: phpize
program: php-config
Installing man pages: install-arm/man/man1/
page: phpize.1
page: php-config.1


Configure and Compile thttpd



$ export CC=/usr/arm/bin/arm-linux-gcc
$ export CXX=/usr/arm/bin/arm-linux-cpp
$
export CPP=/usr/arm/bin/arm-linux-cpp
$ ./configure --host=i386-linux-gnu --target=arm --prefix=install-arm
$ make


thttpd's make install doesn't seem to work for me... looks like I need to manually create the install directories inside install-arm... Anyway, after running make thttpd should be in the current directory already.


Build php with simpleXML and DOM support



$ ./configure --host=i386-linux-gnu --target=arm --prefix=install-arm \\\\
--disable-short-tags \\\\
--without-mysql --without-pear --disable-all --disable-short-tags \\\\
--with-thttpd=../../thttpd/thttpd-2.21b --enable-simplexml --enable-dom --enable-libxml


Then, there's this error during configure:



Configuring extensions
checking whether to enable LIBXML support... yes
checking libxml2 install dir... no
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.


So I downloaded libxml2 source code from: http://ftp.debian.org/debian/pool/main/libx/libxml2/libxml2_2.6.16.orig.tar.gz


Configure and compile just as usual: (Take note that --prefix needs an absolute path.)



$ export CC=/usr/arm/bin/arm-linux-gcc
$ export CXX=/usr/arm/bin/arm-linux-cpp
$ export CPP=/usr/arm/bin/arm-linux-cpp
$ ./configure --host=i386-linux-gnu --target=arm --prefix=$PWD/install-arm
$ make


Then re-configure php telling it where to find the libxml2 files.



$ ./configure --host=i386-linux-gnu --target=arm --prefix=install-arm \\\\
--disable-short-tags \\\\
--without-mysql --without-pear --disable-all --disable-short-tags \\\\
--with-thttpd=../thttpd-2.21b \\\\
--enable-simplexml --enable-dom --enable-libxml \\\\
--with-libxml-dir=/home/dennis/packages/php/libxml2-2.6.16/install-arm


Creating smaller binaries


And then change the main php Makefile to create stripped binaries.



EXTRA_LDFLAGS = -rdynamic -L/home/dennis/packages/php/libxml2-2.6.16/install-arm/lib -s


Try compiling php again.



$ make
$ make install


Okay, we need all binaries to be sripped to save space. Re-compile libxml2 setting the LDFLAG as follows: (we also need to stamp the resulting ELF file with the library path /lib)



LDFLAGS = -s -Xlinker -rpath /lib -Xlinker -rpath-link /usr/arm/arm-linux/lib


Hmmm... still the resulting binary file is not stripped... Ah! There's actually a Makefile rule install-strip; we just have to change STRIP to use arm-linux-strip.



STRIP = /usr/arm/bin/arm-linux-strip


Reconfigure php with LDFLAGS set:



$ export LDFLAGS="-s -Xlinker -rpath /lib -Xlinker -rpath-link /usr/arm/arm-linux/lib"
$ ./configure --host=i386-linux-gnu --target=arm --prefix=install-arm --disable-short-tags \\\\
--without-mysql --without-pear --disable-all --disable-short-tags --with-thttpd=../thttpd-2.21b \\\\
--enable-simplexml --enable-dom --enable-libxml \\\\
--with-libxml-dir=/home/dennis/packages/php/libxml2-2.6.16/install-arm


Installing on the target machine


Finally, on the target machine, we need to put the libxml library and the appropriate soft links in /lib since this is needed by thttpd.



libxml2.so -> libxml2.so.2.6.16
libxml2.so.2 -> libxml2.so.2.6.16


thttpd binary can go to /usr/bin or /bin or anywhere you like. You can configure it at runtime by passing a configuration file to it.



/usr/sbin/thttpd -C /var/www/thttpd.conf


Sample thttpd.conf



# Configuration file for thttpd
port=80
dir=/usr/sbin/
logfile=/var/log/thttpd.log


Compile script


Here's a little script to re-create thttpd with php and xml support. For this to work properly, the following directories must be on the same level:



libxml2-2.6.16/
php-5.2.1/
thttpd-2.21b/


compile.sh



#!/bin/sh

echo -e "\\\\r[$0] Setup compile environment...\\\\r"
export CC=/usr/arm/bin/arm-linux-gcc
export CXX=/usr/arm/bin/arm-linux-cpp
export CPP=/usr/arm/bin/arm-linux-cpp
export LDFLAGS="-s -Xlinker -rpath /lib -Xlinker -rpath-link /usr/arm/arm-linux/lib"

case $1 in
"libxml")
echo -e "\\\\r[$0] Configure and compile libxml-2-2.6.16...\\\\r"
cd libxml2-2.6.16/
rm -f config.cache
make distclean
make clean
./configure --host=i386-linux-gnu --target=arm --prefix=$PWD/install-arm
make
make install
;;

"php")
echo -e "\\\\r[$0] Configure and compile php...\\\\r"
cd php-5.2.1/
rm -f config.cache
make distclean
make clean
./configure --host=i386-linux-gnu --target=arm --prefix=install-arm --disable-short-tags --without-mysql \\\\
--without-pear --disable-all --disable-short-tags --with-thttpd=../thttpd-2.21b/ \\\\
--enable-simplexml --enable-session --enable-libxml -with-libxml-dir=../libxml2-2.6.16/install-arm
make
make install
;;

"thttpd")
echo -e "\\\\r[$0] Configure and compile thttpd...\\\\r"
cd thttpd-2.21b/
rm -f config.cache
make distclean
make clean
./configure --host=i386-linux-gnu --target=arm --prefix=install-arm
make
make install
;;

"")
echo -e "USAGE: ./compile.sh