1 # Capstone Disassembler Engine 2 # By Nguyen Anh Quynh <aquynh (at] gmail.com>, 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 | grep -i mingw | 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 68 ifneq (,$(findstring arm,$(CAPSTONE_ARCHS))) 69 SOURCES += test_arm.c 70 endif 71 ifneq (,$(findstring aarch64,$(CAPSTONE_ARCHS))) 72 SOURCES += test_arm64.c 73 endif 74 ifneq (,$(findstring mips,$(CAPSTONE_ARCHS))) 75 SOURCES += test_mips.c 76 endif 77 ifneq (,$(findstring powerpc,$(CAPSTONE_ARCHS))) 78 SOURCES += test_ppc.c 79 endif 80 ifneq (,$(findstring sparc,$(CAPSTONE_ARCHS))) 81 SOURCES += test_sparc.c 82 endif 83 ifneq (,$(findstring systemz,$(CAPSTONE_ARCHS))) 84 SOURCES += test_systemz.c 85 endif 86 ifneq (,$(findstring x86,$(CAPSTONE_ARCHS))) 87 SOURCES += test_x86.c 88 endif 89 ifneq (,$(findstring xcore,$(CAPSTONE_ARCHS))) 90 SOURCES += test_xcore.c 91 endif 92 93 OBJS = $(addprefix $(OBJDIR)/,$(SOURCES:.c=.o)) 94 BINARY = $(addprefix $(TESTDIR)/,$(SOURCES:.c=$(BIN_EXT))) 95 96 all: $(BINARY) 97 98 clean: 99 rm -rf $(OBJS) $(BINARY) $(TESTDIR)/*.exe $(TESTDIR)/*.static $(OBJDIR)/lib$(LIBNAME).* $(OBJDIR)/$(LIBNAME).* 100 101 $(BINARY): $(OBJS) 102 103 $(TESTDIR)/%$(BIN_EXT): $(OBJDIR)/%.o 104 @mkdir -p $(@D) 105 ifeq ($(V),0) 106 ifeq ($(CAPSTONE_SHARED),yes) 107 $(call log,LINK,$(notdir $@)) 108 @$(link-dynamic) 109 endif 110 ifeq ($(CAPSTONE_STATIC),yes) 111 $(call log,LINK,$(notdir $(call staticname,$@))) 112 @$(link-static) 113 endif 114 else 115 ifeq ($(CAPSTONE_SHARED),yes) 116 $(link-dynamic) 117 endif 118 ifeq ($(CAPSTONE_STATIC),yes) 119 $(link-static) 120 endif 121 endif 122 123 $(OBJDIR)/%.o: %.c 124 @mkdir -p $(@D) 125 ifeq ($(V),0) 126 $(call log,CC,$(@:$(OBJDIR)/%=%)) 127 @$(compile) 128 else 129 $(compile) 130 endif 131 132 133 define link-dynamic 134 $(CC) $(LDFLAGS) $< -l$(LIBNAME) -o $@ 135 endef 136 137 138 define link-static 139 $(CC) $(LDFLAGS) $< $(ARCHIVE) -o $(call staticname,$@) 140 endef 141 142 143 staticname = $(subst $(BIN_EXT),,$(1)).static$(BIN_EXT) 144