Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions COMPILE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
56 changes: 33 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
24 changes: 18 additions & 6 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
# Capstone Disassembler Engine
# By Nguyen Anh Quynh <aquynh@gmail.com>, 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
40 changes: 24 additions & 16 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) $(SOURCES:.c=) $(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 $@