Initial checkin of SAT solvers
[satlib.git] / glucose-syrup / mtl / template.mk
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
8 PWD        = $(shell pwd)
9 EXEC      ?= $(notdir $(PWD))
10
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)
15
16 PCOBJS     = $(addsuffix p,  $(COBJS))
17 DCOBJS     = $(addsuffix d,  $(COBJS))
18 RCOBJS     = $(addsuffix r,  $(COBJS))
19
20 #CXX        ?= /usr/gcc-/bin/g++-4.7.0
21 CXX       ?= g++
22 CFLAGS    ?= -Wall -Wno-parentheses -std=c++11
23 LFLAGS    ?= -Wall -lpthread 
24
25 COPTIMIZE ?= -O3
26
27 CFLAGS    += -I$(MROOT) -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS
28 LFLAGS    += -lz
29
30 .PHONY : s p d r rs clean 
31
32 s:      $(EXEC)
33 p:      $(EXEC)_profile
34 d:      $(EXEC)_debug
35 r:      $(EXEC)_release
36 rs:     $(EXEC)_static
37
38 libs:   lib$(LIB)_standard.a
39 libp:   lib$(LIB)_profile.a
40 libd:   lib$(LIB)_debug.a
41 libr:   lib$(LIB)_release.a
42
43 ## Compile options
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
48
49 ## Link options
50 $(EXEC):                LFLAGS += -g
51 $(EXEC)_profile:        LFLAGS += -g -pg
52 $(EXEC)_debug:          LFLAGS += -g
53 #$(EXEC)_release:       LFLAGS += ...
54 $(EXEC)_static:         LFLAGS += --static
55
56 ## Dependencies
57 $(EXEC):                $(COBJS)
58 $(EXEC)_profile:        $(PCOBJS)
59 $(EXEC)_debug:          $(DCOBJS)
60 $(EXEC)_release:        $(RCOBJS)
61 $(EXEC)_static:         $(RCOBJS)
62
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))
67
68
69 ## Build rule
70 %.o %.op %.od %.or:     %.cc
71         @echo Compiling: $(subst $(MROOT)/,,$@)
72         @$(CXX) $(CFLAGS) -c -o $@ $<
73
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 $@
78
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)) )"
82         @$(AR) -rcsv $@ $^
83
84 ## Library Soft Link rule:
85 libs libp libd libr:
86         @echo "Making Soft Link: $^ -> lib$(LIB).a"
87         @ln -sf $^ lib$(LIB).a
88
89 ## Clean rule
90 clean:
91         @rm -f $(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static \
92           $(COBJS) $(PCOBJS) $(DCOBJS) $(RCOBJS) *.core depend.mk 
93
94 ## Make dependencies
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; \
103               fi; \
104           done
105
106 -include $(MROOT)/mtl/config.mk
107 -include depend.mk