Created
June 6, 2014 02:07
-
-
Save allex/95a1f5a61bd73db1bf9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Copyright (C) 2010-2013 Alibaba Group Holding Limited | |
ngx_soext='.so' | |
CC=cc | |
CFLAGS=' -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -DNDK_SET_VAR -fPIC' | |
CPP='cc -E' | |
LINK='$(CC) -rdynamic -fPIC -shared ' | |
NGX_INCLUDE_PATH=/home/work/nginx/include | |
CORE_LIBS='-Wl,-E -lpthread -ldl -lcrypt -L/usr/local/lib -lluajit-5.1 -lm ../pcre-8.32/.libs/libpcre.a -lssl -lcrypto -ldl -lz' | |
CORE_LINK='' | |
NGX_LD_OPT='' | |
NGX_PREFIX=/home/work/nginx | |
NGX_RPATH=NO | |
ngx_regex_dirsep='\/' | |
ngx_cont=' \ | |
' | |
ngx_cc='$(CC) -c $(CFLAGS) $(CORE_INCS) $(HTTP_INCS)' | |
ngx_tab=' \ | |
' | |
ngx_objout='-o ' | |
NGX_AUX='' | |
ngx_long_regex_cont=' \\\ | |
' | |
ngx_dirsep='/' | |
ngx_binext='' | |
ngx_long_start='' | |
ngx_long_cont=' \ | |
' | |
ngx_rcc='' | |
ngx_spacer=' | |
' | |
ngx_objext='o' | |
ngx_regex_cont=' \\\ | |
' | |
ngx_include_opt='-I ' | |
ngx_binout='-o ' | |
NGX_DSO_PATH=modules/ | |
NGX_AUTOCONF_ERR=autoconf.err | |
NGX_AUTOTEST=autotest | |
NGX_AUTO_CONFIG_H='objs/ngx_shared_config.h' | |
NGX_CONFIGURE=" --prefix=/home/work/nginx --with-http_spdy_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_upstream_session_sticky_module=shared --with-http_upstream_session_sticky_module=shared --with-http_sub_module --with-pcre=../pcre-8.32 --with-pcre-jit --add-module=../lua-nginx-module --add-module=./src/nginx-upstream-fair --add-module=./src/headers-more-nginx-module --add-module=./src/ngx_cache_purge --add-module=./src/ngx_devel_kit" | |
ngx_feature_file=' | |
# Copyright (C) Igor Sysoev | |
# Copyright (C) Nginx, Inc. | |
echo $ngx_n "checking for $ngx_feature ...$ngx_c" | |
cat << END >> $NGX_AUTOCONF_ERR | |
---------------------------------------- | |
checking for $ngx_feature | |
END | |
ngx_found=no | |
if test -n "$ngx_feature_name"; then | |
ngx_have_feature=`echo $ngx_feature_name \ | |
| tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ` | |
fi | |
if test -n "$ngx_feature_path"; then | |
for ngx_temp in $ngx_feature_path; do | |
ngx_feature_inc_path="$ngx_feature_inc_path -I $ngx_temp" | |
done | |
fi | |
cat << END > $NGX_AUTOTEST.c | |
#include <sys/types.h> | |
$NGX_INCLUDE_UNISTD_H | |
$ngx_feature_incs | |
int main() { | |
$ngx_feature_test; | |
return 0; | |
} | |
END | |
ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS $ngx_feature_inc_path \ | |
-o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_TEST_LD_OPT $ngx_feature_libs" | |
ngx_feature_inc_path= | |
eval "/bin/sh -c \"$ngx_test\" >> $NGX_AUTOCONF_ERR 2>&1" | |
if [ -x $NGX_AUTOTEST ]; then | |
case "$ngx_feature_run" in | |
yes) | |
# /bin/sh is used to intercept "Killed" or "Abort trap" messages | |
if /bin/sh -c $NGX_AUTOTEST >> $NGX_AUTOCONF_ERR 2>&1; then | |
echo " found" | |
ngx_found=yes | |
if test -n "$ngx_feature_name"; then | |
have=$ngx_have_feature . auto/have | |
fi | |
else | |
echo " found but is not working" | |
fi | |
;; | |
value) | |
# /bin/sh is used to intercept "Killed" or "Abort trap" messages | |
if /bin/sh -c $NGX_AUTOTEST >> $NGX_AUTOCONF_ERR 2>&1; then | |
echo " found" | |
ngx_found=yes | |
cat << END >> $NGX_AUTO_CONFIG_H | |
#ifndef $ngx_feature_name | |
#define $ngx_feature_name `$NGX_AUTOTEST` | |
#endif | |
END | |
else | |
echo " found but is not working" | |
fi | |
;; | |
bug) | |
# /bin/sh is used to intercept "Killed" or "Abort trap" messages | |
if /bin/sh -c $NGX_AUTOTEST >> $NGX_AUTOCONF_ERR 2>&1; then | |
echo " not found" | |
else | |
echo " found" | |
ngx_found=yes | |
if test -n "$ngx_feature_name"; then | |
have=$ngx_have_feature . auto/have | |
fi | |
fi | |
;; | |
*) | |
echo " found" | |
ngx_found=yes | |
if test -n "$ngx_feature_name"; then | |
have=$ngx_have_feature . auto/have | |
fi | |
;; | |
esac | |
else | |
echo " not found" | |
echo "----------" >> $NGX_AUTOCONF_ERR | |
cat $NGX_AUTOTEST.c >> $NGX_AUTOCONF_ERR | |
echo "----------" >> $NGX_AUTOCONF_ERR | |
echo $ngx_test >> $NGX_AUTOCONF_ERR | |
echo "----------" >> $NGX_AUTOCONF_ERR | |
fi | |
rm $NGX_AUTOTEST*' | |
ngx_have_file=' | |
# Copyright (C) Igor Sysoev | |
# Copyright (C) Nginx, Inc. | |
cat << END >> $NGX_AUTO_CONFIG_H | |
#ifndef $have | |
#define $have 1 | |
#endif | |
END' | |
DSO_CORE_DEPS=' /home/work/nginx/include/nginx.h /home/work/nginx/include/ /home/work/nginx/include/ngx_config.h /home/work/nginx/include/ /home/work/nginx/include/ngx_core.h /home/work/nginx/include/ /home/work/nginx/include/ngx_log.h /home/work/nginx/include/ /home/work/nginx/include/ngx_palloc.h /home/work/nginx/include/ /home/work/nginx/include/ngx_array.h /home/work/nginx/include/ /home/work/nginx/include/ngx_list.h /home/work/nginx/include/ /home/work/nginx/include/ngx_hash.h /home/work/nginx/include/ /home/work/nginx/include/ngx_buf.h /home/work/nginx/include/ /home/work/nginx/include/ngx_queue.h /home/work/nginx/include/ /home/work/nginx/include/ngx_string.h /home/work/nginx/include/ /home/work/nginx/include/ngx_parse.h /home/work/nginx/include/ /home/work/nginx/include/ngx_inet.h /home/work/nginx/include/ /home/work/nginx/include/ngx_file.h /home/work/nginx/include/ /home/work/nginx/include/ngx_crc.h /home/work/nginx/include/ /home/work/nginx/include/ngx_crc32.h /home/work/nginx/include/ /home/work/nginx/include/ngx_murmurhash.h /home/work/nginx/include/ /home/work/nginx/include/ngx_md5.h /home/work/nginx/include/ /home/work/nginx/include/ngx_sha1.h /home/work/nginx/include/ /home/work/nginx/include/ngx_rbtree.h /home/work/nginx/include/ /home/work/nginx/include/ngx_trie.h /home/work/nginx/include/ /home/work/nginx/include/ngx_segment_tree.h /home/work/nginx/include/ /home/work/nginx/include/ngx_radix_tree.h /home/work/nginx/include/ /home/work/nginx/include/ngx_slab.h /home/work/nginx/include/ /home/work/nginx/include/ngx_times.h /home/work/nginx/include/ /home/work/nginx/include/ngx_shmtx.h /home/work/nginx/include/ /home/work/nginx/include/ngx_connection.h /home/work/nginx/include/ /home/work/nginx/include/ngx_cycle.h /home/work/nginx/include/ /home/work/nginx/include/ngx_conf_file.h /home/work/nginx/include/ /home/work/nginx/include/ngx_resolver.h /home/work/nginx/include/ /home/work/nginx/include/ngx_open_file_cache.h /home/work/nginx/include/ /home/work/nginx/include/ngx_crypt.h /home/work/nginx/include/ /home/work/nginx/include/ngx_event.h /home/work/nginx/include/ /home/work/nginx/include/ngx_event_timer.h /home/work/nginx/include/ /home/work/nginx/include/ngx_event_posted.h /home/work/nginx/include/ /home/work/nginx/include/ngx_event_busy_lock.h /home/work/nginx/include/ /home/work/nginx/include/ngx_event_connect.h /home/work/nginx/include/ /home/work/nginx/include/ngx_event_pipe.h /home/work/nginx/include/ /home/work/nginx/include/ngx_time.h /home/work/nginx/include/ /home/work/nginx/include/ngx_errno.h /home/work/nginx/include/ /home/work/nginx/include/ngx_alloc.h /home/work/nginx/include/ /home/work/nginx/include/ngx_files.h /home/work/nginx/include/ /home/work/nginx/include/ngx_channel.h /home/work/nginx/include/ /home/work/nginx/include/ngx_shmem.h /home/work/nginx/include/ /home/work/nginx/include/ngx_process.h /home/work/nginx/include/ /home/work/nginx/include/ngx_setaffinity.h /home/work/nginx/include/ /home/work/nginx/include/ngx_setproctitle.h /home/work/nginx/include/ /home/work/nginx/include/ngx_atomic.h /home/work/nginx/include/ /home/work/nginx/include/ngx_gcc_atomic_x86.h /home/work/nginx/include/ /home/work/nginx/include/ngx_thread.h /home/work/nginx/include/ /home/work/nginx/include/ngx_socket.h /home/work/nginx/include/ /home/work/nginx/include/ngx_os.h /home/work/nginx/include/ /home/work/nginx/include/ngx_user.h /home/work/nginx/include/ /home/work/nginx/include/ngx_pipe.h /home/work/nginx/include/ /home/work/nginx/include/ngx_sysinfo.h /home/work/nginx/include/ /home/work/nginx/include/ngx_process_cycle.h /home/work/nginx/include/ /home/work/nginx/include/ngx_linux_config.h /home/work/nginx/include/ /home/work/nginx/include/ngx_linux.h /home/work/nginx/include/ /home/work/nginx/include/ngx_syslog.h /home/work/nginx/include/ /home/work/nginx/include/ngx_proc.h /home/work/nginx/include/ /home/work/nginx/include/ngx_event_openssl.h /home/work/nginx/include/ /home/work/nginx/include/ngx_regex.h /home/work/nginx/include/ /home/work/nginx/include/pcre.h /home/work/nginx/include/ /home/work/nginx/include/ngx_auto_config.h' | |
DSO_HTTP_DEPS=' ngx_http.h ngx_http_request.h ngx_http_config.h ngx_http_core_module.h ngx_http_cache.h ngx_http_variables.h ngx_http_script.h ngx_http_upstream.h ngx_http_upstream_round_robin.h ngx_http_busy_lock.h ngx_http_ssi_filter_module.h ngx_http_spdy.h ngx_http_spdy_module.h ngx_http_ssl_module.h' | |
DSO_ALL_INCS=' -I/usr/local/include/luajit-2.1 -I../lua-nginx-module/src/api -I./src/ngx_devel_kit/objs -Iobjs/addon/ndk -I../pcre-8.32 -Iobjs -I./src/ngx_devel_kit/src ' | |
ALL_INCS= | |
CORE_INCS= | |
HTTP_INCS= | |
CORE_DEPS= | |
HTTP_DEPS= | |
NGX_OBJS=objs | |
opt= | |
help=no | |
for option | |
do | |
opt="$opt `echo $option | sed -e \"s/\(--[^=]*=\)\(.* .*\)/\1'\2'/\"`" | |
case "$option" in | |
-*=*) value=`echo "$option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;; | |
*) value="" ;; | |
esac | |
case "$option" in | |
--help) help=yes ;; | |
-h) help=yes ;; | |
--dst=) NGX_DSO_PREFIX="!" ;; | |
--dst=*) NGX_DSO_PREFIX="$value" ;; | |
-d=*) NGX_DSO_PREFIX="$value" ;; | |
--add-module=*) NGX_DSO_ADDONS="$NGX_DSO_ADDONS $value" ;; | |
-a=*) NGX_DSO_ADDONS="$NGX_DSO_ADDONS $value" ;; | |
--nginx-include=*) NGX_INCLUDE_PATH="$value" ;; | |
-s=*) NGX_INCLUDE_PATH="$value" ;; | |
*) | |
echo "$0: error: invalid option \"$option\"" | |
exit 1 | |
;; | |
esac | |
done | |
if ! test -n "$option" ; then | |
help=yes | |
fi | |
if [ $help = yes ]; then | |
cat << END | |
-h, --help display this help and exit | |
-d, --dst=PATH set module installation path | |
-a, --add-module=PATH external module which will be compiled(absolute path) | |
-s, --nginx-include=SOURCE set nginx include path(absolute path) | |
END | |
exit 1 | |
fi | |
# arg1 is addon dir | |
# arg2 is addon deps | |
# arg3 is addon src | |
generate_make () { | |
# mkdir build temp | |
cd $1 | |
dso_binout=$ngx_addon_name | |
NGX_DSO_MAKEFILE=objs/Makefile | |
NGX_ADDON_DEPS=$2 | |
cat << END > $NGX_DSO_MAKEFILE | |
CC = $CC | |
CFLAGS = $CFLAGS | |
CPP = $CPP | |
LINK = $LINK | |
CORE_LIBS = $CORE_LIBS | |
CORE_INCS = $CORE_INCS | |
HTTP_INCS = $HTTP_INCS | |
CORE_LINK = $CORE_LINK | |
NGX_LD_OPT = $NGX_LD_OPT | |
END | |
cat << END >> $NGX_DSO_MAKEFILE | |
ALL_INCS = $ALL_INCS | |
CORE_DEPS = $CORE_DEPS | |
HTTP_DEPS = $HTTP_DEPS | |
ADDON_DEPS = \$(CORE_DEPS) $NGX_ADDON_DEPS | |
END | |
if test -n "$NGX_LD_OPT$CORE_LIBS"; then | |
ngx_libs=`echo $NGX_LD_OPT $CORE_LIBS \ | |
| sed -e "s/\//$ngx_regex_dirsep/g" -e "s/^/$ngx_long_regex_cont/"` | |
fi | |
for ngx_src in $NGX_ADDON_SRCS | |
do | |
ngx_obj="objs/src/`basename \`dirname $ngx_src\``" | |
test -d $ngx_obj || mkdir -p $ngx_obj | |
ngx_obj=`echo $ngx_obj/\`basename $ngx_src\` | sed -e "s/\//$ngx_regex_dirsep/g"` | |
ngx_obj=`echo $ngx_obj \ | |
| sed -e "s#^\(.*\.\)cpp\\$#$ngx_objs_dir\1$ngx_objext#g" \ | |
-e "s#^\(.*\.\)cc\\$#$ngx_objs_dir\1$ngx_objext#g" \ | |
-e "s#^\(.*\.\)c\\$#$ngx_objs_dir\1$ngx_objext#g" \ | |
-e "s#^\(.*\.\)S\\$#$ngx_objs_dir\1$ngx_objext#g"` | |
ngx_dso_all_objs="$ngx_dso_all_objs $ngx_obj" | |
done | |
ngx_deps=`echo $ngx_dso_all_objs $ngx_res $LINK_DEPS \ | |
| sed -e "s/ *\([^ ][^ ]*\)/$ngx_regex_cont\1/g" \ | |
-e "s/\//$ngx_regex_dirsep/g"` | |
ngx_objs=`echo $ngx_dso_all_objs \ | |
| sed -e "s/ *\([^ ][^ ]*\)/$ngx_long_regex_cont\1/g" \ | |
-e "s/\//$ngx_regex_dirsep/g"` | |
ngx_link=${CORE_LINK:+`echo $CORE_LINK \ | |
| sed -e "s/\//$ngx_regex_dirsep%%/g" -e "s/^/$ngx_long_regex_cont/"`} | |
cat << END >> $NGX_DSO_MAKEFILE | |
$NGX_OBJS${ngx_dirsep}${dso_binout}${ngx_soext}: $ngx_deps$ngx_spacer | |
\$(LINK) ${ngx_long_start}${ngx_binout} $NGX_OBJS${ngx_dirsep}${dso_binout}${ngx_soext}$ngx_long_cont$ngx_objs$ngx_libs$ngx_link | |
$ngx_rcc | |
${ngx_long_end} | |
END | |
for ngx_src in $NGX_ADDON_SRCS | |
do | |
ngx_obj="objs/src/`basename \`dirname $ngx_src\``" | |
test -d $ngx_obj || mkdir -p $ngx_obj | |
ngx_obj=`echo $ngx_obj/\`basename $ngx_src\` | sed -e "s#/#$ngx_regex_dirsep#g"` | |
ngx_obj=`echo $ngx_obj \ | |
| sed -e "s#^\(.*\.\)cpp\\$#$ngx_objs_dir\1$ngx_objext#g" \ | |
-e "s#^\(.*\.\)cc\\$#$ngx_objs_dir\1$ngx_objext#g" \ | |
-e "s#^\(.*\.\)c\\$#$ngx_objs_dir\1$ngx_objext#g" \ | |
-e "s#^\(.*\.\)S\\$#$ngx_objs_dir\1$ngx_objext#g"` | |
ngx_src=`echo $ngx_src | sed -e "s#/#$ngx_regex_dirsep#g"` | |
cat << END >> $NGX_DSO_MAKEFILE | |
$ngx_obj: \$(ADDON_DEPS)$ngx_cont$ngx_src | |
$ngx_cc\$(ALL_INCS)$ngx_tab$ngx_objout$ngx_obj$ngx_tab$ngx_src$NGX_AUX | |
END | |
done | |
make -f $NGX_DSO_MAKEFILE | |
if test -n "$NGX_DSO_PREFIX"; then | |
test ! -f $NGX_DSO_PREFIX${dso_binout}${ngx_soext} \ | |
|| unlink $NGX_DSO_PREFIX${dso_binout}${ngx_soext} | |
echo copying $NGX_OBJS${ngx_dirsep}${dso_binout}${ngx_soext} to $NGX_DSO_PREFIX | |
cp $NGX_OBJS${ngx_dirsep}${dso_binout}${ngx_soext} $NGX_DSO_PREFIX | |
else | |
test ! -f $NGX_PREFIX${ngx_dirsep}$NGX_DSO_PATH${ngx_dirsep}${dso_binout}${ngx_soext} \ | |
|| unlink $NGX_PREFIX${ngx_dirsep}$NGX_DSO_PATH${ngx_dirsep}${dso_binout}${ngx_soext} | |
echo copying $NGX_OBJS${ngx_dirsep}${dso_binout}${ngx_soext} to $NGX_PREFIX${ngx_dirsep}$NGX_DSO_PATH | |
cp $NGX_OBJS${ngx_dirsep}${dso_binout}${ngx_soext} $NGX_PREFIX/$NGX_DSO_PATH | |
fi | |
} | |
if test -n "$NGX_DSO_ADDONS"; then | |
echo configuring additional modules | |
for dai in $DSO_ALL_INCS | |
do | |
ALL_INCS="$ALL_INCS $dai" | |
done | |
ALL_INCS="$ALL_INCS -I$NGX_INCLUDE_PATH" | |
for dcd in $DSO_CORE_DEPS | |
do | |
if test -n "$dcd"; then | |
case ".$dcd" in | |
./*) | |
CORE_DEPS="$CORE_DEPS $dcd" | |
;; | |
*) | |
CORE_DEPS="$CORE_DEPS $NGX_INCLUDE_PATH/$dcd" | |
;; | |
esac | |
fi | |
done | |
for dhd in $DSO_HTTP_DEPS | |
do | |
if test -n "$dhd"; then | |
case ".$dhd" in | |
./*) | |
HTTP_DEPS="$HTTP_DEPS $dhd" | |
;; | |
*) | |
HTTP_DEPS="$HTTP_DEPS $NGX_INCLUDE_PATH/$dhd" | |
;; | |
esac | |
fi | |
done | |
for ngx_addon_dir in $NGX_DSO_ADDONS | |
do | |
echo "adding module in $ngx_addon_dir" | |
if test -f $ngx_addon_dir/config; then | |
NGX_ADDON_SRCS= | |
NGX_ADDON_DEPS= | |
CORE_LIBS_TEMP=$CORE_LIBS | |
CORE_LIBS= | |
cd $ngx_addon_dir | |
CORE_INCS_TEMP=$CORE_INCS | |
HTTP_INCS_TEMP=$HTTP_INCS | |
CORE_LIBS_TEMP=$CORE_LIBS | |
CORE_INCS= | |
HTTP_INCS= | |
CORE_LIBS= | |
if test -d $NGX_OBJS; then | |
rm -rf $NGX_OBJS | |
fi | |
mkdir -p $NGX_OBJS/auto | |
touch $NGX_AUTOCONF_ERR | |
touch $NGX_AUTOTEST | |
touch $NGX_AUTO_CONFIG_H | |
cat << END > $NGX_OBJS/auto/feature | |
$ngx_feature_file | |
END | |
cat << END > $NGX_OBJS/auto/have | |
$ngx_have_file | |
END | |
cd $NGX_OBJS | |
. $ngx_addon_dir/config | |
dso_core_incs=`echo $CORE_INCS \ | |
| sed -e "s/ *\([^ ][^ ]*\)/$ngx_regex_cont$ngx_include_opt\1/g" \ | |
-e "s/\//$ngx_regex_dirsep/g"` | |
dso_http_incs=`echo $HTTP_INCS \ | |
| sed -e "s/ *\([^ ][^ ]*\)/$ngx_regex_cont$ngx_include_opt\1/g" \ | |
-e "s/\//$ngx_regex_dirsep/g"` | |
dso_core_libs=`echo $CORE_LIBS \ | |
| sed -e "s/\//$ngx_regex_dirsep/g"` | |
if test -n "$dso_core_incs"; then | |
CORE_INCS="$CORE_INCS_TEMP -I $dso_core_incs" | |
else | |
CORE_INCS=$CORE_INCS_TEMP | |
fi | |
if test -n "$dso_http_incs"; then | |
HTTP_INCS="$HTTP_INCS_TEMP -I $dso_http_incs" | |
else | |
HTTP_INCS=$HTTP_INCS_TEMP | |
fi | |
if test -n "$dso_core_libs"; then | |
CORE_LIBS="$CORE_LIBS_TEMP $dso_core_libs" | |
else | |
CORE_LIBS=$CORE_LIBS_TEMP | |
fi | |
cd - | |
cd $ngx_addon_dir | |
echo " + $ngx_addon_name will be compiled" | |
generate_make $ngx_addon_dir $NGX_ADDON_DEPS $NGX_ADDON_SRCS $ngx_addon_name | |
else | |
echo "$0: error: no $ngx_addon_dir/config was found" | |
exit 1 | |
fi | |
done | |
else | |
echo "please specify the module path" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment