Xiaobo Sun

          Eclipse-Unix http://umlfact.berlios.de/~s_xsun/

          Makefile example

          #libxml2 and glibmm are not neccessary to compile the main.cpp
          #macro
          libxml2:=../../libxml2
          libxml++:=..
          glibmm:=../../glibmm
          #adds include directives
          CC:=g++
          CCINCLUDE:= -I$(libxml++)/include/libxml++-2.6 -I$(libxml++)/lib/libxml++-2.6/include "
                  -I$(libxml2)/include -I$(glibmm)/include
          #linking
          LD:=g++
          LDSTDLIBS:= -L$(libxml++)/lib -L$(libxml2)/lib -L$(glibmm)/lib
          LDLIBS:= -lxml++-2.6
          LDLIBFLAGS:= -shared $(LDLIBS) $(LDSTDLIBS)
          LDEXEFLAGS:= $(LDSTDLIBS) $(LDLIBS)
          #extending library path
          #export VAR:=... means make it effective in the subprocess(Makefile)
          #export LD_LIBRARY_PATH:=... doesn't work because it's only effective in the subprocesses, not parentprocess(shell)
          #therefore the LD_RUN_PATH which allocates dynamic libs to the exe file must be set and export to take effect in the ld cmd
          LD_LIBRARY_PATH:=$(libxml++)/lib:$(LD_LIBRARY_PATH)
          export LD_RUN_PATH:=$(LD_LIBRARY_PATH)
          #list of source files for building the target
          SRC:= main.cpp
          OBJ:=$(patsubst %.cpp,%.o,$(filter %.cpp,$(SRC)))
          #targets
          # $^ everyone behinds the : , and $< first one behinds the :
          # $(OBJ): %.o: %.cpp is another common implicit rule is for the construction of .o files out of .cpp
          .PHONY: all clean
          all: $(OBJ)
                  $(LD) $(LDEXEFLAGS) $^ -o $@

          $(OBJ): %.o: %.cpp
                  $(CC) $(CCINCLUDE) -c $< -o $@
          clean:
                  rm -f $(OBJ) all *~ \.*.swp

          posted on 2008-10-09 13:55 Xiaobo Sun 閱讀(988) 評論(3)  編輯  收藏 所屬分類: C++

          評論

          # re: Makefile example 2008-10-09 13:57 Xiaobo Sun

          # macro
          GSOAPPATH=../../
          CCINCLUDE= -I$(GSOAPPATH)
          #CCINCLUDE+= -I$(RESPONSEPATH)
          CCFLAGS= -Wall -g
          OBJECTS= soapServiceRequestIFSOAPService.o soapC.o stdsoap2.o \
          soapServiceResponseIFSOAPProxy.o
          # targets
          all : server++ client++

          server++ : server.cpp $(OBJECTS)
          g++ $(CCFLAGS) $(CCINCLUDE) $^ -o $@

          client++ : client.cpp soapC.o stdsoap2.o soapServiceResponseIFSOAPProxy.o
          g++ $(CCFLAGS) $(CCINCLUDE) $^ -o $@

          soapServiceRequestIFSOAPService.o : soapServiceRequestIFSOAPService.cpp
          g++ -c $(CCINCLUDE) $^

          soapC.o : soapC.cpp
          g++ -c $(CCINCLUDE) $^

          stdsoap2.o : $(GSOAPPATH)stdsoap2.cpp
          g++ -c $(CCINCLUDE) $^

          soapServiceResponseIFSOAPProxy.o : soapServiceResponseIFSOAPProxy.cpp
          g++ -c $(CCINCLUDE) $^

          clean :
          rm -f server++ client++ *.o *~ *.swp

          .PHONY : all clean
            回復  更多評論   

          # re: Makefile example 2008-10-09 14:07 Xiaobo Sun

          看一個例子:
          objects = foo.o bar.o
          all: $(objects)
          $(objects): %.o: %.c
          $(CC) -c $(CFLAGS) $< -o $@
          上面的例子中,指明了我們的目標從$object中獲取,“%.o”表明要所有以“.o”結尾的
          目標,也就是“foo.o bar.o”,也就是變量$object集合的模式,而依賴模式“%.c”則取模
          式“%.o”的“%”,也就是“foo bar”,并為其加下“.c”的后綴,于是,我們的依賴目標
          就是“foo.c bar.c”。而命令中的“$<”和“$@”則是自動化變量,“$<”表示所有的依賴
          目標集(也就是“foo.c bar.c”),“$@”表示目標集(也就是“foo.o bar.o”)。于是,
          上面的規則展開后等價于下面的規則:
          foo.o : foo.c
          $(CC) -c $(CFLAGS) foo.c -o foo.o
          bar.o : bar.c
          $(CC) -c $(CFLAGS) bar.c -o bar.o
          試想,如果我們的“%.o”有幾百個,那種我們只要用這種很簡單的“靜態模式規則”就
          可以寫完一堆規則,實在是太有效率了  回復  更多評論   

          # re: Makefile example 2008-10-09 15:08 Xiaobo Sun

          如果你要傳遞變量到下級Makefile中,那么你可以使用這樣的聲明:
          export <variable ...>;

          export variable := value
          其等價于:
          variable := value
          export variable

          export variable += value
          其等價于:
          variable += value
          export variable  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2008年10月>
          2829301234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          導航

          統計

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 梅河口市| 泰来县| 谢通门县| 青浦区| 长白| 蓬溪县| 泰和县| 泽普县| 静安区| 黄石市| 天镇县| 阳春市| 武邑县| 吉林市| 象山县| 奉化市| 浮山县| 大庆市| 集安市| 轮台县| 宁晋县| 彭阳县| 青海省| 昌都县| 湘阴县| 密山市| 凤冈县| 宝清县| 玉龙| 信丰县| 昌吉市| 永安市| 孟连| 阳信县| 子洲县| 如东县| 祁门县| 遂宁市| 荣昌县| 罗甸县| 革吉县|