2013-11-27 12:11:31 +08:00
|
|
|
# Capstone Disassembler Engine
|
2014-03-10 11:58:57 +08:00
|
|
|
# By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-03-01 20:44:58 +08:00
|
|
|
include ../config.mk
|
2014-05-01 22:53:52 +08:00
|
|
|
include ../functions.mk
|
2014-03-01 20:44:58 +08:00
|
|
|
|
2014-05-01 21:22:25 +08:00
|
|
|
# Verbose output?
|
|
|
|
V ?= 0
|
|
|
|
|
2013-11-27 12:11:31 +08:00
|
|
|
INCDIR = ../include
|
2014-04-29 15:00:34 +08:00
|
|
|
ifndef BUILDDIR
|
2014-04-29 16:24:30 +08:00
|
|
|
TESTDIR = .
|
2014-04-29 15:00:34 +08:00
|
|
|
OBJDIR = .
|
2014-04-29 16:24:30 +08:00
|
|
|
LIBDIR = ..
|
2014-04-29 15:00:34 +08:00
|
|
|
else
|
2014-04-30 05:02:36 +08:00
|
|
|
TESTDIR = $(BUILDDIR)/tests
|
2014-04-30 06:06:41 +08:00
|
|
|
OBJDIR = $(BUILDDIR)/obj/tests
|
2014-04-30 05:02:36 +08:00
|
|
|
LIBDIR = $(BUILDDIR)
|
2014-04-29 15:00:34 +08:00
|
|
|
endif
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-01-16 21:07:59 +08:00
|
|
|
ifeq ($(CROSS),)
|
|
|
|
CC ?= cc
|
|
|
|
else
|
|
|
|
CC = $(CROSS)gcc
|
|
|
|
endif
|
|
|
|
|
2014-01-16 19:08:49 +08:00
|
|
|
|
2014-10-02 15:49:53 +08:00
|
|
|
CFLAGS += -Wall -I$(INCDIR)
|
2014-05-10 15:50:38 +08:00
|
|
|
LDFLAGS += -L$(LIBDIR)
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-07-05 05:38:20 +08:00
|
|
|
CFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
|
|
|
|
LDFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
|
|
|
|
|
2013-11-27 12:11:31 +08:00
|
|
|
LIBNAME = capstone
|
|
|
|
|
2013-11-29 02:22:50 +08:00
|
|
|
BIN_EXT =
|
2014-01-09 15:49:44 +08:00
|
|
|
AR_EXT = a
|
2013-11-29 02:22:50 +08:00
|
|
|
|
|
|
|
# Cygwin?
|
|
|
|
IS_CYGWIN := $(shell $(CC) -dumpmachine | grep -i cygwin | wc -l)
|
|
|
|
ifeq ($(IS_CYGWIN),1)
|
|
|
|
CFLAGS := $(CFLAGS:-fPIC=)
|
|
|
|
BIN_EXT = .exe
|
2014-05-14 14:53:51 +08:00
|
|
|
AR_EXT = lib
|
2013-11-29 02:22:50 +08:00
|
|
|
else
|
|
|
|
# mingw?
|
2018-12-20 15:09:27 +08:00
|
|
|
IS_MINGW := $(shell $(CC) --version 2>/dev/null | grep -i "\(mingw\|MSYS\)" | wc -l)
|
2013-11-29 02:22:50 +08:00
|
|
|
ifeq ($(IS_MINGW),1)
|
|
|
|
CFLAGS := $(CFLAGS:-fPIC=)
|
|
|
|
BIN_EXT = .exe
|
2014-05-14 14:53:51 +08:00
|
|
|
AR_EXT = lib
|
2013-11-29 02:22:50 +08:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2014-06-04 00:26:33 +08:00
|
|
|
ifeq ($(CAPSTONE_STATIC),yes)
|
|
|
|
ifeq ($(IS_MINGW),1)
|
|
|
|
ARCHIVE = $(LIBDIR)/$(LIBNAME).$(AR_EXT)
|
|
|
|
else ifeq ($(IS_CYGWIN),1)
|
|
|
|
ARCHIVE = $(LIBDIR)/$(LIBNAME).$(AR_EXT)
|
|
|
|
else
|
|
|
|
ARCHIVE = $(LIBDIR)/lib$(LIBNAME).$(AR_EXT)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2013-11-29 02:22:50 +08:00
|
|
|
.PHONY: all clean
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2015-06-16 17:32:03 +08:00
|
|
|
SOURCES = test_basic.c test_detail.c test_skipdata.c test_iter.c test_customized_mnem.c
|
2014-03-01 20:44:58 +08:00
|
|
|
ifneq (,$(findstring arm,$(CAPSTONE_ARCHS)))
|
2015-08-10 00:48:45 +08:00
|
|
|
CFLAGS += -DCAPSTONE_HAS_ARM
|
2014-03-01 20:44:58 +08:00
|
|
|
SOURCES += test_arm.c
|
|
|
|
endif
|
|
|
|
ifneq (,$(findstring aarch64,$(CAPSTONE_ARCHS)))
|
2015-08-10 00:48:45 +08:00
|
|
|
CFLAGS += -DCAPSTONE_HAS_ARM64
|
2014-03-01 20:44:58 +08:00
|
|
|
SOURCES += test_arm64.c
|
|
|
|
endif
|
2015-08-04 00:45:08 +08:00
|
|
|
ifneq (,$(findstring m68k,$(CAPSTONE_ARCHS)))
|
|
|
|
CFLAGS += -DCAPSTONE_HAS_M68K
|
|
|
|
SOURCES += test_m68k.c
|
|
|
|
endif
|
2014-03-01 20:44:58 +08:00
|
|
|
ifneq (,$(findstring mips,$(CAPSTONE_ARCHS)))
|
2015-08-10 00:48:45 +08:00
|
|
|
CFLAGS += -DCAPSTONE_HAS_MIPS
|
2014-03-01 20:44:58 +08:00
|
|
|
SOURCES += test_mips.c
|
|
|
|
endif
|
|
|
|
ifneq (,$(findstring powerpc,$(CAPSTONE_ARCHS)))
|
2015-08-10 00:48:45 +08:00
|
|
|
CFLAGS += -DCAPSTONE_HAS_POWERPC
|
2014-03-01 20:44:58 +08:00
|
|
|
SOURCES += test_ppc.c
|
|
|
|
endif
|
2014-03-10 11:58:57 +08:00
|
|
|
ifneq (,$(findstring sparc,$(CAPSTONE_ARCHS)))
|
2015-08-10 00:48:45 +08:00
|
|
|
CFLAGS += -DCAPSTONE_HAS_SPARC
|
2014-03-10 11:58:57 +08:00
|
|
|
SOURCES += test_sparc.c
|
|
|
|
endif
|
2014-03-23 08:35:45 +08:00
|
|
|
ifneq (,$(findstring systemz,$(CAPSTONE_ARCHS)))
|
2015-08-10 00:48:45 +08:00
|
|
|
CFLAGS += -DCAPSTONE_HAS_SYSZ
|
2014-03-23 08:35:45 +08:00
|
|
|
SOURCES += test_systemz.c
|
|
|
|
endif
|
2014-03-01 20:44:58 +08:00
|
|
|
ifneq (,$(findstring x86,$(CAPSTONE_ARCHS)))
|
2015-08-10 00:48:45 +08:00
|
|
|
CFLAGS += -DCAPSTONE_HAS_X86
|
2014-03-01 20:44:58 +08:00
|
|
|
SOURCES += test_x86.c
|
|
|
|
endif
|
2014-05-26 23:02:48 +08:00
|
|
|
ifneq (,$(findstring xcore,$(CAPSTONE_ARCHS)))
|
2015-08-10 00:48:45 +08:00
|
|
|
CFLAGS += -DCAPSTONE_HAS_XCORE
|
2014-05-26 23:02:48 +08:00
|
|
|
SOURCES += test_xcore.c
|
|
|
|
endif
|
2016-05-03 20:52:11 +08:00
|
|
|
ifneq (,$(findstring tms320c64x,$(CAPSTONE_ARCHS)))
|
|
|
|
CFLAGS += -DCAPSTONE_HAS_TMS320C64X
|
|
|
|
SOURCES += test_tms320c64x.c
|
|
|
|
endif
|
M680X: Target ready for pull request (#1034)
* Added new M680X target. Supports M6800/1/2/3/9, HD6301
* M680X: Reformat for coding guide lines. Set alphabetical order in HACK.TXT
* M680X: Prepare for python binding. Move cs_m680x, m680x_insn to m680x_info. Chec
> k cpu type, no default.
* M680X: Add python bindings. Added python tests.
* M680X: Added cpu types to usage message.
* cstool: Avoid segfault for invalid <arch+mode>.
* Make test_m680x.c/test_m680x.py output comparable (diff params: -bu). Keep xprint.py untouched.
* M680X: Update CMake/make for m680x support. Update .gitignore.
* M680X: Reduce compiler warnings.
* M680X: Reduce compiler warnings.
* M680X: Reduce compiler warnings.
* M680X: Make test_m680x.c/test_m680x.py output comparable (diff params: -bu).
* M680X: Add ocaml bindings and tests.
* M680X: Add java bindings and tests.
* M680X: Added tests for all indexed addressing modes. C/Python/Ocaml
* M680X: Naming, use page1 for PAGE1 instructions (without prefix).
* M680X: Naming, use page1 for PAGE1 instructions (without prefix).
* M680X: Used M680X_FIRST_OP_IN_MNEM in tests C/python/java/ocaml.
* M680X: Added access property to cs_m680x_op.
* M680X: Added operand size.
* M680X: Remove compiler warnings.
* M680X: Added READ/WRITE access property per operator.
* M680X: Make reg_inherent_hdlr independent of CPU type.
* M680X: Add HD6309 support + bug fixes
* M680X: Remove errors and warning.
* M680X: Add Bcc/LBcc to group BRAREL (relative branch).
* M680X: Add group JUMP to BVS/BVC/LBVS/LBVC. Remove BRAREL from BRN/LBRN.
* M680X: Remove LBRN from group BRAREL.
* M680X: Refactored cpu_type initialization for better readability.
* M680X: Add two operands for insn having two reg. in mnemonic. e.g. ABX.
* M680X: Remove typo in cstool.c
* M680X: Some format improvements in changed_regs.
* M680X: Remove insn id string list from tests (C/python/java/ocaml).
* M680X: SEXW, set access of reg. D to WRITE.
* M680X: Sort changed_regs in increasing m680x_insn order.
* M680X: Add M68HC11 support + Reduced from two to one INDEXED operand.
* M680X: cstool, also write '(in mnemonic)' for second reg. operand.
* M680X: Add BRN/LBRN to group JUMP and BRAREL.
* M680X: For Bcc/LBcc/BRSET/BRCLR set reg. CC to read access.
* M680X: Correctly print negative immediate values with option CS_OPT_UNSIGNED.
* M680X: Rename some instruction handlers.
* M680X: Add M68HC05 support.
* M680X: Dont print prefix '<' for direct addr. mode.
* M680X: Add M68HC08 support + resorted tables + bug fixes.
* M680X: Add Freescale HCS08 support.
* M680X: Changed group names, avoid spaces.
* M680X: Refactoring, rename addessing mode handlers.
* M680X: indexed addr. mode, changed pre/post inc-/decrement representation.
* M680X: Rename some M6809/HD6309 specific functions.
* M680X: Add CPU12 (68HC12/HCS12) support.
* M680X: Correctly display illegal instruction as FCB .
* M680X: bugfix: BRA/BRN/BSR/LBRA/LBRN/LBSR does not read CC reg.
* M680X: bugfix: Correctly check for sufficient code size for M6809 indexed addressing.
* M680X: Better support for changing insn id within handler for addessing mode.
* M680X: Remove warnings.
* M680X: In set_changed_regs_read_write_counts use own access_mode.
* M680X: Split cpu specific tables into separate *.inc files.
* M680X: Remove warnings.
* M680X: Removed address_mode. Addressing mode is available in operand.type
* M680X: Bugfix: BSET/BCLR/BRSET/BRCLR correct read/modify CC reg.
* M680X: Remove register TMP1. It is first visible in CPU12X.
* M680X: Performance improvement + bug fixes.
* M680X: Performance improvement, make cpu_tables const static.
* M680X: Simplify operand decoding by using two handlers.
* M680X: Replace M680X_OP_INDEX by M680X_OP_CONSTANT + bugfix in java/python/ocaml bindings.
* M680X: Format with astyle.
* M680X: Update documentation.
* M680X: Corrected author for m680x specific files.
* M680X: Make max. number of architectures single source.
2017-10-21 21:44:36 +08:00
|
|
|
ifneq (,$(findstring m680x,$(CAPSTONE_ARCHS)))
|
|
|
|
CFLAGS += -DCAPSTONE_HAS_M680X
|
|
|
|
SOURCES += test_m680x.c
|
|
|
|
endif
|
2018-03-31 17:29:22 +08:00
|
|
|
ifneq (,$(findstring evm,$(CAPSTONE_ARCHS)))
|
|
|
|
CFLAGS += -DCAPSTONE_HAS_EVM
|
|
|
|
SOURCES += test_evm.c
|
|
|
|
endif
|
2018-12-03 04:39:41 +08:00
|
|
|
ifneq (,$(findstring evm,$(CAPSTONE_ARCHS)))
|
|
|
|
CFLAGS += -DCAPSTONE_HAS_MOS65XX
|
|
|
|
SOURCES += test_mos65xx.c
|
|
|
|
endif
|
2014-03-01 20:44:58 +08:00
|
|
|
|
2014-04-29 15:00:34 +08:00
|
|
|
OBJS = $(addprefix $(OBJDIR)/,$(SOURCES:.c=.o))
|
2014-04-29 16:24:30 +08:00
|
|
|
BINARY = $(addprefix $(TESTDIR)/,$(SOURCES:.c=$(BIN_EXT)))
|
2013-11-28 11:57:51 +08:00
|
|
|
|
2013-11-29 02:22:50 +08:00
|
|
|
all: $(BINARY)
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
clean:
|
2014-06-04 00:26:33 +08:00
|
|
|
rm -rf $(OBJS) $(BINARY) $(TESTDIR)/*.exe $(TESTDIR)/*.static $(OBJDIR)/lib$(LIBNAME).* $(OBJDIR)/$(LIBNAME).*
|
2015-06-06 12:22:39 +08:00
|
|
|
# remove orphan files due to renaming from test.c to test_basic.c
|
|
|
|
rm -rf $(TESTDIR)/test.o $(TESTDIR)/test.exe $(TESTDIR)/test.static $(TESTDIR)/test
|
2013-11-28 16:46:15 +08:00
|
|
|
|
2013-11-29 02:22:50 +08:00
|
|
|
$(BINARY): $(OBJS)
|
2013-11-28 16:46:15 +08:00
|
|
|
|
2014-04-30 06:06:12 +08:00
|
|
|
$(TESTDIR)/%$(BIN_EXT): $(OBJDIR)/%.o
|
2014-04-29 15:00:34 +08:00
|
|
|
@mkdir -p $(@D)
|
2014-05-01 21:22:25 +08:00
|
|
|
ifeq ($(V),0)
|
2014-05-01 22:00:52 +08:00
|
|
|
ifeq ($(CAPSTONE_SHARED),yes)
|
2014-06-04 00:43:53 +08:00
|
|
|
$(call log,LINK,$(notdir $@))
|
2014-05-01 21:22:25 +08:00
|
|
|
@$(link-dynamic)
|
2014-05-01 22:00:52 +08:00
|
|
|
endif
|
|
|
|
ifeq ($(CAPSTONE_STATIC),yes)
|
2014-06-04 00:43:53 +08:00
|
|
|
$(call log,LINK,$(notdir $(call staticname,$@)))
|
2014-05-01 21:22:25 +08:00
|
|
|
@$(link-static)
|
2014-05-01 22:00:52 +08:00
|
|
|
endif
|
2014-05-01 21:22:25 +08:00
|
|
|
else
|
2014-05-01 22:00:52 +08:00
|
|
|
ifeq ($(CAPSTONE_SHARED),yes)
|
2014-05-01 21:22:25 +08:00
|
|
|
$(link-dynamic)
|
2014-05-01 22:00:52 +08:00
|
|
|
endif
|
|
|
|
ifeq ($(CAPSTONE_STATIC),yes)
|
2014-05-01 21:22:25 +08:00
|
|
|
$(link-static)
|
|
|
|
endif
|
2014-05-01 22:00:52 +08:00
|
|
|
endif
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-04-29 15:00:34 +08:00
|
|
|
$(OBJDIR)/%.o: %.c
|
|
|
|
@mkdir -p $(@D)
|
2014-05-01 21:22:25 +08:00
|
|
|
ifeq ($(V),0)
|
|
|
|
$(call log,CC,$(@:$(OBJDIR)/%=%))
|
|
|
|
@$(compile)
|
|
|
|
else
|
|
|
|
$(compile)
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
define link-dynamic
|
2014-07-05 05:09:19 +08:00
|
|
|
$(CC) $(LDFLAGS) $< -l$(LIBNAME) -o $@
|
2014-05-01 21:22:25 +08:00
|
|
|
endef
|
|
|
|
|
2014-05-01 22:53:52 +08:00
|
|
|
|
2014-05-01 21:22:25 +08:00
|
|
|
define link-static
|
2014-07-05 05:39:59 +08:00
|
|
|
$(CC) $(LDFLAGS) $< $(ARCHIVE) -o $(call staticname,$@)
|
2014-05-01 21:22:25 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
|
|
staticname = $(subst $(BIN_EXT),,$(1)).static$(BIN_EXT)
|