Welcome! Log In Create A New Profile

Advanced

Cross compilation support for nginx

Daniele Salvatore Albano - Lavoro
March 01, 2011 11:40AM
Hi to all,

this is my first message here :)

I love this webserver and i'm trying to get it running on an x86
embedded system, an alix 2d13. I've built my system using crosstools-ng,
buildroot with some own patches and a really recent kernel, version 2.6.37.

My appliance need to handle a lot of http connection to serve static
pages and, while using lighttpd i got good results, i want more so i'm
trying to switch to nginx!

The main problem is that nginx uses a (really nice) hand-made configure
script (or it seems to be this at me) that natively doesn't support
cross compilation.

My objective is to let nginx to be built using a cross compiler on
linux, actually for x86/32bit.

To do this i patched the configure system to don't run features that
doesn't need to be run and to skip features that need to be run.
Values features, as types size, have been replaced using predefined
values (this could give strange problems in some cases i think, for
example for NGX_SYS_NERR).

I've done really few tests because my toolchain was compiled with uClibc
and the AIO support isn't there (well, this is weird ... i've compiled
it but it isn't there) so i'm switcing to eglibc (not much a problem).
I got nginx compiled, but i didn't test it yet: well it started on the
build machine without segfaulting (my build system uses eglibc 2.11
while i used eglibc 2.12 for the target machine so no much difference).

Modifications are done on 0.9.5 and not on git, but this stuff isn't
directly related to sources so should be ininfluent (i think). Attached
there is a preliminary test patch.

Someone can give a shot to the attached patch, please :)

I've some questions:
- i've seen that ngx_error.c need to get max error messages count, i've
workaraounded the problem manually adding it to the configure script but
it's an hack but really i didn't have any idea on how to resolve it;
- i've used NGX_PLATFORM and crossbuild to define a crossbuild setting
it to cross-linux-32, is this fine?
- mmap(MAP_ANON|MAP_SHARED) and mmap("/dev/zero", MAP_SHARED) features
can't be tested because need to run, must them be dropped or must be
enabled by default?

I've compiled it using
../configure --with-poll_module --with-file-aio --with-ipv6
--with-http_flv_module --with-http_gzip_static_module --without-pcre
--without-http_gzip_module --without-http-cache
--without-http_rewrite_module --without-http_uwsgi_module
--without-http_scgi_module
--with-cc="/home/daniele/sviluppo/wifiguide/ct-ng/toolchain/bin/i586-itechcon-linux-gnu-cc
--sysroot=/home/daniele/sviluppo/wifiguide/ct-ng/toolchain/i586-itechcon-linux-gnu/sysroot"
--with-cpp="/home/daniele/sviluppo/wifiguide/ct-ng/toolchain/bin/i586-itechcon-linux-gnu-cpp

--sysroot=/home/daniele/sviluppo/wifiguide/ct-ng/toolchain/i586-itechcon-linux-gnu/sysroot"
--with-cpu-opt="pentium" --crossbuild=cross-linux-32


Attached there are configure and make output too.


Best regards,
Daniele

--
Daniele Salvatore Albano
____________________________________________________________
|
Daniele Salvatore Albano | web site:
IT Consultant | http://www.daccii.it
Website Design and Development |
Software Engineer and Developer | e-mail:
Linux Servers SetUp And Administration | info@daccii.it
Embedded Network Solutions | d.albano@gmail.com

Ai sensi del D.Lgs. 196/2003 si precisa che le informazioni contenute in
questo messaggio sono riservate ed a uso esclusivo del destinatario.
Qualora il messaggio in parola Le fosse pervenuto per errore, La
invitiamo ad eliminarlo senza copiarlo e a non inoltrarlo a terzi,
dandocene gentilmente comunicazione. Grazie.
Pursuant to Legislative Decree No. 196/2003, you are hereby informed
that this message contains confidential information intended only for
the use of the addressee. If you are not the addressee, and have
received this message by mistake, please delete it and immediately
notify us. You may not copy or disseminate this message to anyone. Thank
you.
diff -ru nginx-0.9.5-original/auto/cc/conf nginx-0.9.5/auto/cc/conf
--- nginx-0.9.5-original/auto/cc/conf 2010-07-05 15:02:25.000000000 +0200
+++ nginx-0.9.5/auto/cc/conf 2011-03-01 12:49:11.000000000 +0100
@@ -128,7 +128,13 @@

