#------------------------------------------------------------------------------- # Sample makefile for building the code samples. Read inline comments for # documentation. # # Eli Bendersky (eliben@gmail.com) # This code is in the public domain #------------------------------------------------------------------------------- # The following variables will likely need to be customized, depending on where # and how you built LLVM & Clang. They can be overridden by setting them on the # make command line: "make VARNAME=VALUE", etc. LLVM_VERSION := -3.8 # CXX has to be a fairly modern C++ compiler that supports C++11. gcc 4.8 and # higher or Clang 3.2 and higher are recommended. Best of all, if you build LLVM # from sources, use the same compiler you built LLVM with. CXX := clang++$(LLVM_VERSION) CXXFLAGS := -fno-rtti -g PLUGIN_CXXFLAGS := -fpic LLVM_CXXFLAGS := `llvm-config$(LLVM_VERSION) --cxxflags` LLVM_LDFLAGS := `llvm-config$(LLVM_VERSION) --ldflags --libs --system-libs` # Plugins shouldn't link LLVM and Clang libs statically, because they are # already linked into the main executable (opt or clang). LLVM doesn't like its # libs to be linked more than once because it uses globals for configuration # and plugin registration, and these trample over each other. LLVM_LDFLAGS_NOLIBS := `llvm-config$(LLVM_VERSION) --ldflags` PLUGIN_LDFLAGS := -shared CLANG_INCLUDES := -I/usr/lib/llvm$(LLVM_VERSION)/include # List of Clang libraries to link. The proper -L will be provided by the # call to llvm-config # Note that I'm using -Wl,--{start|end}-group around the Clang libs; this is # because there are circular dependencies that make the correct order difficult # to specify and maintain. The linker group options make the linking somewhat # slower, but IMHO they're still perfectly fine for tools that link with Clang. CLANG_LIBS := \ -Wl,--start-group \ -lclangAST \ -lclangAnalysis \ -lclangBasic \ -lclangDriver \ -lclangEdit \ -lclangFrontend \ -lclangFrontendTool \ -lclangLex \ -lclangParse \ -lclangSema \ -lclangEdit \ -lclangASTMatchers \ -lclangRewrite \ -lclangRewriteFrontend \ -lclangStaticAnalyzerFrontend \ -lclangStaticAnalyzerCheckers \ -lclangStaticAnalyzerCore \ -lclangSerialization \ -lclangToolingCore \ -lclangTooling \ -Wl,--end-group # Internal paths in this project: where to find sources, and where to put # build artifacts. SRC_DIR := src BUILDDIR := build .PHONY: all all: make_builddir \ emit_build_config \ $(BUILDDIR)/add_mc2_annotations .PHONY: test test: emit_build_config python3 test/all_tests.py .PHONY: emit_build_config emit_build_config: make_builddir @echo $(LLVM_BIN_PATH) > $(BUILDDIR)/_build_config .PHONY: make_builddir make_builddir: @test -d $(BUILDDIR) || mkdir $(BUILDDIR) $(BUILDDIR)/add_mc2_annotations: $(SRC_DIR)/add_mc2_annotations.cpp $(CXX) $(CXXFLAGS) $(LLVM_CXXFLAGS) $(CLANG_INCLUDES) $^ \ $(CLANG_LIBS) $(LLVM_LDFLAGS) -o $@ .PHONY: clean clean: rm -rf $(BUILDDIR)/* *.dot test/*.pyc test/__pycache__