Debian Codegraph @

Makefile

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
1 # Capstone Disassembly Engine
2 # By Nguyen Anh Quynh <[email protected]>, 2013-2014
3
4 include config.mk
5 include pkgconfig.mk # package version
6 include functions.mk
7
8 # Verbose output?
9 V ?= 0
10
11 OS := $(shell uname)
12 ifeq ($(OS),Darwin)
13 LIBARCHS ?= x86_64 arm64
14 PREFIX ?= /usr/local
15 endif
16
17 ifeq ($(PKG_EXTRA),)
18 PKG_VERSION = $(PKG_MAJOR).$(PKG_MINOR)
19 else
20 PKG_VERSION = $(PKG_MAJOR).$(PKG_MINOR).$(PKG_EXTRA)
21 endif
22
23 ifeq ($(CROSS),)
24 RANLIB ?= ranlib
25 else ifeq ($(ANDROID), 1)
26 CC = $(CROSS)/../../bin/clang
27 AR = $(CROSS)/ar
28 RANLIB = $(CROSS)/ranlib
29 STRIP = $(CROSS)/strip
30 else
31 CC = $(CROSS)gcc
32 AR = $(CROSS)ar
33 RANLIB = $(CROSS)ranlib
34 STRIP = $(CROSS)strip
35 endif
36
37 ifeq ($(OS),OS/390)
38 RANLIB = touch
39 endif
40
41 ifneq (,$(findstring yes,$(CAPSTONE_DIET)))
42 CFLAGS ?= -Os
43 CFLAGS += -DCAPSTONE_DIET
44 else
45 CFLAGS ?= -O3
46 endif
47
48 # C99 has been enforced elsewhere like xcode
49 CFLAGS += -std=gnu99
50
51 ifneq (,$(findstring yes,$(CAPSTONE_X86_ATT_DISABLE)))
52 CFLAGS += -DCAPSTONE_X86_ATT_DISABLE
53 endif
54
55 ifeq ($(CC),xlc)
56 CFLAGS += -qcpluscmt -qkeyword=inline -qlanglvl=extc1x -Iinclude
57 ifneq ($(OS),OS/390)
58 CFLAGS += -fPIC
59 endif
60 else
•61 CFLAGS += -fPIC -Wall -Wwrite-strings -Wmissing-prototypes -Iinclude -D_FORTIFY_SOURCE=2
62 endif
63
64 ifeq ($(CAPSTONE_USE_SYS_DYN_MEM),yes)
65 CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM
66 endif
67
68 ifeq ($(CAPSTONE_HAS_OSXKERNEL), yes)
69 CFLAGS += -DCAPSTONE_HAS_OSXKERNEL
70 SDKROOT ?= $(shell xcodebuild -version -sdk macosx Path)
71 CFLAGS += -mmacosx-version-min=10.5 \
72 -isysroot$(SDKROOT) \
73 -I$(SDKROOT)/System/Library/Frameworks/Kernel.framework/Headers \
74 -mkernel \
75 -fno-builtin
76 endif
77
78 PREFIX ?= /usr
79 DESTDIR ?=
80 ifndef BUILDDIR
81 BLDIR = .
82 OBJDIR = .
83 else
84 BLDIR = $(abspath $(BUILDDIR))
85 OBJDIR = $(BLDIR)/obj
86 endif
87 INCDIR ?= $(PREFIX)/include
88
89 UNAME_S := $(shell uname -s)
90
91 LIBDIRARCH ?= lib
92 # Uncomment the below line to installs x86_64 libs to lib64/ directory.
93 # Or better, pass 'LIBDIRARCH=lib64' to 'make install/uninstall' via 'make.sh'.
94 #LIBDIRARCH ?= lib64
95 LIBDIR = $(DESTDIR)$(PREFIX)/$(LIBDIRARCH)
96 BINDIR = $(DESTDIR)$(PREFIX)/bin
97
98 LIBDATADIR = $(LIBDIR)
99
100 # Don't redefine $LIBDATADIR when global environment variable
101 # USE_GENERIC_LIBDATADIR is set. This is used by the pkgsrc framework.
102
103 ifndef USE_GENERIC_LIBDATADIR
104 ifeq ($(UNAME_S), FreeBSD)
105 LIBDATADIR = $(DESTDIR)$(PREFIX)/libdata
106 endif
107 ifeq ($(UNAME_S), DragonFly)
108 LIBDATADIR = $(DESTDIR)$(PREFIX)/libdata
109 endif
110 endif
111
112 INSTALL_BIN ?= install
113 INSTALL_DATA ?= $(INSTALL_BIN) -m0644
114 INSTALL_LIB ?= $(INSTALL_BIN) -m0755
115
116 LIBNAME = capstone
117
118
119 DEP_ARM =
•120 DEP_ARM += $(sort $(wildcard arch/ARM/ARM*.inc))
121
122 LIBOBJ_ARM =
123 ifneq (,$(findstring arm,$(CAPSTONE_ARCHS)))
124 CFLAGS += -DCAPSTONE_HAS_ARM
•125 LIBSRC_ARM += $(sort $(wildcard arch/ARM/ARM*.c))
126 LIBOBJ_ARM += $(LIBSRC_ARM:%.c=$(OBJDIR)/%.o)
127 endif
128
129 DEP_ARM64 =
•130 DEP_ARM64 += $(sort $(wildcard arch/AArch64/AArch64*.inc))
131
132 LIBOBJ_ARM64 =
133 ifneq (,$(findstring aarch64,$(CAPSTONE_ARCHS)))
134 CFLAGS += -DCAPSTONE_HAS_ARM64
•135 LIBSRC_ARM64 += $(sort $(wildcard arch/AArch64/AArch64*.c))
136 LIBOBJ_ARM64 += $(LIBSRC_ARM64:%.c=$(OBJDIR)/%.o)
137 endif
138
139
140 DEP_M68K =
•141 DEP_M68K += $(sort $(wildcard arch/M68K/M68K*.inc))
142 DEP_M68K += $(sort $(wildcard arch/M68K/M68K*.h))
143
144 LIBOBJ_M68K =
145 ifneq (,$(findstring m68k,$(CAPSTONE_ARCHS)))
146 CFLAGS += -DCAPSTONE_HAS_M68K
•147 LIBSRC_M68K += $(sort $(wildcard arch/M68K/M68K*.c))
148 LIBOBJ_M68K += $(LIBSRC_M68K:%.c=$(OBJDIR)/%.o)
149 endif
150
151 DEP_MIPS =
•152 DEP_MIPS += $(sort $(wildcard arch/Mips/Mips*.inc))
153
154 LIBOBJ_MIPS =
155 ifneq (,$(findstring mips,$(CAPSTONE_ARCHS)))
156 CFLAGS += -DCAPSTONE_HAS_MIPS
•157 LIBSRC_MIPS += $(sort $(wildcard arch/Mips/Mips*.c))
158 LIBOBJ_MIPS += $(LIBSRC_MIPS:%.c=$(OBJDIR)/%.o)
159 endif
160
•161 DEP_SH = $(sort $(wildcard arch/SH/SH*.inc))
162
163 LIBOBJ_SH =
164 ifneq (,$(findstring sh,$(CAPSTONE_ARCHS)))
165 CFLAGS += -DCAPSTONE_HAS_SH
•166 LIBSRC_SH += $(sort $(wildcard arch/SH/SH*.c))
167 LIBOBJ_SH += $(LIBSRC_SH:%.c=$(OBJDIR)/%.o)
168 endif
169
170 DEP_PPC =
•171 DEP_PPC += $(sort $(wildcard arch/PowerPC/PPC*.inc))
172
173 LIBOBJ_PPC =
174 ifneq (,$(findstring powerpc,$(CAPSTONE_ARCHS)))
175 CFLAGS += -DCAPSTONE_HAS_POWERPC
•176 LIBSRC_PPC += $(sort $(wildcard arch/PowerPC/PPC*.c))
177 LIBOBJ_PPC += $(LIBSRC_PPC:%.c=$(OBJDIR)/%.o)
178 endif
179
180
181 DEP_SPARC =
•182 DEP_SPARC += $(sort $(wildcard arch/Sparc/Sparc*.inc))
183
184 LIBOBJ_SPARC =
185 ifneq (,$(findstring sparc,$(CAPSTONE_ARCHS)))
186 CFLAGS += -DCAPSTONE_HAS_SPARC
•187 LIBSRC_SPARC += $(sort $(wildcard arch/Sparc/Sparc*.c))
188 LIBOBJ_SPARC += $(LIBSRC_SPARC:%.c=$(OBJDIR)/%.o)
189 endif
190
191
192 DEP_SYSZ =
•193 DEP_SYSZ += $(sort $(wildcard arch/SystemZ/SystemZ*.inc))
194
195 LIBOBJ_SYSZ =
196 ifneq (,$(findstring systemz,$(CAPSTONE_ARCHS)))
197 CFLAGS += -DCAPSTONE_HAS_SYSZ
•198 LIBSRC_SYSZ += $(sort $(wildcard arch/SystemZ/SystemZ*.c))
199 LIBOBJ_SYSZ += $(LIBSRC_SYSZ:%.c=$(OBJDIR)/%.o)
200 endif
201
202
203 # by default, we compile full X86 instruction sets
204 X86_REDUCE =
205 ifneq (,$(findstring yes,$(CAPSTONE_X86_REDUCE)))
206 X86_REDUCE = _reduce
207 CFLAGS += -DCAPSTONE_X86_REDUCE -Os
208 endif
209
210
211 DEP_X86 =
•212 DEP_X86 += $(sort $(wildcard arch/X86/X86*.inc))
213
214 LIBOBJ_X86 =
215 ifneq (,$(findstring x86,$(CAPSTONE_ARCHS)))
216 CFLAGS += -DCAPSTONE_HAS_X86
217 LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86DisassemblerDecoder.o
218 LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86Disassembler.o
219 LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86InstPrinterCommon.o
220 LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86IntelInstPrinter.o
221 # assembly syntax is irrelevant in Diet mode, when this info is suppressed
222 ifeq (,$(findstring yes,$(CAPSTONE_DIET)))
223 ifeq (,$(findstring yes,$(CAPSTONE_X86_ATT_DISABLE)))
224 LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86ATTInstPrinter.o
225 endif
226 endif
227 LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86Mapping.o
228 LIBOBJ_X86 += $(OBJDIR)/arch/X86/X86Module.o
229 endif
230
231
232 DEP_XCORE =
•233 DEP_XCORE += $(sort $(wildcard arch/XCore/XCore*.inc))
234
235 LIBOBJ_XCORE =
236 ifneq (,$(findstring xcore,$(CAPSTONE_ARCHS)))
237 CFLAGS += -DCAPSTONE_HAS_XCORE
•238 LIBSRC_XCORE += $(sort $(wildcard arch/XCore/XCore*.c))
239 LIBOBJ_XCORE += $(LIBSRC_XCORE:%.c=$(OBJDIR)/%.o)
240 endif
241
242
243 DEP_TMS320C64X =
•244 DEP_TMS320C64X += $(sort $(wildcard arch/TMS320C64x/TMS320C64x*.inc))
245
246 LIBOBJ_TMS320C64X =
247 ifneq (,$(findstring tms320c64x,$(CAPSTONE_ARCHS)))
248 CFLAGS += -DCAPSTONE_HAS_TMS320C64X
•249 LIBSRC_TMS320C64X += $(sort $(wildcard arch/TMS320C64x/TMS320C64x*.c))
250 LIBOBJ_TMS320C64X += $(LIBSRC_TMS320C64X:%.c=$(OBJDIR)/%.o)
251 endif
252
253 DEP_M680X =
•254 DEP_M680X += $(sort $(wildcard arch/M680X/*.inc))
255 DEP_M680X += $(sort $(wildcard arch/M680X/M680X*.h))
256
257 LIBOBJ_M680X =
258 ifneq (,$(findstring m680x,$(CAPSTONE_ARCHS)))
259 CFLAGS += -DCAPSTONE_HAS_M680X
•260 LIBSRC_M680X += $(sort $(wildcard arch/M680X/*.c))
261 LIBOBJ_M680X += $(LIBSRC_M680X:%.c=$(OBJDIR)/%.o)
262 endif
263
264
265 DEP_EVM =
•266 DEP_EVM += $(sort $(wildcard arch/EVM/EVM*.inc))
267
268 LIBOBJ_EVM =
269 ifneq (,$(findstring evm,$(CAPSTONE_ARCHS)))
270 CFLAGS += -DCAPSTONE_HAS_EVM
•271 LIBSRC_EVM += $(sort $(wildcard arch/EVM/EVM*.c))
272 LIBOBJ_EVM += $(LIBSRC_EVM:%.c=$(OBJDIR)/%.o)
273 endif
274
275 DEP_RISCV =
•276 DEP_RISCV += $(sort $(wildcard arch/RISCV/RISCV*.inc))
277
278 LIBOBJ_RISCV =
279 ifneq (,$(findstring riscv,$(CAPSTONE_ARCHS)))
280 CFLAGS += -DCAPSTONE_HAS_RISCV
•281 LIBSRC_RISCV += $(sort $(wildcard arch/RISCV/RISCV*.c))
282 LIBOBJ_RISCV += $(LIBSRC_RISCV:%.c=$(OBJDIR)/%.o)
283 endif
284
285 DEP_WASM =
•286 DEP_WASM += $(sort $(wildcard arch/WASM/WASM*.inc))
287
288 LIBOBJ_WASM =
289 ifneq (,$(findstring wasm,$(CAPSTONE_ARCHS)))
290 CFLAGS += -DCAPSTONE_HAS_WASM
•291 LIBSRC_WASM += $(sort $(wildcard arch/WASM/WASM*.c))
292 LIBOBJ_WASM += $(LIBSRC_WASM:%.c=$(OBJDIR)/%.o)
293 endif
294
295
296 DEP_MOS65XX =
•297 DEP_MOS65XX += $(sort $(wildcard arch/MOS65XX/MOS65XX*.inc))
298
299 LIBOBJ_MOS65XX =
300 ifneq (,$(findstring mos65xx,$(CAPSTONE_ARCHS)))
301 CFLAGS += -DCAPSTONE_HAS_MOS65XX
•302 LIBSRC_MOS65XX += $(sort $(wildcard arch/MOS65XX/MOS65XX*.c))
303 LIBOBJ_MOS65XX += $(LIBSRC_MOS65XX:%.c=$(OBJDIR)/%.o)
304 endif
305
306
307 DEP_BPF =
•308 DEP_BPF += $(sort $(wildcard arch/BPF/BPF*.inc))
309
310 LIBOBJ_BPF =
311 ifneq (,$(findstring bpf,$(CAPSTONE_ARCHS)))
312 CFLAGS += -DCAPSTONE_HAS_BPF
•313 LIBSRC_BPF += $(sort $(wildcard arch/BPF/BPF*.c))
314 LIBOBJ_BPF += $(LIBSRC_BPF:%.c=$(OBJDIR)/%.o)
315 endif
316
317 DEP_TRICORE =
•318 DEP_TRICORE +=$(sort $(wildcard arch/TriCore/TriCore*.inc))
319
320 LIBOBJ_TRICORE =
321 ifneq (,$(findstring tricore,$(CAPSTONE_ARCHS)))
322 CFLAGS += -DCAPSTONE_HAS_TRICORE
•323 LIBSRC_TRICORE += $(sort $(wildcard arch/TriCore/TriCore*.c))
324 LIBOBJ_TRICORE += $(LIBSRC_TRICORE:%.c=$(OBJDIR)/%.o)
325 endif
326
327
328 LIBOBJ =
329 LIBOBJ += $(OBJDIR)/cs.o $(OBJDIR)/utils.o $(OBJDIR)/SStream.o $(OBJDIR)/MCInstrDesc.o $(OBJDIR)/MCRegisterInfo.o $(OBJDIR)/MCInst.o $(OBJDIR)/Mapping.o
330 LIBOBJ += $(LIBOBJ_ARM) $(LIBOBJ_ARM64) $(LIBOBJ_M68K) $(LIBOBJ_MIPS) $(LIBOBJ_PPC) $(LIBOBJ_RISCV) $(LIBOBJ_SPARC) $(LIBOBJ_SYSZ) $(LIBOBJ_SH)
331 LIBOBJ += $(LIBOBJ_X86) $(LIBOBJ_XCORE) $(LIBOBJ_TMS320C64X) $(LIBOBJ_M680X) $(LIBOBJ_EVM) $(LIBOBJ_MOS65XX) $(LIBOBJ_WASM) $(LIBOBJ_BPF)
332 LIBOBJ += $(LIBOBJ_TRICORE)
333
334
335 ifeq ($(PKG_EXTRA),)
336 PKGCFGDIR = $(LIBDATADIR)/pkgconfig
337 else
338 PKGCFGDIR ?= $(LIBDATADIR)/pkgconfig
339 ifeq ($(PKGCFGDIR),)
340 PKGCFGDIR = $(LIBDATADIR)/pkgconfig
341 endif
342 endif
343
344 API_MAJOR=$(shell echo `grep -e CS_API_MAJOR include/capstone/capstone.h | grep -v = | awk '{print $$3}'` | awk '{print $$1}')
345 VERSION_EXT =
346
347 IS_APPLE := $(shell $(CC) -dM -E - < /dev/null 2> /dev/null | grep __apple_build_version__ | wc -l | tr -d " ")
348 ifeq ($(IS_APPLE),1)
349 # on MacOS, do not build in Universal format by default
350 MACOS_UNIVERSAL ?= no
351 ifeq ($(MACOS_UNIVERSAL),yes)
352 CFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
353 LDFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
354 endif
355 EXT = dylib
356 VERSION_EXT = $(API_MAJOR).$(EXT)
357 $(LIBNAME)_LDFLAGS += -dynamiclib -install_name lib$(LIBNAME).$(VERSION_EXT) -current_version $(PKG_MAJOR).$(PKG_MINOR).$(PKG_EXTRA) -compatibility_version $(PKG_MAJOR).$(PKG_MINOR)
358 AR_EXT = a
359 # Homebrew wants to make sure its formula does not disable FORTIFY_SOURCE
360 # However, this is not really necessary because 'CAPSTONE_USE_SYS_DYN_MEM=yes' by default
361 ifneq ($(HOMEBREW_CAPSTONE),1)
362 ifneq ($(CAPSTONE_USE_SYS_DYN_MEM),yes)
363 # remove string check because OSX kernel complains about missing symbols
364 CFLAGS += -D_FORTIFY_SOURCE=0
365 endif
366 endif
367 else
368 CFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
369 LDFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
370 ifeq ($(OS), AIX)
371 $(LIBNAME)_LDFLAGS += -qmkshrobj
372 else
373 $(LIBNAME)_LDFLAGS += -shared
374 endif
375 # Cygwin?
376 IS_CYGWIN := $(shell $(CC) -dumpmachine 2>/dev/null | grep -i cygwin | wc -l)
377 ifeq ($(IS_CYGWIN),1)
378 EXT = dll
379 AR_EXT = lib
380 # Cygwin doesn't like -fPIC
381 CFLAGS := $(CFLAGS:-fPIC=)
382 # On Windows we need the shared library to be executable
383 else
384 # mingw?
385 IS_MINGW := $(shell $(CC) --version 2>/dev/null | grep -i "\(mingw\|MSYS\)" | wc -l)
386 ifeq ($(IS_MINGW),1)
387 EXT = dll
388 AR_EXT = lib
389 # mingw doesn't like -fPIC either
390 CFLAGS := $(CFLAGS:-fPIC=)
391 # On Windows we need the shared library to be executable
392 else
393 # Linux, *BSD
394 EXT = so
395 VERSION_EXT = $(EXT).$(API_MAJOR)
396 AR_EXT = a
397 $(LIBNAME)_LDFLAGS += -Wl,-soname,lib$(LIBNAME).$(VERSION_EXT)
398 endif
399 endif
400 endif
401
402 ifeq ($(CAPSTONE_SHARED),yes)
403 ifeq ($(IS_MINGW),1)
404 LIBRARY = $(BLDIR)/$(LIBNAME).$(VERSION_EXT)
405 else ifeq ($(IS_CYGWIN),1)
406 LIBRARY = $(BLDIR)/$(LIBNAME).$(EXT)
407 else # *nix
408 LIBRARY = $(BLDIR)/lib$(LIBNAME).$(VERSION_EXT)
409 CFLAGS += -fvisibility=hidden
410 endif
411 endif
412
413 ifeq ($(CAPSTONE_STATIC),yes)
414 ifeq ($(IS_MINGW),1)
415 ARCHIVE = $(BLDIR)/$(LIBNAME).$(AR_EXT)
416 else ifeq ($(IS_CYGWIN),1)
417 ARCHIVE = $(BLDIR)/$(LIBNAME).$(AR_EXT)
418 else
419 ARCHIVE = $(BLDIR)/lib$(LIBNAME).$(AR_EXT)
420 endif
421 endif
422
423 PKGCFGF = $(BLDIR)/$(LIBNAME).pc
424
425 .PHONY: all clean install uninstall dist
426
427 all: $(LIBRARY) $(ARCHIVE) $(PKGCFGF)
428 ifeq (,$(findstring yes,$(CAPSTONE_BUILD_CORE_ONLY)))
429 @V=$(V) CC=$(CC) $(MAKE) -C cstool
430 ifndef BUILDDIR
431 $(MAKE) -C tests
432 else
433 $(MAKE) -C tests BUILDDIR=$(BLDIR)
434 endif
435 $(call install-library,$(BLDIR)/tests/)
436 endif
437
438 ifeq ($(CAPSTONE_SHARED),yes)
439 $(LIBRARY): $(LIBOBJ)
440 ifeq ($(V),0)
441 $(call log,LINK,$(@:$(BLDIR)/%=%))
442 @$(create-library)
443 else
444 $(create-library)
445 endif
446 endif
447
448 $(LIBOBJ): config.mk
449
450 $(LIBOBJ_ARM): $(DEP_ARM)
451 $(LIBOBJ_ARM64): $(DEP_ARM64)
452 $(LIBOBJ_M68K): $(DEP_M68K)
453 $(LIBOBJ_MIPS): $(DEP_MIPS)
454 $(LIBOBJ_PPC): $(DEP_PPC)
455 $(LIBOBJ_SH): $(DEP_SH)
456 $(LIBOBJ_SPARC): $(DEP_SPARC)
457 $(LIBOBJ_SYSZ): $(DEP_SYSZ)
458 $(LIBOBJ_X86): $(DEP_X86)
459 $(LIBOBJ_XCORE): $(DEP_XCORE)
460 $(LIBOBJ_TMS320C64X): $(DEP_TMS320C64X)
461 $(LIBOBJ_M680X): $(DEP_M680X)
462 $(LIBOBJ_EVM): $(DEP_EVM)
463 $(LIBOBJ_RISCV): $(DEP_RISCV)
464 $(LIBOBJ_WASM): $(DEP_WASM)
465 $(LIBOBJ_MOS65XX): $(DEP_MOS65XX)
466 $(LIBOBJ_BPF): $(DEP_BPF)
467 $(LIBOBJ_TRICORE): $(DEP_TRICORE)
468
469 ifeq ($(CAPSTONE_STATIC),yes)
470 $(ARCHIVE): $(LIBOBJ)
471 @rm -f $(ARCHIVE)
472 ifeq ($(V),0)
473 $(call log,AR,$(@:$(BLDIR)/%=%))
474 @$(create-archive)
475 else
476 $(create-archive)
477 endif
478 endif
479
480 $(PKGCFGF):
481 ifeq ($(V),0)
482 $(call log,GEN,$(@:$(BLDIR)/%=%))
483 @$(generate-pkgcfg)
484 else
485 $(generate-pkgcfg)
486 endif
487
488 # create a list of auto dependencies
489 AUTODEPS:= $(patsubst %.o,%.d, $(LIBOBJ))
490
491 # include by auto dependencies
492 -include $(AUTODEPS)
493
494 install: $(PKGCFGF) $(ARCHIVE) $(LIBRARY)
495 mkdir -p $(LIBDIR)
496 $(call install-library,$(LIBDIR))
497 ifeq ($(CAPSTONE_STATIC),yes)
498 $(INSTALL_DATA) $(ARCHIVE) $(LIBDIR)
499 endif
500 mkdir -p $(DESTDIR)$(INCDIR)/$(LIBNAME)
501 $(INSTALL_DATA) include/capstone/*.h $(DESTDIR)$(INCDIR)/$(LIBNAME)
502 mkdir -p $(PKGCFGDIR)
503 $(INSTALL_DATA) $(PKGCFGF) $(PKGCFGDIR)
504 ifeq (,$(findstring yes,$(CAPSTONE_BUILD_CORE_ONLY)))
505 mkdir -p $(BINDIR)
506 $(INSTALL_LIB) cstool/cstool $(BINDIR)
507 endif
508
509 uninstall:
510 rm -rf $(DESTDIR)$(INCDIR)/$(LIBNAME)
511 rm -f $(LIBDIR)/lib$(LIBNAME).*
512 rm -f $(PKGCFGDIR)/$(LIBNAME).pc
513 ifeq (,$(findstring yes,$(CAPSTONE_BUILD_CORE_ONLY)))
514 rm -f $(BINDIR)/cstool
515 endif
516
517 clean:
518 rm -f $(LIBOBJ)
519 rm -f $(BLDIR)/lib$(LIBNAME).* $(BLDIR)/$(LIBNAME).pc
520 rm -f $(PKGCFGF)
521 rm -f $(AUTODEPS)
522 [ "${ANDROID}" = "1" ] && rm -rf android-ndk-* || true
523
524 ifeq (,$(findstring yes,$(CAPSTONE_BUILD_CORE_ONLY)))
525 $(MAKE) -C cstool clean
526 $(MAKE) -C tests clean
527 $(MAKE) -C suite/fuzz clean
528 rm -f $(BLDIR)/tests/lib$(LIBNAME).$(EXT)
529 endif
530
531 ifdef BUILDDIR
532 rm -rf $(BUILDDIR)
533 endif
534
535 ifeq (,$(findstring yes,$(CAPSTONE_BUILD_CORE_ONLY)))
536 $(MAKE) -C bindings/python clean
537 $(MAKE) -C bindings/java clean
538 $(MAKE) -C bindings/ocaml clean
539 endif
540
541
542 TAG ?= HEAD
543 ifeq ($(TAG), HEAD)
544 DIST_VERSION = latest
545 else
546 DIST_VERSION = $(TAG)
547 endif
548
549 dist:
550 git archive --format=tar.gz --prefix=capstone-$(DIST_VERSION)/ $(TAG) > capstone-$(DIST_VERSION).tgz
551 git archive --format=zip --prefix=capstone-$(DIST_VERSION)/ $(TAG) > capstone-$(DIST_VERSION).zip
552
553 TESTS = test_basic test_detail test_arm test_arm64 test_m68k test_mips test_ppc test_sparc test_tricore
554 TESTS += test_systemz test_x86 test_xcore test_iter test_evm test_riscv test_mos65xx test_wasm test_bpf
555 TESTS += test_basic.static test_detail.static test_arm.static test_arm64.static
556 TESTS += test_m68k.static test_mips.static test_ppc.static test_sparc.static
557 TESTS += test_systemz.static test_x86.static test_xcore.static test_m680x.static
558 TESTS += test_skipdata test_skipdata.static test_iter.static test_evm.static test_riscv.static
559 TESTS += test_mos65xx.static test_wasm.static test_bpf.static
560
561 check: $(TESTS)
562
563 checkfuzz: fuzztest fuzzallcorp
564
565 test_%:
566 ./tests/$@ > /dev/null && echo OK || echo FAILED
567
568 FUZZ_INPUTS = $(shell find suite/MC -type f -name '*.cs')
569
570 buildfuzz:
571 ifndef BUILDDIR
572 $(MAKE) -C suite/fuzz
573 else
574 $(MAKE) -C suite/fuzz BUILDDIR=$(BLDIR)
575 endif
576
577 fuzztest:
578 ./suite/fuzz/fuzz_disasm $(FUZZ_INPUTS)
579
580 fuzzallcorp:
•581 ifneq ($(sort $(wildcard suite/fuzz/corpus-libFuzzer-capstone_fuzz_disasmnext-latest)),)
582 ./suite/fuzz/fuzz_bindisasm suite/fuzz/corpus-libFuzzer-capstone_fuzz_disasmnext-latest/ > fuzz_bindisasm.log || (tail -1 fuzz_bindisasm.log; false)
583 else
584 @echo "Skipping tests on whole corpus"
585 endif
586
587 $(OBJDIR)/%.o: %.c
588 @mkdir -p $(@D)
589 ifeq ($(V),0)
590 $(call log,CC,$(@:$(OBJDIR)/%=%))
591 @$(compile)
592 else
593 $(compile)
594 endif
595
596
597 ifeq ($(CAPSTONE_SHARED),yes)
598 define install-library
599 $(INSTALL_LIB) $(LIBRARY) $1
600 $(if $(VERSION_EXT),
601 cd $1 && \
602 rm -f lib$(LIBNAME).$(EXT) && \
603 ln -s lib$(LIBNAME).$(VERSION_EXT) lib$(LIBNAME).$(EXT))
604 endef
605 else
606 define install-library
607 endef
608 endif
609
610 ifeq ($(AR_FLAGS),)
611 AR_FLAGS := q
612 endif
613
614 define create-archive
615 $(AR) $(AR_FLAGS) $(ARCHIVE) $(LIBOBJ)
616 $(RANLIB) $(ARCHIVE)
617 endef
618
619
620 define create-library
621 $(CC) $(LDFLAGS) $($(LIBNAME)_LDFLAGS) $(LIBOBJ) -o $(LIBRARY)
622 endef
623
624
625 define generate-pkgcfg
626 mkdir -p $(BLDIR)
627 echo 'Name: capstone' > $(PKGCFGF)
628 echo 'Description: Capstone disassembly engine' >> $(PKGCFGF)
629 echo 'Version: $(PKG_VERSION)' >> $(PKGCFGF)
630 echo 'libdir=$(LIBDIR)' >> $(PKGCFGF)
631 echo 'includedir=$(INCDIR)/capstone' >> $(PKGCFGF)
632 echo 'archive=$${libdir}/libcapstone.a' >> $(PKGCFGF)
633 echo 'Libs: -L$${libdir} -lcapstone' >> $(PKGCFGF)
634 echo 'Cflags: -I$${includedir}' >> $(PKGCFGF)
635 echo 'archs=${CAPSTONE_ARCHS}' >> $(PKGCFGF)
636 endef