ngx_feature="gcc builtin atomic operations"
ngx_feature_name=NGX_HAVE_GCC_ATOMIC
- ngx_feature_run=yes
+ if [[ "$NGX_PLATFORM" != cross-* ]];
+ then
+ ngx_feature_run=yes
+ else
+ ngx_feature="$ngx_feature (cross compilation, can't run)"
+ ngx_feature_run=no
+ fi
ngx_feature_incs=
ngx_feature_path=
ngx_feature_libs=
@@ -142,13 +148,18 @@
__sync_synchronize();"
. auto/feature

-
if [ "$NGX_CC_NAME" = "ccc" ]; then
echo "checking for C99 variadic macros ... disabled"
else
ngx_feature="C99 variadic macros"
ngx_feature_name="NGX_HAVE_C99_VARIADIC_MACROS"
- ngx_feature_run=yes
+ if [[ "$NGX_PLATFORM" != cross-* ]];
+ then
+ ngx_feature_run=yes
+ else
+ ngx_feature="$ngx_feature (cross compilation, can't run)"
+ ngx_feature_run=no
+ fi
ngx_feature_incs="#include <stdio.h>
#define var(dummy, ...) sprintf(__VA_ARGS__)"
ngx_feature_path=
@@ -162,7 +173,13 @@

ngx_feature="gcc variadic macros"
ngx_feature_name="NGX_HAVE_GCC_VARIADIC_MACROS"
- ngx_feature_run=yes
+ if [[ "$NGX_PLATFORM" != cross-* ]];
+ then
+ ngx_feature_run=yes
+ else
+ ngx_feature="$ngx_feature (cross compilation, can't run)"
+ ngx_feature_run=no
+ fi
ngx_feature_incs="#include <stdio.h>
#define var(dummy, args...) sprintf(args)"
ngx_feature_path=
@@ -172,7 +189,6 @@
if (buf[0] != '1') return 1"
. auto/feature

-
# ngx_feature="inline"
# ngx_feature_name=
# ngx_feature_run=no
diff -ru nginx-0.9.5-original/auto/cc/name nginx-0.9.5/auto/cc/name
--- nginx-0.9.5-original/auto/cc/name 2007-11-15 15:22:12.000000000 +0100
+++ nginx-0.9.5/auto/cc/name 2011-03-01 12:48:56.000000000 +0100
@@ -6,7 +6,7 @@

ngx_feature="C compiler"
ngx_feature_name=
- ngx_feature_run=yes
+ ngx_feature_run=no
ngx_feature_incs=
ngx_feature_path=
ngx_feature_libs=
diff -ru nginx-0.9.5-original/auto/os/conf nginx-0.9.5/auto/os/conf
--- nginx-0.9.5-original/auto/os/conf 2009-05-10 21:49:14.000000000 +0200
+++ nginx-0.9.5/auto/os/conf 2011-03-01 15:09:22.000000000 +0100
@@ -57,6 +57,10 @@
CORE_DEPS="$UNIX_DEPS $POSIX_DEPS"
CORE_SRCS="$UNIX_SRCS"
;;
+
+ cross-linux-*)
+ . auto/os/linux
+ ;;

*)
CORE_INCS="$UNIX_INCS"
diff -ru nginx-0.9.5-original/auto/os/linux nginx-0.9.5/auto/os/linux
--- nginx-0.9.5-original/auto/os/linux 2009-11-03 17:29:47.000000000 +0100
+++ nginx-0.9.5/auto/os/linux 2011-03-01 13:01:34.000000000 +0100
@@ -45,7 +45,13 @@

