Debian Codegraph @

AspectC++/Makefile

raw ◀ ▶
1 Debian patch touch this file
1 # ******************************
2 # * S E T T I N G S *
3 # ******************************
4
5 # AspectC++ supports alternative frontends: Puma or Clang
6 # It can be configured the 'make FRONTEND=...'. Default is Clang.
7 export FRONTEND ?= Clang
8
9 # PUMA root
10 PUMA ?= ../Puma
11
12 # ACModel root
13 ACMODEL ?= ACModel
14
15 # LLVM config command
16 LLVMCONF ?= llvm-config
17
18 # libxml2 config command
19 XML2CONF ?= xml2-config
20
21 # default target
22 TARGET ?= linux-release
23
24 # include the PUMA configuration variables
25 # => set _TARGET, RELEASE, CFLAGS, CXXFLAGS, CPPFLAGS, etc.
26 include $(PUMA)/vars.mk
27
28 PLATFORM := $(shell echo $(_TARGET) | cut -d _ -f1)
29 ARCH := $(shell echo $(_TARGET) | cut -d _ -f2-)
30
31 # check whether we compile for Windows: TARGET-Variable starts with 'win'
32 ifneq ($(filter win%,$(TARGET)),)
33 WIN := yes
34 EXT := .exe
35 endif
36
37 # libxml2 settings
38 LIBXML2_INC := $(shell $(XML2CONF) --cflags)
39 ifeq ($(PLATFORM),macos)
40 # Don't mess up the compiler's include hierarchy
41 SDKROOT := $(shell xcrun --show-sdk-path)
42 LIBXML2_INC := $(filterout -I$(SDKROOT)/usr/include, $(LIBXML2_INC))
43 endif
44 LIBXML2_INC := $(patsubst -I/%, -isystem /%, $(LIBXML2_INC))
45 LIBXML2_LIB := $(shell $(XML2CONF) --libs)
46
47 # Check Clang version and define all necessary symbols (LLVM_*)
48 ifneq ($(MAKECMDGOALS),clean)
49 ifeq ($(FRONTEND),Clang)
50 include config/clang.mk
51 endif
52 endif
53
54 # linker settings
55 export SHARED # if defined, sub-makes should see this setting, too
56
57 ifneq ($(PLATFORM),macos)
58 ifeq ($(SHARED),)
59 LDFLAGS += -static
60 endif
61 ifeq ($(FRONTEND),Puma)
62 LDFLAGS += -Wl,-Bstatic -L$(PUMA)/lib/$(TARGET) -lPuma
63 ifneq ($(SHARED),)
64 LDFLAGS += -Wl,-Bdynamic
65 endif
66 else # FRONTEND is Clang
67 LDFLAGS += -L$(PUMA)/lib/$(TARGET) -lMiniPuma
68 ifneq ($(SHARED),)
69 LDFLAGS += #-Wl,-Bdynamic
70 endif
71 endif
72 else
73 ifeq ($(FRONTEND),Puma)
74 LDFLAGS += -L$(PUMA)/lib/$(TARGET) -lPuma
75 else # FRONTEND is Clang
76 LDFLAGS += -L$(PUMA)/lib/$(TARGET) -lMiniPuma
77 endif
78 endif
79
80 LDFLAGS += $(LIBXML2_LIB)
81 ifneq ($(FRONTEND),Puma)
82 LDFLAGS += -lclangRewriteFrontend -lclangRewrite -lclangFrontend -lclangSerialization -lclangDriver -lclangParse -lclangSema -lclangAnalysis -lclangEdit -lclangAST -lclangLex -lclangBasic -lLLVMAsmParser -lLLVMMCParser -lLLVMBitReader -lLLVMTransformUtils -lLLVMCore -lLLVMMC -lLLVMOption -lLLVMSupport
•83 ifeq ($(filter-out 18 19 20 21 22 23 24, $(LLVM_MAJOR)),)
84 LDFLAGS += -lclangAPINotes -lclangSupport -lclangASTMatchers -lclangBasic # extra libs for clang-18/19
85 endif
86 ifneq ($(PLATFORM),macos)
87 # On the ARMEL platform we also need -latomic. This is a workaround for a gcc bug.
88 LDFLAGS += -Wl,--as-needed -latomic -Wl,--no-as-needed
89 # ... until here
90 # LDFLAGS += `$(LLVMCONF) --libs`
91 LDFLAGS += $(patsubst %,-Xlinker --wrap=%,$(LLVM_SYMBOLS))
92 else
93 # Mac OS X is special, we patch the clang libraries below.
94 LDFLAGS := libclangSema.o $(filter-out -lclangSema, $(LDFLAGS))
95 endif
96 LDFLAGS += `$(LLVMCONF) --ldflags`
97 # - Additional libraries ("--libs") needed
98 # - Starting with 4.0 "--system-libs" returns nothing if the debian clang package is used. "--link-static" forces
99 # "--system-libs" to return the system libs in all cases
100 LDFLAGS += $(shell $(LLVMCONF) --libs --system-libs --link-static)
101
102 # On Windows (MinGW) fix the linker flags; llvm-config is not perfect
103 # 1. replace libzstd.dll.a with a normal -l
104 # 2. add -lversion
105 ifeq ($(WIN),yes)
106 LDFLAGS := $(patsubst %/libzstd.dll.a, -lzstd, $(LDFLAGS)) -lversion
107 endif
108
109 # workaround for strange MacOS config from clang
110 ifeq ($(PLATFORM),macos)
111 LDFLAGS := $(filter-out -llibxml2.tbd, $(LDFLAGS))
112 endif
113 endif
114
115 # compiler settings
116 ifeq ($(WIN),yes)
117 RES := windres
118 RCFILES := win-ac++.rc
119 ifeq ($(SHARED),)
120 CPPFLAGS += -DLIBXML_STATIC # the MinGW libxml2 requires this; otherwise linker problems
121 endif
122 endif
123
124 CPPFLAGS += -I$(PUMA)/extern -I$(PUMA)/include $(LIBXML2_INC)
125 ifeq ($(FRONTEND),Puma)
126 CPPFLAGS += -DFRONTEND_PUMA
127 else
128 FILTEROUT :=
129 ifeq ($(RELEASE),debug)
130 # filter-out "-DNDEBUG" added by LLVMCONF, if LLVM is in built in release-mode
131 FILTEROUT := -DNDEBUG
132 endif
133 LLVM_CPPFLAGS := $(shell $(LLVMCONF) --cppflags)
134 ifeq ($(WIN),yes)
135 # llvm-config on Windows generates path name with '\' that mingw g++ can't handle properly
136 LLVM_CPPFLAGS := $(subst \,/,$(LLVM_CPPFLAGS))
137 endif
138 LLVM_CPPFLAGS := $(patsubst -I/%, -isystem /%, $(LLVM_CPPFLAGS))
139 CPPFLAGS += $(filter-out $(FILTEROUT),$(LLVM_CPPFLAGS))
140 CPPFLAGS += -DFRONTEND_CLANG
141 CXXFLAGS += -fno-rtti -Wno-strict-aliasing -Wno-nonnull # hide annoying warnings in Clang headers
142 # Clang >= 11 uses C++14 features; "c++14" does not work -> WIN32 not defined on Windows!
143 # clang >= 18 requires C++17
144 CXXFLAGS += -std=gnu++17
145 endif
146
147 # profiling
148 ifneq ($(GPROF),)
149 LDFLAGS := $(LDFLAGS) -lc_p -lm_p
150 CXXFLAGS += -pg
151 endif
152
153 ifneq ($(PROFILING),)
154 CPPFLAGS += -DPROFILING
155 endif
156
157 # use libacmodel
158 LDFLAGS += -L$(ACMODEL)/lib/$(TARGET) -lacmodel
159 ACMODELLIB := $(ACMODEL)/lib/$(TARGET)/libacmodel.a
160
161 # ******************************
162 # * S O U R C E S *
163 # ******************************
164
165 BINDIR := bin/$(TARGET)
166
167 #programm to compile
168 PROG := $(BINDIR)/ac++$(EXT)
169
170 # sources; front-end specific files for the wrong frontend are filtered out
171 CCSOURCES := $(wildcard *.cc)
172 ifeq ($(FRONTEND),Puma)
173 CCSOURCES := $(filter-out Clang%.cc, $(CCSOURCES))
174 else
175 CLANG_PATCHED_SOURCES := $(filter Clang-$(LLVM_VERSION)-%.cc, $(CCSOURCES))
176 CCSOURCES := $(filter-out Puma%.cc, $(CCSOURCES))
177 CCSOURCES := $(filter-out Clang-%.cc, $(CCSOURCES)) $(CLANG_PATCHED_SOURCES)
178 endif
179
180 OBJECTDIR := ObjFiles/$(TARGET)
181 OBJECTS := $(addprefix $(OBJECTDIR)/,$(CCSOURCES:.cc=.o) $(RCFILES:.rc=.o))
182
183 DEPDIR := DepFiles/$(TARGET)
184 DEPS := $(addprefix $(DEPDIR)/,$(CCSOURCES:.cc=.d))
185 # dependency file generation flags for g++; note that "=" is used instead of ":="
186 DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d
187 DEPFLAGS_SHOW := -MT <file.o> -MMD -MP -MF <file.d>
188
189 CONFIGDIR := config
190
191 DIRS := $(OBJECTDIR) $(DEPDIR) $(BINDIR)
192
193 # ******************************
194 # * E X A M P L E / T E S T *
195 # ******************************
196
197 # tool selection
198 export AC := $(shell pwd)/$(PROG)
199 export AG := $(shell pwd)/$(BINDIR)/ag++$(EXT)
200
201 MAKE ?= make
202
203 # ac++ settings for tests
204 ACFLAGS := -k -v 9
205
206 ACEXAMPLES = coverage helloworld modules profiling singleton threads
207
208
209 .PHONY: $(ACEXAMPLES)
210
211
212 # ******************************
213 # * T A R G E T S *
214 # ******************************
215
216 define _show_target
217 @echo "---"
218 @echo "Making AspectC++ for TARGET=$(TARGET)"
219 @echo " Compiler = $(CXX) $(DEPFLAGS_SHOW) $(CPPFLAGS) $(CXXFLAGS)"
220 @echo " Linker = $(CXX) $(CXXFLAGS) <objects> $(LDFLAGS)"
221 @echo "---"
222 endef
223
224 all:
225 @$(MAKE) -C ACModel
226 @$(call _show_target)
227 @$(MAKE) $(PROG)
228
229 #.NOTPARALLEL: all
230
231 strip: $(PROG)
232 @$(STRIP) $<
233
234 showtarget:
235 @$(call _show_target)
236
237 clean: testclean exampleclean
238 @$(MAKE) -C ACModel clean
239 @echo Making it clean.
240 @rm -rf core core.* *~ $(PROG) $(OBJECTDIR) $(DEPDIR) $(ERROR_FILE)
241
242 cleanall: doxygen-clean clean
243
244 test: $(PROG) testall
245
246 example: $(PROG) $(addsuffix .example_make, $(ACEXAMPLES))
247
248 examplerun: example $(addsuffix .example_run, $(ACEXAMPLES))
249
250 exampleclean:
251 @rm -rf examples/*-out
252 @rm -rf examples/*.acp
253 @rm -rf examples/*.acp.lock
254
255 doxygen:
256 @echo "Making AspectC++ documentation with doxygen"
257 @doxygen doc/doxygen.conf && echo "=> see doc/doxygen/html/index.html"
258
259 doxygen-clean:
260 @rm -rf doc/doxygen
261
262 .PHONY: all strip showtarget \
263 test clean cleanall example examplerun exampleclean \
264 doxygen doxygen-clean
265
266 # ******************************
267 # * R U L E S *
268 # ******************************
269
270 $(DIRS) :
271 @mkdir -p $@
272
273 $(PROG): $(OBJECTS) $(ACMODELLIB)
274 # For clang on macOS we create relinked objects with the patched symbols.
275 ifneq ($(FRONTEND),Puma)
276 ifeq ($(PLATFORM),macos)
277 @echo "Creating patched clang libraries ..."
278 @$(LD) -arch $(ARCH) -r `$(LLVMCONF) --libdir`/libclangSema.a -o libclangSema.o -all_load \
279 -macos_version_min $(shell otool -l `$(LLVMCONF) --libdir`/libclangSema.a | grep minos | sort -n | head -1 | cut -f3 -w) \
280 $(foreach SYM, $(LLVM_SYMBOLS_SEMA), -alias $(SYM) ___real$(SYM) -unexported_symbol $(SYM))
281 endif
282 endif
283 @echo "Linking $@."
284 @mkdir -p $(BINDIR)
285 @$(CXX) -o $@ $(CXXFLAGS) $^ $(LDFLAGS)
286
287 $(OBJECTDIR)/%.o : %.cc
288 @echo Making object file $@.
289 @mkdir -p $(OBJECTDIR) $(DEPDIR)
290 @$(CXX) $(DEPFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
291
292 # -Wold-style-cast to find classic C casts "a = (A*)b;"
293
294 ifeq ($(WIN),yes)
295 $(OBJECTDIR)/%.o : %.rc
296 @echo Compiling Windows resource file
297 @mkdir -p $(OBJECTDIR)
298 @$(RES) $(filter -D%,$(CPPFLAGS)) $< $@
299
300 endif
301
302 test%:
303 $(MAKE) -C tests -s $*
304
305 %.example_make: %
306 cd examples/$< ; \
307 $(AC) $(ACFLAGS) -I. -p . -d ../$<-out \
308 -r ../$<.acp ; \
309 cp Makefile ../$<-out/Makefile; \
310 cd ../$<-out; g++ -o $< *.cc -lpthread
311
312 %.example_run: %.example_make
313 @echo ""
314 @echo ---- Running $* ----
315 @cd examples/$*-out; `find . -type f -perm -700`
316
317 include $(wildcard $(DEPS))