blob: dce07f70cfbd61bcb8fde7b1a377875f3e5916d6 [file] [log] [blame]
Nguyen Anh Quynh61882e52014-05-18 00:39:49 +08001This documentation explains how to compile, install & run Capstone on MacOSX,
2Linux, *BSD & Solaris. We also show steps to cross-compile for Microsoft Windows.
3
4To natively compile for Windows using Microsoft Visual Studio, see COMPILE_MSVC.TXT.
5
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08006 *-*-*-*-*-*
7
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08008Capstone requires no prerequisite packages, so it is easy to compile & install.
9
10
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080011
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +080012(0) Tailor Capstone to your need.
13
Nguyen Anh Quynh48a14ca2014-03-23 08:35:45 +080014 Out of 7 archtitectures supported by Capstone (Arm, Arm64, Mips, PPC, Sparc,
Nguyen Anh Quynh18759b32014-04-29 14:00:16 +080015 SystemZ & X86), if you just need several selected archs, choose which ones you
16 want to compile in by editing "config.mk" before going to next steps.
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +080017
Nguyen Anh Quynh48a14ca2014-03-23 08:35:45 +080018 By default, all 7 architectures are compiled.
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +080019
Nguyen Anh Quynh18759b32014-04-29 14:00:16 +080020 The other way of customize Capstone without having to edit config.mk is to
21 pass the desired options on the commandline to ./make.sh. Currently,
22 Capstone supports 4 options, as followings.
23
24 - CAPSTONE_ARCHS: specify list of architectures to compiled in.
Nguyen Anh Quynhe31327d2014-04-29 14:25:15 +080025 - CAPSTONE_USE_SYS_DYN_MEM: change this if you have your own dynamic memory management.
Nguyen Anh Quynh18759b32014-04-29 14:00:16 +080026 - CAPSTONE_DIET: use this to make the output binaries more compact.
27 - CAPSTONE_X86_REDUCE: another option to make X86 binary smaller.
28
Nguyen Anh Quynh01f48392014-05-15 11:06:43 +080029 By default, Capstone use system dynamic memory management, and both DIET and X86_REDUCE
30 modes are disable.
31
Nguyen Anh Quynh18759b32014-04-29 14:00:16 +080032 To avoid editing config.mk for these customization, can pass their values to
33 make.sh, as followings.
34
Nguyen Anh Quynhe31327d2014-04-29 14:25:15 +080035 $ CAPSTONE_ARCHS="arm aarch64 x86" CAPSTONE_USE_SYS_DYN_MEM=no CAPSTONE_DIET=yes CAPSTONE_X86_REDUCE=yes ./make.sh
Nguyen Anh Quynh18759b32014-04-29 14:00:16 +080036
37 NOTE: on commandline, put these values in front of ./make.sh, not after it.
38
Nguyen Anh Quynh18759b32014-04-29 14:00:16 +080039 For each option, refer to docs/README for more details.
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +080040
41
Nguyen Anh Quynhf08ed972014-04-07 22:13:56 +080042
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +080043(1) Compile from source
44
Nguyen Anh Quynhdba00f82014-01-17 14:20:54 +080045 On *nix (such as MacOSX, Linux, *BSD, Solaris):
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +080046
Nguyen Anh Quynhfe5e7f32014-01-17 14:56:03 +080047 - To compile for current platform, run:
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +080048
Nguyen Anh Quynhdba00f82014-01-17 14:20:54 +080049 $ ./make.sh
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080050
Nguyen Anh Quynhde6dd292014-04-14 14:40:25 +080051 - On 64-bit OS, run the command below to cross-compile Capstone for 32-bit binary:
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080052
Nguyen Anh Quynhde6dd292014-04-14 14:40:25 +080053 $ ./make.sh nix32
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080054
55
56
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +080057(2) Install Capstone on *nix
58
59 To install Capstone, run:
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080060
Nguyen Anh Quynhdba00f82014-01-17 14:20:54 +080061 $ sudo ./make.sh install
Nguyen Anh Quynhde6dd292014-04-14 14:40:25 +080062
Nguyen Anh Quynhdba00f82014-01-17 14:20:54 +080063 For FreeBSD/OpenBSD, where sudo is unavailable, run:
Nguyen Anh Quynhf74bebf2013-12-09 13:53:11 +080064
Nguyen Anh Quynhde6dd292014-04-14 14:40:25 +080065 $ su; ./make.sh install
Nguyen Anh Quynhf74bebf2013-12-09 13:53:11 +080066
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +080067 Users are then required to enter root password to copy Capstone into machine
68 system directories.
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080069
Nguyen Anh Quynh9919e3b2014-01-22 10:17:17 +080070 Afterwards, run ./tests/test* to see the tests disassembling sample code.
Nguyen Anh Quynhdba00f82014-01-17 14:20:54 +080071
72
Nguyen Anh Quynhfe5e7f32014-01-17 14:56:03 +080073 NOTE: The core framework installed by "./make.sh install" consist of
74 following files:
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080075
Patroklos Argyroudisa6503fe2013-11-27 14:25:34 +020076 /usr/include/capstone/capstone.h
77 /usr/include/capstone/x86.h
78 /usr/include/capstone/arm.h
79 /usr/include/capstone/arm64.h
80 /usr/include/capstone/mips.h
Nguyen Anh Quynhdba00f82014-01-17 14:20:54 +080081 /usr/include/capstone/ppc.h
Nguyen Anh Quynh05e27132014-03-10 11:58:57 +080082 /usr/include/capstone/sparc.h
Nguyen Anh Quynh48a14ca2014-03-23 08:35:45 +080083 /usr/include/capstone/systemz.h
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080084 /usr/lib/libcapstone.so (for Linux/*nix), or /usr/lib/libcapstone.dylib (OSX)
Nguyen Anh Quynh04271222013-12-09 11:12:47 +080085 /usr/lib/libcapstone.a
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080086
87
88
Nguyen Anh Quynhf08ed972014-04-07 22:13:56 +080089(3) Cross-compile for Windows from *nix
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +080090
91 To cross-compile for Windows, Linux & gcc-mingw-w64-i686 (and also gcc-mingw-w64-x86-64
92 for 64-bit binaries) are required.
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080093
Nguyen Anh Quynhfe5e7f32014-01-17 14:56:03 +080094 - To cross-compile Windows 32-bit binary, simply run:
Nguyen Anh Quynhde6dd292014-04-14 14:40:25 +080095
Nguyen Anh Quynhdba00f82014-01-17 14:20:54 +080096 $ ./make.sh cross-win32
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080097
Nguyen Anh Quynhfe5e7f32014-01-17 14:56:03 +080098 - To cross-compile Windows 64-bit binary, run:
Nguyen Anh Quynhde6dd292014-04-14 14:40:25 +080099
Nguyen Anh Quynhdba00f82014-01-17 14:20:54 +0800100 $ ./make.sh cross-win64
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800101
Nguyen Anh Quynh9919e3b2014-01-22 10:17:17 +0800102 Resulted files libcapstone.dll, libcapstone.dll.a & tests/test*.exe can then
103 be used on Windows machine.
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800104
105
106
Nguyen Anh Quynhf08ed972014-04-07 22:13:56 +0800107(4) Cross-compile for iOS from Mac OSX.
Nguyen Anh Quynh2eecc6c2014-04-01 10:22:54 +0800108
109 To cross-compile for iOS (iPhone/iPad/iPod), Mac OSX with XCode installed is required.
110
111 - To cross-compile for ArmV7 (iPod 4, iPad 1/2/3, iPhone4, iPhone4S), run:
112 $ ./make.sh ios_armv7
113
114 - To cross-compile for ArmV7s (iPad 4, iPhone 5C, iPad mini), run:
115 $ ./make.sh ios_armv7s
116
117 - To cross-compile for Arm64 (iPhone 5S, iPad mini Retina, iPad Air), run:
118 $ ./make.sh ios_arm64
119
120 - To cross-compile for all iDevices (armv7 + armv7s + arm64), run:
121 $ ./make.sh ios
122
123 Resulted files libcapstone.dylib, libcapstone.a & tests/test* can then
124 be used on iOS devices.
125
126
127
Nguyen Anh Quynhf08ed972014-04-07 22:13:56 +0800128(5) Cross-compile for Android
129
130 To cross-compile for Android (smartphone/tablet), Android NDK is required.
131
132 $ ./make.sh cross-android
133
134 Resulted files libcapstone.so, libcapstone.a & tests/test* can then
135 be used on Android devices.
136
137
138
139(6) Compile on Windows with Cygwin
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +0800140
141 To compile under Cygwin gcc-mingw-w64-i686 or x86_64-w64-mingw32 run:
Daniel Godas-Lopezcf05e112013-11-28 18:23:39 +0000142
Nguyen Anh Quynhde6dd292014-04-14 14:40:25 +0800143 - To compile Windows 32-bit binary under Cygwin, run:
144
Nguyen Anh Quynhdba00f82014-01-17 14:20:54 +0800145 $ ./make.sh cygwin-mingw32
Daniel Godas-Lopezcf05e112013-11-28 18:23:39 +0000146
Nguyen Anh Quynhde6dd292014-04-14 14:40:25 +0800147 - To compile Windows 64-bit binary under Cygwin, run:
148
Nguyen Anh Quynhdba00f82014-01-17 14:20:54 +0800149 $ ./make.sh cygwin-mingw64
Daniel Godas-Lopezcf05e112013-11-28 18:23:39 +0000150
Nguyen Anh Quynh9919e3b2014-01-22 10:17:17 +0800151 Resulted files libcapstone.dll, libcapstone.dll.a & tests/test*.exe can then
152 be used on Windows machine.
Daniel Godas-Lopezcf05e112013-11-28 18:23:39 +0000153
Nguyen Anh Quynhfe5e7f32014-01-17 14:56:03 +0800154
Nguyen Anh Quynhf08ed972014-04-07 22:13:56 +0800155
156(7) By default, "cc" (default C compiler on the system) is used as compiler.
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +0800157
Nguyen Anh Quynhde6dd292014-04-14 14:40:25 +0800158 - To use "clang" compiler instead, run the command below:
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +0800159
Nguyen Anh Quynhdba00f82014-01-17 14:20:54 +0800160 $ ./make.sh clang
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800161
Nguyen Anh Quynhfe5e7f32014-01-17 14:56:03 +0800162 - To use "gcc" compiler instead, run:
Oliver Pinter6e2c0752014-01-16 12:16:21 +0100163
Nguyen Anh Quynhdba00f82014-01-17 14:20:54 +0800164 $ ./make.sh gcc
Oliver Pinter6e2c0752014-01-16 12:16:21 +0100165
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800166
167
Nguyen Anh Quynhde6dd292014-04-14 14:40:25 +0800168(8) To uninstall Capstone, run the command below:
Nguyen Anh Quynh919875b2014-04-14 14:00:12 +0800169
170 $ sudo ./make.sh uninstall
171
172
173
174(9) Language bindings
Nguyen Anh Quynha6a11532013-12-24 17:03:45 +0800175
Nguyen Anh Quynh9919e3b2014-01-22 10:17:17 +0800176 So far, Python, Ocaml & Java are supported by bindings in the main code.
177 Look for the bindings under directory bindings/, and refer to README file
178 of corresponding languages.
179
180 Community also provide bindings for C#, Go, Ruby & Vala. Links to these can
181 be found at address http://capstone-engine.org/download.html