-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
99 lines (77 loc) · 3.01 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#
# Unix/Linux makefile
# Abulhair Saparov
#
#
# List of source files
#
PCFG_INDUCTION_CPP_SRCS=pcfg_induction.cpp
PCFG_INDUCTION_DBG_OBJS=$(PCFG_INDUCTION_CPP_SRCS:.cpp=.debug.o)
PCFG_INDUCTION_OBJS=$(PCFG_INDUCTION_CPP_SRCS:.cpp=.release.o)
MATH_INDUCTION_CPP_SRCS=math_induction.cpp
MATH_INDUCTION_DBG_OBJS=$(MATH_INDUCTION_CPP_SRCS:.cpp=.debug.o)
MATH_INDUCTION_OBJS=$(MATH_INDUCTION_CPP_SRCS:.cpp=.release.o)
#
# Compile and link options
#
CPP=g++
cc-option = $(shell $(CPP) -Werror $(1) -c -x c /dev/null -o /dev/null 2>/dev/null; echo $$?)
LIBRARY_PKG_LIBS=
PKG_LIBS=-pthread
NO_AS_NEEDED=-Wl,--no-as-needed
ifeq ($(call cc-option, $(NO_AS_NEEDED)),0)
PKG_LIBS += $(NO_AS_NEEDED)
endif
GLIBC := $(word 2,$(shell getconf GNU_LIBC_VERSION 2>/dev/null))
ifeq "$(.SHELLSTATUS)" "0"
GLIBC_HAS_RT := $(shell expr $(GLIBC) \>= 2.17)
ifeq "$(GLIBC_HAS_RT)" "0"
LIBRARY_PKG_LIBS += -lrt
PKG_LIBS += -lrt
endif
endif
WARNING_FLAGS=-Wall -Wpedantic
override CPPFLAGS_DBG += $(WARNING_FLAGS) -I. -g -march=native -mtune=native -std=c++11
override CPPFLAGS += $(WARNING_FLAGS) -I. -Ofast -DNDEBUG -march=native -mtune=native -std=c++11 -fno-stack-protector
override LDFLAGS_DBG += -g $(LIB_PATHS) $(PKG_LIBS)
override LDFLAGS += $(LIB_PATHS) -fwhole-program $(PKG_LIBS)
#
# GNU Make: targets that don't build files
#
.PHONY: all debug clean distclean
#
# Make targets
#
all: pcfg_induction
debug: pcfg_induction_dbg
-include $(PCFG_INDUCTION_OBJS:.release.o=.release.d)
-include $(PCFG_INDUCTION_DBG_OBJS:.debug.o=.debug.d)
-include $(MATH_INDUCTION_OBJS:.release.o=.release.d)
-include $(MATH_INDUCTION_DBG_OBJS:.debug.o=.debug.d)
define make_dependencies
$(1) $(2) -c $(3).$(4) -o $(3).$(5).o
$(1) -MM $(2) $(3).$(4) > $(3).$(5).d
@mv -f $(3).$(5).d $(3).$(5).d.tmp
@sed -e 's|.*:|$(3).$(5).o:|' < $(3).$(5).d.tmp > $(3).$(5).d
@sed -e 's/.*://' -e 's/\\$$//' < $(3).$(5).d.tmp | fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $(3).$(5).d
@rm -f $(3).$(5).d.tmp
endef
%.release.o: %.cpp
$(call make_dependencies,$(CPP),$(CPPFLAGS),$*,cpp,release)
%.release.pic.o: %.cpp
$(call make_dependencies,$(CPP),$(CPPFLAGS),$*,cpp,release.pic)
%.debug.o: %.cpp
$(call make_dependencies,$(CPP),$(CPPFLAGS_DBG),$*,cpp,debug)
%.debug.pic.o: %.cpp
$(call make_dependencies,$(CPP),$(CPPFLAGS_DBG),$*,cpp,debug.pic)
pcfg_induction: $(LIBS) $(PCFG_INDUCTION_OBJS)
$(CPP) -o pcfg_induction $(CPPFLAGS) $(LDFLAGS) $(PCFG_INDUCTION_OBJS)
pcfg_induction_dbg: $(LIBS) $(PCFG_INDUCTION_DBG_OBJS)
$(CPP) -o pcfg_induction_dbg $(CPPFLAGS_DBG) $(LDFLAGS_DBG) $(PCFG_INDUCTION_DBG_OBJS)
math_induction: $(LIBS) $(MATH_INDUCTION_OBJS)
$(CPP) -o math_induction $(CPPFLAGS) $(LDFLAGS) $(MATH_INDUCTION_OBJS)
math_induction_dbg: $(LIBS) $(MATH_INDUCTION_DBG_OBJS)
$(CPP) -o math_induction_dbg $(CPPFLAGS_DBG) $(LDFLAGS_DBG) $(MATH_INDUCTION_DBG_OBJS)
clean:
${RM} -f *.o */*.o */*/*.o *.d */*.d */*/*.d pcfg_induction pcfg_induction.exe pcfg_induction_dbg pcfg_induction_dbg.exe math_induction math_induction.exe math_induction_dbg math_induction_dbg.exe $(LIBS)