-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
106 lines (83 loc) · 2.96 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
.RECIPEPREFIX +=
# For which architecture are we compiling? Default to host.
ARCH ?= $(shell uname -m | sed -e s/x86_64/x86/)
CC=gcc
CXX=g++
# Install directories
PREFIX?=/usr/local
INCLUDEDIR?=$(PREFIX)/include
LIBDIR?=$(PREFIX)/lib64
PKGLIBDIR?=$(LIBDIR)/pkgconfig
# Build settings
SRCDIR := src
ARCH_SRCDIR := src/$(ARCH)
INCLUDES := include src
# we'll need some architecture specific definitions
INCLUDES += src/$(ARCH)
# x86 will use xed for decode/encode of instructions
ifeq ($(ARCH),x86)
LIBS += libs/xed/obj/libxed.a
LIBS_INCLUDES += libs/xed/include/public/xed/
LIBS_INCLUDES += libs/xed/obj/
GEN_FILES += src/x86/gen/gen-defs.h
endif
GEN_CFLAGS = -O3 -MMD -MP -fPIC
GEN_CFLAGS += $(foreach dir,$(INCLUDES),-I$(dir))
GEN_CFLAGS += -Werror -Wall -Wextra
GEN_CFLAGS += -Wmissing-declarations -Wredundant-decls -Wpointer-arith
GEN_CFLAGS += -Wwrite-strings -Wswitch-default -Wmissing-include-dirs -Wundef
# generators don't rely on any libs
CFLAGS = $(GEN_CFLAGS) $(foreach dir,$(LIBS_INCLUDES),-I$(dir))
CONLYFLAGS := -std=gnu99
CXXFLAGS := -std=c++14
CSRC = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/util/*.c) $(wildcard $(ARCH_SRCDIR)/*.c)
CXXSRC = $(wildcard $(SRCDIR)/*.cpp) $(wildcard $(SRCDIR)/util/*.cpp) $(wildcard $(ARCH_SRCDIR)/*.cpp)
COBJ = $(CSRC:.c=.o)
CXXOBJ = $(CXXSRC:.cpp=.o)
DEP = $(CSRC:.c=.d) $(CXXSRC:.cpp=.d)
# Build targets
.PHONY: all
all: libdrob.so tests
.PHONY: debug
debug: CFLAGS += -DDEBUG -g
debug: all
libdrob.so: $(COBJ) $(CXXOBJ) $(LIBS)
$(CXX) -shared $^ -o $@
# in order to have the include directories for xed, build it first
libs/xed/include/public/xed/: libs/xed/obj/libxed.a
libs/xed/obj/: libs/xed/obj/libxed.a
libs/xed/obj/libxed.a:
git submodule update --init --recursive
cd libs/xed; ./mfile.py --extra-flags "-fPIC" --no-encoder --limit-strings --no-amd --no-mpx
# x86 definition generator
src/x86/gen/gen-defs: src/x86/gen/gen-defs.o
src/x86/gen/gen-defs.o: src/x86/gen/gen-defs.cpp
$(CXX) $(GEN_CFLAGS) $(CXXFLAGS) -o $@ -c $<
src/x86/gen/gen-defs.h: src/x86/gen/gen-defs
./src/x86/gen/gen-defs > $@
.PHONY: tests
tests: libdrob.so
$(MAKE) -C tests
%.o: %.c $(LIBS_INCLUDES) $(GEN_FILES)
$(CC) $(CFLAGS) $(CONLYFLAGS) -o $@ -c $<
%.o: %.cpp $(LIBS_INCLUDES) $(GEN_FILES)
$(CXX) $(CFLAGS) $(CXXFLAGS) -o $@ -c $<
libdrob.pc:
echo 'libdir=${DESTDIR}$(LIBDIR)' >> libdrob.pc
echo 'includedir=$(DESTDIR)$(LIBDIR)' >> libdrob.pc
cat libdrob.pc.in >> libdrob.pc
.PHONY: install
install: libdrob.so libdrob.pc
mkdir -p $(DESTDIR)$(LIBDIR)
cp libdrob.so $(DESTDIR)$(LIBDIR)/libdrob.so
mkdir -p $(DESTDIR)$(INCLUDEDIR)
cp include/drob.h $(DESTDIR)$(INCLUDEDIR)/drob.h
mkdir -p $(DESTDIR)$(PKGLIBDIR)
cp libdrob.pc $(DESTDIR)$(PKGLIBDIR)/libdrob.pc
ldconfig $(DESTDIR)$(LIBDIR)
.PHONY: clean
clean:
rm -f libdrob.so $(COBJ) $(CXXOBJ) $(DEP) $(GEN_FILES) libdrob.pc
rm -f src/x86/gen/gen-defs.o src/x86/gen/gen-defs.d src/x86/gen/gen-defs
$(MAKE) -C tests clean
-include $(DEP)