1.Makefile中include的作用
在Makefile使用include关键字可以把别的Makefile包含进来,这很像C语言的#include,被包含的文件会原模原样的放在当前文件的包含位置。include的语法是:
include <filename>;
filename可以是当前操作系统Shell的文件模式(可以保含路径和通配符)
在 include前面可以有一些空字符,但是绝不能是[Tab]键开始。include和<filename>;可以用一个或多个空格隔 开。 举个例子,你有这样几个Makefile:a.mk、b.mk、c.mk,还有一个文件叫foo.make,以及一个变量$(bar),其包含了 e.mk 和f.mk,那么,下面的语句:
include foo.make *.mk $(bar)
等价于:
include foo.make a.mk b.mk c.mk e.mk f.mk
2. CFLAGS 和CXXFLAGS 的作用
CFLAGS 表示用于 C 编译器的选项,
CXXFLAGS 表示用于 C++ 编译器的选项。
这两个变量实际上涵盖了编译和汇编两个步骤。
3. make -f ***.mk $@ TARGET="***" LIBS="***" .... 后面接的变量是做什么的
@make -f $(MKHOME)/mak/mkstand.mak $@ TARGET="$(PRGTARG)" OBJS="$(PRGOBJS)" LIBS="$(PRGLIBS)" DEFS="$(PRGDEFS)" DBNM="$(PRGDBNM)"
中 mkstand.mak后面接的参数 是作为变量传入了 mkstand.mak 文件中
4.Makefile里面 -l 和 -L的区别
-l-->指定连接时期望连接的库的名字
-L-->指定连接库的搜索路径
5.实际项目makefile分析:
5.1顶层makefile分析
#目标,目的就为了执行下面的程序
debug all: debugtuxsvrexec
#没什么用
release: releasetuxsvrexec
#下面的操作,只是为了要执行other.mk文件而已,并没有任何的作用
# DO NOT modify any code below!!!
releasedynamic debugdynamic releasestatic debugstatic releaseexec debugexec releasetuxsvrexec debugtuxsvrexec clean:
@make -f other.mk $@
@rm -f *.o
make的步骤:
make -f other.mk debugtuxsvrexec
5.2 中间层makefile
PROCURRPATH = $(SRCHOME)/file
PRGOBJS = $(PROCURRPATH)/other.o
PRGTARG = OTHER
PRGLIBS = -ldbsutil -lcnutil -ltxnutil -ldbopr
TUXSERVICE = OTHERSVC
# used for db2 database
PRGDBNM =
#!!!!!!注意!!!!!!
#如果使用上层的make来执行当前的makefile ,则下面的两个变量没有任何意义,使用了上层传入的变量
#只有当使用make -f other.mk 命令执行当前makefie时,这个变量才有意义
#原因? 不清楚。
debug all: debugtuxsvrexec
release: releasetuxsvrexec
# # DO NOT modify any code below!!!
releasedynamic debugdynamic releasestatic debugstatic releaseexec debugexec debugtuxsvrexec releasetuxsvrexec clean:
@make -f $(MKHOME)/mak/mkstand.mak $@ TARGET="$(PRGTARG)" OBJS="$(PRGOBJS)" LIBS="$(PRGLIBS)" DEFS="$(PRGDEFS)" DBNM="$(PRGDBNM)"
rm -f tp*
make的步骤:
make -f /app/tcard/core/src/mak/mkstand.mak debugtuxsvrexec TARGET="OTHER" OBJS="/app/tcard/core/src/file/other.o" LIBS="-ldbsutil -lcnutil -ltxnutil -ldbopr " DEFS="-D__DEBUG__" DBNM=""
5.3底层makefile分析
#|----------------------------------------------------------------------------|
#| FILE NAME : mksstand.mak |
#| DESCRIPTIONS : Makefile for all kind of platform, for c and pc file, |
#| for lib(dynamic & static) and execuatable object |
#|----------------------------------------------------------------------------|
#头文件 倒入
include $(MKHOME)/mak/platform.mak
include $(MKHOME)/mak/database.mak
include $(MKHOME)/mak/tuxedo.mak
# environment variables must be define outside of makefile
#
# $FEHOME : home directory of develop
# $CCFLG : compiler options for c source code
# $CXXFLG : compiler options for c++ source code
# $DLFLG : link options for dynamic library
# $SLFLG : link options for static library
# $EXFLG : link options for excecuteable object
# $DBFLG : debug mode options
# $OPFLG : optimize mode options
# $DLFIX : suffix of dynamic library
# $SLFIX : suffix of static library
# $OBJS : c object files list
# $LIBS : libs required for executable object
# $DEFS : define flag list
# $TARGET : target objetc name
# $TUXSVCS: tuxedo services name
# $TUXRSMN: tuxedo resource manager name
# $DBNM : db name (for db2)
# commands
PC = proc
EC = esql
DB2 = db2
JAVAC = javac
JAVAH = javah
RMIC = rmic
RM = rm -f
CP = cp
MV = mv
CD = cd
ECHO = @echo
# paths and flags
SYSINCP = /usr/include
SYSLIBP = /usr/lib64
JINCP = $(JAVA_HOME)/include
JMDINCP = $(JAVA_HOME)/include/$(JAVAMD)
XMLINCP = $(APPHOME)/libxml/include/libxml2
XMLLIBP = $(APPHOME)/libxml/lib
FEHOME = $(SRCHOME)
BINP = $(APPHOME)/bin
TUXBINP = $(APPHOME)/bin
LIBP = $(APPHOME)/lib
LIBX = $(APPHOME)/lib3rd
INCP = $(FEHOME)/include
INCX = $(FEHOME)/../lib3rd/include
CLSP = $(BINP)/classes
JLIBP = $(JAVA_HOME)/lib
#头文件路径
INCPS = -I$(SYSINCP) -I$(INCP) -I$(DBINCP) -I$(TUXINCP) -I$(JINCP) -I$(JMDINCP) -I$(XMLINCP) -I$(INCX) -I.
#链接库
LIBPS = -L$(SYSLIBP) -L$(XLIBP) -L$(LIBP) $(DBLIBP) -L$(TUXLIBP) -L$(XMLLIBP) -L$(LIBX)
#表示的是c编译器的选项
CCFLGS = $(RLFLG) $(CCFLG) $(DEFS) $(TUXDEF) $(DBDEF) $(OSDEF) $(PROCDEF) $(BITDEF) $(INCPS)
#表示的是c++编译器的选项
CXXFLGS = $(RLFLG) $(CXXFLG) $(DEFS) $(TUXDEF) $(DBDEF) $(OSDEF) $(PROCDEF) $(BITDEF) $(INCPS)
#在LIBPS 前面加上 -G 编译器选项,在编译的时候,产生调试信息)
DLFLGS = $(DLFLG) $(LIBPS)
EXFLGS = $(EXFLG) $(LIBPS)
#生成的动态库的路径
DLTARG = $(LIBP)/lib$(TARGET)$(DLFIX)
SLTARG = $(LIBP)/lib$(TARGET)$(SLFIX)
#生成的可执行文件的路in个
EXTARG = $(BINP)/$(TARGET)
#生成的TUXEDO服务的路径
TUXTARG = $(TUXBINP)/$(TARGET)
#执行 生成那个一目标,是由上一层的makefile绝对的
debugdynamic: setdebug $(DLTARG)
releasedynamic: setrelease $(DLTARG)
debugstatic: setdebug $(SLTARG)
releasestatic: setrelease $(SLTARG)
debugexec: setdebug $(EXTARG)
releaseexec : setrelease $(EXTARG)
debugtuxsvrexec: setdebug $(TUXTARG)
releasetuxsvrexec : setrelease $(TUXTARG)
javaclasses : $(OBJS)
$(ECHO) "Finish java package [$(TARGET)]"
rmi :
$(ECHO) "rmic [$(TARGET)] ..."
@$(CD) `dirname $(TARGET)`; \
$(RMIC) `basename $(TARGET)`
#预编译的命令吧
setdebug:
$(ECHO) $(DBFLG) > $(FEHOME)/mak/.mak.tmp
setrelease:
$(ECHO) $(OPFLG) > $(FEHOME)/mak/.mak.tmp
$(SLTARG): $(OBJS)
$(ECHO) "Linking [$(SLTARG)] ..."
#SLINK = ar SLFLG ruc
# ar ruc -ldbsutil -lcnutil -ltxnutil -ldbopr(对应other.mk来说)
@$(SLINK) $(SLFLG) $@ $(OBJS)
@$(RM) $(FEHOME)/mak/.mak.tmp
#动态库编译过程:这次才是真正的进行编译操作
#OBJS 是从上层的makefile文件传进来的 ***.o
$(DLTARG): $(OBJS)
$(ECHO) "Linking [$(DLTARG)] ..."
#DLINK = ld DLFLGS= -G +链接库? other.o 链接库的路径 -lm -lc 一些db需要的动态库
#ld -G -ldbsutil -lcnutil -ltxnutil -ldbopr ****.o -L$(SYSLIBP) -L$(XLIBP) -L$(LIBP) $(DBLIBP) -L$(TUXLIBP)
#-L$(XMLLIBP) -L$(LIBX) -lm -lc -lclntsh -lclient11 `cat $(ORACLE_HOME)/lib/sysliblist`
@$(DLINK) -o $@ $(DLFLGS) $(OBJS) $(LIBPS) $(UXLIBS) $(DBLIBS)
# @if [ $(OSTYPE) = aix ]; \
# then \
# $(DLINK) -o $@ $(DLFLGS) $(OBJS) $(LIBS) $(UXLIBS); \
# else \
# $(DLINK) -o `basename $@` $(DLFLGS) $(OBJS) $(LIBS); \
# $(MV) `basename $@` `dirname $@`; \
# fi
@$(RM) $(FEHOME)/mak/.mak.tmp
$(EXTARG): $(OBJS)
@$(ECHO) "Linking [$(EXTARG)] ..."
@$(CC) -o $@ $(EXFLGS) $(OBJS) $(LIBS) $(DBLIBS)
@$(RM) $(FEHOME)/mak/.mak.tmp
#TUXEDO服务编译过程
#OBJS 是从上层的makefile文件传进来的 ***.o
$(TUXTARG): $(OBJS)
$(ECHO) "buildserver [$(TUXTARG)] ..."
@CFLAGS="$(EXFLGS)" \
$(TUXBS) -o $@ -f "$(OBJS)" $(TUXSVCS) -s "$(TUXSERVICE)" -f "$(LIBS)" $(TUXRSMN)
# implicit
.SUFFIXES:
.SUFFIXES: .java .class .xc .ec .pc .sqC .sqc .cp .cpp .c .o
.xc.o:
$(ECHO) "Compiling [$@] ..."
@$(RM) $*$(DBFIX)
@$(CP) $*.xc $*$(DBFIX)
@if [ $(DBTYPE) = ora ]; \
then \
$(PC) lines=yes define=$(DBD) include=$(TUXINCP) include=$(INCP) include=$(JINCP) include=$(JMDINCP) include=$(LIBX) include=`dirname $@` code=ANSI_C iname=$*$(DBFIX); \
$(CC) -o $@ `cat $(FEHOME)/mak/.mak.tmp` $(CCFLGS) -c $*.c; \
$(RM) $*.lis; \
else \
$(EC) -e -ED$(DBD) $(INCPS) $*$(DBFIX); \
$(CC) -o $@ `cat $(FEHOME)/mak/.mak.tmp` $(CCFLGS) -c `basename $*`.c; \
$(RM) `basename $*`.c; \
fi
@$(RM) $*$(DBFIX) $*.c
.pc.o:
$(ECHO) "Compiling [$@] ..."
@$(PC) char_map=string lines=yes define=$(DBD) include=$(TUXINCP) include=$(INCP) include=$(JINCP) include=$(XMLINCP) include=$(JMDINCP) include=`dirname $@` code=ANSI_C iname=`basename $*`$(DBFIX)
@$(CD) `dirname $@` ; \
${CC} -o $@ `cat $(FEHOME)/mak/.mak.tmp` $(CCFLGS) -c $*.c
@$(RM) $*.lis $*.c
.ec.o:
$(ECHO) "Compiling [$@] ..."
@$(EC) -e -ED$(DBD) $(INCPS) $*$(DBFIX)
@$(CD) `dirname $@` ; \
$(CC) -o $@ `cat $(FEHOME)/mak/.mak.tmp` $(CCFLGS) -c `basename $*`.c; \
$(RM) `basename $*`.c
.sqc.o:
$(ECHO) "Compiling [$@] ..."
@$(RM) $*.bnd
@$(DB2) connect to $(DBNM)
@DB2INCLUDE=$(INCP) \
$(DB2) prep $< bindfile
@$(DB2) bind $*.bnd
@$(DB2) connect reset
@$(DB2) terminate
@$(CD) `dirname $@` ; \
$(CC) -o $@ `cat $(FEHOME)/mak/.mak.tmp` $(CCFLGS) -c `basename $*`.c
@$(RM) $*.bnd $*.c
.sqC.o:
$(ECHO) "Compiling [$@] ..."
@$(RM) $*.bnd
@$(DB2) connect to $(DBNM)
@DB2INCLUDE=$(INCP) \
$(DB2) prep $< bindfile
@$(DB2) bind $*.bnd
@$(DB2) connect reset
@$(DB2) terminate
@$(CD) `dirname $@` ; \
$(CXX) -o $@ `cat $(FEHOME)/mak/.mak.tmp` $(CCFLGS) -c `basename $*`.C
@$(RM) $*.bnd $*.C
.cp.o:
$(ECHO) "Compiling [$@] ..."
$(CPRE) -y $(INCPS) -O $*.c $*.cp
@$(CD) `dirname $@` ; \
$(CC) -o $@ `cat $(FEHOME)/mak/.mak.tmp` $(CCFLGS) -c `basename $*`.c
@$(RM) $*.c
.cpp.o:
$(ECHO) "Compiling [$@] ..."
@$(CD) `dirname $@` ; \
$(CXX) -o $@ `cat $(FEHOME)/mak/.mak.tmp` $(CXXFLGS) -c `basename $<`
.c.o:
$(ECHO) "Compiling [$@] ..."
@$(CD) `dirname $@`; \
$(CC) -o $@ `cat $(FEHOME)/mak/.mak.tmp` $(CCFLGS) -c `basename $<`
.java.class:
$(ECHO) "Compiling [$@] ..."
@$(CD) `dirname $@`; \
$(JAVAC) `basename $<`
# clearing object codes
clean: cleanup
@$(RM) $(SLTARG) $(DLTARG) $(EXTARG) $(TUXTARG)
cleanup:
@$(RM) $(OBJS)