httpd Makefile例子分析

  1 # Top level hierarchy.
  2 prefix = /usr/local
  3 exec_prefix = ${prefix}
  4 # Pathname of directory to install the binary.
  5 BINDIR = ${exec_prefix}/sbin
  6 # Pathname of directory to install the man page.
  7 MANDIR = ${prefix}/man
  8 # Pathname of directory to install the CGI programs.
  9 WEBDIR = $(prefix)/www
 10 
 11 # CONFIGURE: The group that the web directory belongs to.  This is so that
 12 # the makeweb program can be installed set-group-id to that group, and make
 13 # subdirectories.  If you're not going to use makeweb, ignore this.
 14 WEBGROUP =    www
 15 
 16 # CONFIGURE: Directory for CGI executables.
 17 CGIBINDIR =    $(WEBDIR)/cgi-bin
 18 
 19 # You shouldn't need to edit anything below here.
 20 #CC        制定编译器
 21 #CCOPT  编译选项 
 22 #        优化: gcc默认提供了5级优 化选项的集合: 
 23 #            -O0:无优化(默认) 
 24 #            -O和-O1:使用能减少目标文件大小以及执行时间并且不会使编译时间明显增加的优化.在编译大型程序的时候会显著增加编译时内存的使用. 
 25 #            -O2: 包含-O1的优化并增加了不需要在目标文件大小和执行速度上进行折衷的优化.编译器不执行循环展开以及函数内联.此选项将增加编译时间和目标文件的执行性能. 
 26 #            -Os:专门优化目标文件大小,执行所有的不增加目标文件大小的-O2优化选项.并且执行专门减小目标文件大小的优化选项. 
 27 #            -O3: 打开所有-O2的优化选项并且增加 -finline-functions, -funswitch-loops,-fpredictive-commoning, -fgcse-after-reload and -ftree-vectorize优化选项. 
 28 #
 29 #INCLS    编译选项
 30 #        -Idir  把dir 加入到搜索头文件的路径列表中。 
 31 #        例子: $ gcc test.c -I../inc -o test
 32 #        INCLS =        -I.表示当前目录下即为头文件目录
 33 #CFLAGS    把所有编译选项合在一起
 34 
 35 CC =        gcc
 36 CCOPT =        -O2
 37 DEFS =         -DHAVE__PROGNAME=1 -DHAVE_FCNTL_H=1 -DHAVE_GRP_H=1 -DHAVE_MEMORY_H=1 -DHAVE_PATHS_H=1 -DHAVE_POLL_H=1 -DHAVE_SYS_POLL_H=1 -DTIME_WITH_SYS_TIME=1 -DHAVE_DIRENT_H=1 -DHAVE_LIBCRYPT=1 -DHAVE_STRERROR=1 -DHAVE_WAITPID=1 -DHAVE_VSNPRINTF=1 -DHAVE_DAEMON=1 -DHAVE_SETSID=1 -DHAVE_GETADDRINFO=1 -DHAVE_GETNAMEINFO=1 -DHAVE_GAI_STRERROR=1 -DHAVE_SIGSET=1 -DHAVE_ATOLL=1 -DHAVE_UNISTD_H=1 -DHAVE_GETPAGESIZE=1 -DHAVE_MMAP=1 -DHAVE_SELECT=1 -DHAVE_POLL=1 -DHAVE_TM_GMTOFF=1 -DHAVE_INT64T=1 -DHAVE_SOCKLENT=1 
 38 INCLS =        -I.
 39 CFLAGS =    $(CCOPT) $(DEFS) $(INCLS)
 40 LDFLAGS =    
 41 LIBS =        -lcrypt 
 42 NETLIBS =    
 43 INSTALL =    /usr/bin/install -c
 44 
 45 
 46 #==================================================================================
 47 #===    .c.o:                                                                    ===
 48 #===    这个规则表示所有的 .o文件都是依赖与相应的.c文件的。                        ===
 49 #===例如mytool.o依赖于mytool.c                                                    ===
 50 #===                                                                            ===
 51 #===    $@表示目标集;这里就是指所有.o文件                                        ===
 52 #===    $<表示依赖目标集;                                                        ===
 53 #===                                                                            ===
 54 #===    gcc -c 表示生成.o的obj文件                                                 ===
 55 #===                                                                            ===
 56 #===    结果同上                                                                ===
 57 #==================================================================================
 58 #======================清除所有.o文件;并重新生成所有.o文件========================
 59 .c.o:
 60     @rm -f $@
 61     $(CC) $(CFLAGS) -c $*.c
 62 #=================================源文件===========================================
 63 SRC =        thttpd.c libhttpd.c fdwatch.c mmc.c timers.c match.c tdate_parse.c
 64 
 65 #==================================================================================
 66 #===    变量的高级用法                                                            ===
 67 #===    foo:=a.o b.o c.o                                                        ===
 68 #===    bar:=$(foo:.o=.c)                                                        ===
 69 #===    这个示例中,先顶一了一个$(foo)变量,二第二行的意思是吧$(foo)中所有.o    ===
 70 #===扩展符全部替换成“.c”,所以$(foo)的值就是a.c b.c c.c.                            ===
 71 #===                                                                            ===
 72 #===    foo:=a.o b.o c.o                                                        ===
 73 #===    bar:=$(foo:%.o=%.c)                                                        ===
 74 #===    结果同上                                                                ===
 75 #==================================================================================
 76 #==============================中间代码文件========================================
 77 OBJ =        $(SRC:.c=.o) 
 78 
 79 ALL =        thttpd
 80 
 81 GENHDR =    mime_encodings.h mime_types.h
 82 #==============================要清除的文件========================================
 83 CLEANFILES =    $(ALL) $(OBJ) $(GENSRC) $(GENHDR)
 84 
 85 SUBDIRS =    cgi-src extras
 86 
 87 all:        this subdirs
 88 this:        $(ALL)
 89 #==============================生成可执行文件========================================
 90 thttpd: $(OBJ)
 91     @rm -f $@
 92     $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $(NETLIBS)
 93 
 94 mime_encodings.h:    mime_encodings.txt
 95     rm -f mime_encodings.h
 96     sed < mime_encodings.txt > mime_encodings.h \
 97       -e 's/#.*//' -e 's/[     ]*$$//' -e '/^$$/d' \
 98       -e 's/[     ][     ]*/", 0, "/' -e 's/^/{ "/' -e 's/$$/", 0 },/'
 99 
