Simple and intelligent makefile for searching source files (bin or lib can be expanded at Will)

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.