Debian Codegraph @

capstone/tests/Makefile

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