2015-08-21 07:04:50 +00:00
|
|
|
# Unicorn Engine
|
|
|
|
# By Nguyen Anh Quynh <aquynh@gmail.com>, 2015
|
|
|
|
|
|
|
|
include ../config.mk
|
|
|
|
|
Unit testing in CI (#651)
- in appveyor, install clang and cmake in cygwin, enable package upgrades, and build cmocka and enable testing for gcc only
- in `gitignore`, ignore generated cmocka folder
- in travis, use brew in osx to install cmocka, and enable testing for gcc and clang on os x and linux
- in `Makefile`, change to use `uname -s` to determine os type
- make `install-cmocka-linux.sh`, a simple shell script to download and install cmocka on linux
- in `bindings/Makefile`, enable `make -c` to call subdirectory makefiles instead of `cd [dir] && make` and include environment variables for runtime access to generated libraries
- in `samples/Makefile`, change to use `uname -s` to determine os type, remove `clean_bins` from `all` command, and include `Werror` for compile strictness
- in `tests/unit/Makefile`, add `cflags` for compile time access to cmocka headers and library, include execute vars for runtime access to cmocka and unicorn libs
- in `tests/unit/test_tb_x86.c`, comment out assert that would not compile
2016-10-21 16:21:10 +00:00
|
|
|
UNAME_S := $(shell uname -s)
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2016-11-19 15:40:38 +00:00
|
|
|
LIBDIR = ..
|
2016-11-19 09:20:05 +00:00
|
|
|
BIN_EXT =
|
2016-11-19 15:40:38 +00:00
|
|
|
AR_EXT = a
|
2016-11-19 09:20:05 +00:00
|
|
|
|
2015-08-21 07:04:50 +00:00
|
|
|
# Verbose output?
|
|
|
|
V ?= 0
|
|
|
|
|
2016-11-19 09:17:48 +00:00
|
|
|
CFLAGS += -Wall -Werror -I../include
|
2016-12-24 07:04:34 +00:00
|
|
|
|
2016-12-19 15:51:59 +00:00
|
|
|
LDFLAGS += -L$(LIBDIR) -lunicorn -lpthread -lm
|
2016-12-24 09:48:15 +00:00
|
|
|
ifeq ($(UNAME_S), Linux)
|
2016-12-24 07:04:34 +00:00
|
|
|
LDFLAGS += -lrt
|
|
|
|
endif
|
|
|
|
|
|
|
|
LDLIBS += -lpthread -lunicorn -lm
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2016-11-19 09:17:48 +00:00
|
|
|
ifneq ($(CROSS),)
|
2015-08-21 07:04:50 +00:00
|
|
|
CC = $(CROSS)gcc
|
|
|
|
endif
|
|
|
|
|
2016-04-20 22:38:27 +00:00
|
|
|
ifeq ($(UNICORN_ASAN),yes)
|
2016-11-19 09:17:48 +00:00
|
|
|
CC = clang
|
|
|
|
CXX = clang++
|
2016-04-20 22:38:27 +00:00
|
|
|
AR = llvm-ar
|
2016-11-19 09:17:48 +00:00
|
|
|
CFLAGS += -fsanitize=address -fno-omit-frame-pointer
|
2016-11-19 15:40:38 +00:00
|
|
|
LDFLAGS := -fsanitize=address ${LDFLAGS}
|
2016-04-20 22:38:27 +00:00
|
|
|
endif
|
|
|
|
|
2015-08-21 07:04:50 +00:00
|
|
|
# Cygwin?
|
Unit testing in CI (#651)
- in appveyor, install clang and cmake in cygwin, enable package upgrades, and build cmocka and enable testing for gcc only
- in `gitignore`, ignore generated cmocka folder
- in travis, use brew in osx to install cmocka, and enable testing for gcc and clang on os x and linux
- in `Makefile`, change to use `uname -s` to determine os type
- make `install-cmocka-linux.sh`, a simple shell script to download and install cmocka on linux
- in `bindings/Makefile`, enable `make -c` to call subdirectory makefiles instead of `cd [dir] && make` and include environment variables for runtime access to generated libraries
- in `samples/Makefile`, change to use `uname -s` to determine os type, remove `clean_bins` from `all` command, and include `Werror` for compile strictness
- in `tests/unit/Makefile`, add `cflags` for compile time access to cmocka headers and library, include execute vars for runtime access to cmocka and unicorn libs
- in `tests/unit/test_tb_x86.c`, comment out assert that would not compile
2016-10-21 16:21:10 +00:00
|
|
|
ifneq ($(filter CYGWIN%,$(UNAME_S)),)
|
2015-08-21 07:04:50 +00:00
|
|
|
CFLAGS := $(CFLAGS:-fPIC=)
|
2016-11-19 09:17:48 +00:00
|
|
|
LDLIBS += -lssp
|
2016-11-19 09:20:05 +00:00
|
|
|
BIN_EXT = .exe
|
2016-11-19 15:40:38 +00:00
|
|
|
AR_EXT = a
|
2015-08-21 07:04:50 +00:00
|
|
|
# mingw?
|
Unit testing in CI (#651)
- in appveyor, install clang and cmake in cygwin, enable package upgrades, and build cmocka and enable testing for gcc only
- in `gitignore`, ignore generated cmocka folder
- in travis, use brew in osx to install cmocka, and enable testing for gcc and clang on os x and linux
- in `Makefile`, change to use `uname -s` to determine os type
- make `install-cmocka-linux.sh`, a simple shell script to download and install cmocka on linux
- in `bindings/Makefile`, enable `make -c` to call subdirectory makefiles instead of `cd [dir] && make` and include environment variables for runtime access to generated libraries
- in `samples/Makefile`, change to use `uname -s` to determine os type, remove `clean_bins` from `all` command, and include `Werror` for compile strictness
- in `tests/unit/Makefile`, add `cflags` for compile time access to cmocka headers and library, include execute vars for runtime access to cmocka and unicorn libs
- in `tests/unit/test_tb_x86.c`, comment out assert that would not compile
2016-10-21 16:21:10 +00:00
|
|
|
else ifneq ($(filter MINGW%,$(UNAME_S)),)
|
2015-08-21 07:04:50 +00:00
|
|
|
CFLAGS := $(CFLAGS:-fPIC=)
|
2016-11-19 09:20:05 +00:00
|
|
|
BIN_EXT = .exe
|
2016-12-27 08:30:07 +00:00
|
|
|
AR_EXT = a
|
2016-11-19 15:40:38 +00: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 07:04:50 +00:00
|
|
|
endif
|
|
|
|
|
2016-11-19 09:17:48 +00:00
|
|
|
.PHONY: all clean
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2015-08-24 09:48:30 +00:00
|
|
|
UNICORN_ARCHS := $(shell if [ -e ../config.log ]; then cat ../config.log;\
|
2015-08-21 07:04:50 +00:00
|
|
|
else printf "$(UNICORN_ARCHS)"; fi)
|
|
|
|
|
|
|
|
SOURCES =
|
|
|
|
ifneq (,$(findstring arm,$(UNICORN_ARCHS)))
|
|
|
|
SOURCES += sample_arm.c
|
2017-03-13 14:32:44 +00:00
|
|
|
SOURCES += sample_armeb.c
|
2015-08-21 07:04:50 +00:00
|
|
|
endif
|
|
|
|
ifneq (,$(findstring aarch64,$(UNICORN_ARCHS)))
|
|
|
|
SOURCES += sample_arm64.c
|
2017-04-24 15:25:30 +00:00
|
|
|
SOURCES += sample_arm64eb.c
|
2015-08-21 07:04:50 +00:00
|
|
|
endif
|
|
|
|
ifneq (,$(findstring mips,$(UNICORN_ARCHS)))
|
|
|
|
SOURCES += sample_mips.c
|
|
|
|
endif
|
2016-11-19 09:17:48 +00:00
|
|
|
#ifneq (,$(findstring ppc,$(UNICORN_ARCHS)))
|
2015-08-21 07:04:50 +00:00
|
|
|
#SOURCES += sample_ppc.c
|
2016-11-19 09:17:48 +00:00
|
|
|
#endif
|
2015-08-21 07:04:50 +00:00
|
|
|
ifneq (,$(findstring sparc,$(UNICORN_ARCHS)))
|
|
|
|
SOURCES += sample_sparc.c
|
|
|
|
endif
|
|
|
|
ifneq (,$(findstring x86,$(UNICORN_ARCHS)))
|
|
|
|
SOURCES += sample_x86.c
|
|
|
|
SOURCES += shellcode.c
|
2015-09-04 17:27:03 +00:00
|
|
|
SOURCES += mem_apis.c
|
2016-03-24 15:56:13 +00:00
|
|
|
SOURCES += sample_x86_32_gdt_and_seg_regs.c
|
2016-04-05 03:52:26 +00:00
|
|
|
SOURCES += sample_batch_reg.c
|
2015-08-21 07:04:50 +00:00
|
|
|
endif
|
|
|
|
ifneq (,$(findstring m68k,$(UNICORN_ARCHS)))
|
|
|
|
SOURCES += sample_m68k.c
|
|
|
|
endif
|
|
|
|
|
2016-11-19 09:20:05 +00:00
|
|
|
BINS = $(SOURCES:.c=$(BIN_EXT))
|
|
|
|
OBJS = $(SOURCES:.c=.o)
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2016-11-19 09:17:48 +00:00
|
|
|
all: $(BINS)
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2016-11-19 09:20:05 +00:00
|
|
|
$(BINS): $(OBJS)
|
|
|
|
|
2016-11-19 09:17:48 +00:00
|
|
|
clean:
|
|
|
|
rm -rf *.o $(BINS)
|
2016-11-19 09:20:05 +00:00
|
|
|
|
|
|
|
%$(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
|
2018-10-06 08:49:08 +00:00
|
|
|
$(CC) $< ${CFLAGS} $(LDFLAGS) -o $@
|
2016-11-19 09:20:05 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
|
|
define link-static
|
2018-10-06 08:49:08 +00:00
|
|
|
$(CC) $< $(ARCHIVE) ${CFLAGS} $(LDFLAGS) -o $(call staticname,$@)
|
2016-11-19 09:20:05 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
|
|
staticname = $(subst $(BIN_EXT),,$(1)).static$(BIN_EXT)
|
2016-11-19 09:29:51 +00:00
|
|
|
|
|
|
|
define log
|
|
|
|
@printf " %-7s %s\n" "$(1)" "$(2)"
|
|
|
|
endef
|
|
|
|
|
|
|
|
define compile
|
|
|
|
${CC} ${CFLAGS} -c $< -o $@
|
|
|
|
endef
|