From e17e7f391b0c72634dad50276d5dc39b5c762c20 Mon Sep 17 00:00:00 2001 From: Daniel Godas-Lopez Date: Thu, 28 Nov 2013 18:22:50 +0000 Subject: [PATCH 1/3] unified the targets for *nix and windows --- Makefile | 56 +++++++++++++++++++++++++++++--------------------- tests/Makefile | 40 +++++++++++++++++++++--------------- 2 files changed, 57 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index 062587bdcb..52fa170208 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,9 @@ # NOTE: at the moment this Makefile is for *nix only. CC = $(CROSS)gcc -AR ?= ar -RANLIB ?= ranlib -STRIP ?= strip +AR ?= $(CROSS)ar +RANLIB ?= $(CROSS)ranlib +STRIP ?= $(CROSS)strip CFLAGS += -fPIC -O3 -Wall -Iinclude LDFLAGS += -shared @@ -28,17 +28,37 @@ LIBOBJ += arch/ARM/ARMDisassembler.o arch/ARM/ARMInstPrinter.o arch/ARM/mapping. LIBOBJ += arch/AArch64/AArch64BaseInfo.o arch/AArch64/AArch64Disassembler.o arch/AArch64/AArch64InstPrinter.o arch/AArch64/mapping.o LIBOBJ += MCInst.o -# OSX is the exception +EXT = so +AR_EXT = a + +# OSX? UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) EXT = dylib else -# by default, lib extension is .so -EXT = so +# Cygwin? +IS_CYGWIN := $(shell $(CC) -dumpmachine | grep -i cygwin | wc -l) +ifeq ($(IS_CYGWIN),1) +EXT = dll +AR_EXT = dll.a +# Cygwin doesn't like -fPIC +CFLAGS := $(CFLAGS:-fPIC=) +# On Windows we need the shared library to be executable +else +# mingw? +IS_MINGW := $(shell $(CC) --version | grep -i mingw | wc -l) +ifeq ($(IS_MINGW),1) +EXT = dll +AR_EXT = dll.a +# mingw doesn't like -fPIC either +CFLAGS := $(CFLAGS:-fPIC=) +# On Windows we need the shared library to be executable +endif +endif endif -.PHONY: all clean lib archive windows win_lib install uninstall +.PHONY: all clean lib archive install uninstall all: lib archive $(MAKE) -C tests @@ -50,14 +70,14 @@ lib: $(LIBOBJ) #strip lib$(LIBNAME).$(EXT) archive: $(LIBOBJ) - rm -f lib$(LIBNAME).a - $(AR) q lib$(LIBNAME).a $(LIBOBJ) - $(RANLIB) lib$(LIBNAME).a + rm -f lib$(LIBNAME).$(AR_EXT) + $(AR) q lib$(LIBNAME).$(AR_EXT) $(LIBOBJ) + $(RANLIB) lib$(LIBNAME).$(AR_EXT) install: archive lib mkdir -p $(LIBDIR) $(INSTALL_LIBRARY) lib$(LIBNAME).$(EXT) $(LIBDIR) - $(INSTALL_DATA) lib$(LIBNAME).a $(LIBDIR) + $(INSTALL_DATA) lib$(LIBNAME).$(AR_EXT) $(LIBDIR) mkdir -p $(INCDIR)/$(LIBNAME) $(INSTALL_DATA) include/capstone.h $(INCDIR)/$(LIBNAME) $(INSTALL_DATA) include/x86.h $(INCDIR)/$(LIBNAME) @@ -68,20 +88,10 @@ install: archive lib uninstall: rm -rf $(INCDIR)/$(LIBNAME) rm -f $(LIBDIR)/lib$(LIBNAME).$(EXT) - rm -f $(LIBDIR)/lib$(LIBNAME).a - -# Mingw32 -windows: win_lib - $(INSTALL_DATA) $(LIBNAME).dll tests - $(MAKE) -C tests windows - -# Mingw32 -win_lib: $(LIBOBJ) - $(CC) $(LDFLAGS) $(LIBOBJ) -o $(LIBNAME).dll - $(STRIP) $(LIBNAME).dll + rm -f $(LIBDIR)/lib$(LIBNAME).$(AR_EXT) clean: - rm -f $(LIBOBJ) lib$(LIBNAME).* $(LIBNAME).dll + rm -f $(LIBOBJ) lib$(LIBNAME).* #cd bindings/ruby; $(MAKE) clean; rm -rf Makefile $(MAKE) -C bindings/python clean $(MAKE) -C bindings/csharp clean diff --git a/tests/Makefile b/tests/Makefile index b31bbba4f4..63538df020 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -10,29 +10,37 @@ CFLAGS += -fPIC -O3 -Wall -I$(INCDIR) -L$(LIBDIR) LIBNAME = capstone -.PHONY: all clean win_test linux windows +BIN_EXT = + +# Cygwin? +IS_CYGWIN := $(shell $(CC) -dumpmachine | grep -i cygwin | wc -l) +ifeq ($(IS_CYGWIN),1) +CFLAGS := $(CFLAGS:-fPIC=) +BIN_EXT = .exe +else +# mingw? +IS_MINGW := $(shell $(CC) --version | grep -i mingw | wc -l) +ifeq ($(IS_MINGW),1) +CFLAGS := $(CFLAGS:-fPIC=) +BIN_EXT = .exe +endif +endif + +.PHONY: all clean SOURCES = test.c test_detail.c test_x86.c test_arm64.c test_arm.c test_mips.c OBJS = $(SOURCES:.c=.o) -BINARY_LINUX = $(SOURCES:.c=) -BINARY_WINDOWS = $(SOURCES:.c=.exe) +BINARY = $(SOURCES:.c=$(BIN_EXT)) -all: nix - -nix: $(OBJS) $(BINARY_LINUX) - -# Mingw32 -windows: $(OBJS) $(BINARY_WINDOWS) +all: $(BINARY) clean: - rm -rf $(OBJS) $(BINARY_LINUX) $(BINARY_WINDOWS) *.dll *.so + rm -rf $(OBJS) $(BINARY) $(SOURCES:.c=.exe) lib$(LIBNAME).* -%.exe: %.o - ${CC} $(CFLAGS) $^ -O3 -Wall $(LIBNAME).dll -o $@ +$(BINARY): $(OBJS) -%: %.o - ${CC} $(CFLAGS) $^ -O3 -Wall -l$(LIBNAME) -o $@ +%$(BIN_EXT): %.o + ${CC} $(CFLAGS) $< -O3 -Wall -l$(LIBNAME) -o $@ -.c.o: +%.o: %.c ${CC} ${CFLAGS} -c $< -o $@ - From f1820ffc636cee5f3ebbb89a2db4850c898d0306 Mon Sep 17 00:00:00 2001 From: Daniel Godas-Lopez Date: Thu, 28 Nov 2013 18:23:39 +0000 Subject: [PATCH 2/3] added cygwin targets to the script and made cross-win* targets explicit --- COMPILE | 17 +++++++++++++---- compile.sh | 24 ++++++++++++++++++------ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/COMPILE b/COMPILE index da07a17a6d..3163419e53 100644 --- a/COMPILE +++ b/COMPILE @@ -45,20 +45,29 @@ only following files: if you want 64-bit binaries) are required. - To cross-compile Windows 32-bit binary, simply run - $ ./compile.sh win32 + $ ./compile.sh cross-win32 - To cross-compile Windows 64-bit binary, simply run - $ ./compile.sh win64 + $ ./compile.sh cross-win64 Resulted files "capstone.dll" and "tests/test*.exe" can then be used on Windows machine. -(4) By default, gcc is used as compiler. If you want to use "clang" instead, compile +(4) To compile under Cygwin gcc-mingw-w64-i686 or x86_64-w64-mingw32 run: + + - To compile Windows 32-bit binary under Cygwin, simply run + $ ./compile.sh cygwin-mingw32 + + - To compile Windows 64-bit binary under Cygwin, simply run + $ ./compile.sh cygwin-mingw64 + + +(5) By default, gcc is used as compiler. If you want to use "clang" instead, compile the code with: $ ./compile.sh clang -(5) So far Python, Ruby, Ocaml, Java, C# and Go are supported by bindings. Look for the bindings +(6) So far, Python, Ruby, Ocaml, Java, C# and Go are supported by bindings. Look for the bindings under directory bindings/, and refer to README file of corresponding languages. diff --git a/compile.sh b/compile.sh index 08ffb84679..580be80d08 100755 --- a/compile.sh +++ b/compile.sh @@ -3,11 +3,23 @@ # Capstone Disassembler Engine # By Nguyen Anh Quynh , 2013> +function build { + CROSS= make clean + + if [ ${CC}x != x ]; then + make CC=$CC + else + make + fi +} + case "$1" in - "" ) make clean; make;; - "nix32" ) make clean; CFLAGS=-m32 LDFLAGS=-m32 make;; - "clang" ) make clean; make CC=clang;; - "win32" ) make clean; make CROSS=i686-w64-mingw32- windows;; - "win64" ) make clean; make CROSS=x86_64-w64-mingw32- windows;; - * ) echo "Usage: compile.sh [nix32|clang|win32|win64]"; exit 1;; + "" ) build;; + "nix32" ) CFLAGS=-m32 LDFLAGS=-m32 build;; + "clang" ) CC=clang build;; + "cross-win32" ) CROSS=i686-w64-mingw32- build;; + "cross-win64" ) CROSS=x86_64-w64-mingw32- build;; + "cygwin-mingw32" ) CROSS=i686-pc-mingw32- build;; + "cygwin-mingw64" ) CROSS=x86_64-w64-mingw32- build;; + * ) echo "Usage: compile.sh [nix32|clang|cross-win32|cross-win64|cygwin-mingw32|cygwin-mingw64]"; exit 1;; esac From fa5325bf10f3f692ba2c37a5165f7f1080411809 Mon Sep 17 00:00:00 2001 From: Daniel Godas-Lopez Date: Fri, 29 Nov 2013 11:31:09 +0000 Subject: [PATCH 3/3] now the clean target deletes all binaries from all targets --- tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index 63538df020..4eb33a616a 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -35,7 +35,7 @@ BINARY = $(SOURCES:.c=$(BIN_EXT)) all: $(BINARY) clean: - rm -rf $(OBJS) $(BINARY) $(SOURCES:.c=.exe) lib$(LIBNAME).* + rm -rf $(OBJS) $(SOURCES:.c=) $(SOURCES:.c=.exe) lib$(LIBNAME).* $(BINARY): $(OBJS)