最近在做icomet到f-stack的移植,需要参考nginx的Makefile文件,学习nginx是如何移植的。
这里参考的是/home/dpdk/f-stack/app/nginx-1.16.0下的makefile文件,具体如下:
default: build
clean:
rm -rf Makefile objs #删除objs目标文件
build:
$(MAKE) -f objs/Makefile #编译objs下的Makefile文件
install:
$(MAKE) -f objs/Makefile install #安装objs下的Makefile文件
modules:
$(MAKE) -f objs/Makefile modules #
upgrade:
/usr/local/nginx_fstack/sbin/nginx -t
kill -USR2 `cat /usr/local/nginx_fstack/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx_fstack/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx_fstack/logs/nginx.pid.oldbin`
Makefile只负责编译当前目录中的对象。子目录中的对象,由子目录中的Makefile负责。此时需要关注objs下的Makefile文件。对比f-stack中nginx和普通nginx的makefile。
1.nginx的Makefile分析
(1)变量赋值
CC,CFLAGS,CPP,LINK($CC),ALL_INCS(-I...),CORE_DEPS, CORE_INCS, HTTP_DEPS, HTTP_INCS
(2)目标
build: binary modules manpage
binary: objs/nginx
objs/nginx: objs/src/core/nginx.o \
(3).o文件的编译规则
objs/ngx_modules.o: $(CORE_DEPS) objs/ngx_modules.c
(CC) -c $(CFLAGS) $(CORE_INCS) -o objs/ngx_modules.o objs/ngx_modules.c
...
objs/src/http/ngx_http.o: $(CORE_DEPS) $(HTTP_DEPS) src/http/ngx_http.c
$(CC) -c $(CFLAGS) $(CORE_INCS) $(HTTP_INCS) -o objs/src/http/ngx_http.o src/http/ngx_http.c
(4)安装构建
install: build
创建目录,拷贝objs/nginx,/usr/local/nginx/sbin/nginx
conf/... /usr/local/nginx/conf/...
创建目录/usr/local/nginx/logs
2.和原生nginx的makefile分析其中不同点:
(1)CFLAGS: 指定头文件(.h文件)的路径,f-stack的nginx指定了f-stack的lib(/home/dpdk/f-stack/lib)
(2)objs/nginx下新增三个目标:
objs/src/event/modules/ngx_kqueue_module.o
objs/src/event/modules/ngx_ff_module.o
objs/src/event/modules/ngx_ff_host_event_module.o
(3)-ldl -lpthread -lcrypt -lpcre -lz -L/home/dpdk/f-stack/lib -Wl,--whole-archive,-lfstack,--no-whole-archive -L/home/dpdk/f-stack/dpdk/build/lib -Wl,--whole-archive,-ldpdk,--no-whole-archive -Wl,--no-whole-archive -lrt -lm -ldl -lcrypto -lpthread -lnuma \
(4)编译三个目标文件
objs/src/event/modules/ngx_kqueue_module.o: $(CORE_DEPS) \
src/event/modules/ngx_kqueue_module.c
$(CC) -c $(CFLAGS) $(CORE_INCS) \
-o objs/src/event/modules/ngx_kqueue_module.o \
src/event/modules/ngx_kqueue_module.c
objs/src/event/modules/ngx_ff_module.o: $(CORE_DEPS) \
src/event/modules/ngx_ff_module.c
$(CC) -c $(CFLAGS) $(CORE_INCS) \
-o objs/src/event/modules/ngx_ff_module.o \
src/event/modules/ngx_ff_module.c
objs/src/event/modules/ngx_ff_host_event_module.o: $(CORE_DEPS) \
src/event/modules/ngx_ff_host_event_module.c
$(CC) -c $(CFLAGS) $(CORE_INCS) \
-o objs/src/event/modules/ngx_ff_host_event_module.o \
src/event/modules/ngx_ff_host_event_module.c