1## 2## Template makefile for Standard, Profile, Debug, Release, and Release-static versions 3## 4## eg: "make rs" for a statically linked release version. 5## "make d" for a debug version (no optimizations). 6## "make" for the standard version (optimized, but with debug information and assertions active) 7 8PWD = $(shell pwd) 9EXEC ?= $(notdir $(PWD)) 10 11CSRCS = $(wildcard $(PWD)/*.cc) 12DSRCS = $(foreach dir, $(DEPDIR), $(filter-out $(MROOT)/$(dir)/Main.cc, $(wildcard $(MROOT)/$(dir)/*.cc))) 13CHDRS = $(wildcard $(PWD)/*.h) 14COBJS = $(CSRCS:.cc=.o) $(DSRCS:.cc=.o) 15 16PCOBJS = $(addsuffix p, $(COBJS)) 17DCOBJS = $(addsuffix d, $(COBJS)) 18RCOBJS = $(addsuffix r, $(COBJS)) 19 20CXX ?= g++ 21CFLAGS += -Wall -Wno-parentheses -std=c++11 22LFLAGS += -Wall -lpthread 23 24COPTIMIZE ?= -O3 25 26CFLAGS += -I$(MROOT) -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS 27LFLAGS += -lz 28 29.PHONY : s p d r rs clean 30 31s: $(EXEC) 32p: $(EXEC)_profile 33d: $(EXEC)_debug 34r: $(EXEC)_release 35rs: $(EXEC)_static 36 37libs: lib$(LIB)_standard.a 38libp: lib$(LIB)_profile.a 39libd: lib$(LIB)_debug.a 40libr: lib$(LIB)_release.a 41 42## Compile options 43%.o: CFLAGS +=$(COPTIMIZE) -g -D DEBUG 44%.op: CFLAGS +=$(COPTIMIZE) -pg -g -D NDEBUG 45%.od: CFLAGS +=-O0 -g -D DEBUG 46%.or: CFLAGS +=$(COPTIMIZE) -g -D NDEBUG 47 48## Link options 49$(EXEC): LFLAGS += -g 50$(EXEC)_profile: LFLAGS += -g -pg 51$(EXEC)_debug: LFLAGS += -g 52#$(EXEC)_release: LFLAGS += ... 53$(EXEC)_static: LFLAGS += --static 54 55## Dependencies 56$(EXEC): $(COBJS) 57$(EXEC)_profile: $(PCOBJS) 58$(EXEC)_debug: $(DCOBJS) 59$(EXEC)_release: $(RCOBJS) 60$(EXEC)_static: $(RCOBJS) 61 62lib$(LIB)_standard.a: $(filter-out */Main.o, $(COBJS)) 63lib$(LIB)_profile.a: $(filter-out */Main.op, $(PCOBJS)) 64lib$(LIB)_debug.a: $(filter-out */Main.od, $(DCOBJS)) 65lib$(LIB)_release.a: $(filter-out */Main.or, $(RCOBJS)) 66 67 68## Build rule 69%.o %.op %.od %.or: %.cc 70 @echo Compiling: $(subst $(MROOT)/,,$@) 71 @$(CXX) $(CFLAGS) -c -o $@ $< 72 73## Linking rules (standard/profile/debug/release) 74$(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static: 75 @echo Linking: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )" 76 @$(CXX) $^ $(LFLAGS) -o $@ 77 78## Library rules (standard/profile/debug/release) 79lib$(LIB)_standard.a lib$(LIB)_profile.a lib$(LIB)_release.a lib$(LIB)_debug.a: 80 @echo Making library: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )" 81 @$(AR) -rcsv $@ $^ 82 83## Library Soft Link rule: 84libs libp libd libr: 85 @echo "Making Soft Link: $^ -> lib$(LIB).a" 86 @ln -sf $^ lib$(LIB).a 87 88## Clean rule 89allclean: clean 90 91 @rm -f ../simp/*.o ../simp/*.or ../simp/*.od ../core/*.o ../core/*.or ../core/*.od 92clean: 93 rm -f $(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static \ 94 $(COBJS) $(PCOBJS) $(DCOBJS) $(RCOBJS) *.core depend.mk 95 96## Make dependencies 97depend.mk: $(CSRCS) $(CHDRS) 98 @echo Making dependencies 99 @$(CXX) $(CFLAGS) -I$(MROOT) \ 100 $(CSRCS) -MM | sed 's|\(.*\):|$(PWD)/\1 $(PWD)/\1r $(PWD)/\1d $(PWD)/\1p:|' > depend.mk 101 @for dir in $(DEPDIR); do \ 102 if [ -r $(MROOT)/$${dir}/depend.mk ]; then \ 103 echo Depends on: $${dir}; \ 104 cat $(MROOT)/$${dir}/depend.mk >> depend.mk; \ 105 fi; \ 106 done 107 108-include $(MROOT)/mtl/config.mk 109-include depend.mk 110