Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 1 | # Capstone Disassembler Engine |
Nguyen Anh Quynh | 05e2713 | 2014-03-10 11:58:57 +0800 | [diff] [blame] | 2 | # By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 3 | |
Nguyen Anh Quynh | 8abb345 | 2014-03-01 20:44:58 +0800 | [diff] [blame] | 4 | include ../config.mk |
| 5 | |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 6 | INCDIR = ../include |
| 7 | LIBDIR = .. |
| 8 | |
Nguyen Anh Quynh | d80cede | 2014-01-16 21:07:59 +0800 | [diff] [blame] | 9 | ifeq ($(CROSS),) |
| 10 | CC ?= cc |
| 11 | else |
| 12 | CC = $(CROSS)gcc |
| 13 | endif |
| 14 | |
opn | 73b6068 | 2014-01-16 12:08:49 +0100 | [diff] [blame] | 15 | |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 16 | CFLAGS += -fPIC -O3 -Wall -I$(INCDIR) -L$(LIBDIR) |
| 17 | |
| 18 | LIBNAME = capstone |
| 19 | |
Daniel Godas-Lopez | 0f7c432 | 2013-11-28 18:22:50 +0000 | [diff] [blame] | 20 | BIN_EXT = |
Nguyen Anh Quynh | d159a03 | 2014-01-09 15:49:44 +0800 | [diff] [blame] | 21 | AR_EXT = a |
Daniel Godas-Lopez | 0f7c432 | 2013-11-28 18:22:50 +0000 | [diff] [blame] | 22 | |
| 23 | # Cygwin? |
| 24 | IS_CYGWIN := $(shell $(CC) -dumpmachine | grep -i cygwin | wc -l) |
| 25 | ifeq ($(IS_CYGWIN),1) |
| 26 | CFLAGS := $(CFLAGS:-fPIC=) |
| 27 | BIN_EXT = .exe |
Nguyen Anh Quynh | d159a03 | 2014-01-09 15:49:44 +0800 | [diff] [blame] | 28 | AR_EXT = dll.a |
Daniel Godas-Lopez | 0f7c432 | 2013-11-28 18:22:50 +0000 | [diff] [blame] | 29 | else |
| 30 | # mingw? |
| 31 | IS_MINGW := $(shell $(CC) --version | grep -i mingw | wc -l) |
| 32 | ifeq ($(IS_MINGW),1) |
| 33 | CFLAGS := $(CFLAGS:-fPIC=) |
| 34 | BIN_EXT = .exe |
Nguyen Anh Quynh | d159a03 | 2014-01-09 15:49:44 +0800 | [diff] [blame] | 35 | AR_EXT = dll.a |
Daniel Godas-Lopez | 0f7c432 | 2013-11-28 18:22:50 +0000 | [diff] [blame] | 36 | endif |
| 37 | endif |
| 38 | |
| 39 | .PHONY: all clean |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 40 | |
Nguyen Anh Quynh | 8abb345 | 2014-03-01 20:44:58 +0800 | [diff] [blame] | 41 | SOURCES = test.c test_detail.c |
| 42 | ifneq (,$(findstring arm,$(CAPSTONE_ARCHS))) |
| 43 | SOURCES += test_arm.c |
| 44 | endif |
| 45 | ifneq (,$(findstring aarch64,$(CAPSTONE_ARCHS))) |
| 46 | SOURCES += test_arm64.c |
| 47 | endif |
| 48 | ifneq (,$(findstring mips,$(CAPSTONE_ARCHS))) |
| 49 | SOURCES += test_mips.c |
| 50 | endif |
| 51 | ifneq (,$(findstring powerpc,$(CAPSTONE_ARCHS))) |
| 52 | SOURCES += test_ppc.c |
| 53 | endif |
Nguyen Anh Quynh | 05e2713 | 2014-03-10 11:58:57 +0800 | [diff] [blame] | 54 | ifneq (,$(findstring sparc,$(CAPSTONE_ARCHS))) |
| 55 | SOURCES += test_sparc.c |
| 56 | endif |
Nguyen Anh Quynh | 48a14ca | 2014-03-23 08:35:45 +0800 | [diff] [blame] | 57 | ifneq (,$(findstring systemz,$(CAPSTONE_ARCHS))) |
| 58 | SOURCES += test_systemz.c |
| 59 | endif |
Nguyen Anh Quynh | 8abb345 | 2014-03-01 20:44:58 +0800 | [diff] [blame] | 60 | ifneq (,$(findstring x86,$(CAPSTONE_ARCHS))) |
| 61 | SOURCES += test_x86.c |
| 62 | endif |
| 63 | |
danghvu | a0f93bd | 2013-11-28 02:46:15 -0600 | [diff] [blame] | 64 | OBJS = $(SOURCES:.c=.o) |
Daniel Godas-Lopez | 0f7c432 | 2013-11-28 18:22:50 +0000 | [diff] [blame] | 65 | BINARY = $(SOURCES:.c=$(BIN_EXT)) |
pancake | ad3cbaf | 2013-11-28 04:57:51 +0100 | [diff] [blame] | 66 | |
Daniel Godas-Lopez | 0f7c432 | 2013-11-28 18:22:50 +0000 | [diff] [blame] | 67 | all: $(BINARY) |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 68 | |
| 69 | clean: |
Nguyen Anh Quynh | d159a03 | 2014-01-09 15:49:44 +0800 | [diff] [blame] | 70 | rm -rf $(OBJS) $(SOURCES:.c=) *.exe *.static lib$(LIBNAME).* |
danghvu | a0f93bd | 2013-11-28 02:46:15 -0600 | [diff] [blame] | 71 | |
Daniel Godas-Lopez | 0f7c432 | 2013-11-28 18:22:50 +0000 | [diff] [blame] | 72 | $(BINARY): $(OBJS) |
danghvu | a0f93bd | 2013-11-28 02:46:15 -0600 | [diff] [blame] | 73 | |
Daniel Godas-Lopez | 0f7c432 | 2013-11-28 18:22:50 +0000 | [diff] [blame] | 74 | %$(BIN_EXT): %.o |
Nguyen Anh Quynh | e29eaf9 | 2014-01-03 12:13:48 +0800 | [diff] [blame] | 75 | ${CC} $(CFLAGS) $(LDFLAGS) $< -O3 -Wall -l$(LIBNAME) -o $@ |
Nguyen Anh Quynh | d159a03 | 2014-01-09 15:49:44 +0800 | [diff] [blame] | 76 | ${CC} $(CFLAGS) $(LDFLAGS) $< -O3 -Wall ../lib$(LIBNAME).$(AR_EXT) -o $(subst $(BIN_EXT),,$@).static$(BIN_EXT) |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 77 | |
Daniel Godas-Lopez | 0f7c432 | 2013-11-28 18:22:50 +0000 | [diff] [blame] | 78 | %.o: %.c |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 79 | ${CC} ${CFLAGS} -c $< -o $@ |