100 mime_types.h:    mime_types.txt
101     rm -f mime_types.h
102     sed < mime_types.txt > mime_types.h \
103       -e 's/#.*//' -e 's/[     ]*$$//' -e '/^$$/d' \
104       -e 's/[     ][     ]*/", 0, "/' -e 's/^/{ "/' -e 's/$$/", 0 },/'
105 #==================================================================================
106 # mime_types.txt文件内容如下
107 #
108 # A list of file extensions followed by the corresponding MIME type.
109 # Extensions not found in the table are returned as text/plain.
110 #
111 #a    application/octet-stream
112 #aab    application/x-authorware-bin
113 #aam    application/x-authorware-map
114 #aas    application/x-authorware-seg
115 #ai    application/postscript
116 #
117 #
118 #=== -e 's/#.*//' 把所有#号开头的行替换成空行                                                        ===
119 #=== -e 's/[     ]*$$//' 
120 #===    bar:=$(foo:.o=.c)                                                        ===
121 #===    这个示例中,先顶一了一个$(foo)变量,二第二行的意思是吧$(foo)中所有.o    ===
122 #===扩展符全部替换成“.c”,所以$(foo)的值就是a.c b.c c.c.                            ===
123 #===                                                                            ===
124 #===    foo:=a.o b.o c.o                                                        ===
125 #===    bar:=$(foo:%.o=%.c)                                                        ===
126 #===    结果同上                                                                ===
127 #==================================================================================
128 
129 subdirs:
130     for i in $(SUBDIRS) ; do ( \
131         cd $$i ; \
132         pwd ; \
133         $(MAKE) $(MFLAGS) \
134         WEBDIR=$(WEBDIR) \
135         CGIBINDIR=$(CGIBINDIR) \
136         MANDIR=$(MANDIR) \
137         WEBGROUP=$(WEBGROUP) \
138     ) ; done
139 
140 
141 install:    installthis install-man installsubdirs
142 
143 installthis:
144     -mkdir -p $(DESTDIR)$(BINDIR)
145     $(INSTALL) -m 555 -o bin -g bin thttpd $(DESTDIR)$(BINDIR)
146 
147 install-man:
148     -mkdir -p $(DESTDIR)$(MANDIR)/man8
149     $(INSTALL) -m 444 -o bin -g bin thttpd.8 $(DESTDIR)$(MANDIR)/man8
150 
151 installsubdirs:
152     for i in $(SUBDIRS) ; do ( \
153         cd $$i ; \
154         pwd ; \
155         $(MAKE) $(MFLAGS) \
156         WEBDIR=$(WEBDIR) \
157         CGIBINDIR=$(CGIBINDIR) \
158         MANDIR=$(MANDIR) \
159         WEBGROUP=$(WEBGROUP) \
160         install \
161     ) ; done
162 
163 
164 clean:        cleansubdirs
165     rm -f $(CLEANFILES)
166 
167 distclean:    distcleansubdirs
168     rm -f $(CLEANFILES) Makefile config.cache config.log config.status tags
169 
170 cleansubdirs:
171     for i in $(SUBDIRS) ; do ( \
172         cd $$i ; \
173         pwd ; \
174         $(MAKE) $(MFLAGS) clean \
175     ) ; done
176 
177 distcleansubdirs:
178     for i in $(SUBDIRS) ; do ( \
179         cd $$i ; \
180         pwd ; \
181         $(MAKE) $(MFLAGS) distclean \
182     ) ; done
183 
184 tags:
185     ctags -wtd *.c *.h
186 
187 tar:
188     @name=`sed -n -e '/SERVER_SOFTWARE/!d' -e 's,.*thttpd/,thttpd-,' -e 's, .*,,p' version.h` ; \
189       rm -rf $$name ; \
190       mkdir $$name ; \
191       tar cf - `cat FILES` | ( cd $$name ; tar xfBp - ) ; \
192       chmod 644 $$name/Makefile.in $$name/config.h $$name/mime_encodings.txt $$name/mime_types.txt ; \
193       chmod 755 $$name/cgi-bin $$name/cgi-src $$name/contrib $$name/contrib/redhat-rpm $$name/extras $$name/scripts ; \
194       tar cf $$name.tar $$name ; \
195       rm -rf $$name ; \
196       gzip $$name.tar
197 
198 thttpd.o:    config.h version.h libhttpd.h fdwatch.h mmc.h timers.h match.h
199 libhttpd.o:    config.h version.h libhttpd.h mime_encodings.h mime_types.h \
200         mmc.h timers.h match.h tdate_parse.h
201 fdwatch.o:    fdwatch.h
202 mmc.o:        mmc.h libhttpd.h
203 timers.o:    timers.h
204 match.o:    match.h
205 tdate_parse.o:    tdate_parse.h

 

转载于:https://www.cnblogs.com/ztteng/articles/3114230.html

你可能感兴趣的:(httpd Makefile例子分析)