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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
# ******************************
# * 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
# LLVM config command
LLVMCONF ?= llvm-config
# default target
TARGET ?= linux-release
# include the PUMA configuration variables
# => set _TARGET, RELEASE, CFLAGS, CXXFLAGS, CPPFLAGS, etc.
include $(PUMA)/vars.mk
# check whether we compile for Windows: TARGET-Variable starts with 'win'
ifneq ($(filter win%,$(TARGET)),)
WIN := yes
EXT := .exe
endif
# libxml2 settings
LIBXML2_INC := `xml2-config --cflags`
LIBXML2_LIB := `xml2-config --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 ($(_TARGET),macosx_x86_64)
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 ($(_TARGET),macosx_x86_64)
LDFLAGS += -lclangRewriteFrontend -lclangRewrite -lclangFrontend -lclangSerialization -lclangDriver -lclangParse -lclangSema -lclangAnalysis -lclangEdit -lclangAST -lclangLex -lclangBasic -lLLVMAsmParser -lLLVMMCParser -lLLVMBitReader -lLLVMTransformUtils -lLLVMCore -lLLVMMC -lLLVMOption -lLLVMSupport
LDFLAGS += $(patsubst %,-Xlinker --wrap=%,$(LLVM_SYMBOLS))
else
# Mac OS X is special, we patch the clang libraries below.
LDFLAGS += libclangSema.o libclangLex.o -lclangRewriteFrontend -lclangRewrite -lclangFrontend -lclangSerialization -lclangDriver -lclangParse -lclangAnalysis -lclangEdit -lclangAST -lclangBasic -lLLVMAsmParser -lLLVMMCParser -lLLVMBitReader -lLLVMTransformUtils -lLLVMCore -lLLVMMC -lLLVMOption -lLLVMSupport
endif
LDFLAGS += `$(LLVMCONF) --ldflags`
ifeq ($(filter 3.9%, $(LLVM_VERSION))$(filter 4.0%, $(LLVM_VERSION))$(filter 5.0%, $(LLVM_VERSION))$(filter 6.0%, $(LLVM_VERSION)),)
# if clang < 3.9:
LDFLAGS += `$(LLVMCONF) --system-libs` # in 3.6 ldflags doesn't contain the system libs anymore
else
# if clang >= 3.9:
# - 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 += `$(LLVMCONF) --libs --system-libs --link-static`
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=$(LLVM_INTERFACE)
CXXFLAGS += -fno-rtti -Wno-strict-aliasing # hide annoying warning in Clang header
CXXFLAGS += -std=gnu++11 # Clang uses C++11 features; "c++11" does not work -> WIN32 not defined on Windows!
endif
# profiling
ifneq ($(GPROF),)
LDFLAGS := $(LDFLAGS) -lc_p -lm_p
CXXFLAGS += -pg
endif
ifneq ($(PROFILING),)
CPPFLAGS += -DPROFILING
endif
# use libacmodel
LDFLAGS += -LACModel/lib/$(TARGET) -lacmodel
# ******************************
# * 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
CCSOURCES := $(filter-out Puma%.cc, $(CCSOURCES))
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)
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: libacmodel showtarget $(PROG)
#.NOTPARALLEL: all
strip: $(PROG)
@$(STRIP) $<
showtarget:
@echo "---"
@echo "Making AspectC++ for TARGET=$(TARGET)"
@echo " Compiler = $(CXX) $(CPPFLAGS) $(CXXFLAGS)"
@echo " Linker = $(CXX) $(CXXFLAGS) <objects> $(LDFLAGS)"
@echo "---"
clean: testclean exampleclean
@echo Making it clean.
@$(MAKE) -C ACModel 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 test clean cleanall example examplerun exampleclean \
showtarget doxygen doxygen-clean libacmodel
# ******************************
# * R U L E S *
# ******************************
$(DIRS) :
@mkdir -p $@
libacmodel :
@$(MAKE) -C ACModel
$(PROG): $(OBJECTS) | libacmodel
# For clang on macosx_x86_64 we create relinked objects with the patched symbols.
ifneq ($(FRONTEND),Puma)
ifeq ($(_TARGET),macosx_x86_64)
@echo "Creating patched clang libraries ..."
@$(LD) -r `$(LLVMCONF) --libdir`/libclangSema.a -o libclangSema.o -all_load \
$(foreach SYM, $(LLVM_SYMBOLS_SEMA), -alias $(SYM) ___real$(SYM) -unexported_symbol $(SYM))
@$(LD) -r `$(LLVMCONF) --libdir`/libclangLex.a -o libclangLex.o -all_load \
$(foreach SYM, $(LLVM_SYMBOLS_LEX), -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
|