ngx_feature="epoll"
ngx_feature_name="NGX_HAVE_EPOLL"
-ngx_feature_run=yes
+if [[ "$NGX_PLATFORM" != cross-* ]];
+then
+ ngx_feature_run=yes
+else
+ ngx_feature="$ngx_feature (cross compilation, can't run)"
+ ngx_feature_run=no
+fi
ngx_feature_incs="#include <sys/epoll.h>"
ngx_feature_path=
ngx_feature_libs=
@@ -70,7 +76,13 @@
CC_AUX_FLAGS="$cc_aux_flags -D_GNU_SOURCE"
ngx_feature="sendfile()"
ngx_feature_name="NGX_HAVE_SENDFILE"
-ngx_feature_run=yes
+if [[ "$NGX_PLATFORM" != cross-* ]];
+then
+ ngx_feature_run=yes
+else
+ ngx_feature="$ngx_feature (cross compilation, can't run)"
+ ngx_feature_run=no
+fi
ngx_feature_incs="#include <sys/sendfile.h>
#include <errno.h>"
ngx_feature_path=
@@ -91,7 +103,13 @@
CC_AUX_FLAGS="$cc_aux_flags -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64"
ngx_feature="sendfile64()"
ngx_feature_name="NGX_HAVE_SENDFILE64"
-ngx_feature_run=yes
+if [[ "$NGX_PLATFORM" != cross-* ]];
+then
+ ngx_feature_run=yes
+else
+ ngx_feature="$ngx_feature (cross compilation, can't run)"
+ ngx_feature_run=no
+fi
ngx_feature_incs="#include <sys/sendfile.h>
#include <errno.h>"
ngx_feature_path=
@@ -109,7 +127,13 @@

ngx_feature="prctl(PR_SET_DUMPABLE)"
ngx_feature_name="NGX_HAVE_PR_SET_DUMPABLE"
-ngx_feature_run=yes
+if [[ "$NGX_PLATFORM" != cross-* ]];
+then
+ ngx_feature_run=yes
+else
+ ngx_feature="$ngx_feature (cross compilation, can't run)"
+ ngx_feature_run=no
+fi
ngx_feature_incs="#include <sys/prctl.h>"
ngx_feature_path=
ngx_feature_libs=
diff -ru nginx-0.9.5-original/auto/types/sizeof nginx-0.9.5/auto/types/sizeof
--- nginx-0.9.5-original/auto/types/sizeof 2006-06-28 18:00:26.000000000 +0200
+++ nginx-0.9.5/auto/types/sizeof 2011-03-01 13:20:43.000000000 +0100
@@ -13,7 +13,9 @@

ngx_size=

-cat << END > $NGX_AUTOTEST.c
+if [[ "$NGX_PLATFORM" != cross-* ]];
+then
+ cat << END > $NGX_AUTOTEST.c

#include <sys/types.h>
#include <sys/time.h>
@@ -31,21 +33,47 @@
END


-ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
- -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
+ ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
+ -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"

-eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"
+ eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"


-if [ -x $NGX_AUTOTEST ]; then
- ngx_size=`$NGX_AUTOTEST`
- echo " $ngx_size bytes"
+ if [ -x $NGX_AUTOTEST ]; then
+ ngx_size=`$NGX_AUTOTEST`
+ echo " $ngx_size bytes"
+ fi
+
+
+ rm -f $NGX_AUTOTEST
+else
+
+ if [[ "$NGX_PLATFORM" == cross-*-32 ]];
+ then
+ case "$ngx_type" in
+ "int") ngx_size=4 ;;
+ "long") ngx_size=4 ;;
+ "long long") ngx_size=8 ;;
+ "void *") ngx_size=4 ;;
+
+ "size_t") ngx_size=4 ;;
+ "off_t") ngx_size=4 ;;
+ "time_t") ngx_size=4 ;;
+
+ "sig_atomic_t") ngx_size=4 ;;
+ "socklen_t") ngx_size=4 ;;
+ "in_addr_t") ngx_size=4 ;;
+ "in_port_t") ngx_size=2 ;;
+ "rlim_t") ngx_size=4 ;;
+ esac
+ elif [[ "$NGX_PLATFORM" == cross-*-64 ]];
+ then
+ echo "Cross compiling to 64 bit not supported, failing test"
+ ngx_size=0
+ fi
fi


