forked from capstone-engine/capstone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
188 lines (161 loc) · 4.61 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
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
# Capstone Disassembler Engine
# By Nguyen Anh Quynh <[email protected]>, 2013>
include config.mk
ifeq ($(CROSS),)
CC ?= cc
AR ?= ar
RANLIB ?= ranlib
STRIP ?= strip
else
CC = $(CROSS)gcc
AR = $(CROSS)ar
RANLIB = $(CROSS)ranlib
STRIP = $(CROSS)strip
endif
CFLAGS += -fPIC -O3 -Wall -Iinclude
ifeq ($(USE_SYS_DYN_MEM),yes)
CFLAGS += -DUSE_SYS_DYN_MEM
endif
LDFLAGS += -shared
PREFIX ?= /usr
DESTDIR ?=
INCDIR = $(DESTDIR)$(PREFIX)/include
LIBDIR = $(DESTDIR)$(PREFIX)/lib
# on x86_64, we might have /usr/lib64 directory instead of /usr/lib
MACHINE := $(shell uname -m)
ifeq ($(MACHINE), x86_64)
ifeq (,$(wildcard $(LIBDIR)))
LIBDIR = $(DESTDIR)$(PREFIX)/lib64
else
LIBDIR = $(DESTDIR)$(PREFIX)/lib
endif
endif
INSTALL_BIN ?= install
INSTALL_DATA ?= $(INSTALL_BIN) -m0644
INSTALL_LIBRARY ?= $(INSTALL_BIN) -m0755
LIBNAME = capstone
LIBOBJ =
LIBOBJ += cs.o utils.o SStream.o MCInstrDesc.o MCRegisterInfo.o
ifneq (,$(findstring x86,$(CAPSTONE_ARCHS)))
CFLAGS += -DCAPSTONE_HAS_X86
LIBOBJ += arch/X86/X86DisassemblerDecoder.o
LIBOBJ += arch/X86/X86Disassembler.o
LIBOBJ += arch/X86/X86IntelInstPrinter.o
LIBOBJ += arch/X86/X86ATTInstPrinter.o
LIBOBJ += arch/X86/X86Mapping.o
LIBOBJ += arch/X86/X86Module.o
endif
ifneq (,$(findstring arm,$(CAPSTONE_ARCHS)))
CFLAGS += -DCAPSTONE_HAS_ARM
LIBOBJ += arch/ARM/ARMDisassembler.o
LIBOBJ += arch/ARM/ARMInstPrinter.o
LIBOBJ += arch/ARM/ARMMapping.o
LIBOBJ += arch/ARM/ARMModule.o
endif
ifneq (,$(findstring mips,$(CAPSTONE_ARCHS)))
CFLAGS += -DCAPSTONE_HAS_MIPS
LIBOBJ += arch/Mips/MipsDisassembler.o
LIBOBJ += arch/Mips/MipsInstPrinter.o
LIBOBJ += arch/Mips/MipsMapping.o
LIBOBJ += arch/Mips/MipsModule.o
endif
ifneq (,$(findstring powerpc,$(CAPSTONE_ARCHS)))
CFLAGS += -DCAPSTONE_HAS_POWERPC
LIBOBJ += arch/PowerPC/PPCDisassembler.o
LIBOBJ += arch/PowerPC/PPCInstPrinter.o
LIBOBJ += arch/PowerPC/PPCMapping.o
LIBOBJ += arch/PowerPC/PPCModule.o
endif
ifneq (,$(findstring aarch64,$(CAPSTONE_ARCHS)))
CFLAGS += -DCAPSTONE_HAS_ARM64
LIBOBJ += arch/AArch64/AArch64BaseInfo.o
LIBOBJ += arch/AArch64/AArch64Disassembler.o
LIBOBJ += arch/AArch64/AArch64InstPrinter.o
LIBOBJ += arch/AArch64/AArch64Mapping.o
LIBOBJ += arch/AArch64/AArch64Module.o
endif
LIBOBJ += MCInst.o
UNAME_S := $(shell uname -s)
# OSX?
ifeq ($(UNAME_S),Darwin)
EXT = dylib
AR_EXT = a
else
# Cygwin?
IS_CYGWIN := $(shell $(CC) -dumpmachine | grep -i cygwin | wc -l)
ifeq ($(IS_CYGWIN),1)
EXT = dll
AR_EXT = dll.a
# Cygwin doesn't like -fPIC
CFLAGS := $(CFLAGS:-fPIC=)
# On Windows we need the shared library to be executable
else
# mingw?
IS_MINGW := $(shell $(CC) --version | grep -i mingw | wc -l)
ifeq ($(IS_MINGW),1)
EXT = dll
AR_EXT = dll.a
# mingw doesn't like -fPIC either
CFLAGS := $(CFLAGS:-fPIC=)
# On Windows we need the shared library to be executable
else
# Linux, *BSD
EXT = so
AR_EXT = a
LDFLAGS += -Wl,-soname,$(LIBRARY)
endif
endif
endif
LIBRARY = lib$(LIBNAME).$(EXT)
ARCHIVE = lib$(LIBNAME).$(AR_EXT)
PKGCFGF = $(LIBNAME).pc
VERSION=$(shell echo `grep -e PKG_MAJOR -e PKG_MINOR CONFIG | grep -v = | awk '{print $$3}'` | awk '{print $$1"."$$2}')
.PHONY: all clean install uninstall
all: $(LIBRARY) $(ARCHIVE) $(PKGCFGF)
$(MAKE) -C tests
$(INSTALL_DATA) lib$(LIBNAME).$(EXT) tests
$(LIBRARY): $(LIBOBJ)
$(CC) $(LDFLAGS) $(LIBOBJ) -o $(LIBRARY)
$(ARCHIVE): $(LIBOBJ)
rm -f $(ARCHIVE)
$(AR) q $(ARCHIVE) $(LIBOBJ)
$(RANLIB) $(ARCHIVE)
$(PKGCFGF):
echo 'Name: capstone' > $(PKGCFGF)
echo 'Description: Capstone disassembler engine' >> $(PKGCFGF)
echo 'Version: $(VERSION)' >> $(PKGCFGF)
echo 'libdir=$(LIBDIR)' >> $(PKGCFGF)
echo 'includedir=$(PREFIX)/include/capstone' >> $(PKGCFGF)
echo 'archive=$${libdir}/libcapstone.a' >> $(PKGCFGF)
echo 'Libs: -L$${libdir} -lcapstone' >> $(PKGCFGF)
echo 'Cflags: -I$${includedir}' >> $(PKGCFGF)
install: $(PKGCFGF) $(ARCHIVE) $(LIBRARY)
mkdir -p $(LIBDIR)
$(INSTALL_LIBRARY) lib$(LIBNAME).$(EXT) $(LIBDIR)
$(INSTALL_DATA) lib$(LIBNAME).$(AR_EXT) $(LIBDIR)
mkdir -p $(INCDIR)/$(LIBNAME)
$(INSTALL_DATA) include/*.h $(INCDIR)/$(LIBNAME)
mkdir -p $(LIBDIR)/pkgconfig
$(INSTALL_DATA) $(PKGCFGF) $(LIBDIR)/pkgconfig/
uninstall:
rm -rf $(INCDIR)/$(LIBNAME)
rm -f $(LIBDIR)/lib$(LIBNAME).$(EXT)
rm -f $(LIBDIR)/lib$(LIBNAME).$(AR_EXT)
rm -f $(LIBDIR)/pkgconfig/$(LIBNAME).pc
clean:
rm -f $(LIBOBJ) lib$(LIBNAME).*
rm -f $(PKGCFGF)
$(MAKE) -C bindings/python clean
$(MAKE) -C bindings/java clean
$(MAKE) -C bindings/ocaml clean
$(MAKE) -C tests clean
TAG ?= HEAD
ifeq ($(TAG), HEAD)
DIST_VERSION = latest
else
DIST_VERSION = $(TAG)
endif
dist:
git archive --format=tar.gz --prefix=capstone-$(DIST_VERSION)/ $(TAG) > capstone-$(DIST_VERSION).tar.gz
.c.o:
$(CC) $(CFLAGS) -c $< -o $@