-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
102 lines (75 loc) · 3 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
#----------------------------------------------------------
# Makefile for building an example LLVM pass "out-of-tree"
#----------------------------------------------------------
# Run 'make VERBOSE=1' to output executed commands
ifdef VERBOSE
VERB :=
else
VERB := @
endif
# Run 'make LLVM_VERSION=<V>' to set LLVM version to <V>
LLVM_VERSION := "7"
# Set C++ compiler and compiler flags used to compile the project
CXX := clang++-$(LLVM_VERSION)
CXXFLAGS := -fPIC
# Set linker and linker flags used to link the project's object files
LD := $(CXX)
LDFLAGS :=
# Path to the llvm-config tool
# If this tool resides in a global path, 'llvm-config' should suffice
LLVM_CONFIG := llvm-config-$(LLVM_VERSION)
# Compiler and linker flags needed to link against the LLVM libraries
LLVM_CXXFLAGS := `$(LLVM_CONFIG) --cxxflags`
LLVM_LDFLAGS_LIB := `$(LLVM_CONFIG) --ldflags --system-libs`
LLVM_LDFLAGS_APP := `$(LLVM_CONFIG) --ldflags --libs --system-libs`
# Additional include path to find LLVM headers
LLVM_INCLUDE := -I`$(LLVM_CONFIG) --includedir`
# Directories for the source and object files, as well as for the dependency files
DIR_SRC := src
DIR_OBJ := obj
DIR_DEP := dep
DIR_LIB := lib
# Target file
DIR_BIN := bin
TARGET_LIB := $(DIR_BIN)/passes.so
TARGET_APP := $(DIR_BIN)/app
# Get all source and object files
SRC_FILES := $(shell find $(DIR_SRC) -name "*.cpp")
SRC_FILES_LIB := $(shell find $(DIR_SRC)/$(DIR_LIB) -name "*.cpp")
OBJ_FILES := $(patsubst %.cpp, $(DIR_OBJ)/%.o, $(SRC_FILES:$(DIR_SRC)/%=%))
OBJ_FILES_LIB := $(patsubst %.cpp, $(DIR_OBJ)/%.o, $(SRC_FILES_LIB:$(DIR_SRC)/%=%))
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
# Print 'header' whenever make is issued
$(info --------------------------)
$(info Example LLVM analysis pass)
$(info --------------------------)
$(info )
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
.PHONY: all
all: $(TARGET_LIB) $(TARGET_APP)
$(TARGET_LIB): $(OBJ_FILES_LIB)
$(VERB)mkdir -p $(DIR_BIN)
@echo -e 'LD\t$@'
$(VERB)$(CXX) -shared $(LDFLAGS) $^ $(LLVM_LDFLAGS_LIB) -o $@
$(TARGET_APP): $(OBJ_FILES)
$(VERB)mkdir -p $(DIR_BIN)
@echo -e 'LD\t$@'
$(VERB)$(CXX) $(LDFLAGS) $^ $(LLVM_LDFLAGS_APP) -o $@
-include $(patsubst %.cpp, $(DIR_DEP)/%.md, $(SRC_FILES:$(DIR_SRC)/%=%))
$(DIR_OBJ)/%.o: $(DIR_SRC)/%.cpp
$(VERB)mkdir -p $(dir $@)
$(VERB)mkdir -p $(dir $(@:$(DIR_OBJ)/%=$(DIR_DEP)/%))
@echo -e 'DEP\t$<'
$(VERB)$(CXX) -I $(DIR_SRC) $(LLVM_CXXFLAGS) $(CXXFLAGS) $(LLVM_INCLUDE) -MM -MP -MT $@ -MT $(@:$(DIR_OBJ)/%.o=$(DIR_DEP)/%.md) $< > $(@:$(DIR_OBJ)/%.o=$(DIR_DEP)/%.md)
@echo -e 'CMPL\t$<'
$(VERB)$(CXX) -I $(DIR_SRC) $(LLVM_CXXFLAGS) $(CXXFLAGS) $(LLVM_INCLUDE) -c $< -o $@
.PHONY: clean
clean:
@echo -e 'RM\t $(DIR_OBJ)'
$(VERB)rm -rf $(DIR_OBJ)
@echo -e 'RM\t $(DIR_BIN)'
$(VERB)rm -rf $(DIR_BIN)
@echo -e 'RM\t $(DIR_DEP)'
$(VERB)rm -rf $(DIR_DEP)