blob: cc42a789520980d9a1480a0d453669f1e9327bb3 [file] [log] [blame]
Nguyen Anh Quynh296a2312014-03-05 23:50:41 +08001# Capstone Disassembly Engine
Nguyen Anh Quynh1ed8bb62014-03-10 23:14:30 -07002# By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014
Nguyen Anh Quynh5e107ab2013-12-31 23:38:28 +08003
danghvu6f52bf92013-12-19 22:43:01 -06004include config.mk
Nguyen Anh Quynh3ff259c2014-03-07 17:11:18 +08005include pkgconfig.mk # package version
Nguyen Anh Quynh58a00472014-05-01 22:53:52 +08006include functions.mk
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08007
Ole André Vadla Ravnåsf536d402014-05-01 15:22:25 +02008# Verbose output?
9V ?= 0
10
11ifeq ($(PKG_EXTRA),)
12PKG_VERSION = $(PKG_MAJOR).$(PKG_MINOR)
13else
14PKG_VERSION = $(PKG_MAJOR).$(PKG_MINOR).$(PKG_EXTRA)
15endif
16
Nguyen Anh Quynhd80cede2014-01-16 21:07:59 +080017ifeq ($(CROSS),)
18CC ?= cc
19AR ?= ar
20RANLIB ?= ranlib
21STRIP ?= strip
22else
23CC = $(CROSS)gcc
24AR = $(CROSS)ar
25RANLIB = $(CROSS)ranlib
26STRIP = $(CROSS)strip
27endif
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080028
Nguyen Anh Quynh77af9fb2014-04-29 07:11:55 +080029ifneq (,$(findstring yes,$(CAPSTONE_DIET)))
30CFLAGS ?= -Os
31CFLAGS += -DCAPSTONE_DIET
32else
33CFLAGS ?= -O3
34endif
35
baguette86e84502014-08-17 20:59:05 +020036ifneq (,$(findstring yes,$(CAPSTONE_X86_ATT_DISABLE)))
37CFLAGS += -DCAPSTONE_X86_ATT_DISABLE
38endif
39
Nguyen Anh Quynh77af9fb2014-04-29 07:11:55 +080040CFLAGS += -fPIC -Wall -Iinclude
Nguyen Anh Quynh59492c22014-01-05 23:41:31 +080041
Nguyen Anh Quynhe31327d2014-04-29 14:25:15 +080042ifeq ($(CAPSTONE_USE_SYS_DYN_MEM),yes)
Nguyen Anh Quynh87a3f692014-05-10 19:26:32 +080043CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM
Nguyen Anh Quynh59492c22014-01-05 23:41:31 +080044endif
45
reverserbcf09f42015-04-09 18:28:19 +010046ifeq ($(CAPSTONE_HAS_OSXKERNEL), yes)
47CFLAGS += -DCAPSTONE_HAS_OSXKERNEL
Pbb8741bd2015-11-10 23:02:26 +010048SDKROOT ?= $(shell xcodebuild -version -sdk macosx Path)
49CFLAGS += -mmacosx-version-min=10.5 \
50 -isysroot$(SDKROOT) \
51 -I$(SDKROOT)/System/Library/Frameworks/Kernel.framework/Headers \
52 -mkernel \
53 -fno-builtin
reverserbcf09f42015-04-09 18:28:19 +010054endif
55
Ole André Vadla Ravnås6583f062014-07-04 23:09:19 +020056CFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
Ole André Vadla Ravnåsb202b912014-07-04 23:38:20 +020057LDFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
Ole André Vadla Ravnås6583f062014-07-04 23:09:19 +020058
pancake02cad6e2013-11-27 15:38:44 +010059PREFIX ?= /usr
60DESTDIR ?=
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +020061ifndef BUILDDIR
Nguyen Anh Quynh6ae472f2014-04-29 16:29:55 +080062BLDIR = .
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +020063OBJDIR = .
64else
Ole André Vadla Ravnås7a734392014-04-30 00:06:41 +020065BLDIR = $(abspath $(BUILDDIR))
Nguyen Anh Quynh6ae472f2014-04-29 16:29:55 +080066OBJDIR = $(BLDIR)/obj
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +020067endif
pancake02cad6e2013-11-27 15:38:44 +010068INCDIR = $(DESTDIR)$(PREFIX)/include
Nguyen Anh Quynh9f0e6c22013-12-25 22:47:28 +080069
Nguyen Anh Quynh235a2742014-03-29 21:09:35 +080070UNAME_S := $(shell uname -s)
Nguyen Anh Quynhad6cc982014-04-08 23:34:44 +080071
Nguyen Anh Quynh360bf1e2014-04-14 13:36:46 +080072LIBDIRARCH ?= lib
73# Uncomment the below line to installs x86_64 libs to lib64/ directory.
74# Or better, pass 'LIBDIRARCH=lib64' to 'make install/uninstall' via 'make.sh'.
75#LIBDIRARCH ?= lib64
76LIBDIR = $(DESTDIR)$(PREFIX)/$(LIBDIRARCH)
Nguyen Anh Quynh34603272016-10-10 22:54:16 +080077BINDIR = $(DESTDIR)$(PREFIX)/bin
pancake02cad6e2013-11-27 15:38:44 +010078
Oliver Pinterc5ecae52014-03-23 02:19:59 +010079LIBDATADIR = $(LIBDIR)
Kamil Rytarowski453b41a2015-07-27 04:03:48 +020080
81# Don't redefine $LIBDATADIR when global environment variable
82# USE_GENERIC_LIBDATADIR is set. This is used by the pkgsrc framework.
83
84ifndef USE_GENERIC_LIBDATADIR
Oliver Pinterc5ecae52014-03-23 02:19:59 +010085ifeq ($(UNAME_S), FreeBSD)
86LIBDATADIR = $(DESTDIR)$(PREFIX)/libdata
Oliver Pinterc5ecae52014-03-23 02:19:59 +010087endif
Oliver Pinter25efded2014-03-23 19:10:13 +010088ifeq ($(UNAME_S), DragonFly)
89LIBDATADIR = $(DESTDIR)$(PREFIX)/libdata
90endif
Kamil Rytarowski453b41a2015-07-27 04:03:48 +020091endif
Oliver Pinterc5ecae52014-03-23 02:19:59 +010092
Nguyen Anh Quynh64d40832014-01-17 20:55:21 +080093INSTALL_BIN ?= install
94INSTALL_DATA ?= $(INSTALL_BIN) -m0644
Oliver Pinterc5ecae52014-03-23 02:19:59 +010095INSTALL_LIB ?= $(INSTALL_BIN) -m0755
pancake02cad6e2013-11-27 15:38:44 +010096
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080097LIBNAME = capstone
pancakeca9f1b22013-12-06 17:03:41 +010098
Nguyen Anh Quynh42c6b1a2013-12-30 00:15:25 +080099
Nguyen Anh Quynh4a328ca2014-02-28 23:09:04 +0800100DEP_ARM =
101DEP_ARM += arch/ARM/ARMGenAsmWriter.inc
102DEP_ARM += arch/ARM/ARMGenDisassemblerTables.inc
103DEP_ARM += arch/ARM/ARMGenInstrInfo.inc
104DEP_ARM += arch/ARM/ARMGenRegisterInfo.inc
105DEP_ARM += arch/ARM/ARMGenSubtargetInfo.inc
106
107LIBOBJ_ARM =
Nguyen Anh Quynh9cc56a32014-01-15 16:01:55 +0800108ifneq (,$(findstring arm,$(CAPSTONE_ARCHS)))
109 CFLAGS += -DCAPSTONE_HAS_ARM
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +0200110 LIBOBJ_ARM += $(OBJDIR)/arch/ARM/ARMDisassembler.o
111 LIBOBJ_ARM += $(OBJDIR)/arch/ARM/ARMInstPrinter.o
112 LIBOBJ_ARM += $(OBJDIR)/arch/ARM/ARMMapping.o
113 LIBOBJ_ARM += $(OBJDIR)/arch/ARM/ARMModule.o
danghvu02db4882013-12-20 00:57:12 -0600114endif
Nguyen Anh Quynh42c6b1a2013-12-30 00:15:25 +0800115
Nguyen Anh Quynh4a328ca2014-02-28 23:09:04 +0800116DEP_ARM64 =
117DEP_ARM64 += arch/AArch64/AArch64GenAsmWriter.inc
118DEP_ARM64 += arch/AArch64/AArch64GenInstrInfo.inc
119DEP_ARM64 += arch/AArch64/AArch64GenSubtargetInfo.inc
120DEP_ARM64 += arch/AArch64/AArch64GenDisassemblerTables.inc
121DEP_ARM64 += arch/AArch64/AArch64GenRegisterInfo.inc
122
123LIBOBJ_ARM64 =
124ifneq (,$(findstring aarch64,$(CAPSTONE_ARCHS)))
125 CFLAGS += -DCAPSTONE_HAS_ARM64
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +0200126 LIBOBJ_ARM64 += $(OBJDIR)/arch/AArch64/AArch64BaseInfo.o
127 LIBOBJ_ARM64 += $(OBJDIR)/arch/AArch64/AArch64Disassembler.o
128 LIBOBJ_ARM64 += $(OBJDIR)/arch/AArch64/AArch64InstPrinter.o
129 LIBOBJ_ARM64 += $(OBJDIR)/arch/AArch64/AArch64Mapping.o
130 LIBOBJ_ARM64 += $(OBJDIR)/arch/AArch64/AArch64Module.o
Nguyen Anh Quynh4a328ca2014-02-28 23:09:04 +0800131endif
132
133
134DEP_MIPS =
135DEP_MIPS += arch/Mips/MipsGenAsmWriter.inc
136DEP_MIPS += arch/Mips/MipsGenDisassemblerTables.inc
137DEP_MIPS += arch/Mips/MipsGenInstrInfo.inc
138DEP_MIPS += arch/Mips/MipsGenRegisterInfo.inc
139DEP_MIPS += arch/Mips/MipsGenSubtargetInfo.inc
140
141LIBOBJ_MIPS =
142ifneq (,$(findstring mips,$(CAPSTONE_ARCHS)))
143 CFLAGS += -DCAPSTONE_HAS_MIPS
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +0200144 LIBOBJ_MIPS += $(OBJDIR)/arch/Mips/MipsDisassembler.o
145 LIBOBJ_MIPS += $(OBJDIR)/arch/Mips/MipsInstPrinter.o
146 LIBOBJ_MIPS += $(OBJDIR)/arch/Mips/MipsMapping.o
147 LIBOBJ_MIPS += $(OBJDIR)/arch/Mips/MipsModule.o
Nguyen Anh Quynh4a328ca2014-02-28 23:09:04 +0800148endif
149
150
151DEP_PPC =
152DEP_PPC += arch/PowerPC/PPCGenAsmWriter.inc
153DEP_PPC += arch/PowerPC/PPCGenInstrInfo.inc
154DEP_PPC += arch/PowerPC/PPCGenSubtargetInfo.inc
155DEP_PPC += arch/PowerPC/PPCGenDisassemblerTables.inc
156DEP_PPC += arch/PowerPC/PPCGenRegisterInfo.inc
157
158LIBOBJ_PPC =
159ifneq (,$(findstring powerpc,$(CAPSTONE_ARCHS)))
160 CFLAGS += -DCAPSTONE_HAS_POWERPC
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +0200161 LIBOBJ_PPC += $(OBJDIR)/arch/PowerPC/PPCDisassembler.o
162 LIBOBJ_PPC += $(OBJDIR)/arch/PowerPC/PPCInstPrinter.o
163 LIBOBJ_PPC += $(OBJDIR)/arch/PowerPC/PPCMapping.o
164 LIBOBJ_PPC += $(OBJDIR)/arch/PowerPC/PPCModule.o
Nguyen Anh Quynh4a328ca2014-02-28 23:09:04 +0800165endif
166
167
Nguyen Anh Quynh05e27132014-03-10 11:58:57 +0800168DEP_SPARC =
169DEP_SPARC += arch/Sparc/SparcGenAsmWriter.inc
170DEP_SPARC += arch/Sparc/SparcGenInstrInfo.inc
171DEP_SPARC += arch/Sparc/SparcGenSubtargetInfo.inc
172DEP_SPARC += arch/Sparc/SparcGenDisassemblerTables.inc
173DEP_SPARC += arch/Sparc/SparcGenRegisterInfo.inc
174
175LIBOBJ_SPARC =
176ifneq (,$(findstring sparc,$(CAPSTONE_ARCHS)))
177 CFLAGS += -DCAPSTONE_HAS_SPARC
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +0200178 LIBOBJ_SPARC += $(OBJDIR)/arch/Sparc/SparcDisassembler.o
179 LIBOBJ_SPARC += $(OBJDIR)/arch/Sparc/SparcInstPrinter.o
180 LIBOBJ_SPARC += $(OBJDIR)/arch/Sparc/SparcMapping.o
181 LIBOBJ_SPARC += $(OBJDIR)/arch/Sparc/SparcModule.o
Nguyen Anh Quynh05e27132014-03-10 11:58:57 +0800182endif
183
184
Nguyen Anh Quynh48a14ca2014-03-23 08:35:45 +0800185DEP_SYSZ =
186DEP_SYSZ += arch/SystemZ/SystemZGenAsmWriter.inc
187DEP_SYSZ += arch/SystemZ/SystemZGenInstrInfo.inc
188DEP_SYSZ += arch/SystemZ/SystemZGenSubtargetInfo.inc
189DEP_SYSZ += arch/SystemZ/SystemZGenDisassemblerTables.inc
190DEP_SYSZ += arch/SystemZ/SystemZGenRegisterInfo.inc
191
192LIBOBJ_SYSZ =
193ifneq (,$(findstring systemz,$(CAPSTONE_ARCHS)))
194 CFLAGS += -DCAPSTONE_HAS_SYSZ
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +0200195 LIBOBJ_SYSZ += $(OBJDIR)/arch/SystemZ/SystemZDisassembler.o
196 LIBOBJ_SYSZ += $(OBJDIR)/arch/SystemZ/SystemZInstPrinter.o
197 LIBOBJ_SYSZ += $(OBJDIR)/arch/SystemZ/SystemZMapping.o
198 LIBOBJ_SYSZ += $(OBJDIR)/arch/SystemZ/SystemZModule.o
199 LIBOBJ_SYSZ += $(OBJDIR)/arch/SystemZ/SystemZMCTargetDesc.o
Nguyen Anh Quynh48a14ca2014-03-23 08:35:45 +0800200endif
201
202
Nguyen Anh Quynh95181482014-03-25 23:20:41 +0800203# by default, we compile full X86 instruction sets
Nguyen Anh Quynh59b54892014-03-27 10:54:44 +0800204X86_REDUCE =
205ifneq (,$(findstring yes,$(CAPSTONE_X86_REDUCE)))
206X86_REDUCE = _reduce
Nguyen Anh Quynh81d930a2014-03-28 10:28:57 +0800207CFLAGS += -DCAPSTONE_X86_REDUCE -Os
Nguyen Anh Quynh95181482014-03-25 23:20:41 +0800208endif
209
Nguyen Anh Quynh4a328ca2014-02-28 23:09:04 +0800210DEP_X86 =
Nguyen Anh Quynh59b54892014-03-27 10:54:44 +0800211DEP_X86 += arch/X86/X86GenAsmWriter$(X86_REDUCE).inc
212DEP_X86 += arch/X86/X86GenAsmWriter1$(X86_REDUCE).inc
213DEP_X86 += arch/X86/X86GenDisassemblerTables$(X86_REDUCE).inc
214DEP_X86 += arch/X86/X86GenInstrInfo$(X86_REDUCE).inc
Nguyen Anh Quynh4a328ca2014-02-28 23:09:04 +0800215DEP_X86 += arch/X86/X86GenRegisterInfo.inc
216
217LIBOBJ_X86 =
218ifneq (,$(findstring x86,$(CAPSTONE_ARCHS)))
219 CFLAGS += -DCAPSTONE_HAS_X86
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +0200220 LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86DisassemblerDecoder.o
221 LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86Disassembler.o
222 LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86IntelInstPrinter.o
Nguyen Anh Quynh50689082014-05-14 12:26:53 +0800223# assembly syntax is irrelevant in Diet mode, when this info is suppressed
224ifeq (,$(findstring yes,$(CAPSTONE_DIET)))
baguette86e84502014-08-17 20:59:05 +0200225ifeq (,$(findstring yes,$(CAPSTONE_X86_ATT_DISABLE)))
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +0200226 LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86ATTInstPrinter.o
Nguyen Anh Quynh50689082014-05-14 12:26:53 +0800227endif
baguette86e84502014-08-17 20:59:05 +0200228endif
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +0200229 LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86Mapping.o
230 LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86Module.o
Nguyen Anh Quynh4a328ca2014-02-28 23:09:04 +0800231endif
232
Nguyen Anh Quynhc80d8402014-05-26 23:02:48 +0800233
234DEP_XCORE =
235DEP_XCORE += arch/XCore/XCoreGenAsmWriter.inc
236DEP_XCORE += arch/XCore/XCoreGenInstrInfo.inc
237DEP_XCORE += arch/XCore/XCoreGenDisassemblerTables.inc
238DEP_XCORE += arch/XCore/XCoreGenRegisterInfo.inc
239
240LIBOBJ_XCORE =
241ifneq (,$(findstring xcore,$(CAPSTONE_ARCHS)))
242 CFLAGS += -DCAPSTONE_HAS_XCORE
243 LIBOBJ_XCORE += $(OBJDIR)/arch/XCore/XCoreDisassembler.o
244 LIBOBJ_XCORE += $(OBJDIR)/arch/XCore/XCoreInstPrinter.o
245 LIBOBJ_XCORE += $(OBJDIR)/arch/XCore/XCoreMapping.o
246 LIBOBJ_XCORE += $(OBJDIR)/arch/XCore/XCoreModule.o
247endif
248
249
Nguyen Anh Quynh4a328ca2014-02-28 23:09:04 +0800250LIBOBJ =
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +0200251LIBOBJ += $(OBJDIR)/cs.o $(OBJDIR)/utils.o $(OBJDIR)/SStream.o $(OBJDIR)/MCInstrDesc.o $(OBJDIR)/MCRegisterInfo.o
Nguyen Anh Quynhc80d8402014-05-26 23:02:48 +0800252LIBOBJ += $(LIBOBJ_ARM) $(LIBOBJ_ARM64) $(LIBOBJ_MIPS) $(LIBOBJ_PPC) $(LIBOBJ_SPARC) $(LIBOBJ_SYSZ) $(LIBOBJ_X86) $(LIBOBJ_XCORE)
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +0200253LIBOBJ += $(OBJDIR)/MCInst.o
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800254
Nguyen Anh Quynh4a328ca2014-02-28 23:09:04 +0800255
Nguyen Anh Quynhaf0e9372014-04-12 23:10:46 +0800256PKGCFGDIR ?= $(LIBDATADIR)/pkgconfig
Nguyen Anh Quynh315f02d2014-03-25 06:43:19 +0800257API_MAJOR=$(shell echo `grep -e CS_API_MAJOR include/capstone.h | grep -v = | awk '{print $$3}'` | awk '{print $$1}')
Nguyen Anh Quynhc0c0d522014-03-17 17:31:33 +0800258VERSION_EXT =
Nguyen Anh Quynh8f856c72014-02-24 15:17:40 +0800259
Ron Pinzd0863842015-12-16 11:46:00 -0500260IS_APPLE := $(shell $(CC) -dM -E - < /dev/null | grep -cm 1 -e __apple_build_version__ -e __APPLE_CC__)
Ole André Vadla Ravnåsc20b0492014-05-01 14:14:57 +0200261ifeq ($(IS_APPLE),1)
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800262EXT = dylib
pancake26943332014-02-04 08:37:55 +0100263VERSION_EXT = $(API_MAJOR).$(EXT)
danghvue1c7a212014-05-14 02:13:36 -0500264$(LIBNAME)_LDFLAGS += -dynamiclib -install_name lib$(LIBNAME).$(VERSION_EXT) -current_version $(PKG_MAJOR).$(PKG_MINOR).$(PKG_EXTRA) -compatibility_version $(PKG_MAJOR).$(PKG_MINOR)
Nguyen Anh Quynh4ebdd212013-12-25 23:54:45 +0800265AR_EXT = a
Nguyen Anh Quynhe3606d92014-04-12 18:02:55 +0800266# Homebrew wants to make sure its formula does not disable FORTIFY_SOURCE
Nguyen Anh Quynhe31327d2014-04-29 14:25:15 +0800267# However, this is not really necessary because 'CAPSTONE_USE_SYS_DYN_MEM=yes' by default
Nguyen Anh Quynh189e83a2014-03-29 22:36:05 +0800268ifneq ($(HOMEBREW_CAPSTONE),1)
Nguyen Anh Quynhe31327d2014-04-29 14:25:15 +0800269ifneq ($(CAPSTONE_USE_SYS_DYN_MEM),yes)
Nguyen Anh Quynhc77cf3a2014-03-07 22:06:51 +0800270# remove string check because OSX kernel complains about missing symbols
271CFLAGS += -D_FORTIFY_SOURCE=0
272endif
Nguyen Anh Quynh189e83a2014-03-29 22:36:05 +0800273endif
pancake02cad6e2013-11-27 15:38:44 +0100274else
danghvue1c7a212014-05-14 02:13:36 -0500275$(LIBNAME)_LDFLAGS += -shared
Daniel Godas-Lopez0f7c4322013-11-28 18:22:50 +0000276# Cygwin?
277IS_CYGWIN := $(shell $(CC) -dumpmachine | grep -i cygwin | wc -l)
278ifeq ($(IS_CYGWIN),1)
279EXT = dll
Nguyen Anh Quynh76087d22014-05-14 14:53:51 +0800280AR_EXT = lib
Daniel Godas-Lopez0f7c4322013-11-28 18:22:50 +0000281# Cygwin doesn't like -fPIC
282CFLAGS := $(CFLAGS:-fPIC=)
283# On Windows we need the shared library to be executable
284else
285# mingw?
286IS_MINGW := $(shell $(CC) --version | grep -i mingw | wc -l)
287ifeq ($(IS_MINGW),1)
288EXT = dll
Nguyen Anh Quynh76087d22014-05-14 14:53:51 +0800289AR_EXT = lib
Daniel Godas-Lopez0f7c4322013-11-28 18:22:50 +0000290# mingw doesn't like -fPIC either
291CFLAGS := $(CFLAGS:-fPIC=)
292# On Windows we need the shared library to be executable
Nguyen Anh Quynh4ebdd212013-12-25 23:54:45 +0800293else
294# Linux, *BSD
Nguyen Anh Quynhc0c0d522014-03-17 17:31:33 +0800295EXT = so
296VERSION_EXT = $(EXT).$(API_MAJOR)
Nguyen Anh Quynh6d5381e2014-03-17 10:37:08 +0800297AR_EXT = a
danghvue1c7a212014-05-14 02:13:36 -0500298$(LIBNAME)_LDFLAGS += -Wl,-soname,lib$(LIBNAME).$(VERSION_EXT)
Daniel Godas-Lopez0f7c4322013-11-28 18:22:50 +0000299endif
300endif
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800301endif
302
Ole André Vadla Ravnås927fcbc2014-05-01 16:00:52 +0200303ifeq ($(CAPSTONE_SHARED),yes)
Nguyen Anh Quynh0936b562014-06-04 00:26:33 +0800304ifeq ($(IS_MINGW),1)
305LIBRARY = $(BLDIR)/$(LIBNAME).$(EXT)
306else ifeq ($(IS_CYGWIN),1)
307LIBRARY = $(BLDIR)/$(LIBNAME).$(EXT)
308else # *nix
Nguyen Anh Quynh6ae472f2014-04-29 16:29:55 +0800309LIBRARY = $(BLDIR)/lib$(LIBNAME).$(EXT)
Hilko Bengend83bf842015-02-26 18:37:32 +0100310CFLAGS += -fvisibility=hidden
Ole André Vadla Ravnås927fcbc2014-05-01 16:00:52 +0200311endif
Nguyen Anh Quynh0936b562014-06-04 00:26:33 +0800312endif
313
Ole André Vadla Ravnås927fcbc2014-05-01 16:00:52 +0200314ifeq ($(CAPSTONE_STATIC),yes)
Nguyen Anh Quynh0936b562014-06-04 00:26:33 +0800315ifeq ($(IS_MINGW),1)
316ARCHIVE = $(BLDIR)/$(LIBNAME).$(AR_EXT)
317else ifeq ($(IS_CYGWIN),1)
318ARCHIVE = $(BLDIR)/$(LIBNAME).$(AR_EXT)
319else
Nguyen Anh Quynh6ae472f2014-04-29 16:29:55 +0800320ARCHIVE = $(BLDIR)/lib$(LIBNAME).$(AR_EXT)
Ole André Vadla Ravnås927fcbc2014-05-01 16:00:52 +0200321endif
Nguyen Anh Quynh0936b562014-06-04 00:26:33 +0800322endif
323
Nguyen Anh Quynh6ae472f2014-04-29 16:29:55 +0800324PKGCFGF = $(BLDIR)/$(LIBNAME).pc
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800325
Nguyen Anh Quynh5bbbfce2014-02-28 10:49:46 +0800326.PHONY: all clean install uninstall dist
pancakeca9f1b22013-12-06 17:03:41 +0100327
Nguyen Anh Quynh80ff30b2013-12-09 00:38:44 +0800328all: $(LIBRARY) $(ARCHIVE) $(PKGCFGF)
Nguyen Anh Quynh19af3ec2015-01-30 09:07:51 +0800329ifeq (,$(findstring yes,$(CAPSTONE_BUILD_CORE_ONLY)))
Nguyen Anh Quynh34603272016-10-10 22:54:16 +0800330 @V=$(V) $(MAKE) -C cstool
Nguyen Anh Quynh243d41e2015-01-28 04:42:34 +0800331ifndef BUILDDIR
332 cd tests && $(MAKE)
333else
334 cd tests && $(MAKE) BUILDDIR=$(BLDIR)
335endif
Akihiko Odaki798821f2016-09-03 10:54:56 +0900336 $(call install-library,$(BLDIR)/tests/)
Ole André Vadla Ravnås927fcbc2014-05-01 16:00:52 +0200337endif
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800338
Ole André Vadla Ravnås927fcbc2014-05-01 16:00:52 +0200339ifeq ($(CAPSTONE_SHARED),yes)
pancakeaddb1922014-02-28 02:44:07 +0100340$(LIBRARY): $(LIBOBJ)
Ole André Vadla Ravnåsf536d402014-05-01 15:22:25 +0200341ifeq ($(V),0)
Nguyen Anh Quynh8c0ab862014-06-03 23:43:53 +0700342 $(call log,LINK,$(@:$(BLDIR)/%=%))
Ole André Vadla Ravnåsf536d402014-05-01 15:22:25 +0200343 @$(create-library)
344else
345 $(create-library)
346endif
Ole André Vadla Ravnås927fcbc2014-05-01 16:00:52 +0200347endif
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800348
Nguyen Anh Quynhaeb0c402014-03-27 17:54:27 +0800349$(LIBOBJ): config.mk
350
Nguyen Anh Quynh4a328ca2014-02-28 23:09:04 +0800351$(LIBOBJ_ARM): $(DEP_ARM)
352$(LIBOBJ_ARM64): $(DEP_ARM64)
353$(LIBOBJ_MIPS): $(DEP_MIPS)
354$(LIBOBJ_PPC): $(DEP_PPC)
Nguyen Anh Quynh05e27132014-03-10 11:58:57 +0800355$(LIBOBJ_SPARC): $(DEP_SPARC)
Nguyen Anh Quynh48a14ca2014-03-23 08:35:45 +0800356$(LIBOBJ_SYSZ): $(DEP_SYSZ)
Nguyen Anh Quynh4a328ca2014-02-28 23:09:04 +0800357$(LIBOBJ_X86): $(DEP_X86)
Nguyen Anh Quynhc80d8402014-05-26 23:02:48 +0800358$(LIBOBJ_XCORE): $(DEP_XCORE)
Nguyen Anh Quynh4a328ca2014-02-28 23:09:04 +0800359
Ole André Vadla Ravnås927fcbc2014-05-01 16:00:52 +0200360ifeq ($(CAPSTONE_STATIC),yes)
pancakeca9f1b22013-12-06 17:03:41 +0100361$(ARCHIVE): $(LIBOBJ)
Ole André Vadla Ravnåsf536d402014-05-01 15:22:25 +0200362 @rm -f $(ARCHIVE)
363ifeq ($(V),0)
364 $(call log,AR,$(@:$(BLDIR)/%=%))
365 @$(create-archive)
366else
367 $(create-archive)
368endif
Ole André Vadla Ravnås927fcbc2014-05-01 16:00:52 +0200369endif
pancakef1cbce22013-11-27 15:31:26 +0100370
pancakeca9f1b22013-12-06 17:03:41 +0100371$(PKGCFGF):
Ole André Vadla Ravnåsf536d402014-05-01 15:22:25 +0200372ifeq ($(V),0)
373 $(call log,GEN,$(@:$(BLDIR)/%=%))
374 @$(generate-pkgcfg)
Nguyen Anh Quynh3ff259c2014-03-07 17:11:18 +0800375else
Ole André Vadla Ravnåsf536d402014-05-01 15:22:25 +0200376 $(generate-pkgcfg)
Nguyen Anh Quynh3ff259c2014-03-07 17:11:18 +0800377endif
pancake44ce0fb2013-12-03 04:11:37 +0100378
pancakeca9f1b22013-12-06 17:03:41 +0100379install: $(PKGCFGF) $(ARCHIVE) $(LIBRARY)
pancake02cad6e2013-11-27 15:38:44 +0100380 mkdir -p $(LIBDIR)
Akihiko Odaki798821f2016-09-03 10:54:56 +0900381 $(call install-library,$(LIBDIR))
Ole André Vadla Ravnås927fcbc2014-05-01 16:00:52 +0200382ifeq ($(CAPSTONE_STATIC),yes)
Nguyen Anh Quynh0936b562014-06-04 00:26:33 +0800383 $(INSTALL_DATA) $(ARCHIVE) $(LIBDIR)
Ole André Vadla Ravnås927fcbc2014-05-01 16:00:52 +0200384endif
pancake02cad6e2013-11-27 15:38:44 +0100385 mkdir -p $(INCDIR)/$(LIBNAME)
Nguyen Anh Quynh35240562014-01-04 09:18:48 +0800386 $(INSTALL_DATA) include/*.h $(INCDIR)/$(LIBNAME)
Nguyen Anh Quynh9b4b3772014-04-12 18:06:54 +0800387 mkdir -p $(PKGCFGDIR)
388 $(INSTALL_DATA) $(PKGCFGF) $(PKGCFGDIR)/
Nguyen Anh Quynh34603272016-10-10 22:54:16 +0800389 mkdir -p $(BINDIR)
390 $(INSTALL_LIB) cstool/cstool $(BINDIR)
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800391
392uninstall:
pancake02cad6e2013-11-27 15:38:44 +0100393 rm -rf $(INCDIR)/$(LIBNAME)
Nguyen Anh Quynh6d5381e2014-03-17 10:37:08 +0800394 rm -f $(LIBDIR)/lib$(LIBNAME).*
Nguyen Anh Quynh9b4b3772014-04-12 18:06:54 +0800395 rm -f $(PKGCFGDIR)/$(LIBNAME).pc
Nguyen Anh Quynh34603272016-10-10 22:54:16 +0800396 rm -f $(BINDIR)/cstool
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800397
398clean:
Nguyen Anh Quynh5519a682014-04-29 16:24:30 +0800399 rm -f $(LIBOBJ)
Nguyen Anh Quynh0936b562014-06-04 00:26:33 +0800400 rm -f $(BLDIR)/lib$(LIBNAME).* $(BLDIR)/$(LIBNAME).*
Nguyen Anh Quynhd63ddac2014-01-09 10:35:58 +0800401 rm -f $(PKGCFGF)
Nguyen Anh Quynh34603272016-10-10 22:54:16 +0800402 $(MAKE) -C cstool clean
Nguyen Tan Cong3d6e56a2015-01-28 00:35:44 +0700403
Nguyen Anh Quynh19af3ec2015-01-30 09:07:51 +0800404ifeq (,$(findstring yes,$(CAPSTONE_BUILD_CORE_ONLY)))
danghvuad664202014-05-12 14:27:38 -0500405 cd tests && $(MAKE) clean
Nguyen Anh Quynh6ae472f2014-04-29 16:29:55 +0800406 rm -f $(BLDIR)/tests/lib$(LIBNAME).$(EXT)
Nguyen Tan Cong3d6e56a2015-01-28 00:35:44 +0700407endif
Nguyen Anh Quynh6ae472f2014-04-29 16:29:55 +0800408
409ifdef BUILDDIR
410 rm -rf $(BUILDDIR)
411endif
Nguyen Anh Quynh5519a682014-04-29 16:24:30 +0800412
Nguyen Anh Quynh19af3ec2015-01-30 09:07:51 +0800413ifeq (,$(findstring yes,$(CAPSTONE_BUILD_CORE_ONLY)))
danghvuad664202014-05-12 14:27:38 -0500414 cd bindings/python && $(MAKE) clean
415 cd bindings/java && $(MAKE) clean
416 cd bindings/ocaml && $(MAKE) clean
Nguyen Tan Cong3d6e56a2015-01-28 00:35:44 +0700417endif
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800418
Nguyen Anh Quynha580d922014-01-18 12:47:15 +0800419
420TAG ?= HEAD
421ifeq ($(TAG), HEAD)
422DIST_VERSION = latest
423else
424DIST_VERSION = $(TAG)
425endif
426
pancake35cef7f2014-01-18 03:42:15 +0100427dist:
Nguyen Anh Quynh186d5012014-01-22 18:46:20 +0800428 git archive --format=tar.gz --prefix=capstone-$(DIST_VERSION)/ $(TAG) > capstone-$(DIST_VERSION).tgz
Nguyen Anh Quynhf4f72532014-03-11 12:29:16 +0800429 git archive --format=zip --prefix=capstone-$(DIST_VERSION)/ $(TAG) > capstone-$(DIST_VERSION).zip
pancake35cef7f2014-01-18 03:42:15 +0100430
Nguyen Anh Quynh984d4502014-10-01 16:42:29 +0800431
432TESTS = test test_detail test_arm test_arm64 test_mips test_ppc test_sparc
Nguyen Anh Quynhb16dc852014-11-02 08:21:34 +0800433TESTS += test_systemz test_x86 test_xcore test_iter
Nguyen Anh Quynh984d4502014-10-01 16:42:29 +0800434TESTS += test.static test_detail.static test_arm.static test_arm64.static
435TESTS += test_mips.static test_ppc.static test_sparc.static
436TESTS += test_systemz.static test_x86.static test_xcore.static
Nguyen Anh Quynhb16dc852014-11-02 08:21:34 +0800437TESTS += test_skipdata test_skipdata.static test_iter.static
Nguyen Anh Quynh984d4502014-10-01 16:42:29 +0800438check:
439 @for t in $(TESTS); do \
440 echo Check $$t ... ; \
Akihiko Odaki798821f2016-09-03 10:54:56 +0900441 LD_LIBRARY_PATH=./tests ./tests/$$t > /dev/null && echo OK || echo FAILED; \
Nguyen Anh Quynh984d4502014-10-01 16:42:29 +0800442 done
443
Ole André Vadla Ravnås35f937d2014-04-29 09:00:34 +0200444$(OBJDIR)/%.o: %.c
445 @mkdir -p $(@D)
Ole André Vadla Ravnåsf536d402014-05-01 15:22:25 +0200446ifeq ($(V),0)
447 $(call log,CC,$(@:$(OBJDIR)/%=%))
448 @$(compile)
449else
450 $(compile)
451endif
452
Ole André Vadla Ravnåsf536d402014-05-01 15:22:25 +0200453
Akihiko Odaki798821f2016-09-03 10:54:56 +0900454ifeq ($(CAPSTONE_SHARED),yes)
455define install-library
456 $(INSTALL_LIB) $(LIBRARY) $1
457 $(if $(VERSION_EXT),
458 cd $1 && \
459 mv lib$(LIBNAME).$(EXT) lib$(LIBNAME).$(VERSION_EXT) && \
460 ln -s lib$(LIBNAME).$(VERSION_EXT) lib$(LIBNAME).$(EXT))
461endef
462else
463define install-library
464endef
465endif
466
467
Ole André Vadla Ravnåsf536d402014-05-01 15:22:25 +0200468define create-archive
469 $(AR) q $(ARCHIVE) $(LIBOBJ)
470 $(RANLIB) $(ARCHIVE)
471endef
472
Nguyen Anh Quynh58a00472014-05-01 22:53:52 +0800473
Ole André Vadla Ravnåsf536d402014-05-01 15:22:25 +0200474define create-library
danghvue1c7a212014-05-14 02:13:36 -0500475 $(CC) $(LDFLAGS) $($(LIBNAME)_LDFLAGS) $(LIBOBJ) -o $(LIBRARY)
Ole André Vadla Ravnåsf536d402014-05-01 15:22:25 +0200476endef
477
Nguyen Anh Quynh58a00472014-05-01 22:53:52 +0800478
Ole André Vadla Ravnåsf536d402014-05-01 15:22:25 +0200479define generate-pkgcfg
480 echo 'Name: capstone' > $(PKGCFGF)
481 echo 'Description: Capstone disassembly engine' >> $(PKGCFGF)
482 echo 'Version: $(PKG_VERSION)' >> $(PKGCFGF)
483 echo 'libdir=$(LIBDIR)' >> $(PKGCFGF)
Nguyen Anh Quynhfff13072014-10-02 16:14:26 +0800484 echo 'includedir=$(INCDIR)/capstone' >> $(PKGCFGF)
Ole André Vadla Ravnåsf536d402014-05-01 15:22:25 +0200485 echo 'archive=$${libdir}/libcapstone.a' >> $(PKGCFGF)
486 echo 'Libs: -L$${libdir} -lcapstone' >> $(PKGCFGF)
487 echo 'Cflags: -I$${includedir}' >> $(PKGCFGF)
488endef