Makefile教程(五)nginx的Makefile文件

最近在做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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值