nginx的編譯過程,第一步是configure。咱們使用 --help能夠看到configure的不少配置。linux
configure的過程作的事情其實就是檢測環境,而後根據環境生成Makefile,包含各類參數的c頭文件等(ngx_auto_config.h/ ngx_auto_headers.h)。這個c頭文件包含了全部根據當前環境配置的參數。nginx
這裏的Makefile文件指的是根目錄下的Makefile, 這個是後面make命令的入口git
objs文件夾裏面有這幾個文件:github
configure過程當中不單單是使用簡單的shell命令來檢測環境,還會生成一些簡單的c程序,而且用編譯器編譯執行,獲取輸出來獲取環境參數。只是這些c程序和編譯後的文件在獲取參數完成以後會刪除,因此咱們實際看不到這個文件的存在。shell
這些shell命令,c程序的一些輸出和錯誤信息都記錄在這個autoconf.err中了,實際上這個文件沒有什麼用。測試
這個obj/Makefile纔是本質的構建程序和模塊的過程。全部須要加載的模塊和一些設置都在這邊了。ui
咱們能夠看一下,它使用的編譯器是cc, cc編譯器在linux上就是gcc。 gcc是一個各類不一樣語言的編譯器。gcc表明 the GNU Compiler Collection。 好比你的代碼後綴是.c, 它會調用c的編譯器還有linker去連接c的庫。atom
這個就是configure出來的一個重要成果,本機環境的一些配置,好比int多少位之類的。.net
這個是configure出來的,判斷一些header是否存在。3d
這個文件就告訴咱們了咱們此次編譯nginx到底有多少個模塊。
其中的一些模塊是很重要的,可是咱們也能夠自主選擇。
have=NGX_SBIN_PATH value="\"$NGX_SBIN_PATH\"" . auto/define
auto/define的定義:
# Copyright (C) Igor Sysoev # Copyright (C) Nginx, Inc. cat << END >> $NGX_AUTO_CONFIG_H #ifndef $have #define $have $value #endif END
結合起來的意思就是,若是我在參數裏面設置了NGX_SBIN_PATH(有參數能夠設置),那麼我就在ngx_auto_config.h中增長這個宏定義:
#ifndef NGX_SBIN_PATH #define NGX_SBIN_PATH "sbin/nginx" #endif
cat << END >> $NGX_AUTO_CONFIG_H #ifndef $have #define $have 1 #endif END
意思其實就是auto/define的翻版,只是若是這裏的value是1
好比
have=NGX_HAVE_EPOLL . auto/have
等同
#ifndef NGX_HAVE_EPOLL #define NGX_HAVE_EPOLL 1 #endif
ngx_feature="GeoIP IPv6 support" ngx_feature_name="NGX_HAVE_GEOIP_V6" ngx_feature_run=no ngx_feature_incs="#include <stdio.h> #include <GeoIP.h>" #ngx_feature_path= #ngx_feature_libs= ngx_feature_test="printf(\"%d\", GEOIP_CITY_EDITION_REV0_V6);" . auto/feature
上面這個是個feature的模版,它的目的是爲了檢查當前的環境是否包含這個feature, 好比上面的例子就是判斷這個機器環境是否支持GEO IPV6。
還能夠看看下面這個例子:
ngx_feature="GeoIP library in /opt/local/" ngx_feature_path="/opt/local/include" if [ $NGX_RPATH = YES ]; then ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -lGeoIP" else ngx_feature_libs="-L/opt/local/lib -lGeoIP" fi . auto/feature
feature的代碼就不貼出來了, 具體作了下面幾個事情:
ngx_include="inttypes.h"; . auto/include
生成一個簡單的c文件:
cat << END > $NGX_AUTOTEST.c $NGX_INCLUDE_SYS_PARAM_H #include <$ngx_include> int main(void) { return 0; } END
判斷檢測環境是否有這個頭文件。
ngx_module_type=HTTP if :; then ngx_module_name="ngx_http_module \ ngx_http_core_module \ ngx_http_log_module \ ngx_http_upstream_module" ngx_module_incs="src/http src/http/modules" ngx_module_deps="src/http/ngx_http.h \ src/http/ngx_http_request.h \ src/http/ngx_http_config.h \ src/http/ngx_http_core_module.h \ src/http/ngx_http_cache.h \ src/http/ngx_http_variables.h \ src/http/ngx_http_script.h \ src/http/ngx_http_upstream.h \ src/http/ngx_http_upstream_round_robin.h" ngx_module_srcs="src/http/ngx_http.c \ src/http/ngx_http_core_module.c \ src/http/ngx_http_special_response.c \ src/http/ngx_http_request.c \ src/http/ngx_http_parse.c \ src/http/modules/ngx_http_log_module.c \ src/http/ngx_http_request_body.c \ src/http/ngx_http_variables.c \ src/http/ngx_http_script.c \ src/http/ngx_http_upstream.c \ src/http/ngx_http_upstream_round_robin.c" ngx_module_libs= ngx_module_link=YES . auto/module
這個auto/module會對每個模塊設置一些模塊須要的變量,好比模塊的源碼地址,模塊依賴的lib庫等。
checking for OS + Linux 3.10.0-514.16.1.el7.x86_64 x86_64 checking for C compiler ... found + using GNU C compiler + gcc version: 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) checking for gcc -pipe switch ... found checking for -Wl,-E switch ... found checking for gcc builtin atomic operations ... found checking for C99 variadic macros ... found checking for gcc variadic macros ... found checking for gcc builtin 64 bit byteswap ... 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 Linux specific features checking for epoll ... found checking for EPOLLRDHUP ... found checking for EPOLLEXCLUSIVE ... not found checking for O_PATH ... not found checking for sendfile() ... found checking for sendfile64() ... found checking for sys/prctl.h ... found checking for prctl(PR_SET_DUMPABLE) ... found checking for prctl(PR_SET_KEEPCAPS) ... found checking for capabilities ... found checking for crypt_r() ... found checking for sys/vfs.h ... found checking for nobody 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 sched_setaffinity() ... found checking for SO_SETFIB ... not found checking for SO_REUSEPORT ... found checking for SO_ACCEPTFILTER ... not found checking for SO_BINDANY ... not found checking for IP_TRANSPARENT ... found checking for IP_BINDANY ... not found checking for IP_BIND_ADDRESS_NO_PORT ... not found checking for IP_RECVDSTADDR ... not found checking for IP_SENDSRCADDR ... not found checking for IP_PKTINFO ... found checking for IPV6_RECVPKTINFO ... found checking for TCP_DEFER_ACCEPT ... found checking for TCP_KEEPIDLE ... found checking for TCP_FASTOPEN ... not found checking for TCP_INFO ... found checking for accept4() ... found checking for eventfd() ... found checking for int size ... 4 bytes checking for long size ... 8 bytes checking for long long size ... 8 bytes checking for void * size ... 8 bytes checking for uint32_t ... found checking for uint64_t ... found checking for sig_atomic_t ... found checking for sig_atomic_t size ... 4 bytes 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 byte ordering ... little endian checking for size_t size ... 8 bytes checking for off_t size ... 8 bytes checking for time_t size ... 8 bytes checking for AF_INET6 ... found checking for setproctitle() ... not found checking for pread() ... found checking for pwrite() ... found checking for pwritev() ... found checking for sys_nerr ... found checking for localtime_r() ... found checking for clock_gettime(CLOCK_MONOTONIC) ... not found checking for clock_gettime(CLOCK_MONOTONIC) in librt ... found checking for posix_memalign() ... found checking for memalign() ... found checking for mmap(MAP_ANON|MAP_SHARED) ... found checking for mmap("/dev/zero", MAP_SHARED) ... found checking for System V shared memory ... found checking for POSIX semaphores ... not found checking for POSIX semaphores in libpthread ... 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 checking for sysconf(_SC_NPROCESSORS_ONLN) ... found checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found checking for openat(), fstatat() ... found checking for getaddrinfo() ... found checking for zlib library ... found creating objs/Makefile Configuration summary + PCRE library is not used + OpenSSL library is not used + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" 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" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp
咱們其實能夠對着 xmind 的流程和 configure 這個程序來看就很清晰了
https://github.com/its-tech/nginx-1.14.0-research/blob/master/configure
再加上前面幾個configure語法就能看懂了。