-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
99 lines (77 loc) · 2.93 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
#
DATALOG_TO_LAMBDA_CPP_SRCS=datalog_to_lambda.cpp
DATALOG_TO_LAMBDA_DBG_OBJS=$(DATALOG_TO_LAMBDA_CPP_SRCS:.cpp=.debug.o)
DATALOG_TO_LAMBDA_OBJS=$(DATALOG_TO_LAMBDA_CPP_SRCS:.cpp=.release.o)
PARSER_CPP_SRCS=parser.cpp
PARSER_DBG_OBJS=$(PARSER_CPP_SRCS:.cpp=.debug.o)
PARSER_OBJS=$(PARSER_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: datalog_to_lambda parser
debug: datalog_to_lambda_dbg parser_dbg
-include $(DATALOG_TO_LAMBDA_OBJS:.release.o=.release.d)
-include $(DATALOG_TO_LAMBDA_DBG_OBJS:.debug.o=.debug.d)
-include $(PARSER_OBJS:.release.o=.release.d)
-include $(PARSER_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)
datalog_to_lambda: $(LIBS) $(DATALOG_TO_LAMBDA_OBJS)
$(CPP) -o datalog_to_lambda $(CPPFLAGS) $(LDFLAGS) $(DATALOG_TO_LAMBDA_OBJS)
datalog_to_lambda_dbg: $(LIBS) $(DATALOG_TO_LAMBDA_DBG_OBJS)
$(CPP) -o datalog_to_lambda_dbg $(CPPFLAGS_DBG) $(LDFLAGS_DBG) $(DATALOG_TO_LAMBDA_DBG_OBJS)
parser: $(LIBS) $(PARSER_OBJS)
$(CPP) -o parser $(CPPFLAGS) $(LDFLAGS) $(PARSER_OBJS)
parser_dbg: $(LIBS) $(PARSER_DBG_OBJS)
$(CPP) -o parser_dbg $(CPPFLAGS_DBG) $(LDFLAGS_DBG) $(PARSER_DBG_OBJS)
clean:
${RM} -f *.o */*.o */*/*.o *.d */*.d */*/*.d datalog_to_lambda datalog_to_lambda.exe datalog_to_lambda_dbg datalog_to_lambda_dbg.exe parser parser_dbg parser.exe parser_dbg.exe $(LIBS)