2013-11-27 04:11:31 +00:00
|
|
|
# Capstone Disassembler Engine
|
|
|
|
# By Nguyen Anh Quynh <aquynh@gmail.com>, 2013>
|
2013-12-31 15:38:28 +00:00
|
|
|
|
2013-12-20 04:43:01 +00:00
|
|
|
include config.mk
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2014-01-16 13:07:59 +00:00
|
|
|
ifeq ($(CROSS),)
|
|
|
|
CC ?= cc
|
|
|
|
AR ?= ar
|
|
|
|
RANLIB ?= ranlib
|
|
|
|
STRIP ?= strip
|
|
|
|
else
|
|
|
|
CC = $(CROSS)gcc
|
|
|
|
AR = $(CROSS)ar
|
|
|
|
RANLIB = $(CROSS)ranlib
|
|
|
|
STRIP = $(CROSS)strip
|
|
|
|
endif
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2013-12-06 16:03:41 +00:00
|
|
|
CFLAGS += -fPIC -O3 -Wall -Iinclude
|
2014-01-05 15:41:31 +00:00
|
|
|
|
|
|
|
ifeq ($(USE_SYS_DYN_MEM),yes)
|
|
|
|
CFLAGS += -DUSE_SYS_DYN_MEM
|
|
|
|
endif
|
|
|
|
|
2013-11-27 04:11:31 +00:00
|
|
|
LDFLAGS += -shared
|
|
|
|
|
2013-11-27 14:38:44 +00:00
|
|
|
PREFIX ?= /usr
|
|
|
|
DESTDIR ?=
|
|
|
|
INCDIR = $(DESTDIR)$(PREFIX)/include
|
2013-12-25 14:47:28 +00:00
|
|
|
|
2013-11-27 14:38:44 +00:00
|
|
|
LIBDIR = $(DESTDIR)$(PREFIX)/lib
|
2013-12-25 14:47:28 +00:00
|
|
|
# on x86_64, we might have /usr/lib64 directory instead of /usr/lib
|
|
|
|
MACHINE := $(shell uname -m)
|
|
|
|
ifeq ($(MACHINE), x86_64)
|
2014-01-01 13:40:49 +00:00
|
|
|
ifeq (,$(wildcard $(LIBDIR)))
|
|
|
|
LIBDIR = $(DESTDIR)$(PREFIX)/lib64
|
|
|
|
else
|
|
|
|
LIBDIR = $(DESTDIR)$(PREFIX)/lib
|
|
|
|
endif
|
2013-12-25 14:47:28 +00:00
|
|
|
endif
|
2013-11-27 14:38:44 +00:00
|
|
|
|
|
|
|
INSTALL_DATA ?= install -m0644
|
|
|
|
INSTALL_LIBRARY ?= install -m0755
|
|
|
|
|
2013-11-27 04:11:31 +00:00
|
|
|
LIBNAME = capstone
|
2013-12-06 16:03:41 +00:00
|
|
|
|
2013-11-27 04:11:31 +00:00
|
|
|
LIBOBJ =
|
2013-12-02 02:30:01 +00:00
|
|
|
LIBOBJ += cs.o utils.o SStream.o MCInstrDesc.o MCRegisterInfo.o
|
2013-12-29 16:15:25 +00:00
|
|
|
|
2014-01-15 08:01:55 +00:00
|
|
|
ifneq (,$(findstring arm,$(CAPSTONE_ARCHS)))
|
|
|
|
CFLAGS += -DCAPSTONE_HAS_ARM
|
|
|
|
LIBOBJ += arch/ARM/ARMDisassembler.o
|
|
|
|
LIBOBJ += arch/ARM/ARMInstPrinter.o
|
|
|
|
LIBOBJ += arch/ARM/mapping.o
|
|
|
|
LIBOBJ += arch/ARM/module.o
|
|
|
|
endif
|
2014-01-14 15:08:20 +00:00
|
|
|
ifneq (,$(findstring mips,$(CAPSTONE_ARCHS)))
|
|
|
|
CFLAGS += -DCAPSTONE_HAS_MIPS
|
|
|
|
LIBOBJ += arch/Mips/MipsDisassembler.o
|
|
|
|
LIBOBJ += arch/Mips/MipsInstPrinter.o
|
|
|
|
LIBOBJ += arch/Mips/mapping.o
|
|
|
|
LIBOBJ += arch/Mips/module.o
|
|
|
|
endif
|
2013-12-29 16:15:25 +00:00
|
|
|
ifneq (,$(findstring powerpc,$(CAPSTONE_ARCHS)))
|
2014-01-09 04:06:44 +00:00
|
|
|
CFLAGS += -DCAPSTONE_HAS_POWERPC
|
2013-12-29 16:15:25 +00:00
|
|
|
LIBOBJ += arch/PowerPC/PPCDisassembler.o
|
|
|
|
LIBOBJ += arch/PowerPC/PPCInstPrinter.o
|
2014-01-04 16:00:05 +00:00
|
|
|
LIBOBJ += arch/PowerPC/mapping.o
|
2013-12-29 16:15:25 +00:00
|
|
|
LIBOBJ += arch/PowerPC/module.o
|
|
|
|
endif
|
2013-12-22 03:28:34 +00:00
|
|
|
ifneq (,$(findstring x86,$(CAPSTONE_ARCHS)))
|
2014-01-09 04:06:44 +00:00
|
|
|
CFLAGS += -DCAPSTONE_HAS_X86
|
2013-12-29 16:15:25 +00:00
|
|
|
LIBOBJ += arch/X86/X86DisassemblerDecoder.o
|
|
|
|
LIBOBJ += arch/X86/X86Disassembler.o
|
|
|
|
LIBOBJ += arch/X86/X86IntelInstPrinter.o
|
|
|
|
LIBOBJ += arch/X86/X86ATTInstPrinter.o
|
|
|
|
LIBOBJ += arch/X86/mapping.o arch/X86/module.o
|
2013-12-19 18:10:24 +00:00
|
|
|
endif
|
2013-12-22 03:28:34 +00:00
|
|
|
ifneq (,$(findstring aarch64,$(CAPSTONE_ARCHS)))
|
2014-01-09 04:06:44 +00:00
|
|
|
CFLAGS += -DCAPSTONE_HAS_ARM64
|
2013-12-29 16:15:25 +00:00
|
|
|
LIBOBJ += arch/AArch64/AArch64BaseInfo.o
|
|
|
|
LIBOBJ += arch/AArch64/AArch64Disassembler.o
|
|
|
|
LIBOBJ += arch/AArch64/AArch64InstPrinter.o
|
|
|
|
LIBOBJ += arch/AArch64/mapping.o
|
|
|
|
LIBOBJ += arch/AArch64/module.o
|
2013-12-20 06:57:12 +00:00
|
|
|
endif
|
2013-12-29 16:15:25 +00:00
|
|
|
|
2013-11-27 04:11:31 +00:00
|
|
|
LIBOBJ += MCInst.o
|
|
|
|
|
|
|
|
UNAME_S := $(shell uname -s)
|
2013-12-31 15:38:28 +00:00
|
|
|
# OSX?
|
2013-11-27 04:11:31 +00:00
|
|
|
ifeq ($(UNAME_S),Darwin)
|
|
|
|
EXT = dylib
|
2013-12-25 15:54:45 +00:00
|
|
|
AR_EXT = a
|
2013-11-27 14:38:44 +00:00
|
|
|
else
|
2013-11-28 18:22:50 +00:00
|
|
|
# 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
|
2013-12-25 15:54:45 +00:00
|
|
|
else
|
|
|
|
# Linux, *BSD
|
|
|
|
EXT = so
|
|
|
|
AR_EXT = a
|
|
|
|
LDFLAGS += -Wl,-soname,$(LIBRARY)
|
2013-11-28 18:22:50 +00:00
|
|
|
endif
|
|
|
|
endif
|
2013-11-27 04:11:31 +00:00
|
|
|
endif
|
|
|
|
|
2013-12-06 16:03:41 +00:00
|
|
|
LIBRARY = lib$(LIBNAME).$(EXT)
|
|
|
|
ARCHIVE = lib$(LIBNAME).$(AR_EXT)
|
|
|
|
PKGCFGF = $(LIBNAME).pc
|
|
|
|
|
2013-12-13 01:24:41 +00:00
|
|
|
VERSION=$(shell echo `grep -e PKG_MAJOR -e PKG_MINOR CONFIG | grep -v = | awk '{print $$3}'` | awk '{print $$1"."$$2}')
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2013-12-06 16:03:41 +00:00
|
|
|
.PHONY: all clean install uninstall
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2013-12-08 16:38:44 +00:00
|
|
|
all: $(LIBRARY) $(ARCHIVE) $(PKGCFGF)
|
2013-11-27 14:38:44 +00:00
|
|
|
$(MAKE) -C tests
|
|
|
|
$(INSTALL_DATA) lib$(LIBNAME).$(EXT) tests
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2013-12-06 16:03:41 +00:00
|
|
|
$(LIBRARY): $(LIBOBJ)
|
|
|
|
$(CC) $(LDFLAGS) $(LIBOBJ) -o $(LIBRARY)
|
2013-11-27 14:31:26 +00:00
|
|
|
|
2013-12-06 16:03:41 +00:00
|
|
|
$(ARCHIVE): $(LIBOBJ)
|
|
|
|
rm -f $(ARCHIVE)
|
|
|
|
$(AR) q $(ARCHIVE) $(LIBOBJ)
|
|
|
|
$(RANLIB) $(ARCHIVE)
|
2013-12-03 03:11:37 +00:00
|
|
|
|
2013-12-06 16:03:41 +00:00
|
|
|
$(PKGCFGF):
|
2013-12-22 05:23:20 +00:00
|
|
|
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)
|
2013-12-03 03:11:37 +00:00
|
|
|
|
2013-12-06 16:03:41 +00:00
|
|
|
install: $(PKGCFGF) $(ARCHIVE) $(LIBRARY)
|
2013-11-27 14:38:44 +00:00
|
|
|
mkdir -p $(LIBDIR)
|
|
|
|
$(INSTALL_LIBRARY) lib$(LIBNAME).$(EXT) $(LIBDIR)
|
2013-11-28 18:22:50 +00:00
|
|
|
$(INSTALL_DATA) lib$(LIBNAME).$(AR_EXT) $(LIBDIR)
|
2013-11-27 14:38:44 +00:00
|
|
|
mkdir -p $(INCDIR)/$(LIBNAME)
|
2014-01-04 01:18:48 +00:00
|
|
|
$(INSTALL_DATA) include/*.h $(INCDIR)/$(LIBNAME)
|
2013-12-03 03:11:37 +00:00
|
|
|
mkdir -p $(LIBDIR)/pkgconfig
|
2013-12-06 16:03:41 +00:00
|
|
|
$(INSTALL_DATA) $(PKGCFGF) $(LIBDIR)/pkgconfig/
|
2013-11-27 04:11:31 +00:00
|
|
|
|
|
|
|
uninstall:
|
2013-11-27 14:38:44 +00:00
|
|
|
rm -rf $(INCDIR)/$(LIBNAME)
|
|
|
|
rm -f $(LIBDIR)/lib$(LIBNAME).$(EXT)
|
2013-11-28 18:22:50 +00:00
|
|
|
rm -f $(LIBDIR)/lib$(LIBNAME).$(AR_EXT)
|
2013-12-03 03:11:37 +00:00
|
|
|
rm -f $(LIBDIR)/pkgconfig/$(LIBNAME).pc
|
2013-11-27 04:11:31 +00:00
|
|
|
|
|
|
|
clean:
|
2013-11-28 18:22:50 +00:00
|
|
|
rm -f $(LIBOBJ) lib$(LIBNAME).*
|
2014-01-09 02:35:58 +00:00
|
|
|
rm -f $(PKGCFGF)
|
2013-11-27 14:38:44 +00:00
|
|
|
$(MAKE) -C bindings/python clean
|
2013-11-28 16:18:02 +00:00
|
|
|
$(MAKE) -C bindings/java clean
|
2013-11-27 14:38:44 +00:00
|
|
|
$(MAKE) -C bindings/ocaml clean
|
|
|
|
$(MAKE) -C tests clean
|
2013-11-27 04:11:31 +00:00
|
|
|
|
|
|
|
.c.o:
|
2013-12-06 16:03:41 +00:00
|
|
|
$(CC) $(CFLAGS) -c $< -o $@
|