Nguyen Anh Quynh | 296a231 | 2014-03-05 23:50:41 +0800 | [diff] [blame] | 1 | # Capstone Disassembly Engine |
Nguyen Anh Quynh | 1ed8bb6 | 2014-03-10 23:14:30 -0700 | [diff] [blame] | 2 | # By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 |
Nguyen Anh Quynh | 5e107ab | 2013-12-31 23:38:28 +0800 | [diff] [blame] | 3 | |
danghvu | 6f52bf9 | 2013-12-19 22:43:01 -0600 | [diff] [blame] | 4 | include config.mk |
Nguyen Anh Quynh | 3ff259c | 2014-03-07 17:11:18 +0800 | [diff] [blame] | 5 | include pkgconfig.mk # package version |
Nguyen Anh Quynh | 58a0047 | 2014-05-01 22:53:52 +0800 | [diff] [blame] | 6 | include functions.mk |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 7 | |
Ole André Vadla Ravnås | f536d40 | 2014-05-01 15:22:25 +0200 | [diff] [blame] | 8 | # Verbose output? |
| 9 | V ?= 0 |
| 10 | |
| 11 | ifeq ($(PKG_EXTRA),) |
| 12 | PKG_VERSION = $(PKG_MAJOR).$(PKG_MINOR) |
| 13 | else |
| 14 | PKG_VERSION = $(PKG_MAJOR).$(PKG_MINOR).$(PKG_EXTRA) |
| 15 | endif |
| 16 | |
Nguyen Anh Quynh | d80cede | 2014-01-16 21:07:59 +0800 | [diff] [blame] | 17 | ifeq ($(CROSS),) |
| 18 | CC ?= cc |
| 19 | AR ?= ar |
| 20 | RANLIB ?= ranlib |
| 21 | STRIP ?= strip |
| 22 | else |
| 23 | CC = $(CROSS)gcc |
| 24 | AR = $(CROSS)ar |
| 25 | RANLIB = $(CROSS)ranlib |
| 26 | STRIP = $(CROSS)strip |
| 27 | endif |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 28 | |
Nguyen Anh Quynh | 77af9fb | 2014-04-29 07:11:55 +0800 | [diff] [blame] | 29 | ifneq (,$(findstring yes,$(CAPSTONE_DIET))) |
| 30 | CFLAGS ?= -Os |
| 31 | CFLAGS += -DCAPSTONE_DIET |
| 32 | else |
| 33 | CFLAGS ?= -O3 |
| 34 | endif |
| 35 | |
| 36 | CFLAGS += -fPIC -Wall -Iinclude |
Nguyen Anh Quynh | 59492c2 | 2014-01-05 23:41:31 +0800 | [diff] [blame] | 37 | |
Nguyen Anh Quynh | e31327d | 2014-04-29 14:25:15 +0800 | [diff] [blame] | 38 | ifeq ($(CAPSTONE_USE_SYS_DYN_MEM),yes) |
Nguyen Anh Quynh | 87a3f69 | 2014-05-10 19:26:32 +0800 | [diff] [blame] | 39 | CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM |
Nguyen Anh Quynh | 59492c2 | 2014-01-05 23:41:31 +0800 | [diff] [blame] | 40 | endif |
| 41 | |
Ole André Vadla Ravnås | 6583f06 | 2014-07-04 23:09:19 +0200 | [diff] [blame] | 42 | CFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch)) |
Ole André Vadla Ravnås | b202b91 | 2014-07-04 23:38:20 +0200 | [diff] [blame] | 43 | LDFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch)) |
Ole André Vadla Ravnås | 6583f06 | 2014-07-04 23:09:19 +0200 | [diff] [blame] | 44 | |
pancake | 02cad6e | 2013-11-27 15:38:44 +0100 | [diff] [blame] | 45 | PREFIX ?= /usr |
| 46 | DESTDIR ?= |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 47 | ifndef BUILDDIR |
Nguyen Anh Quynh | 6ae472f | 2014-04-29 16:29:55 +0800 | [diff] [blame] | 48 | BLDIR = . |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 49 | OBJDIR = . |
| 50 | else |
Ole André Vadla Ravnås | 7a73439 | 2014-04-30 00:06:41 +0200 | [diff] [blame] | 51 | BLDIR = $(abspath $(BUILDDIR)) |
Nguyen Anh Quynh | 6ae472f | 2014-04-29 16:29:55 +0800 | [diff] [blame] | 52 | OBJDIR = $(BLDIR)/obj |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 53 | endif |
pancake | 02cad6e | 2013-11-27 15:38:44 +0100 | [diff] [blame] | 54 | INCDIR = $(DESTDIR)$(PREFIX)/include |
Nguyen Anh Quynh | 9f0e6c2 | 2013-12-25 22:47:28 +0800 | [diff] [blame] | 55 | |
Nguyen Anh Quynh | 235a274 | 2014-03-29 21:09:35 +0800 | [diff] [blame] | 56 | UNAME_S := $(shell uname -s) |
Nguyen Anh Quynh | ad6cc98 | 2014-04-08 23:34:44 +0800 | [diff] [blame] | 57 | |
Nguyen Anh Quynh | 360bf1e | 2014-04-14 13:36:46 +0800 | [diff] [blame] | 58 | LIBDIRARCH ?= lib |
| 59 | # Uncomment the below line to installs x86_64 libs to lib64/ directory. |
| 60 | # Or better, pass 'LIBDIRARCH=lib64' to 'make install/uninstall' via 'make.sh'. |
| 61 | #LIBDIRARCH ?= lib64 |
| 62 | LIBDIR = $(DESTDIR)$(PREFIX)/$(LIBDIRARCH) |
pancake | 02cad6e | 2013-11-27 15:38:44 +0100 | [diff] [blame] | 63 | |
Oliver Pinter | c5ecae5 | 2014-03-23 02:19:59 +0100 | [diff] [blame] | 64 | LIBDATADIR = $(LIBDIR) |
Oliver Pinter | c5ecae5 | 2014-03-23 02:19:59 +0100 | [diff] [blame] | 65 | ifeq ($(UNAME_S), FreeBSD) |
| 66 | LIBDATADIR = $(DESTDIR)$(PREFIX)/libdata |
Oliver Pinter | c5ecae5 | 2014-03-23 02:19:59 +0100 | [diff] [blame] | 67 | endif |
Oliver Pinter | 25efded | 2014-03-23 19:10:13 +0100 | [diff] [blame] | 68 | ifeq ($(UNAME_S), DragonFly) |
| 69 | LIBDATADIR = $(DESTDIR)$(PREFIX)/libdata |
| 70 | endif |
Oliver Pinter | c5ecae5 | 2014-03-23 02:19:59 +0100 | [diff] [blame] | 71 | |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 72 | INSTALL_BIN ?= install |
| 73 | INSTALL_DATA ?= $(INSTALL_BIN) -m0644 |
Oliver Pinter | c5ecae5 | 2014-03-23 02:19:59 +0100 | [diff] [blame] | 74 | INSTALL_LIB ?= $(INSTALL_BIN) -m0755 |
pancake | 02cad6e | 2013-11-27 15:38:44 +0100 | [diff] [blame] | 75 | |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 76 | LIBNAME = capstone |
pancake | ca9f1b2 | 2013-12-06 17:03:41 +0100 | [diff] [blame] | 77 | |
Nguyen Anh Quynh | 42c6b1a | 2013-12-30 00:15:25 +0800 | [diff] [blame] | 78 | |
Nguyen Anh Quynh | 4a328ca | 2014-02-28 23:09:04 +0800 | [diff] [blame] | 79 | DEP_ARM = |
| 80 | DEP_ARM += arch/ARM/ARMGenAsmWriter.inc |
| 81 | DEP_ARM += arch/ARM/ARMGenDisassemblerTables.inc |
| 82 | DEP_ARM += arch/ARM/ARMGenInstrInfo.inc |
| 83 | DEP_ARM += arch/ARM/ARMGenRegisterInfo.inc |
| 84 | DEP_ARM += arch/ARM/ARMGenSubtargetInfo.inc |
| 85 | |
| 86 | LIBOBJ_ARM = |
Nguyen Anh Quynh | 9cc56a3 | 2014-01-15 16:01:55 +0800 | [diff] [blame] | 87 | ifneq (,$(findstring arm,$(CAPSTONE_ARCHS))) |
| 88 | CFLAGS += -DCAPSTONE_HAS_ARM |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 89 | LIBOBJ_ARM += $(OBJDIR)/arch/ARM/ARMDisassembler.o |
| 90 | LIBOBJ_ARM += $(OBJDIR)/arch/ARM/ARMInstPrinter.o |
| 91 | LIBOBJ_ARM += $(OBJDIR)/arch/ARM/ARMMapping.o |
| 92 | LIBOBJ_ARM += $(OBJDIR)/arch/ARM/ARMModule.o |
danghvu | 02db488 | 2013-12-20 00:57:12 -0600 | [diff] [blame] | 93 | endif |
Nguyen Anh Quynh | 42c6b1a | 2013-12-30 00:15:25 +0800 | [diff] [blame] | 94 | |
Nguyen Anh Quynh | 4a328ca | 2014-02-28 23:09:04 +0800 | [diff] [blame] | 95 | DEP_ARM64 = |
| 96 | DEP_ARM64 += arch/AArch64/AArch64GenAsmWriter.inc |
| 97 | DEP_ARM64 += arch/AArch64/AArch64GenInstrInfo.inc |
| 98 | DEP_ARM64 += arch/AArch64/AArch64GenSubtargetInfo.inc |
| 99 | DEP_ARM64 += arch/AArch64/AArch64GenDisassemblerTables.inc |
| 100 | DEP_ARM64 += arch/AArch64/AArch64GenRegisterInfo.inc |
| 101 | |
| 102 | LIBOBJ_ARM64 = |
| 103 | ifneq (,$(findstring aarch64,$(CAPSTONE_ARCHS))) |
| 104 | CFLAGS += -DCAPSTONE_HAS_ARM64 |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 105 | LIBOBJ_ARM64 += $(OBJDIR)/arch/AArch64/AArch64BaseInfo.o |
| 106 | LIBOBJ_ARM64 += $(OBJDIR)/arch/AArch64/AArch64Disassembler.o |
| 107 | LIBOBJ_ARM64 += $(OBJDIR)/arch/AArch64/AArch64InstPrinter.o |
| 108 | LIBOBJ_ARM64 += $(OBJDIR)/arch/AArch64/AArch64Mapping.o |
| 109 | LIBOBJ_ARM64 += $(OBJDIR)/arch/AArch64/AArch64Module.o |
Nguyen Anh Quynh | 4a328ca | 2014-02-28 23:09:04 +0800 | [diff] [blame] | 110 | endif |
| 111 | |
| 112 | |
| 113 | DEP_MIPS = |
| 114 | DEP_MIPS += arch/Mips/MipsGenAsmWriter.inc |
| 115 | DEP_MIPS += arch/Mips/MipsGenDisassemblerTables.inc |
| 116 | DEP_MIPS += arch/Mips/MipsGenInstrInfo.inc |
| 117 | DEP_MIPS += arch/Mips/MipsGenRegisterInfo.inc |
| 118 | DEP_MIPS += arch/Mips/MipsGenSubtargetInfo.inc |
| 119 | |
| 120 | LIBOBJ_MIPS = |
| 121 | ifneq (,$(findstring mips,$(CAPSTONE_ARCHS))) |
| 122 | CFLAGS += -DCAPSTONE_HAS_MIPS |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 123 | LIBOBJ_MIPS += $(OBJDIR)/arch/Mips/MipsDisassembler.o |
| 124 | LIBOBJ_MIPS += $(OBJDIR)/arch/Mips/MipsInstPrinter.o |
| 125 | LIBOBJ_MIPS += $(OBJDIR)/arch/Mips/MipsMapping.o |
| 126 | LIBOBJ_MIPS += $(OBJDIR)/arch/Mips/MipsModule.o |
Nguyen Anh Quynh | 4a328ca | 2014-02-28 23:09:04 +0800 | [diff] [blame] | 127 | endif |
| 128 | |
| 129 | |
| 130 | DEP_PPC = |
| 131 | DEP_PPC += arch/PowerPC/PPCGenAsmWriter.inc |
| 132 | DEP_PPC += arch/PowerPC/PPCGenInstrInfo.inc |
| 133 | DEP_PPC += arch/PowerPC/PPCGenSubtargetInfo.inc |
| 134 | DEP_PPC += arch/PowerPC/PPCGenDisassemblerTables.inc |
| 135 | DEP_PPC += arch/PowerPC/PPCGenRegisterInfo.inc |
| 136 | |
| 137 | LIBOBJ_PPC = |
| 138 | ifneq (,$(findstring powerpc,$(CAPSTONE_ARCHS))) |
| 139 | CFLAGS += -DCAPSTONE_HAS_POWERPC |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 140 | LIBOBJ_PPC += $(OBJDIR)/arch/PowerPC/PPCDisassembler.o |
| 141 | LIBOBJ_PPC += $(OBJDIR)/arch/PowerPC/PPCInstPrinter.o |
| 142 | LIBOBJ_PPC += $(OBJDIR)/arch/PowerPC/PPCMapping.o |
| 143 | LIBOBJ_PPC += $(OBJDIR)/arch/PowerPC/PPCModule.o |
Nguyen Anh Quynh | 4a328ca | 2014-02-28 23:09:04 +0800 | [diff] [blame] | 144 | endif |
| 145 | |
| 146 | |
Nguyen Anh Quynh | 05e2713 | 2014-03-10 11:58:57 +0800 | [diff] [blame] | 147 | DEP_SPARC = |
| 148 | DEP_SPARC += arch/Sparc/SparcGenAsmWriter.inc |
| 149 | DEP_SPARC += arch/Sparc/SparcGenInstrInfo.inc |
| 150 | DEP_SPARC += arch/Sparc/SparcGenSubtargetInfo.inc |
| 151 | DEP_SPARC += arch/Sparc/SparcGenDisassemblerTables.inc |
| 152 | DEP_SPARC += arch/Sparc/SparcGenRegisterInfo.inc |
| 153 | |
| 154 | LIBOBJ_SPARC = |
| 155 | ifneq (,$(findstring sparc,$(CAPSTONE_ARCHS))) |
| 156 | CFLAGS += -DCAPSTONE_HAS_SPARC |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 157 | LIBOBJ_SPARC += $(OBJDIR)/arch/Sparc/SparcDisassembler.o |
| 158 | LIBOBJ_SPARC += $(OBJDIR)/arch/Sparc/SparcInstPrinter.o |
| 159 | LIBOBJ_SPARC += $(OBJDIR)/arch/Sparc/SparcMapping.o |
| 160 | LIBOBJ_SPARC += $(OBJDIR)/arch/Sparc/SparcModule.o |
Nguyen Anh Quynh | 05e2713 | 2014-03-10 11:58:57 +0800 | [diff] [blame] | 161 | endif |
| 162 | |
| 163 | |
Nguyen Anh Quynh | 48a14ca | 2014-03-23 08:35:45 +0800 | [diff] [blame] | 164 | DEP_SYSZ = |
| 165 | DEP_SYSZ += arch/SystemZ/SystemZGenAsmWriter.inc |
| 166 | DEP_SYSZ += arch/SystemZ/SystemZGenInstrInfo.inc |
| 167 | DEP_SYSZ += arch/SystemZ/SystemZGenSubtargetInfo.inc |
| 168 | DEP_SYSZ += arch/SystemZ/SystemZGenDisassemblerTables.inc |
| 169 | DEP_SYSZ += arch/SystemZ/SystemZGenRegisterInfo.inc |
| 170 | |
| 171 | LIBOBJ_SYSZ = |
| 172 | ifneq (,$(findstring systemz,$(CAPSTONE_ARCHS))) |
| 173 | CFLAGS += -DCAPSTONE_HAS_SYSZ |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 174 | LIBOBJ_SYSZ += $(OBJDIR)/arch/SystemZ/SystemZDisassembler.o |
| 175 | LIBOBJ_SYSZ += $(OBJDIR)/arch/SystemZ/SystemZInstPrinter.o |
| 176 | LIBOBJ_SYSZ += $(OBJDIR)/arch/SystemZ/SystemZMapping.o |
| 177 | LIBOBJ_SYSZ += $(OBJDIR)/arch/SystemZ/SystemZModule.o |
| 178 | LIBOBJ_SYSZ += $(OBJDIR)/arch/SystemZ/SystemZMCTargetDesc.o |
Nguyen Anh Quynh | 48a14ca | 2014-03-23 08:35:45 +0800 | [diff] [blame] | 179 | endif |
| 180 | |
| 181 | |
Nguyen Anh Quynh | 9518148 | 2014-03-25 23:20:41 +0800 | [diff] [blame] | 182 | # by default, we compile full X86 instruction sets |
Nguyen Anh Quynh | 59b5489 | 2014-03-27 10:54:44 +0800 | [diff] [blame] | 183 | X86_REDUCE = |
| 184 | ifneq (,$(findstring yes,$(CAPSTONE_X86_REDUCE))) |
| 185 | X86_REDUCE = _reduce |
Nguyen Anh Quynh | 81d930a | 2014-03-28 10:28:57 +0800 | [diff] [blame] | 186 | CFLAGS += -DCAPSTONE_X86_REDUCE -Os |
Nguyen Anh Quynh | 9518148 | 2014-03-25 23:20:41 +0800 | [diff] [blame] | 187 | endif |
| 188 | |
Nguyen Anh Quynh | 4a328ca | 2014-02-28 23:09:04 +0800 | [diff] [blame] | 189 | DEP_X86 = |
Nguyen Anh Quynh | 59b5489 | 2014-03-27 10:54:44 +0800 | [diff] [blame] | 190 | DEP_X86 += arch/X86/X86GenAsmWriter$(X86_REDUCE).inc |
| 191 | DEP_X86 += arch/X86/X86GenAsmWriter1$(X86_REDUCE).inc |
| 192 | DEP_X86 += arch/X86/X86GenDisassemblerTables$(X86_REDUCE).inc |
| 193 | DEP_X86 += arch/X86/X86GenInstrInfo$(X86_REDUCE).inc |
Nguyen Anh Quynh | 4a328ca | 2014-02-28 23:09:04 +0800 | [diff] [blame] | 194 | DEP_X86 += arch/X86/X86GenRegisterInfo.inc |
| 195 | |
| 196 | LIBOBJ_X86 = |
| 197 | ifneq (,$(findstring x86,$(CAPSTONE_ARCHS))) |
| 198 | CFLAGS += -DCAPSTONE_HAS_X86 |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 199 | LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86DisassemblerDecoder.o |
| 200 | LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86Disassembler.o |
| 201 | LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86IntelInstPrinter.o |
Nguyen Anh Quynh | 5068908 | 2014-05-14 12:26:53 +0800 | [diff] [blame] | 202 | # assembly syntax is irrelevant in Diet mode, when this info is suppressed |
| 203 | ifeq (,$(findstring yes,$(CAPSTONE_DIET))) |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 204 | LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86ATTInstPrinter.o |
Nguyen Anh Quynh | 5068908 | 2014-05-14 12:26:53 +0800 | [diff] [blame] | 205 | endif |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 206 | LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86Mapping.o |
| 207 | LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86Module.o |
Nguyen Anh Quynh | 4a328ca | 2014-02-28 23:09:04 +0800 | [diff] [blame] | 208 | endif |
| 209 | |
Nguyen Anh Quynh | c80d840 | 2014-05-26 23:02:48 +0800 | [diff] [blame] | 210 | |
| 211 | DEP_XCORE = |
| 212 | DEP_XCORE += arch/XCore/XCoreGenAsmWriter.inc |
| 213 | DEP_XCORE += arch/XCore/XCoreGenInstrInfo.inc |
| 214 | DEP_XCORE += arch/XCore/XCoreGenDisassemblerTables.inc |
| 215 | DEP_XCORE += arch/XCore/XCoreGenRegisterInfo.inc |
| 216 | |
| 217 | LIBOBJ_XCORE = |
| 218 | ifneq (,$(findstring xcore,$(CAPSTONE_ARCHS))) |
| 219 | CFLAGS += -DCAPSTONE_HAS_XCORE |
| 220 | LIBOBJ_XCORE += $(OBJDIR)/arch/XCore/XCoreDisassembler.o |
| 221 | LIBOBJ_XCORE += $(OBJDIR)/arch/XCore/XCoreInstPrinter.o |
| 222 | LIBOBJ_XCORE += $(OBJDIR)/arch/XCore/XCoreMapping.o |
| 223 | LIBOBJ_XCORE += $(OBJDIR)/arch/XCore/XCoreModule.o |
| 224 | endif |
| 225 | |
| 226 | |
Nguyen Anh Quynh | 4a328ca | 2014-02-28 23:09:04 +0800 | [diff] [blame] | 227 | LIBOBJ = |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 228 | LIBOBJ += $(OBJDIR)/cs.o $(OBJDIR)/utils.o $(OBJDIR)/SStream.o $(OBJDIR)/MCInstrDesc.o $(OBJDIR)/MCRegisterInfo.o |
Nguyen Anh Quynh | c80d840 | 2014-05-26 23:02:48 +0800 | [diff] [blame] | 229 | LIBOBJ += $(LIBOBJ_ARM) $(LIBOBJ_ARM64) $(LIBOBJ_MIPS) $(LIBOBJ_PPC) $(LIBOBJ_SPARC) $(LIBOBJ_SYSZ) $(LIBOBJ_X86) $(LIBOBJ_XCORE) |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 230 | LIBOBJ += $(OBJDIR)/MCInst.o |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 231 | |
Nguyen Anh Quynh | 4a328ca | 2014-02-28 23:09:04 +0800 | [diff] [blame] | 232 | |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 233 | PKGCFGDIR ?= $(LIBDATADIR)/pkgconfig |
Nguyen Anh Quynh | 315f02d | 2014-03-25 06:43:19 +0800 | [diff] [blame] | 234 | API_MAJOR=$(shell echo `grep -e CS_API_MAJOR include/capstone.h | grep -v = | awk '{print $$3}'` | awk '{print $$1}') |
Nguyen Anh Quynh | c0c0d52 | 2014-03-17 17:31:33 +0800 | [diff] [blame] | 235 | VERSION_EXT = |
Nguyen Anh Quynh | 8f856c7 | 2014-02-24 15:17:40 +0800 | [diff] [blame] | 236 | |
Ole André Vadla Ravnås | c20b049 | 2014-05-01 14:14:57 +0200 | [diff] [blame] | 237 | IS_APPLE := $(shell $(CC) -dM -E - < /dev/null | grep __apple_build_version__ | wc -l | tr -d " ") |
| 238 | ifeq ($(IS_APPLE),1) |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 239 | EXT = dylib |
pancake | 2694333 | 2014-02-04 08:37:55 +0100 | [diff] [blame] | 240 | VERSION_EXT = $(API_MAJOR).$(EXT) |
danghvu | e1c7a21 | 2014-05-14 02:13:36 -0500 | [diff] [blame] | 241 | $(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 Quynh | 4ebdd21 | 2013-12-25 23:54:45 +0800 | [diff] [blame] | 242 | AR_EXT = a |
Nguyen Anh Quynh | e3606d9 | 2014-04-12 18:02:55 +0800 | [diff] [blame] | 243 | # Homebrew wants to make sure its formula does not disable FORTIFY_SOURCE |
Nguyen Anh Quynh | e31327d | 2014-04-29 14:25:15 +0800 | [diff] [blame] | 244 | # However, this is not really necessary because 'CAPSTONE_USE_SYS_DYN_MEM=yes' by default |
Nguyen Anh Quynh | 189e83a | 2014-03-29 22:36:05 +0800 | [diff] [blame] | 245 | ifneq ($(HOMEBREW_CAPSTONE),1) |
Nguyen Anh Quynh | e31327d | 2014-04-29 14:25:15 +0800 | [diff] [blame] | 246 | ifneq ($(CAPSTONE_USE_SYS_DYN_MEM),yes) |
Nguyen Anh Quynh | c77cf3a | 2014-03-07 22:06:51 +0800 | [diff] [blame] | 247 | # remove string check because OSX kernel complains about missing symbols |
| 248 | CFLAGS += -D_FORTIFY_SOURCE=0 |
| 249 | endif |
Nguyen Anh Quynh | 189e83a | 2014-03-29 22:36:05 +0800 | [diff] [blame] | 250 | endif |
pancake | 02cad6e | 2013-11-27 15:38:44 +0100 | [diff] [blame] | 251 | else |
danghvu | e1c7a21 | 2014-05-14 02:13:36 -0500 | [diff] [blame] | 252 | $(LIBNAME)_LDFLAGS += -shared |
Daniel Godas-Lopez | 0f7c432 | 2013-11-28 18:22:50 +0000 | [diff] [blame] | 253 | # Cygwin? |
| 254 | IS_CYGWIN := $(shell $(CC) -dumpmachine | grep -i cygwin | wc -l) |
| 255 | ifeq ($(IS_CYGWIN),1) |
| 256 | EXT = dll |
Nguyen Anh Quynh | 76087d2 | 2014-05-14 14:53:51 +0800 | [diff] [blame] | 257 | AR_EXT = lib |
Daniel Godas-Lopez | 0f7c432 | 2013-11-28 18:22:50 +0000 | [diff] [blame] | 258 | # Cygwin doesn't like -fPIC |
| 259 | CFLAGS := $(CFLAGS:-fPIC=) |
| 260 | # On Windows we need the shared library to be executable |
| 261 | else |
| 262 | # mingw? |
| 263 | IS_MINGW := $(shell $(CC) --version | grep -i mingw | wc -l) |
| 264 | ifeq ($(IS_MINGW),1) |
| 265 | EXT = dll |
Nguyen Anh Quynh | 76087d2 | 2014-05-14 14:53:51 +0800 | [diff] [blame] | 266 | AR_EXT = lib |
Daniel Godas-Lopez | 0f7c432 | 2013-11-28 18:22:50 +0000 | [diff] [blame] | 267 | # mingw doesn't like -fPIC either |
| 268 | CFLAGS := $(CFLAGS:-fPIC=) |
| 269 | # On Windows we need the shared library to be executable |
Nguyen Anh Quynh | 4ebdd21 | 2013-12-25 23:54:45 +0800 | [diff] [blame] | 270 | else |
| 271 | # Linux, *BSD |
Nguyen Anh Quynh | c0c0d52 | 2014-03-17 17:31:33 +0800 | [diff] [blame] | 272 | EXT = so |
| 273 | VERSION_EXT = $(EXT).$(API_MAJOR) |
Nguyen Anh Quynh | 6d5381e | 2014-03-17 10:37:08 +0800 | [diff] [blame] | 274 | AR_EXT = a |
danghvu | e1c7a21 | 2014-05-14 02:13:36 -0500 | [diff] [blame] | 275 | $(LIBNAME)_LDFLAGS += -Wl,-soname,lib$(LIBNAME).$(VERSION_EXT) |
Daniel Godas-Lopez | 0f7c432 | 2013-11-28 18:22:50 +0000 | [diff] [blame] | 276 | endif |
| 277 | endif |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 278 | endif |
| 279 | |
Ole André Vadla Ravnås | 927fcbc | 2014-05-01 16:00:52 +0200 | [diff] [blame] | 280 | ifeq ($(CAPSTONE_SHARED),yes) |
Nguyen Anh Quynh | 0936b56 | 2014-06-04 00:26:33 +0800 | [diff] [blame] | 281 | ifeq ($(IS_MINGW),1) |
| 282 | LIBRARY = $(BLDIR)/$(LIBNAME).$(EXT) |
| 283 | else ifeq ($(IS_CYGWIN),1) |
| 284 | LIBRARY = $(BLDIR)/$(LIBNAME).$(EXT) |
| 285 | else # *nix |
Nguyen Anh Quynh | 6ae472f | 2014-04-29 16:29:55 +0800 | [diff] [blame] | 286 | LIBRARY = $(BLDIR)/lib$(LIBNAME).$(EXT) |
Ole André Vadla Ravnås | 927fcbc | 2014-05-01 16:00:52 +0200 | [diff] [blame] | 287 | endif |
Nguyen Anh Quynh | 0936b56 | 2014-06-04 00:26:33 +0800 | [diff] [blame] | 288 | endif |
| 289 | |
Ole André Vadla Ravnås | 927fcbc | 2014-05-01 16:00:52 +0200 | [diff] [blame] | 290 | ifeq ($(CAPSTONE_STATIC),yes) |
Nguyen Anh Quynh | 0936b56 | 2014-06-04 00:26:33 +0800 | [diff] [blame] | 291 | ifeq ($(IS_MINGW),1) |
| 292 | ARCHIVE = $(BLDIR)/$(LIBNAME).$(AR_EXT) |
| 293 | else ifeq ($(IS_CYGWIN),1) |
| 294 | ARCHIVE = $(BLDIR)/$(LIBNAME).$(AR_EXT) |
| 295 | else |
Nguyen Anh Quynh | 6ae472f | 2014-04-29 16:29:55 +0800 | [diff] [blame] | 296 | ARCHIVE = $(BLDIR)/lib$(LIBNAME).$(AR_EXT) |
Ole André Vadla Ravnås | 927fcbc | 2014-05-01 16:00:52 +0200 | [diff] [blame] | 297 | endif |
Nguyen Anh Quynh | 0936b56 | 2014-06-04 00:26:33 +0800 | [diff] [blame] | 298 | endif |
| 299 | |
Nguyen Anh Quynh | 6ae472f | 2014-04-29 16:29:55 +0800 | [diff] [blame] | 300 | PKGCFGF = $(BLDIR)/$(LIBNAME).pc |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 301 | |
Nguyen Anh Quynh | 5bbbfce | 2014-02-28 10:49:46 +0800 | [diff] [blame] | 302 | .PHONY: all clean install uninstall dist |
pancake | ca9f1b2 | 2013-12-06 17:03:41 +0100 | [diff] [blame] | 303 | |
Nguyen Anh Quynh | 80ff30b | 2013-12-09 00:38:44 +0800 | [diff] [blame] | 304 | all: $(LIBRARY) $(ARCHIVE) $(PKGCFGF) |
Nguyen Anh Quynh | 375f03c | 2014-04-30 07:19:18 +0800 | [diff] [blame] | 305 | ifndef BUILDDIR |
danghvu | ad66420 | 2014-05-12 14:27:38 -0500 | [diff] [blame] | 306 | cd tests && $(MAKE) |
Nguyen Anh Quynh | 375f03c | 2014-04-30 07:19:18 +0800 | [diff] [blame] | 307 | else |
danghvu | ad66420 | 2014-05-12 14:27:38 -0500 | [diff] [blame] | 308 | cd tests && $(MAKE) BUILDDIR=$(BLDIR) |
Nguyen Anh Quynh | 375f03c | 2014-04-30 07:19:18 +0800 | [diff] [blame] | 309 | endif |
Ole André Vadla Ravnås | 927fcbc | 2014-05-01 16:00:52 +0200 | [diff] [blame] | 310 | ifeq ($(CAPSTONE_SHARED),yes) |
Nguyen Anh Quynh | 0936b56 | 2014-06-04 00:26:33 +0800 | [diff] [blame] | 311 | $(INSTALL_DATA) $(LIBRARY) $(BLDIR)/tests/ |
Ole André Vadla Ravnås | 927fcbc | 2014-05-01 16:00:52 +0200 | [diff] [blame] | 312 | endif |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 313 | |
Ole André Vadla Ravnås | 927fcbc | 2014-05-01 16:00:52 +0200 | [diff] [blame] | 314 | ifeq ($(CAPSTONE_SHARED),yes) |
pancake | addb192 | 2014-02-28 02:44:07 +0100 | [diff] [blame] | 315 | $(LIBRARY): $(LIBOBJ) |
Ole André Vadla Ravnås | f536d40 | 2014-05-01 15:22:25 +0200 | [diff] [blame] | 316 | ifeq ($(V),0) |
Nguyen Anh Quynh | 8c0ab86 | 2014-06-03 23:43:53 +0700 | [diff] [blame] | 317 | $(call log,LINK,$(@:$(BLDIR)/%=%)) |
Ole André Vadla Ravnås | f536d40 | 2014-05-01 15:22:25 +0200 | [diff] [blame] | 318 | @$(create-library) |
| 319 | else |
| 320 | $(create-library) |
| 321 | endif |
Ole André Vadla Ravnås | 927fcbc | 2014-05-01 16:00:52 +0200 | [diff] [blame] | 322 | endif |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 323 | |
Nguyen Anh Quynh | aeb0c40 | 2014-03-27 17:54:27 +0800 | [diff] [blame] | 324 | $(LIBOBJ): config.mk |
| 325 | |
Nguyen Anh Quynh | 4a328ca | 2014-02-28 23:09:04 +0800 | [diff] [blame] | 326 | $(LIBOBJ_ARM): $(DEP_ARM) |
| 327 | $(LIBOBJ_ARM64): $(DEP_ARM64) |
| 328 | $(LIBOBJ_MIPS): $(DEP_MIPS) |
| 329 | $(LIBOBJ_PPC): $(DEP_PPC) |
Nguyen Anh Quynh | 05e2713 | 2014-03-10 11:58:57 +0800 | [diff] [blame] | 330 | $(LIBOBJ_SPARC): $(DEP_SPARC) |
Nguyen Anh Quynh | 48a14ca | 2014-03-23 08:35:45 +0800 | [diff] [blame] | 331 | $(LIBOBJ_SYSZ): $(DEP_SYSZ) |
Nguyen Anh Quynh | 4a328ca | 2014-02-28 23:09:04 +0800 | [diff] [blame] | 332 | $(LIBOBJ_X86): $(DEP_X86) |
Nguyen Anh Quynh | c80d840 | 2014-05-26 23:02:48 +0800 | [diff] [blame] | 333 | $(LIBOBJ_XCORE): $(DEP_XCORE) |
Nguyen Anh Quynh | 4a328ca | 2014-02-28 23:09:04 +0800 | [diff] [blame] | 334 | |
Ole André Vadla Ravnås | 927fcbc | 2014-05-01 16:00:52 +0200 | [diff] [blame] | 335 | ifeq ($(CAPSTONE_STATIC),yes) |
pancake | ca9f1b2 | 2013-12-06 17:03:41 +0100 | [diff] [blame] | 336 | $(ARCHIVE): $(LIBOBJ) |
Ole André Vadla Ravnås | f536d40 | 2014-05-01 15:22:25 +0200 | [diff] [blame] | 337 | @rm -f $(ARCHIVE) |
| 338 | ifeq ($(V),0) |
| 339 | $(call log,AR,$(@:$(BLDIR)/%=%)) |
| 340 | @$(create-archive) |
| 341 | else |
| 342 | $(create-archive) |
| 343 | endif |
Ole André Vadla Ravnås | 927fcbc | 2014-05-01 16:00:52 +0200 | [diff] [blame] | 344 | endif |
pancake | f1cbce2 | 2013-11-27 15:31:26 +0100 | [diff] [blame] | 345 | |
pancake | ca9f1b2 | 2013-12-06 17:03:41 +0100 | [diff] [blame] | 346 | $(PKGCFGF): |
Ole André Vadla Ravnås | f536d40 | 2014-05-01 15:22:25 +0200 | [diff] [blame] | 347 | ifeq ($(V),0) |
| 348 | $(call log,GEN,$(@:$(BLDIR)/%=%)) |
| 349 | @$(generate-pkgcfg) |
Nguyen Anh Quynh | 3ff259c | 2014-03-07 17:11:18 +0800 | [diff] [blame] | 350 | else |
Ole André Vadla Ravnås | f536d40 | 2014-05-01 15:22:25 +0200 | [diff] [blame] | 351 | $(generate-pkgcfg) |
Nguyen Anh Quynh | 3ff259c | 2014-03-07 17:11:18 +0800 | [diff] [blame] | 352 | endif |
pancake | 44ce0fb | 2013-12-03 04:11:37 +0100 | [diff] [blame] | 353 | |
pancake | ca9f1b2 | 2013-12-06 17:03:41 +0100 | [diff] [blame] | 354 | install: $(PKGCFGF) $(ARCHIVE) $(LIBRARY) |
pancake | 02cad6e | 2013-11-27 15:38:44 +0100 | [diff] [blame] | 355 | mkdir -p $(LIBDIR) |
Ole André Vadla Ravnås | 927fcbc | 2014-05-01 16:00:52 +0200 | [diff] [blame] | 356 | ifeq ($(CAPSTONE_SHARED),yes) |
Nguyen Anh Quynh | 7df338c | 2014-03-18 09:28:48 +0800 | [diff] [blame] | 357 | # remove potential broken old libs |
| 358 | rm -f $(LIBDIR)/lib$(LIBNAME).* |
Nguyen Anh Quynh | 0936b56 | 2014-06-04 00:26:33 +0800 | [diff] [blame] | 359 | $(INSTALL_LIB) $(LIBRARY) $(LIBDIR) |
Nguyen Anh Quynh | c0c0d52 | 2014-03-17 17:31:33 +0800 | [diff] [blame] | 360 | ifneq ($(VERSION_EXT),) |
pancake | e030e18 | 2014-02-04 08:36:22 +0100 | [diff] [blame] | 361 | cd $(LIBDIR) && \ |
| 362 | mv lib$(LIBNAME).$(EXT) lib$(LIBNAME).$(VERSION_EXT) && \ |
| 363 | ln -s lib$(LIBNAME).$(VERSION_EXT) lib$(LIBNAME).$(EXT) |
Nguyen Anh Quynh | c0c0d52 | 2014-03-17 17:31:33 +0800 | [diff] [blame] | 364 | endif |
Ole André Vadla Ravnås | 927fcbc | 2014-05-01 16:00:52 +0200 | [diff] [blame] | 365 | endif |
| 366 | ifeq ($(CAPSTONE_STATIC),yes) |
Nguyen Anh Quynh | 0936b56 | 2014-06-04 00:26:33 +0800 | [diff] [blame] | 367 | $(INSTALL_DATA) $(ARCHIVE) $(LIBDIR) |
Ole André Vadla Ravnås | 927fcbc | 2014-05-01 16:00:52 +0200 | [diff] [blame] | 368 | endif |
pancake | 02cad6e | 2013-11-27 15:38:44 +0100 | [diff] [blame] | 369 | mkdir -p $(INCDIR)/$(LIBNAME) |
Nguyen Anh Quynh | 3524056 | 2014-01-04 09:18:48 +0800 | [diff] [blame] | 370 | $(INSTALL_DATA) include/*.h $(INCDIR)/$(LIBNAME) |
Nguyen Anh Quynh | 9b4b377 | 2014-04-12 18:06:54 +0800 | [diff] [blame] | 371 | mkdir -p $(PKGCFGDIR) |
| 372 | $(INSTALL_DATA) $(PKGCFGF) $(PKGCFGDIR)/ |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 373 | |
| 374 | uninstall: |
pancake | 02cad6e | 2013-11-27 15:38:44 +0100 | [diff] [blame] | 375 | rm -rf $(INCDIR)/$(LIBNAME) |
Nguyen Anh Quynh | 6d5381e | 2014-03-17 10:37:08 +0800 | [diff] [blame] | 376 | rm -f $(LIBDIR)/lib$(LIBNAME).* |
Nguyen Anh Quynh | 9b4b377 | 2014-04-12 18:06:54 +0800 | [diff] [blame] | 377 | rm -f $(PKGCFGDIR)/$(LIBNAME).pc |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 378 | |
| 379 | clean: |
Nguyen Anh Quynh | 5519a68 | 2014-04-29 16:24:30 +0800 | [diff] [blame] | 380 | rm -f $(LIBOBJ) |
Nguyen Anh Quynh | 0936b56 | 2014-06-04 00:26:33 +0800 | [diff] [blame] | 381 | rm -f $(BLDIR)/lib$(LIBNAME).* $(BLDIR)/$(LIBNAME).* |
Nguyen Anh Quynh | d63ddac | 2014-01-09 10:35:58 +0800 | [diff] [blame] | 382 | rm -f $(PKGCFGF) |
danghvu | ad66420 | 2014-05-12 14:27:38 -0500 | [diff] [blame] | 383 | cd tests && $(MAKE) clean |
Nguyen Anh Quynh | 6ae472f | 2014-04-29 16:29:55 +0800 | [diff] [blame] | 384 | rm -f $(BLDIR)/tests/lib$(LIBNAME).$(EXT) |
| 385 | |
| 386 | ifdef BUILDDIR |
| 387 | rm -rf $(BUILDDIR) |
| 388 | endif |
Nguyen Anh Quynh | 5519a68 | 2014-04-29 16:24:30 +0800 | [diff] [blame] | 389 | |
danghvu | ad66420 | 2014-05-12 14:27:38 -0500 | [diff] [blame] | 390 | cd bindings/python && $(MAKE) clean |
| 391 | cd bindings/java && $(MAKE) clean |
| 392 | cd bindings/ocaml && $(MAKE) clean |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 393 | |
Nguyen Anh Quynh | a580d92 | 2014-01-18 12:47:15 +0800 | [diff] [blame] | 394 | |
| 395 | TAG ?= HEAD |
| 396 | ifeq ($(TAG), HEAD) |
| 397 | DIST_VERSION = latest |
| 398 | else |
| 399 | DIST_VERSION = $(TAG) |
| 400 | endif |
| 401 | |
pancake | 35cef7f | 2014-01-18 03:42:15 +0100 | [diff] [blame] | 402 | dist: |
Nguyen Anh Quynh | 186d501 | 2014-01-22 18:46:20 +0800 | [diff] [blame] | 403 | git archive --format=tar.gz --prefix=capstone-$(DIST_VERSION)/ $(TAG) > capstone-$(DIST_VERSION).tgz |
Nguyen Anh Quynh | f4f7253 | 2014-03-11 12:29:16 +0800 | [diff] [blame] | 404 | git archive --format=zip --prefix=capstone-$(DIST_VERSION)/ $(TAG) > capstone-$(DIST_VERSION).zip |
pancake | 35cef7f | 2014-01-18 03:42:15 +0100 | [diff] [blame] | 405 | |
Ole André Vadla Ravnås | 35f937d | 2014-04-29 09:00:34 +0200 | [diff] [blame] | 406 | $(OBJDIR)/%.o: %.c |
| 407 | @mkdir -p $(@D) |
Ole André Vadla Ravnås | f536d40 | 2014-05-01 15:22:25 +0200 | [diff] [blame] | 408 | ifeq ($(V),0) |
| 409 | $(call log,CC,$(@:$(OBJDIR)/%=%)) |
| 410 | @$(compile) |
| 411 | else |
| 412 | $(compile) |
| 413 | endif |
| 414 | |
Ole André Vadla Ravnås | f536d40 | 2014-05-01 15:22:25 +0200 | [diff] [blame] | 415 | |
| 416 | define create-archive |
| 417 | $(AR) q $(ARCHIVE) $(LIBOBJ) |
| 418 | $(RANLIB) $(ARCHIVE) |
| 419 | endef |
| 420 | |
Nguyen Anh Quynh | 58a0047 | 2014-05-01 22:53:52 +0800 | [diff] [blame] | 421 | |
Ole André Vadla Ravnås | f536d40 | 2014-05-01 15:22:25 +0200 | [diff] [blame] | 422 | define create-library |
danghvu | e1c7a21 | 2014-05-14 02:13:36 -0500 | [diff] [blame] | 423 | $(CC) $(LDFLAGS) $($(LIBNAME)_LDFLAGS) $(LIBOBJ) -o $(LIBRARY) |
Ole André Vadla Ravnås | f536d40 | 2014-05-01 15:22:25 +0200 | [diff] [blame] | 424 | endef |
| 425 | |
Nguyen Anh Quynh | 58a0047 | 2014-05-01 22:53:52 +0800 | [diff] [blame] | 426 | |
Ole André Vadla Ravnås | f536d40 | 2014-05-01 15:22:25 +0200 | [diff] [blame] | 427 | define generate-pkgcfg |
| 428 | echo 'Name: capstone' > $(PKGCFGF) |
| 429 | echo 'Description: Capstone disassembly engine' >> $(PKGCFGF) |
| 430 | echo 'Version: $(PKG_VERSION)' >> $(PKGCFGF) |
| 431 | echo 'libdir=$(LIBDIR)' >> $(PKGCFGF) |
| 432 | echo 'includedir=$(PREFIX)/include/capstone' >> $(PKGCFGF) |
| 433 | echo 'archive=$${libdir}/libcapstone.a' >> $(PKGCFGF) |
| 434 | echo 'Libs: -L$${libdir} -lcapstone' >> $(PKGCFGF) |
| 435 | echo 'Cflags: -I$${includedir}' >> $(PKGCFGF) |
| 436 | endef |
| 437 | |