2015-08-21 10:04:50 +03:00
|
|
|
# Unicorn Engine
|
|
|
|
# By Nguyen Anh Quynh <aquynh@gmail.com>, 2015
|
|
|
|
|
|
|
|
include ../config.mk
|
|
|
|
|
|
|
|
LIBNAME = unicorn
|
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 19:21:10 +03:00
|
|
|
UNAME_S := $(shell uname -s)
|
2015-08-21 10:04:50 +03:00
|
|
|
|
|
|
|
# Find GLIB
|
|
|
|
ifndef GLIB
|
2015-09-04 14:56:35 +03:00
|
|
|
GLIB = $(shell pkg-config --libs glib-2.0)
|
2015-08-21 10:04:50 +03:00
|
|
|
endif
|
|
|
|
|
|
|
|
UNICORN_DEP_LIBS_STATIC += -lpthread -lm $(GLIB)
|
|
|
|
|
|
|
|
# Verbose output?
|
|
|
|
V ?= 0
|
|
|
|
|
|
|
|
INCDIR = ../include
|
|
|
|
SAMPLEDIR = .
|
|
|
|
OBJDIR = .
|
|
|
|
LIBDIR = ..
|
|
|
|
|
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 19:21:10 +03:00
|
|
|
CFLAGS += -Wall -Werror -I$(INCDIR)
|
2016-01-19 04:11:25 +03:00
|
|
|
LDFLAGS += -lpthread -L$(LIBDIR) -l$(LIBNAME)
|
2015-08-21 10:04:50 +03:00
|
|
|
LDFLAGS_STATIC += $(UNICORN_DEP_LIBS_STATIC)
|
|
|
|
|
|
|
|
ifeq ($(CROSS),)
|
|
|
|
CC ?= cc
|
|
|
|
LDFLAGS += -lm $(GLIB)
|
|
|
|
else
|
|
|
|
CC = $(CROSS)gcc
|
|
|
|
endif
|
|
|
|
|
2016-04-21 01:38:27 +03:00
|
|
|
ifeq ($(UNICORN_ASAN),yes)
|
|
|
|
CC = clang -fsanitize=address -fno-omit-frame-pointer
|
|
|
|
CXX = clang++ -fsanitize=address -fno-omit-frame-pointer
|
|
|
|
AR = llvm-ar
|
|
|
|
LDFLAGS := -fsanitize=address ${LDFLAGS}
|
|
|
|
endif
|
|
|
|
|
2015-08-21 10:04:50 +03:00
|
|
|
|
|
|
|
#CFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
|
|
|
|
#LDFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
|
|
|
|
|
|
|
|
BIN_EXT =
|
|
|
|
AR_EXT = a
|
|
|
|
|
|
|
|
# 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 19:21:10 +03:00
|
|
|
ifneq ($(filter CYGWIN%,$(UNAME_S)),)
|
2015-08-21 10:04:50 +03:00
|
|
|
CFLAGS := $(CFLAGS:-fPIC=)
|
2015-12-17 08:20:57 +03:00
|
|
|
LDFLAGS += -lssp
|
|
|
|
LDFLAGS_STATIC += -lssp
|
2015-08-21 10:04:50 +03:00
|
|
|
BIN_EXT = .exe
|
2015-12-17 08:20:57 +03:00
|
|
|
AR_EXT = a
|
2015-08-21 10:04:50 +03: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 19:21:10 +03:00
|
|
|
else ifneq ($(filter MINGW%,$(UNAME_S)),)
|
2015-08-21 10:04:50 +03:00
|
|
|
CFLAGS := $(CFLAGS:-fPIC=)
|
|
|
|
BIN_EXT = .exe
|
|
|
|
AR_EXT = lib
|
|
|
|
endif
|
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 19:21:10 +03:00
|
|
|
|
2015-08-21 10:04:50 +03:00
|
|
|
|
|
|
|
ifeq ($(UNICORN_STATIC),yes)
|
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 19:21:10 +03:00
|
|
|
ifneq ($(filter MINGW%,$(UNAME_S)),)
|
2015-08-21 10:04:50 +03:00
|
|
|
ARCHIVE = $(LIBDIR)/$(LIBNAME).$(AR_EXT)
|
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 19:21:10 +03:00
|
|
|
else ifneq ($(filter CYGWIN%,$(UNAME_S)),)
|
2015-12-17 08:20:57 +03:00
|
|
|
ARCHIVE = $(LIBDIR)/lib$(LIBNAME).$(AR_EXT)
|
2015-08-21 10:04:50 +03:00
|
|
|
else
|
|
|
|
ARCHIVE = $(LIBDIR)/lib$(LIBNAME).$(AR_EXT)
|
|
|
|
#ARCHIVE_X86 = $(LIBDIR)/lib$(LIBNAME)_x86.$(AR_EXT)
|
|
|
|
#ARCHIVE_ARM = $(LIBDIR)/lib$(LIBNAME)_arm.$(AR_EXT)
|
|
|
|
#ARCHIVE_ARM64 = $(LIBDIR)/lib$(LIBNAME)_arm64.$(AR_EXT)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2016-03-25 17:29:50 +03:00
|
|
|
.PHONY: all clean clean_bins clean_libs
|
2015-08-21 10:04:50 +03:00
|
|
|
|
2015-08-24 12:48:30 +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
|
|
|
|
endif
|
|
|
|
ifneq (,$(findstring aarch64,$(UNICORN_ARCHS)))
|
|
|
|
SOURCES += sample_arm64.c
|
|
|
|
endif
|
|
|
|
ifneq (,$(findstring mips,$(UNICORN_ARCHS)))
|
|
|
|
SOURCES += sample_mips.c
|
|
|
|
endif
|
|
|
|
ifneq (,$(findstring ppc,$(UNICORN_ARCHS)))
|
|
|
|
#SOURCES += sample_ppc.c
|
|
|
|
endif
|
|
|
|
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 20:27:03 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
OBJS = $(addprefix $(OBJDIR)/,$(SOURCES:.c=.o))
|
|
|
|
OBJS_ELF = $(addprefix $(OBJDIR)/,$(SOURCES:.c=))
|
|
|
|
BINARY = $(addprefix $(SAMPLEDIR)/,$(SOURCES:.c=$(BIN_EXT)))
|
|
|
|
|
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 19:21:10 +03:00
|
|
|
all: $(BINARY)
|
2015-08-21 10:04:50 +03:00
|
|
|
|
2016-03-25 17:29:50 +03:00
|
|
|
clean_bins:
|
2015-08-21 10:04:50 +03:00
|
|
|
rm -rf *.o $(OBJS_ELF) $(BINARY) $(SAMPLEDIR)/*.exe $(SAMPLEDIR)/*.static $(OBJDIR)/lib$(LIBNAME)* $(OBJDIR)/$(LIBNAME)*
|
2016-04-05 06:52:26 +03:00
|
|
|
rm -rf sample_x86 sample_arm sample_arm64 sample_mips sample_sparc sample_ppc sample_m68k shellcode mem_apis sample_x86_32_gdt_and_seg_regs sample_batch_reg
|
2015-08-21 10:04:50 +03:00
|
|
|
|
2016-03-25 17:29:50 +03:00
|
|
|
clean_libs:
|
|
|
|
rm -rf libunicorn*.so libunicorn*.lib libunicorn*.dylib unicorn*.dll unicorn*.lib
|
|
|
|
|
|
|
|
clean: clean_bins clean_libs
|
|
|
|
|
2015-08-21 10:04:50 +03:00
|
|
|
$(BINARY): $(OBJS)
|
|
|
|
|
|
|
|
$(SAMPLEDIR)/%$(BIN_EXT): $(OBJDIR)/%.o
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
ifeq ($(V),0)
|
|
|
|
ifeq ($(UNICORN_SHARED),yes)
|
|
|
|
$(call log,LINK,$(notdir $@))
|
|
|
|
@$(link-dynamic)
|
|
|
|
endif
|
|
|
|
ifeq ($(UNICORN_STATIC),yes)
|
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 19:21:10 +03:00
|
|
|
ifneq ($(filter MINGW%,$(UNAME_S)),)
|
2015-08-21 10:04:50 +03:00
|
|
|
$(call log,LINK,$(notdir $(call staticname,$@)))
|
|
|
|
@$(link-static)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
ifeq ($(UNICORN_SHARED),yes)
|
|
|
|
$(link-dynamic)
|
|
|
|
endif
|
|
|
|
ifeq ($(UNICORN_STATIC),yes)
|
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 19:21:10 +03:00
|
|
|
ifneq ($(filter MINGW%,$(UNAME_S)),)
|
2015-08-21 10:04:50 +03:00
|
|
|
$(link-static)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(OBJDIR)/%.o: %.c
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
ifeq ($(V),0)
|
|
|
|
$(call log,CC,$(@:$(OBJDIR)/%=%))
|
|
|
|
@$(compile)
|
|
|
|
else
|
|
|
|
$(compile)
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
define link-dynamic
|
|
|
|
$(CC) $< $(LDFLAGS) -o $@
|
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
|
|
define link-static
|
|
|
|
$(CC) $< $(ARCHIVE) $(LDFLAGS_STATIC) -o $(call staticname,$@)
|
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
|
|
staticname = $(subst $(BIN_EXT),,$(1)).static$(BIN_EXT)
|
|
|
|
|
|
|
|
define log
|
|
|
|
@printf " %-7s %s\n" "$(1)" "$(2)"
|
|
|
|
endef
|
|
|
|
|
|
|
|
define compile
|
|
|
|
${CC} ${CFLAGS} -c $< -o $@
|
|
|
|
endef
|