nginx源代碼對於交叉編譯環境來講是不太友好的,必須得本身改動編譯腳本,並且還經常不止一兩處須要修改.html
幸虧,通過研究編譯腳本和反覆試驗,仍是有辦法作到一鍵編譯的,從原始代碼到目標文件,一鼓作氣.linux
我所使用的源代碼信息爲,nginx
源碼版本: 1.14.0 源碼地址: http://nginx.org/download/nginx-1.14.0.tar.gz 發佈日期: 2018.04.17
在此源代碼上,打一個patch文件. 不瞭解如何使用patch,請自行百度,或者看一下,https://www.cnblogs.com/daemony/p/9569951.htmlui
diff -aNru a/auto/cc/name b/auto/cc/name --- a/auto/cc/name 2018-04-17 23:22:36.000000000 +0800 +++ b/auto/cc/name 2018-09-08 12:46:38.316454500 +0800 @@ -7,7 +7,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 -aNru a/auto/feature b/auto/feature --- a/auto/feature 2018-04-17 23:22:36.000000000 +0800 +++ b/auto/feature 2018-09-08 12:05:13.969148700 +0800 @@ -99,6 +99,16 @@ fi ;; + define) + echo " found" + ngx_found=yes + + if test -n "$ngx_feature_name"; then + have=$ngx_have_feature value=$ngx_feature_value . auto/define + fi + ngx_feature_value=0 + ;; + *) echo " found" ngx_found=yes diff -aNru a/auto/make b/auto/make --- a/auto/make 2018-04-17 23:22:36.000000000 +0800 +++ b/auto/make 2018-09-08 12:33:43.271796200 +0800 @@ -214,6 +214,10 @@ ngx_libs=`echo $NGX_LD_OPT $CORE_LIBS \ | sed -e "s/\//$ngx_regex_dirsep/g" -e "s/^/$ngx_long_regex_cont/"` fi +ngx_libs+=" ${OUT_PATH}/lib/libpcre.a" +ngx_libs+=" ${OUT_PATH}/lib/libssl.a" +ngx_libs+=" ${OUT_PATH}/lib/libcrypto.a" +ngx_libs+=" ${OUT_PATH}/lib/libz.a" ngx_link=${CORE_LINK:+`echo $CORE_LINK \ | sed -e "s/\//$ngx_regex_dirsep/g" -e "s/^/$ngx_long_regex_cont/"`} diff -aNru a/auto/os/linux b/auto/os/linux --- a/auto/os/linux 2018-04-17 23:22:36.000000000 +0800 +++ b/auto/os/linux 2018-09-08 11:59:18.547337600 +0800 @@ -36,7 +36,7 @@ ngx_feature="epoll" ngx_feature_name="NGX_HAVE_EPOLL" -ngx_feature_run=yes +ngx_feature_run=no ngx_feature_incs="#include <sys/epoll.h>" ngx_feature_path= ngx_feature_libs= diff -aNru a/auto/types/sizeof b/auto/types/sizeof --- a/auto/types/sizeof 2018-04-17 23:22:36.000000000 +0800 +++ b/auto/types/sizeof 2018-09-08 12:46:38.320454400 +0800 @@ -40,7 +40,7 @@ if [ -x $NGX_AUTOTEST ]; then - ngx_size=`$NGX_AUTOTEST` + ngx_size=4; echo " $ngx_size bytes" fi diff -aNru a/auto/unix b/auto/unix --- a/auto/unix 2018-04-17 23:22:36.000000000 +0800 +++ b/auto/unix 2018-09-08 12:04:25.474669400 +0800 @@ -729,12 +729,13 @@ ngx_feature="sys_nerr" ngx_feature_name="NGX_SYS_NERR" -ngx_feature_run=value +ngx_feature_run=define +ngx_feature_value=132 ngx_feature_incs='#include <errno.h> #include <stdio.h>' ngx_feature_path= ngx_feature_libs= -ngx_feature_test='printf("%d", sys_nerr);' +ngx_feature_test="printf(\"%d\", $ngx_feature_value);" . auto/feature @@ -868,7 +869,7 @@ ngx_feature="System V shared memory" ngx_feature_name="NGX_HAVE_SYSVSHM" -ngx_feature_run=yes +ngx_feature_run=have ngx_feature_incs="#include <sys/ipc.h> #include <sys/shm.h>" ngx_feature_path= diff -aNru a/configure b/configure --- a/configure 2018-04-17 23:22:36.000000000 +0800 +++ b/configure 2018-09-08 12:29:03.726481400 +0800 @@ -60,7 +60,12 @@ . auto/threads . auto/modules -. auto/lib/conf +#. auto/lib/conf +CORE_INCS+=" ${OUT_PATH}/inc" +have=NGX_PCRE value="1" . auto/define +have=NGX_OPENSSL value="1" . auto/define +have=NGX_SSL value="1" . auto/define +have=NGX_ZLIB value="1" . auto/define case ".$NGX_PREFIX" in .) @@ -100,7 +105,7 @@ . auto/define . auto/make -. auto/lib/make +#. auto/lib/make . auto/install # STUB
這個patch文件就是在一鍵編譯的Makefile中使用,其主要內容爲spa
1 #這兩個變量請自定義.個人實際應用已經在前面include Makefile.pre.mak中定義. 2 COMPILER_PREFIX:=xxx_my_compiler 3 OUT_PATH:=xxx_my_outpath 4 5 ARCHIVE_FILE:=nginx-1.14.0.tar.gz 6 WORKING_PATH:=nginx-1.14.0 7 8 build:build_full 9 10 build_full: compile_full finish_full 11 build_mini:compile_mini finish_mini 12 13 distclean: 14 -rm -rf ${WORKING_PATH}; 15 clean: 16 make -C ${WORKING_PATH} clean; 17 18 openup: 19 @[ -e ${WORKING_PATH} ] || (tar -xzf ${ARCHIVE_FILE}); 20 21 config_full: openup 22 @[ -f ${WORKING_PATH}/Makefile ] || \ 23 (cd ${WORKING_PATH} && patch -p1 <../nginx-1.14.0-full.patch && \ 24 OUT_PATH=${OUT_PATH} ./configure --with-openssl=${OUT_PATH} --with-pcre=${OUT_PATH} --with-zlib=${OUT_PATH} \ 25 --http-proxy-temp-path=/tmp/var/nginx \ 26 --error-log-path=/tmp/var/nginx \ 27 --without-select_module --with-http_ssl_module \ 28 --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module \ 29 --without-http_upstream_hash_module --without-http_upstream_ip_hash_module --without-http_upstream_least_conn_module --without-http_upstream_zone_module \ 30 --without-http_ssi_module --without-http_userid_module --without-http_autoindex_module --without-http_geo_module --without-http_uwsgi_module --without-http_scgi_module --without-http_empty_gif_module --without-http_browser_module \ 31 --without-stream_limit_conn_module --without-stream_access_module --without-stream_upstream_hash_module --without-stream_upstream_least_conn_module --without-stream_upstream_zone_module \ 32 --with-cc=${COMPILER_PREFIX}gcc --with-cpp=${COMPILER_PREFIX}g++;) 33 34 config_mini: openup 35 @[ -f ${WORKING_PATH}/Makefile ] || \ 36 (cd ${WORKING_PATH} && patch -p1 <../nginx-1.14.0-full.patch && \ 37 OUT_PATH=${OUT_PATH} ./configure --with-openssl=${OUT_PATH} --with-pcre=${OUT_PATH} --with-zlib=${OUT_PATH} \ 38 --without-http_proxy_module \ 39 --http-proxy-temp-path=/tmp/var/nginx \ 40 --error-log-path=/tmp/var/nginx \ 41 --without-select_module \ 42 --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module \ 43 --without-http_upstream_hash_module --without-http_upstream_ip_hash_module --without-http_upstream_least_conn_module --without-http_upstream_zone_module \ 44 --without-http_ssi_module --without-http_userid_module --without-http_autoindex_module --without-http_geo_module --without-http_uwsgi_module --without-http_scgi_module --without-http_empty_gif_module --without-http_browser_module \ 45 --without-stream_limit_conn_module --without-stream_access_module --without-stream_upstream_hash_module --without-stream_upstream_least_conn_module --without-stream_upstream_zone_module \ 46 --with-cc=${COMPILER_PREFIX}gcc --with-cpp=${COMPILER_PREFIX}g++; \ 47 sed -i -e "s/\/\.openssl\/include//g" \ 48 -e "s/inc\/.libs\/libpcre.a/lib\/libpcre.a/g" \ 49 -e "s/inc\/.libs\/libz.a/lib\/libz.a/g" \ 50 -e "s/inc\/.openssl\/lib\/libssl.a/lib\/libssl.a/g" \ 51 objs/Makefile;) 52 53 compile_full: config_full 54 make -C ${WORKING_PATH}; 55 compile_mini: config_mini 56 make -C ${WORKING_PATH}; 57 58 finish_full: 59 ifeq (${STRIPED},n) 60 @mkdir -p ${OUT_PATH}/bin; find ${WORKING_PATH} -name "nginx" -exec cp -p {} ${OUT_PATH}/bin \; -exec echo -e "${GREEN}cp -p {} ${OUT_PATH}/bin${NORMAL}" \; 61 else 62 @mkdir -p ${OUT_PATH}/bin; find ${WORKING_PATH} -name "nginx" -exec ${STRIP} -p {} \; -exec cp -p {} ${OUT_PATH}/bin \; -exec echo -e "${GREEN}cp -p {} ${OUT_PATH}/bin${NORMAL}" \; 63 endif 64 65 finish_mini: 66 ifeq (${STRIPED},n) 67 @mkdir -p ${OUT_PATH}/bin; find ${WORKING_PATH} -name "nginx" -exec cp -p {} ${OUT_PATH}/bin \; -exec echo -e "${GREEN}cp -p {} ${OUT_PATH}/bin/nginx_mini${NORMAL}" \; 68 else 69 @mkdir -p ${OUT_PATH}/bin; find ${WORKING_PATH} -name "nginx" -exec ${STRIP} -p {} \; -exec cp -p {} ${OUT_PATH}/bin \; -exec echo -e "${GREEN}cp -p {} ${OUT_PATH}/bin/nginx_mini${NORMAL}" \; 70 endif
剩下內容,我的按本身須要完善Makefile吧.unix