unicorn/samples/Makefile

159 lines
2.9 KiB
Makefile
Raw Normal View History

2015-08-21 10:04:50 +03:00
# Unicorn Engine
# By Nguyen Anh Quynh <aquynh@gmail.com>, 2015
include ../config.mk
UNAME_S := $(shell uname -s)
2015-08-21 10:04:50 +03:00
2016-11-19 18:40:38 +03:00
LIBDIR = ..
BIN_EXT =
2016-11-19 18:40:38 +03:00
AR_EXT = a
2015-08-21 10:04:50 +03:00
# Verbose output?
V ?= 0
CFLAGS += -Wall -Werror -I../include
2016-12-24 10:04:34 +03:00
2016-12-19 18:51:59 +03:00
LDFLAGS += -L$(LIBDIR) -lunicorn -lpthread -lm
2016-12-24 12:48:15 +03:00
ifeq ($(UNAME_S), Linux)
2016-12-24 10:04:34 +03:00
LDFLAGS += -lrt
endif
LDLIBS += -lpthread -lunicorn -lm
2015-08-21 10:04:50 +03:00
ifneq ($(CROSS),)
2015-08-21 10:04:50 +03:00
CC = $(CROSS)gcc
endif
ifeq ($(UNICORN_ASAN),yes)
CC = clang
CXX = clang++
AR = llvm-ar
CFLAGS += -fsanitize=address -fno-omit-frame-pointer
2016-11-19 18:40:38 +03:00
LDFLAGS := -fsanitize=address ${LDFLAGS}
endif
2015-08-21 10:04:50 +03:00
# Cygwin?
ifneq ($(filter CYGWIN%,$(UNAME_S)),)
2015-08-21 10:04:50 +03:00
CFLAGS := $(CFLAGS:-fPIC=)
LDLIBS += -lssp
BIN_EXT = .exe
2016-11-19 18:40:38 +03:00
AR_EXT = a
2015-08-21 10:04:50 +03:00
# mingw?
else ifneq ($(filter MINGW%,$(UNAME_S)),)
2015-08-21 10:04:50 +03:00
CFLAGS := $(CFLAGS:-fPIC=)
BIN_EXT = .exe
AR_EXT = a
2016-11-19 18:40:38 +03:00
endif
ifeq ($(UNICORN_STATIC),yes)
ifneq ($(filter MINGW%,$(UNAME_S)),)
ARCHIVE = $(LIBDIR)/unicorn.$(AR_EXT)
else ifneq ($(filter CYGWIN%,$(UNAME_S)),)
ARCHIVE = $(LIBDIR)/libunicorn.$(AR_EXT)
else
ARCHIVE = $(LIBDIR)/libunicorn.$(AR_EXT)
endif
2015-08-21 10:04:50 +03:00
endif
.PHONY: all clean
2015-08-21 10:04:50 +03:00
UNICORN_ARCHS := $(shell if [ -e ../config.log ]; then cat ../config.log;\
2015-08-21 10:04:50 +03:00
else printf "$(UNICORN_ARCHS)"; fi)
SOURCES =
ifneq (,$(findstring arm,$(UNICORN_ARCHS)))
SOURCES += sample_arm.c
2017-03-13 17:32:44 +03:00
SOURCES += sample_armeb.c
2015-08-21 10:04:50 +03:00
endif
ifneq (,$(findstring aarch64,$(UNICORN_ARCHS)))
SOURCES += sample_arm64.c
SOURCES += sample_arm64eb.c
2015-08-21 10:04:50 +03:00
endif
ifneq (,$(findstring mips,$(UNICORN_ARCHS)))
SOURCES += sample_mips.c
endif
#ifneq (,$(findstring ppc,$(UNICORN_ARCHS)))
2015-08-21 10:04:50 +03:00
#SOURCES += sample_ppc.c
#endif
2015-08-21 10:04:50 +03:00
ifneq (,$(findstring sparc,$(UNICORN_ARCHS)))
SOURCES += sample_sparc.c
endif
ifneq (,$(findstring x86,$(UNICORN_ARCHS)))
SOURCES += sample_x86.c
SOURCES += shellcode.c
SOURCES += mem_apis.c
2016-03-24 18:56:13 +03:00
SOURCES += sample_x86_32_gdt_and_seg_regs.c
2016-04-05 06:52:26 +03:00
SOURCES += sample_batch_reg.c
2015-08-21 10:04:50 +03:00
endif
ifneq (,$(findstring m68k,$(UNICORN_ARCHS)))
SOURCES += sample_m68k.c
endif
ifneq (,$(findstring tricore,$(UNICORN_ARCHS)))
SOURCES += sample_tricore.c
endif
2015-08-21 10:04:50 +03:00
BINS = $(SOURCES:.c=$(BIN_EXT))
OBJS = $(SOURCES:.c=.o)
2015-08-21 10:04:50 +03:00
all: $(BINS)
2015-08-21 10:04:50 +03:00
$(BINS): $(OBJS)
clean:
rm -rf *.o $(BINS)
%$(BIN_EXT): %.o
@mkdir -p $(@D)
ifeq ($(V),0)
ifeq ($(UNICORN_SHARED),yes)
$(call log,LINK,$(notdir $@))
@$(link-dynamic)
endif
ifeq ($(UNICORN_STATIC),yes)
ifneq ($(filter MINGW%,$(UNAME_S)),)
$(call log,LINK,$(notdir $(call staticname,$@)))
@$(link-static)
endif
endif
else
ifeq ($(UNICORN_SHARED),yes)
$(link-dynamic)
endif
ifeq ($(UNICORN_STATIC),yes)
ifneq ($(filter MINGW%,$(UNAME_S)),)
$(link-static)
endif
endif
endif
%.o: %.c
@mkdir -p $(@D)
ifeq ($(V),0)
$(call log,CC,$(@:%=%))
@$(compile)
else
$(compile)
endif
define link-dynamic
$(CC) $< ${CFLAGS} $(LDFLAGS) -o $@
endef
define link-static
$(CC) $< $(ARCHIVE) ${CFLAGS} $(LDFLAGS) -o $(call staticname,$@)
endef
staticname = $(subst $(BIN_EXT),,$(1)).static$(BIN_EXT)
2016-11-19 12:29:51 +03:00
define log
@printf " %-7s %s\n" "$(1)" "$(2)"
endef
define compile
${CC} ${CFLAGS} -c $< -o $@
endef