• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Capstone Disassembler Engine
2# By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014
3
4include ../config.mk
5include ../functions.mk
6
7# Verbose output?
8V ?= 0
9
10INCDIR = ../include
11ifndef BUILDDIR
12TESTDIR = .
13OBJDIR = .
14LIBDIR = ..
15else
16TESTDIR = $(BUILDDIR)/tests
17OBJDIR = $(BUILDDIR)/obj/tests
18LIBDIR = $(BUILDDIR)
19endif
20
21ifeq ($(CROSS),)
22CC ?= cc
23else
24CC = $(CROSS)gcc
25endif
26
27
28CFLAGS += -Wall -I$(INCDIR)
29LDFLAGS += -L$(LIBDIR)
30
31CFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
32LDFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
33
34LIBNAME = capstone
35
36BIN_EXT =
37AR_EXT = a
38
39# Cygwin?
40IS_CYGWIN := $(shell $(CC) -dumpmachine | grep -i cygwin | wc -l)
41ifeq ($(IS_CYGWIN),1)
42CFLAGS := $(CFLAGS:-fPIC=)
43BIN_EXT = .exe
44AR_EXT = lib
45else
46# mingw?
47IS_MINGW := $(shell $(CC) --version 2>/dev/null | grep -i "\(mingw\|MSYS\)" | wc -l)
48ifeq ($(IS_MINGW),1)
49CFLAGS := $(CFLAGS:-fPIC=)
50BIN_EXT = .exe
51AR_EXT = lib
52endif
53endif
54
55ifeq ($(CAPSTONE_STATIC),yes)
56ifeq ($(IS_MINGW),1)
57ARCHIVE = $(LIBDIR)/$(LIBNAME).$(AR_EXT)
58else ifeq ($(IS_CYGWIN),1)
59ARCHIVE = $(LIBDIR)/$(LIBNAME).$(AR_EXT)
60else
61ARCHIVE = $(LIBDIR)/lib$(LIBNAME).$(AR_EXT)
62endif
63endif
64
65.PHONY: all clean
66
67SOURCES = test_basic.c test_detail.c test_skipdata.c test_iter.c test_customized_mnem.c
68ifneq (,$(findstring arm,$(CAPSTONE_ARCHS)))
69CFLAGS += -DCAPSTONE_HAS_ARM
70SOURCES += test_arm.c
71endif
72ifneq (,$(findstring aarch64,$(CAPSTONE_ARCHS)))
73CFLAGS += -DCAPSTONE_HAS_ARM64
74SOURCES += test_arm64.c
75endif
76ifneq (,$(findstring m68k,$(CAPSTONE_ARCHS)))
77CFLAGS += -DCAPSTONE_HAS_M68K
78SOURCES += test_m68k.c
79endif
80ifneq (,$(findstring mips,$(CAPSTONE_ARCHS)))
81CFLAGS += -DCAPSTONE_HAS_MIPS
82SOURCES += test_mips.c
83endif
84ifneq (,$(findstring powerpc,$(CAPSTONE_ARCHS)))
85CFLAGS += -DCAPSTONE_HAS_POWERPC
86SOURCES += test_ppc.c
87endif
88ifneq (,$(findstring sparc,$(CAPSTONE_ARCHS)))
89CFLAGS += -DCAPSTONE_HAS_SPARC
90SOURCES += test_sparc.c
91endif
92ifneq (,$(findstring systemz,$(CAPSTONE_ARCHS)))
93CFLAGS += -DCAPSTONE_HAS_SYSZ
94SOURCES += test_systemz.c
95endif
96ifneq (,$(findstring x86,$(CAPSTONE_ARCHS)))
97CFLAGS += -DCAPSTONE_HAS_X86
98SOURCES += test_x86.c
99endif
100ifneq (,$(findstring xcore,$(CAPSTONE_ARCHS)))
101CFLAGS += -DCAPSTONE_HAS_XCORE
102SOURCES += test_xcore.c
103endif
104ifneq (,$(findstring tms320c64x,$(CAPSTONE_ARCHS)))
105CFLAGS += -DCAPSTONE_HAS_TMS320C64X
106SOURCES += test_tms320c64x.c
107endif
108ifneq (,$(findstring m680x,$(CAPSTONE_ARCHS)))
109CFLAGS += -DCAPSTONE_HAS_M680X
110SOURCES += test_m680x.c
111endif
112ifneq (,$(findstring evm,$(CAPSTONE_ARCHS)))
113CFLAGS += -DCAPSTONE_HAS_EVM
114SOURCES += test_evm.c
115endif
116ifneq (,$(findstring evm,$(CAPSTONE_ARCHS)))
117CFLAGS += -DCAPSTONE_HAS_MOS65XX
118SOURCES += test_mos65xx.c
119endif
120
121OBJS = $(addprefix $(OBJDIR)/,$(SOURCES:.c=.o))
122BINARY = $(addprefix $(TESTDIR)/,$(SOURCES:.c=$(BIN_EXT)))
123
124all: $(BINARY)
125
126clean:
127	rm -rf $(OBJS) $(BINARY) $(TESTDIR)/*.exe $(TESTDIR)/*.static $(OBJDIR)/lib$(LIBNAME).* $(OBJDIR)/$(LIBNAME).*
128	# remove orphan files due to renaming from test.c to test_basic.c
129	rm -rf $(TESTDIR)/test.o $(TESTDIR)/test.exe $(TESTDIR)/test.static $(TESTDIR)/test
130
131$(BINARY): $(OBJS)
132
133$(TESTDIR)/%$(BIN_EXT): $(OBJDIR)/%.o
134	@mkdir -p $(@D)
135ifeq ($(V),0)
136ifeq ($(CAPSTONE_SHARED),yes)
137	$(call log,LINK,$(notdir $@))
138	@$(link-dynamic)
139endif
140ifeq ($(CAPSTONE_STATIC),yes)
141	$(call log,LINK,$(notdir $(call staticname,$@)))
142	@$(link-static)
143endif
144else
145ifeq ($(CAPSTONE_SHARED),yes)
146	$(link-dynamic)
147endif
148ifeq ($(CAPSTONE_STATIC),yes)
149	$(link-static)
150endif
151endif
152
153$(OBJDIR)/%.o: %.c
154	@mkdir -p $(@D)
155ifeq ($(V),0)
156	$(call log,CC,$(@:$(OBJDIR)/%=%))
157	@$(compile)
158else
159	$(compile)
160endif
161
162
163define link-dynamic
164	$(CC) $(LDFLAGS) $< -l$(LIBNAME) -o $@
165endef
166
167
168define link-static
169	$(CC) $(LDFLAGS) $< $(ARCHIVE) -o $(call staticname,$@)
170endef
171
172
173staticname = $(subst $(BIN_EXT),,$(1)).static$(BIN_EXT)
174