-rm -f $NGX_AUTOTEST
-
-
case $ngx_size in
4)
if [ "$ngx_type"="long" ]; then
diff -ru nginx-0.9.5-original/auto/unix nginx-0.9.5/auto/unix
--- nginx-0.9.5-original/auto/unix 2010-12-06 15:51:20.000000000 +0100
+++ nginx-0.9.5/auto/unix 2011-03-01 15:23:05.000000000 +0100
@@ -108,54 +108,65 @@
ngx_feature_test="char buf[1]; ssize_t n; n = pwrite(1, buf, 1, 0)"
. auto/feature

-
-ngx_feature="sys_nerr"
-ngx_feature_name="NGX_SYS_NERR"
-ngx_feature_run=value
-ngx_feature_incs='#include <stdio.h>'
-ngx_feature_path=
-ngx_feature_libs=
-ngx_feature_test='printf("%d", sys_nerr);'
-. auto/feature
-
-
-if [ $ngx_found = no ]; then
-
- # Cygiwn defines _sys_nerr
- ngx_feature="_sys_nerr"
- ngx_feature_name="NGX_SYS_NERR"
- ngx_feature_run=value
- ngx_feature_incs='#include <errno.h>
- #include <stdio.h>'
- ngx_feature_path=
- ngx_feature_libs=
- ngx_feature_test='printf("%d", _sys_nerr);'
- . auto/feature
-fi
-
-
-if [ $ngx_found = no ]; then
-
- # Solaris has no sys_nerr
- ngx_feature='maximum errno'
- ngx_feature_name=NGX_SYS_NERR
- ngx_feature_run=value
- ngx_feature_incs='#include <errno.h>
- #include <stdio.h>'
- ngx_feature_path=
- ngx_feature_libs=
- ngx_feature_test='int n;
- for (n = 1; n < 1000; n++) {
- errno = 0;
- strerror(n);
- if (errno == EINVAL) {
- printf("%d", n);
- return 0;
- }
- }'
- . auto/feature
-fi
-
+case "$NGX_PLATFORM" in
+ cross-linux-*)
+ cat << END >> $NGX_AUTO_CONFIG_H
+
+#ifndef NGX_SYS_NERR
+#define NGX_SYS_NERR 132
+#endif
+
+END
+ ;;
+
+ *)
+ ngx_feature="sys_nerr"
+ ngx_feature_name="NGX_SYS_NERR"
+ ngx_feature_run=value
+ ngx_feature_incs='#include <stdio.h>'
+ ngx_feature_path=
+ ngx_feature_libs=
+ ngx_feature_test='printf("%d", sys_nerr);'
+ . auto/feature
+
+
+ if [ $ngx_found = no ];
+ then
+ # Cygiwn defines _sys_nerr
+ ngx_feature="_sys_nerr"
+ ngx_feature_name="NGX_SYS_NERR"
+ ngx_feature_run=value
+ ngx_feature_incs='#include <errno.h>
+ #include <stdio.h>'
+ ngx_feature_path=
+ ngx_feature_libs=
+ ngx_feature_test='printf("%d", _sys_nerr);'
+ . auto/feature
+ fi
+
+ if [ $ngx_found = no ]; then
+
+ # Solaris has no sys_nerr
+ ngx_feature='maximum errno'
+ ngx_feature_name=NGX_SYS_NERR
+ ngx_feature_run=value
+ ngx_feature_incs='#include <errno.h>
+ #include <stdio.h>'
+ ngx_feature_path=
+ ngx_feature_libs=
+ ngx_feature_test='int n;
+ for (n = 1; n < 1000; n++) {
+ errno = 0;
+ strerror(n);
+ if (errno == EINVAL) {
+ printf("%d", n);
+ return 0;
+ }
+ }'
+ . auto/feature
+ fi
+ ;;
+esac

