Last issue:
Simple and smart source file makefile
Download: http://download.csdn.net/detail/wxqee/4377256
This includes the simple and intelligent source file makefile for searching and the code for this simple and intelligent source file makefile (bin or lib can be expanded at will.
After one day, I wrote a template. The expected scenario is as follows:
In the same project, you need to compile an executable file named appdemo, which depends on another dynamic library named helloworld in this project.
In addition, the source code of the appdemo and helloworld libraries is stored in their respective directories.
What should we do at this time? Let's look at the template layout:
Xiwang @ Ubuntu :~ /Dev/appdemo $ tree
. | --
APP <-- directory for storing the appdemo source code| --
Makefile | '-- Main. cpp | --
Hellolib <-- directory for storing the source code of the helloworld Library| -- Helloworld. cpp | -- helloworld. H | '--
Makefile | --
Makefile | --
Build_bin.mk '--
Build_lib.mk
2 directories, 8 files
The makefile in the root directory controls the compilation of sub-items. build_bin.mk and build_lib.mk are the template for compiling bin or Lib, in this way, you can set some names and cxxflags in the sub-project to compile the source files of the current sub-project. Of course, dependencies between sub-projects (who compiled who, who compiled after) are displayed in the root directory and are not optimized.
File: makefile
# Makefile, 2012-06-15 T1738.PHONY: all cleanall: make -C HelloLibmake -C Appclean:make clean -C HelloLibmake clean -C App
File: build_bin.mk
# build_bin.mk, 2012-06-16 T1928# FoldersSRC_DIR = .BIN = $(NAME)OBJS = $(patsubst %.cpp,%.o,$(wildcard $(SRC_DIR)/*.cpp)).PHONY: all cleanall: $(BIN)$(BIN): $(OBJS)$(CXX) $(CPPFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)%.o: %.cpp$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $^ -o $@clean:$(RM) $(OBJS) $(BIN)
File: APP/makefile
# Makefile, 2012-06-16 T1932## This's a demo makefile using model build_bin.mk to build app, with source# source code in this folder.# # Require ../build_bin.mkNAME = AppDemoVERSION = 1.0.0RELEASE = 01# FlagsCXXFLAGS = -WallCXXFLAGS += -I. -I$(HELLODIR)CPPFLAGS = -D_DEBUGLDFLAGS = -L. -L$(HELLODIR) #<! set folder of helloworld libraryLIBS = -lhelloworld #<! load library helloworld# FoldersHELLODIR = ../HelloLib# END ----------------------------------include ../build_bin.mk
File: build_lib.mk
# build_lib.mk, 2012-06-16 T1928# FoldersSRC_DIR = .BIN = lib$(NAME).soOBJS = $(patsubst %.cpp,%.o,$(wildcard $(SRC_DIR)/*.cpp))CXXFLAGS += -fPIC.PHONY: all cleanall: $(BIN)$(BIN): $(OBJS)$(CXX) $(CPPFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS) -shared%.o: %.cpp$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $^ -o $@clean:$(RM) $(OBJS) $(BIN)
File: hellolib/makefile
# Makefile, 2012-06-16 T1932## This's a demo makefile using model build_bin.mk to build app, with source# source code in this folder.# # Require ../build_bin.mkNAME = AppDemoVERSION = 1.0.0RELEASE = 01# FlagsCXXFLAGS = -WallCXXFLAGS += -I. -I$(HELLODIR)CPPFLAGS = -D_DEBUGLDFLAGS = -L. -L$(HELLODIR) #<! set folder of helloworld libraryLIBS = -lhelloworld #<! load library helloworld# FoldersHELLODIR = ../HelloLib# END ----------------------------------include ../build_bin.mk