2 ## Template makefile for Standard, Profile, Debug, Release, and Release-static versions
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)
9 EXEC ?= $(notdir $(PWD))
11 CSRCS = $(wildcard $(PWD)/*.cc)
12 DSRCS = $(foreach dir, $(DEPDIR), $(filter-out $(MROOT)/$(dir)/Main.cc, $(wildcard $(MROOT)/$(dir)/*.cc)))
13 CHDRS = $(wildcard $(PWD)/*.h)
14 COBJS = $(CSRCS:.cc=.o) $(DSRCS:.cc=.o)
16 PCOBJS = $(addsuffix p, $(COBJS))
17 DCOBJS = $(addsuffix d, $(COBJS))
18 RCOBJS = $(addsuffix r, $(COBJS))
20 #CXX ?= /usr/gcc-/bin/g++-4.7.0
22 CFLAGS ?= -Wall -Wno-parentheses -std=c++11
23 LFLAGS ?= -Wall -lpthread
27 CFLAGS += -I$(MROOT) -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS
30 .PHONY : s p d r rs clean
38 libs: lib$(LIB)_standard.a
39 libp: lib$(LIB)_profile.a
40 libd: lib$(LIB)_debug.a
41 libr: lib$(LIB)_release.a
44 %.o: CFLAGS +=$(COPTIMIZE) -g -D DEBUG
45 %.op: CFLAGS +=$(COPTIMIZE) -pg -g -D NDEBUG
46 %.od: CFLAGS +=-O0 -g -D DEBUG
47 %.or: CFLAGS +=$(COPTIMIZE) -g -D NDEBUG
51 $(EXEC)_profile: LFLAGS += -g -pg
52 $(EXEC)_debug: LFLAGS += -g
53 #$(EXEC)_release: LFLAGS += ...
54 $(EXEC)_static: LFLAGS += --static
58 $(EXEC)_profile: $(PCOBJS)
59 $(EXEC)_debug: $(DCOBJS)
60 $(EXEC)_release: $(RCOBJS)
61 $(EXEC)_static: $(RCOBJS)
63 lib$(LIB)_standard.a: $(filter-out */Main.o, $(COBJS))
64 lib$(LIB)_profile.a: $(filter-out */Main.op, $(PCOBJS))
65 lib$(LIB)_debug.a: $(filter-out */Main.od, $(DCOBJS))
66 lib$(LIB)_release.a: $(filter-out */Main.or, $(RCOBJS))
70 %.o %.op %.od %.or: %.cc
71 @echo Compiling: $(subst $(MROOT)/,,$@)
72 @$(CXX) $(CFLAGS) -c -o $@ $<
74 ## Linking rules (standard/profile/debug/release)
75 $(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static:
76 @echo Linking: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )"
77 @$(CXX) $^ $(LFLAGS) -o $@
79 ## Library rules (standard/profile/debug/release)
80 lib$(LIB)_standard.a lib$(LIB)_profile.a lib$(LIB)_release.a lib$(LIB)_debug.a:
81 @echo Making library: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )"
84 ## Library Soft Link rule:
86 @echo "Making Soft Link: $^ -> lib$(LIB).a"
87 @ln -sf $^ lib$(LIB).a
91 @rm -f $(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static \
92 $(COBJS) $(PCOBJS) $(DCOBJS) $(RCOBJS) *.core depend.mk
95 depend.mk: $(CSRCS) $(CHDRS)
96 @echo Making dependencies
97 @$(CXX) $(CFLAGS) -I$(MROOT) \
98 $(CSRCS) -MM | sed 's|\(.*\):|$(PWD)/\1 $(PWD)/\1r $(PWD)/\1d $(PWD)/\1p:|' > depend.mk
99 @for dir in $(DEPDIR); do \
100 if [ -r $(MROOT)/$${dir}/depend.mk ]; then \
101 echo Depends on: $${dir}; \
102 cat $(MROOT)/$${dir}/depend.mk >> depend.mk; \
106 -include $(MROOT)/mtl/config.mk