Friday, 15 May 2015

make - Makefile template for large C++ project? -



make - Makefile template for large C++ project? -

i need makefile compile in current directory , recursively downwards tree, , preferably utilize compiler's dependency thing (-m, etc.) whenever type "make", little possible recompiled.

also, why not page 1 of makefile documentation?

while suggest using tools cmake or alike, understand easier or improve utilize plain old makefile.

here's makefile i've used on projects, creates dependency-files using gcc:

# project name (executable) project = demoproject # compiler cc = g++ # run options commandline_options = /dev/ttys0 # compiler options during compilation compile_options = -ansi -pedantic -wall #header include directories headers = #libraries linking libs = # dependency options dependency_options = -mm #-- not edit below line -- # subdirs search additional source files subdirs := $(shell ls -f | grep "\/" ) dirs := ./ $(subdirs) source_files := $(foreach d, $(dirs), $(wildcard $(d)*.cpp) ) # create object file of every cpp file objects = $(patsubst %.cpp, %.o, $(source_files)) # dependencies dependencies = $(patsubst %.cpp, %.d, $(source_files)) # create .d files %.d: %.cpp $(cc) $(dependency_options) $< -mt "$*.o $*.d" -mf $*.d # create $(project) default target all: $(dependencies) $(project) $(project): $(objects) $(cc) -o $(project) $(objects) $(libs) # include dependencies (if there any) ifneq "$(strip $(dependencies))" "" include $(dependencies) endif # compile every cpp file object %.o: %.cpp $(cc) -c $(compile_options) -o $@ $< $(headers) # build & run project run: $(project) ./$(project) $(commandline_options) # clean & debug .phony: makefile-debug makefile-debug: .phony: clean clean: rm -f $(project) $(objects) .phony: depclean depclean: rm -f $(dependencies) clean-all: clean depclean

c++ make

No comments:

Post a Comment