Usage of pmake
来源:互联网 发布:lego街景 知乎 编辑:程序博客网 时间:2024/05/22 00:43
Introduction
Pmake is a program designed to simplify themaintenance of other programs. Its input is a list of specifications as to thefiles upon which programs and other files depend. mkdep, a program to constructMakefile dependency lists, is also included.
This doc is not to introduce how to usepmake in detail. The goal of this doc is to introduce how to use the pmaketemplates which under /usr/share/mk. For moredetail, refer to /usr/share/mk/bsd.README.
Mk Template Files
The following mk templates are very usefulwhen you create your project. In this doc, we will deep into them.
bsd.subdir.mk - targets for building subdirectories
bsd.lib.mk -support for building libraries
bsd.prog.mk - building programs from source files
Server Common Targets for three mks:
all:
build the program and its manual page
clean:
remove the program, any object files and the files a.out,
Errs, errs, mklog, and ${PROG}.core.
cleandir:
remove all of the files removed by the target clean, as
well as .depend, tags, and any manualpages.
depend:
make the dependencies for the source files, and store
them in the file .depend.
install:
install the program and its manual pages; if the Makefile
does not itself define the target install, thetargets
beforeinstall and afterinstall may also be used to cause
actions immediately before and after the install target
is executed.
lint:
run lint on the source files
tags:
create a tags file for the source files.
1. Target: all, clean. depend andinstall are often used in our project.
2. Using “.include”to include any files into your makefile, such as “.include<bsd.subdir.mk>”, “../Makefile.env” and so on.
3. <bsd.lib.mk> and <bsd.prog.mk>include the file named "../Makefile.inc"if it exists, as well as the include file <bsd.man.mk>.
4. It's fairly difficult to makethe BSD .mk files work when you're building multiple programs in a singledirectory. It's a lot easier split up the programs than to deal with theproblem. In this doc we introduce two way to build multiple programs in asingle directory..
5. The variable DESTDIR works when you want to install. It's not set anywhere but will change thetree where the file gets installed. Like: pmake DESTDIR=/home/yourdir/install [-fMakefile] install
Make Command
Make command format:
all: one two # file one and two will be made first!
Gcc**** # multi shell commands can follow onetarget.
Make –f Makefile.a #The command will be execute in order.
Chmod777 path
Othercommand…..
Note:
1. Any target can depend on someother files, such as *.c, *.cpp, *.o, lib and binary. These depended files willbe made first before making the target.
2. One target can follow multishell commands. These command swill be executed in order.
bsd.subdir.mk
Usage: Define which subdirs you want tomake in variable SUBDIR.
For all of the directories listed in thevariable SUBDIR, the specified directory will be visited and the target made. Thedefault targets are Server Common Targets.
Example
===================================
MYDIR= toolbox app # internal variable
SUBDIR= TestLib TestLib/demo ${MYDOR}
.include <bsd.subdir.mk>
# DO NOT DELETE
====================================
bsd.lib.mk
<bsd.lib.mk> has support for buildinglibraries, such as *.a, *.so, *.po. Note: profiled libraries(*.po) are built bydefault.
Common Variable
LIB à define the lib your want to build
SRCS à lib’s source files
CFLAGS à define the include dir, which areused to search include files
[ LDFLAGS à define the libs dir, which are used to search libs]
[ LDADD à define the libs you want to link/Additional loader objects]
NOMAN à not to build manual page
INTERNALLIB à internal lib(??)
NO_PROFILE à not to build *.po lib
Example
====================================
LIB = test
SRCS = test.cc
NOMAN=
NO_PROFILE=
INTERNALLIB=
.include "../Makefile.env"
CFLAGS+= -I../myutil
.include <bsd.lib.mk>
# DO NOT DELETE
====================================
bsd.prog.mk
The include file <bsd.prog.mk>handles building programs from one or more source files, along with theirmanual pages.
Common Variable
PROG à name of the program to build; If not supplied, nothing is built.
PROG_CXX à using C++ lib; PROG_CXX overrides the value of PROG if PROG is alsoset.
SRCS à lib’s source files
PROGNAME à installation program name
CFLAGS à define the include dir, which areused to search include files
LDFLAGS à define the libs dir, which are used to search libs
LDADD à define the libs you want to link/Additional loader objects
DPADD à define additional dependencies forthe program. Note: can’t build lib automatically!
SUBDIR à A list of subdirectories that should be built as well. Like <bsd.subdir.mk>.
Example
Make one program:
====================================
PROG= unit-doe
SRCS= doeclient.cc TaskProtocol.pb.cc
NOMAN= # not need to make manual page.
NEED_GBUFFER= # include CFLAGS, LDFALGS and LDADD from “../Makfile.inc”
NEED_SACP=
CFLAGS= -Wall
.include <bsd.prog.mk>
====================================
Make multi programs way 1:
====================================
PROG= doeserver
SRCS= doeserver.cc ServerMixedApp.ccDoeTaskProcess.cc TasksOperation.cc TaskProtocol.pb.cc
BINDIR= /app/bin
BINDIRTOP= /bin
DOECLIENT=unit-doe
DOESERVER=doeserver
DOEPROXY=doeproxy
NOMAN= # not need tomake manual page.
NEED_IPOPT= # include CFLAGS,LDFALGS and LDADD “../Makfile.inc”
NEED_LITHO=
NEED_RESIST=
NEED_DOE=
NEED_SERVER_FRAME=
all: updatelibs # make updatelis before make default “doeserver”,then exec follow command
($(MAKE) -f Makefile.client ${.TARGET})
($(MAKE) -f Makefile.proxy ${.TARGET})
updatelibs: # make dependlibs
(cd../../util && $(MAKE)libutility.a)
(cd ../../SACP &&$(MAKE) libSACP.a)
(cd ../../doe/helper && $(MAKE))
(cd ../lens && $(MAKE) liblens.a)
install: # installation
install -d -m 755 ${DESTDIR}$(BINDIR)
install-m555 ${DOECLIENT} $(DESTDIR)$(BINDIR)
install -m555 ${DOESERVER} $(DESTDIR)$(BINDIR)
install -d -m 755 ${DESTDIR}$(BINDIRTOP)
install -m555${DOEPROXY} $(DESTDIR)$(BINDIRTOP)
.include <bsd.prog.mk> # put before cleantarget, or the deoserver can’t be clean!
clean: cleanall
cleanall:
($(MAKE) -f Makefile.client clean)
($(MAKE) -fMakefile.proxy clean)
====================================
Make multi programs way 2:
====================================
PROG= DoeUnitTest
SRCS= DoeUnitTest.cc
NOMAN = # not needto make manual page.
NEED_BRIONTEST = # include CFLAGS,LDFALGS and LDADD “../Makfile.inc”
TGT_LIST = DoeUnitTest sample1_unittestsample2_unittest # DoeUnitTest will be made by default, even if it don’t list here.
all: updatelibs $(TGT_LIST) # define all targetwe want to make.
clean:
rm -f *.o $(TGT_LIST)
updatelibs: # make dependlibs
(cd ../ && $(MAKE))
sample1_unittest : sample1.osample1_unittest.o # *.o will be made by default.
${CXX} ${CFLAGS} $(LDFLAGS) -o ${.TARGET} sample1.o sample1_unittest.o${LDADD}
sample2_unittest : sample2_unittest.o
${CXX} ${CFLAGS} $(LDFLAGS) -o ${.TARGET} sample2_unittest.o ${LDADD}
.include <../../Makefile.env>
.include <bsd.prog.mk>
====================================
Make lib and programs:
====================================
LIB= retrieval # default maketarget
SRCS= PupilRetrieval.cppPupilRetrievalFrameStacks.cpp
NOMAN = # not need tomake manual page.
INTERNALLIB =
NEED_RENDER= # include CFLAGS,LDFALGS and LDADD “../Makfile.inc”
NEED_UTIL=
NEED_RESIST=
TGT_LIST = asmlpupiltool # define targetswill be made
all: libretrieval.a asmlpupiltool
clean:
rm -f *.o $(TGT_LIST) libretrieval.a
install:
@(install -m 555 asmlpupiltool ${DESTDIR}/app/bin/)
.include <bsd.lib.mk>
LDADD := -lfftw3f ${LDADD} -lodbc -lfetch -lgsl -llapack -lblas-lgslcblas -lexpat -lg2c-lstdc++ -lm
asmlpupiltool: asmlpupiltool.o
${CXX} ${LDFLAGS} -o ${.TARGET} asmlpupiltool.o ${LDADD}
====================================
Makefile Env File
In a large project, we have to deal withmuitl-platform, all kinds of third party lib and internal libs. Thus we candefine some common make env variables in a file, other makefile only need toinclude the env file to load all env variables.
Example
OS Env
====================================
OSTYPE!= uname –s # get OS, suchas Linux, Sun, FreeBSD and so on.
.if ${OSTYPE} == "Linux" # condition compile
SUBDIR+= tacloader tacmanager tacshlibtacutil leafutilsampler tacutilsampler
SUBDIR+= vspgen smo flaremapgen simdoeserver
.endif
=======================================
Third Party Env
=======================================
.ifdef NEED_SERVER_FRAME # define compilermacro
NEED_SACP= # enable compilermacro control variable, the macro must be defined after
NEED_GBUFFER=
CFLAGS+= -I${APP}/comm. # add additional include path
LDFLAGS+= -L${APP}/comm
LDADD+= -lcomm
.endif
.ifdef NEED_SACP #these code mustdefine before “LDADD+= -lutility…”. See Note 4).
CFLAGS+= -I${TOPDIR}/SACP
LDFLAGS+= -L${TOPDIR}/SACP
LDADD+= -lSACP
.endif
#============= NOTE: define NEED_XXXX abovethis line ============
# Because our lib will depend on some thirdparty lib and utility lib!
CFLAGS+= -I${UTIL}
LDFLAGS+= -L${UTIL} -L${THIRD_PARTY}/opt
LDADD+= -lutility -Wl,-Bstatic -larpack-Wl,-Bdynamic -lcrypto -ltiff -ljpeg -lexpat -lpam -lopt
.ifdef NEED_GBUFFER # third party lib should be put after ourlibs.
CFLAGS+= -I${PROTOBUF_DIR}/include
LDFLAGS+= -L${PROTOBUF_DIR}/lib
LDADD+= -Wl,-Bstatic -lprotobuf -Wl,-Bdynamic
.endif
Note:
1) General speaking, the env filewill be included by other makefile automatically or manually.
2) Make tool interpret all kinds of variables inorder. It means that you should define variable beforeyou use it. Thus, you should define macro controlvariable before the macro body.
3) CFLAGS, LDFLAGS and LDADD willbe used in many places. Note: add first display first!
4) Gcc/g++ depend on the order oflibs. Only the former libs can depend on latter libs. Thus,when you define the env file, you must pay attention on the order of libs.
5) If some libs are circular reference, they must be put between -Wl,--start-groupand -Wl,--end-group.
6) –lutility will linklibutility.a or libutility.so, *.so first. If you want to enforce to link lib statically,please use -Wl,-Bstatic to do that. Put theselib you want to link statically after -Wl,-Bstatic and don’t forget to put -Wl,-Bdynamicto recover to link dynamically.
- Usage of pmake
- Usage of Pseudocode
- Usage of MFC CRectTracker
- Usage of awk
- effective usage of strtok
- Usage of Protocol Buffer
- Usage sample of SSL
- usage of >>>、>> and << operators
- Extensive usage of Make
- Usage of Oracle Block
- Usage of TKPROF
- Usage of Ftp
- Usage of Func delegate
- Usage of Vmstat
- Usage Of TRCA
- Usage of #pragma
- The usage of finalize()
- usage of the serialVersionUID
- WM_COPYDATA 进程间传递数据(以字符串为例)
- Flex写的一个工作流设计器原型
- 接口基类
- 线程同步(C# 编程指南)
- Fedora 4升级内核2.6.21并添加zc301摄像头驱动
- Usage of pmake
- C++中的异常(exception)
- 【转】技术总监谈好的程序员如何写代码
- 如何:对制造者线程和使用者线程进行同步(C# 编程指南)
- CSDN
- C#选择集合类需要考虑的问题
- Win7 NetBeans 乱码
- [zz]互联网行业十年大事记
- 析构函数(C# 编程指南)