-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
143 lines (106 loc) · 3.14 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#CPPFLAGS += -Werror -Wextra -Wall -pedantic -fsanitize=undefined,address
CPPFLAGS += -Werror -Wextra -Wall -pedantic
RANLIB := ranlib
build.dir := build/
abc-std-lib := $(build.dir)libabc.a
include config/ar
include config/cxx_and_llvm
include config/prefix
ABC := $(build.dir)abc/abc
ABCFLAGS := -I abc-include
CPPFLAGS += -Wno-unused-parameter -I `$(llvm-config) --includedir`
CXXFLAGS += `$(llvm-config) --cxxflags`
CFLAGS += `$(llvm-config) --cflags`
LDFLAGS += `$(llvm-config) --ldflags --system-libs --libs all`
CXXFLAGS += -std=c++20 -ftrapv
src.cpp := \
$(wildcard abc/*.cpp) \
$(wildcard ast/*.cpp) \
$(wildcard expr/*.cpp) \
$(wildcard gen/*.cpp) \
$(wildcard lexer/*.cpp) \
$(wildcard parser/*.cpp) \
$(wildcard symtab/*.cpp) \
$(wildcard type/*.cpp) \
$(wildcard util/*.cpp)
src.abc := \
$(wildcard abc-lib/*.abc)
src.o := \
$(patsubst %,$(build.dir)%,\
$(src.cpp:.cpp=.o)) \
$(patsubst %,$(build.dir)%,\
$(src.abc:.abc=.o))
src.d := \
$(src.o:.o=.d)
build.subdir := \
$(sort $(dir $(src.o)))
prg.cpp := \
$(wildcard abc/xtest*.cpp) abc/abc.cpp \
$(wildcard ast/xtest*.cpp) \
$(wildcard expr/xtest*.cpp) \
$(wildcard gen/xtest*.cpp) \
$(wildcard lexer/xtest*.cpp) \
$(wildcard parser/xtest*.cpp) \
$(wildcard symtab/xtest*.cpp) \
$(wildcard type/xtest*.cpp) \
$(wildcard util/xtest*.cpp)
prg.abc :=
lib.cpp := \
$(filter-out $(prg.cpp), $(src.cpp))
lib.abc := \
$(filter-out $(prg.abc), $(src.abc))
prg.cpp.o := \
$(patsubst %,$(build.dir)%,\
$(prg.cpp:.cpp=.o))
prg.abc.o := \
$(patsubst %,$(build.dir)%,\
$(prg.abc:.abc=.o))
prg.cpp.exe := \
$(patsubst %,$(build.dir)%,\
$(prg.cpp:.cpp=))
prg.abc.exe := \
$(patsubst %,$(build.dir)%,\
$(prg.abc:.abc=))
lib.cpp.o := \
$(patsubst %,$(build.dir)%,\
$(lib.cpp:.cpp=.o))
lib.abc.o := \
$(patsubst %,$(build.dir)%,\
$(lib.abc:.abc=.o))
$(build.dir)abc/abc.o : abc/abc.cpp \
$(build.dir)prefix \
$(build.dir)libdir \
$(build.dir)includedir \
| $(build.subdir)
$(COMPILE.cpp) -I. -o $@ -MT '$@' -MMD -MP $<
$(build.dir)%.o : %.cpp | $(build.subdir)
$(COMPILE.cpp) -I. -o $@ -MT '$@' -MMD -MP $<
$(build.dir)% : $(build.dir)%.o $(lib.cpp.o)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $^ $(LDFLAGS) $(TARGET_ARCH) -o $@
$(build.dir)%.o : %.abc $(ABC) | $(build.subdir) $(ABC)
$(ABC) -c $(ABCFLAGS) $< -o $@ -MF $(@:%.o=%.d) -MT '$@' -MD -MP
$(abc-std-lib)(%.o) : $(build.dir)%.o | $(build.dir)
$(AR) $(ARFLAGS) $@ $<
$(abc-std-lib) : $(abc-std-lib)($(lib.abc.o)) | $(lib.abc.o)
$(RANLIB) $@
#-- generate files: E.g. headers like inttypes.hdr
gen := $(build.dir)/inttypes.hdr
$(build.dir)/inttypes.hdr: $(build.dir)util/xtest_gen_inttypes_hdr
$(build.dir)/util/xtest_gen_inttypes_hdr > $@
%/: ; @mkdir -p $@
$(info PREFIX=$(PREFIX))
$(info LIBDIR=$(LIBDIR))
$(info INCLUDEDIR=$(INCLUDEDIR))
.DEFAULT_GOAL := all
.PHONY: all
all: $(ABC) $(abc-std-lib) $(prg.cpp.exe) $(lib.cpp.o) $(prg.cpp.o) $(gen)
.PHONY: install
install: $(ABC) $(abc-std-lib) | $(PREFIX)/bin/ $(LIBDIR) $(INCLUDEDIR)
cp abc-include/* $(INCLUDEDIR)
cp $(build.dir)/*.hdr $(INCLUDEDIR)
cp $(abc-std-lib) $(LIBDIR)
cp $(ABC) $(PREFIX)/bin/
.PHONY: clean
clean:
$(RM) -rf $(build.dir)
-include $(src.d)