ngx_feature="localtime_r()"
ngx_feature_name="NGX_HAVE_LOCALTIME_R"
@@ -189,7 +200,13 @@

ngx_feature="mmap(MAP_ANON|MAP_SHARED)"
ngx_feature_name="NGX_HAVE_MAP_ANON"
-ngx_feature_run=yes
+if [[ "$NGX_PLATFORM" != cross-* ]];
+then
+ ngx_feature_run=yes
+else
+ ngx_feature="$ngx_feature (cross compilation, can't run)"
+ ngx_feature_run=no
+fi
ngx_feature_incs="#include <sys/mman.h>"
ngx_feature_path=
ngx_feature_libs=
@@ -199,10 +216,15 @@
if (p == MAP_FAILED) return 1;"
. auto/feature

-
ngx_feature='mmap("/dev/zero", MAP_SHARED)'
ngx_feature_name="NGX_HAVE_MAP_DEVZERO"
-ngx_feature_run=yes
+if [[ "$NGX_PLATFORM" != cross-* ]];
+then
+ ngx_feature_run=yes
+else
+ ngx_feature="$ngx_feature (cross compilation, can't run)"
+ ngx_feature_run=no
+fi
ngx_feature_incs="#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>"
@@ -214,10 +236,15 @@
if (p == MAP_FAILED) return 1;'
. auto/feature

-
ngx_feature="System V shared memory"
ngx_feature_name="NGX_HAVE_SYSVSHM"
-ngx_feature_run=yes
+if [[ "$NGX_PLATFORM" != cross-* ]];
+then
+ ngx_feature_run=yes
+else
+ ngx_feature="$ngx_feature (cross compilation, can't run)"
+ ngx_feature_run=no
+fi
ngx_feature_incs="#include <sys/ipc.h>
#include <sys/shm.h>"
ngx_feature_path=
building for cross-linux-32
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.5.2 (itechcon.it-wifiguide-alix2d13-20110225)
checking for gcc -pipe switch ...m found
checking for gcc builtin atomic operations (cross compilation, can't run) ...a found
checking for C99 variadic macros (cross compilation, can't run) ... found
kchecking for gcc variadic macros (cross compilation, can't run) ...e found
checking for unistd.h ... found
checking for inttypes.h ...
found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for cross-linux-32 specific features
checking for epoll (cross compilation, can't run) ... found
checking for sendfile() (cross compilation, can't run) ... found
checking for sendfile64() (cross compilation, can't run) ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) (cross compilation, can't run) ... found
checking for sched_setaffinity() ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for nobody group ... not found
checking for nogroup group ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for SO_SETFIB ... not found
checking for accept4() ... found
checking for kqueue AIO support ... not found
checking for Linux AIO support ... found
creating objs/Makefile
checking for int size ...checking for long size ...checking for long long size ...checking for void * size ...checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ...checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system endianess ... little endianess
checking for size_t size ...checking for off_t size ...checking for time_t size ...checking for AF_INET6 ... found
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for localtime_r() ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) (cross compilation, can't run) ... found
checking for mmap("/dev/zero", MAP_SHARED) (cross compilation, can't run) ... found
checking for System V shared memory (cross compilation, can't run) ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found

Configuration summary
+ PCRE library is disabled
+ OpenSSL library is not used
+ md5 library is not used
+ sha1 library is not used
+ zlib library is not used

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
make -f objs/Makefile
make[1]: ingresso nella directory _______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Cross compilation support for nginx

Daniele Salvatore Albano - Lavoro 2905 March 01, 2011 11:40AM

Re: Cross compilation support for nginx

Daniele Salvatore Albano - Lavoro 1149 March 01, 2011 11:54AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 89
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready