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