# ****************************** # * S E T T I N G S * # ****************************** # AspectC++ supports alternative frontends: Puma or Clang # It can be configured the 'make FRONTEND=...'. Default is Clang. export FRONTEND ?= Clang # PUMA root PUMA ?= ../Puma # ACModel root ACMODEL ?= ACModel # LLVM config command LLVMCONF ?= llvm-config # libxml2 config command XML2CONF ?= xml2-config # default target TARGET ?= linux-release # include the PUMA configuration variables # => set _TARGET, RELEASE, CFLAGS, CXXFLAGS, CPPFLAGS, etc. include $(PUMA)/vars.mk PLATFORM := $(shell echo $(_TARGET) | cut -d _ -f1) ARCH := $(shell echo $(_TARGET) | cut -d _ -f2-) # check whether we compile for Windows: TARGET-Variable starts with 'win' ifneq ($(filter win%,$(TARGET)),) WIN := yes EXT := .exe endif # libxml2 settings LIBXML2_INC := `$(XML2CONF) --cflags` LIBXML2_LIB := `$(XML2CONF) --libs` # Check Clang version and define all necessary symbols (LLVM_*) ifneq ($(MAKECMDGOALS),clean) ifeq ($(FRONTEND),Clang) include config/clang.mk endif endif # linker settings ifneq ($(PLATFORM),macos) ifeq ($(SHARED),) LDFLAGS += -static endif ifeq ($(FRONTEND),Puma) LDFLAGS += -Wl,-Bstatic -L$(PUMA)/lib/$(TARGET) -lPuma ifneq ($(SHARED),) LDFLAGS += -Wl,-Bdynamic endif else # FRONTEND is Clang LDFLAGS += -L$(PUMA)/lib/$(TARGET) -lMiniPuma ifneq ($(SHARED),) LDFLAGS += #-Wl,-Bdynamic endif endif else ifeq ($(FRONTEND),Puma) LDFLAGS += -L$(PUMA)/lib/$(TARGET) -lPuma else # FRONTEND is Clang LDFLAGS += -L$(PUMA)/lib/$(TARGET) -lMiniPuma endif endif LDFLAGS += $(LIBXML2_LIB) ifneq ($(FRONTEND),Puma) ifneq ($(PLATFORM),macos) LDFLAGS += -lclangRewriteFrontend -lclangRewrite -lclangFrontend -lclangSerialization -lclangDriver -lclangParse -lclangSema -lclangAnalysis -lclangEdit -lclangAST -lclangLex -lclangBasic -lLLVMAsmParser -lLLVMMCParser -lLLVMBitReader -lLLVMTransformUtils -lLLVMCore -lLLVMMC -lLLVMOption -lLLVMSupport ifeq ($(shell $(LLVMCONF) --version),18.1.3) LDFLAGS += -lclangAPINotes -lclangSupport -lclangASTMatchers -lclangBasic # extra libs for clang-18 endif # On the ARMEL platform we also need -latomic. This is a workaround for a gcc bug. LDFLAGS += -Wl,--as-needed -latomic -Wl,--no-as-needed # ... until here # LDFLAGS += `$(LLVMCONF) --libs` LDFLAGS += $(patsubst %,-Xlinker --wrap=%,$(LLVM_SYMBOLS)) else # Mac OS X is special, we patch the clang libraries below. LDFLAGS += libclangSema.o -lclangRewriteFrontend -lclangRewrite -lclangFrontend -lclangSerialization -lclangDriver -lclangParse -lclangAnalysis -lclangEdit -lclangAST -lclangLex -lclangBasic -lLLVMAsmParser -lLLVMMCParser -lLLVMBitReader -lLLVMTransformUtils -lLLVMCore -lLLVMMC -lLLVMOption -lLLVMSupport endif LDFLAGS += `$(LLVMCONF) --ldflags` # - Additional libraries ("--libs") needed # - Starting with 4.0 "--system-libs" returns nothing if the debian clang package is used. "--link-static" forces # "--system-libs" to return the system libs in all cases LDFLAGS += $(shell $(LLVMCONF) --libs --system-libs --link-static) # workaround for strange MacOS config from clang ifeq ($(PLATFORM),macos) LDFLAGS := $(filter-out -llibxml2.tbd, $(LDFLAGS)) endif endif # compiler settings ifeq ($(WIN),yes) RES := windres RCFILES := win-ac++.rc endif CPPFLAGS += -I$(PUMA)/extern -I$(PUMA)/include $(LIBXML2_INC) ifeq ($(FRONTEND),Puma) CPPFLAGS += -DFRONTEND_PUMA else FILTEROUT := ifeq ($(RELEASE),debug) # filter-out "-DNDEBUG" added by LLVMCONF, if LLVM is in built in release-mode FILTEROUT := -DNDEBUG endif LLVM_CPPFLAGS := $(shell $(LLVMCONF) --cppflags) ifeq ($(WIN),yes) # llvm-config on Windows generates path name with '\' that mingw g++ can't handle properly LLVM_CPPFLAGS := $(subst \,/,$(LLVM_CPPFLAGS)) endif CPPFLAGS += $(filter-out $(FILTEROUT),$(LLVM_CPPFLAGS)) CPPFLAGS += -DFRONTEND_CLANG CXXFLAGS += -fno-rtti -Wno-strict-aliasing -Wno-nonnull # hide annoying warnings in Clang headers # Clang >= 11 uses C++14 features; "c++14" does not work -> WIN32 not defined on Windows! # clang >= 18 requires C++17 CXXFLAGS += -std=gnu++17 endif # profiling ifneq ($(GPROF),) LDFLAGS := $(LDFLAGS) -lc_p -lm_p CXXFLAGS += -pg endif ifneq ($(PROFILING),) CPPFLAGS += -DPROFILING endif # use libacmodel LDFLAGS += -L$(ACMODEL)/lib/$(TARGET) -lacmodel ACMODELLIB := $(ACMODEL)/lib/$(TARGET)/libacmodel.a # ****************************** # * S O U R C E S * # ****************************** BINDIR := bin/$(TARGET) #programm to compile PROG := $(BINDIR)/ac++$(EXT) # sources; front-end specific files for the wrong frontend are filtered out CCSOURCES := $(wildcard *.cc) ifeq ($(FRONTEND),Puma) CCSOURCES := $(filter-out Clang%.cc, $(CCSOURCES)) else CLANG_PATCHED_SOURCES := $(filter Clang-$(LLVM_VERSION)-%.cc, $(CCSOURCES)) CCSOURCES := $(filter-out Puma%.cc, $(CCSOURCES)) CCSOURCES := $(filter-out Clang-%.cc, $(CCSOURCES)) $(CLANG_PATCHED_SOURCES) endif OBJECTDIR := ObjFiles/$(TARGET) OBJECTS := $(addprefix $(OBJECTDIR)/,$(CCSOURCES:.cc=.o) $(RCFILES:.rc=.o)) DEPDIR := DepFiles/$(TARGET) DEPS := $(addprefix $(DEPDIR)/,$(CCSOURCES:.cc=.d)) CONFIGDIR := config DIRS := $(OBJECTDIR) $(DEPDIR) $(BINDIR) # ****************************** # * E X A M P L E / T E S T * # ****************************** # tool selection export AC := $(shell pwd)/$(PROG) export AG := $(shell pwd)/$(BINDIR)/ag++$(EXT) MAKE ?= make # ac++ settings for tests ACFLAGS := -k -v 9 ACEXAMPLES = coverage helloworld modules profiling singleton threads .PHONY: $(ACEXAMPLES) # ****************************** # * T A R G E T S * # ****************************** all: @$(MAKE) -C ACModel @$(MAKE) showtarget @$(MAKE) $(PROG) #.NOTPARALLEL: all strip: $(PROG) @$(STRIP) $< showtarget: @echo "---" @echo "Making AspectC++ for TARGET=$(TARGET)" @echo " Compiler = $(CXX) $(CPPFLAGS) $(CXXFLAGS)" @echo " Linker = $(CXX) $(CXXFLAGS) $(LDFLAGS)" @echo "---" clean: testclean exampleclean @$(MAKE) -C ACModel clean @echo Making it clean. @rm -rf core core.* *~ $(PROG) $(OBJECTDIR) $(DEPDIR) $(ERROR_FILE) cleanall: doxygen-clean clean test: $(PROG)$(EXT) testall example: $(PROG)$(EXT) $(addsuffix .example_make, $(ACEXAMPLES)) examplerun: example $(addsuffix .example_run, $(ACEXAMPLES)) exampleclean: @rm -rf examples/*-out @rm -rf examples/*.acp doxygen: @echo "Making AspectC++ documentation with doxygen" @doxygen doc/doxygen.conf && echo "=> see doc/doxygen/html/index.html" doxygen-clean: @rm -rf doc/doxygen .PHONY: all strip showtarget \ test clean cleanall example examplerun exampleclean \ doxygen doxygen-clean # ****************************** # * R U L E S * # ****************************** $(DIRS) : @mkdir -p $@ $(PROG): $(OBJECTS) $(ACMODELLIB) # For clang on macOS we create relinked objects with the patched symbols. ifneq ($(FRONTEND),Puma) ifeq ($(PLATFORM),macos) @echo "Creating patched clang libraries ..." @$(LD) -arch $(ARCH) -r `$(LLVMCONF) --libdir`/libclangSema.a -o libclangSema.o -all_load \ $(foreach SYM, $(LLVM_SYMBOLS_SEMA), -alias $(SYM) ___real$(SYM) -unexported_symbol $(SYM)) endif endif @echo "Linking $@." @mkdir -p $(BINDIR) @$(CXX) -o $@ $(CXXFLAGS) $^ $(LDFLAGS) $(OBJECTDIR)/%.o : %.cc @echo Making dependency file $(DEPDIR)/$(<:%.cc=%.d). @mkdir -p $(DEPDIR) @$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MM -MP -MT $(OBJECTDIR)/$(<:%.cc=%.o) -MT $(DEPDIR)/$(<:%.cc=%.d) $< > $(DEPDIR)/$(<:%.cc=%.d) @echo Making object file $@. @mkdir -p $(OBJECTDIR) @$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< # -Wold-style-cast to find classic C casts "a = (A*)b;" ifeq ($(WIN),yes) $(OBJECTDIR)/%.o : %.rc @echo Compiling Windows resource file @mkdir -p $(OBJECTDIR) @$(RES) $(filter -D%,$(CPPFLAGS)) $< $@ endif test%: $(MAKE) -C tests -s $* %.example_make: % cd examples/$< ; \ $(AC) $(ACFLAGS) -I. -p . -d ../$<-out \ -r ../$<.acp ; \ cp Makefile ../$<-out/Makefile; \ cd ../$<-out; g++ -o $< *.cc -lpthread %.example_run: %.example_make @echo "" @echo ---- Running $* ---- @cd examples/$*-out; `find . -type f -perm -700` ifneq ($(MAKECMDGOALS),clean) -include $(DEPS) endif