-
Notifications
You must be signed in to change notification settings - Fork 41
/
Makefile
143 lines (117 loc) · 3.38 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
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
CC = gcc
CXX = g++
OUTDIR = ./bin
LIB_FILE = libropium.so
LIB_HEADER_FILE = ropium.hpp
BINDINGS_FILE = ropium.so
## Basic default flags
CFLAGS ?=
CXXFLAGS ?=
CXXFLAGS ?=
LDFLAGS ?=
LDLIBS ?=
LDLIBS += -lcapstone
## Flags for debug mode
DEBUG ?= 0
ifeq ($(DEBUG), 1)
CFLAGS += -g -O0
CXXFLAGS += -g -O0
LDFLAGS += -g
else
CFLAGS += -O2
CXXFLAGS += -O2 -Wno-narrowing
endif
## Bindings
BINDINGS ?= 1
ifeq ($(BINDINGS), 1)
CXXFLAGS += `python3-config --cflags` -DPYTHON_BINDINGS -Ibindings/python
BINDINGS_DIR = ./bindings
BINDINGS_SRCS = $(wildcard $(BINDINGS_DIR)/*.cpp)
BINDINGS_OBJS = $(BINDINGS_SRCS:.cpp=.o)
BINDINGS_RULE = bindings
LDLIBS += `python3-config --libs`
else
BINDINGS_RULE =
endif
SRCDIR=./libropium
## Final C++ flags
CXXFLAGS += -std=c++11 -fpermissive -fPIC -I $(SRCDIR)/include -I $(SRCDIR)/dependencies/murmur3 -Wno-write-strings -Wno-sign-compare -Wno-reorder
# Source files
SRCS=$(wildcard $(SRCDIR)/symbolic/*.cpp)
SRCS+=$(wildcard $(SRCDIR)/ir/*.cpp)
SRCS+=$(wildcard $(SRCDIR)/arch/*.cpp)
SRCS+=$(wildcard $(SRCDIR)/ropchain/*.cpp)
SRCS+=$(wildcard $(SRCDIR)/utils/*.cpp)
SRCS+=$(wildcard $(SRCDIR)/database/*.cpp)
SRCS+=$(wildcard $(SRCDIR)/compiler/*.cpp)
OBJS=$(SRCS:.cpp=.o)
TESTDIR = ./tests
TESTSRCS = $(wildcard $(TESTDIR)/*.cpp)
TESTOBJS = $(TESTSRCS:.cpp=.o)
DEPDIR = $(SRCDIR)/dependencies
DEPSRCS = $(DEPDIR)/murmur3/murmur3.c
DEPOBJS = $(DEPSRCS:.c=.o)
INCLUDEDIR = $(SRCDIR)/include
# Compile lib and tests
all: lib tests $(BINDINGS_RULE)
# librop
lib: $(OBJS) $(DEPOBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(OUTDIR)/$(LIB_FILE) -shared $(OBJS) $(DEPOBJS) $(LDLIBS)
# unit tests
tests: $(TESTOBJS) $(OBJS) $(DEPOBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(OUTDIR)/tests $(TESTOBJS) $(OBJS) $(DEPOBJS) $(LDLIBS)
# bindings
bindings: $(BINDINGS_OBJS) $(OBJS) $(DEPOBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(OUTDIR)/$(BINDINGS_FILE) -shared $(BINDINGS_OBJS) $(OBJS) $(DEPOBJS) $(LDLIBS)
# generic
%.o : %.cpp
$(CXX) $(CXXFLAGS) $(LDFLAGS) -c $< -o $@ $(LDLIBS)
%.o : %.c
$(CC) $(CFLAGS) $(LDFLAGS) -c $< -o $@ $(LDLIBS)
# Installation (assuming Linux system)
# If prefix not set, set default
ifeq ($(PREFIX),)
PREFIX = /usr
endif
INSTALL_MESSAGE_RULE=
# Check if lib and binding files exist
ifneq (,$(wildcard ./bin/$(LIB_FILE)))
INSTALL_LIB_RULE=install_lib
INSTALL_MESSAGE_RULE=print_install_message
else
INSTALL_LIB_RULE=
endif
ifneq (,$(wildcard ./bin/$(BINDINGS_FILE)))
INSTALL_BINDINGS_RULE=install_bindings
PYTHONDIR=$(shell python3 -m site --user-site)/
INSTALL_MESSAGE_RULE=print_install_message
else
INSTALL_BINDINGS_RULE=
endif
# make install command
install: $(INSTALL_LIB_RULE) $(INSTALL_BINDINGS_RULE) install_cli_tool $(INSTALL_MESSAGE_RULE)
install_lib:
install -d $(DESTDIR)$(PREFIX)/lib/
install -D $(OUTDIR)/$(LIB_FILE) $(DESTDIR)$(PREFIX)/lib/
install -d $(DESTDIR)$(PREFIX)/include/
install -D $(INCLUDEDIR)/$(LIB_HEADER_FILE) $(DESTDIR)$(PREFIX)/include/
install_bindings:
install -d $(PYTHONDIR)
install -D $(OUTDIR)/$(BINDINGS_FILE) $(PYTHONDIR)
install_cli_tool:
install -d $(DESTDIR)$(PREFIX)/bin/
install -D cli-tool/ropium $(DESTDIR)$(PREFIX)/bin/
print_install_message:
@echo "\nROPium was successfully installed."
# make test command
test:
$(OUTDIR)/tests
# cleaning
cleanall: clean
clean:
rm -f $(OBJS)
rm -f $(DEPOBJS)
rm -f $(TESTOBJS)
rm -f $(BINDINGS_OBJS)
rm -f `find . -type f -name "*.gch"`
rm -f $(OUTDIR)/*