|
| 1 | +This documentation explains how to build & install Keystone on all kind of nix OS. |
| 2 | +For Windows, see [COMPILE-WINDOWS.md](COMPILE-WINDOWS.md) |
| 3 | + |
| 4 | + |
| 5 | +1. Dependency |
| 6 | + |
| 7 | + CMake is required to build keystone. |
| 8 | + |
| 9 | + - On Mac OS X, you can install "cmake" with "brew". |
| 10 | + |
| 11 | + $ brew install cmake |
| 12 | + |
| 13 | + - On Ubuntu Linux, install "cmake" with: |
| 14 | + |
| 15 | + $ sudo apt-get install cmake |
| 16 | + |
| 17 | + |
| 18 | +2. From the root directory of Keystone source, compile its dynamic library |
| 19 | + with the following commands. |
| 20 | + |
| 21 | + $ mkdir build |
| 22 | + $ cd build |
| 23 | + $ ../make-share.sh |
| 24 | + |
| 25 | + In the case you want to compile with all the debug information, replace the |
| 26 | + last line with: |
| 27 | + |
| 28 | + $ ../make-share.sh debug |
| 29 | + |
| 30 | + For Linux distributions following the "Filesystem Hierarchy Standard" and |
| 31 | + put x64 libraries under $PREFIX/lib64, such as Fedora, Redhat & Suse, |
| 32 | + add "fhs" option at the end of make-share.sh script, like below. |
| 33 | + |
| 34 | + $ ../make-share.sh fhs |
| 35 | + |
| 36 | + By default, this builds all architectures, which is: AArch64, ARM, Hexagon, |
| 37 | + Mips, PowerPC, Sparc, SystemZ & X86. To compile just some selected ones, |
| 38 | + pass a semicolon-separated list of targets to LLVM_TARGETS_TO_BUILD, |
| 39 | + like follows if we only want AArch64 & X86. |
| 40 | + |
| 41 | + $ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DLLVM_TARGETS_TO_BUILD="AArch64, X86" -G "Unix Makefiles" .. |
| 42 | + $ make -j8 |
| 43 | + |
| 44 | + You can also compile static a library with: |
| 45 | + |
| 46 | + $ mkdir build |
| 47 | + $ cd build |
| 48 | + $ ../make-lib.sh |
| 49 | + |
| 50 | + In the case you want to compile with all the debug information, replace the |
| 51 | + last line with: |
| 52 | + |
| 53 | + $ ../make-lib.sh debug |
| 54 | + |
| 55 | + For Linux distributions following the "Filesystem Hierarchy Standard" and |
| 56 | + put x64 libraries under $PREFIX/lib64, such as Fedora, Redhat & Suse, |
| 57 | + add "fhs" option at the end of make-share.sh script, like below. |
| 58 | + |
| 59 | + $ ../make-lib.sh fhs |
| 60 | + |
| 61 | + Like above, this builds all architectures. To compile just some selected ones, |
| 62 | + pass a semicolon-separated list of targets to LLVM_TARGETS_TO_BUILD, |
| 63 | + like follows if we only want AArch64 & X86. |
| 64 | + |
| 65 | + $ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DLLVM_TARGETS_TO_BUILD="AArch64, X86" -G "Unix Makefiles" .. |
| 66 | + $ make -j8 |
| 67 | + |
| 68 | + To customize your build by specifying PREFIX or other installation directories, |
| 69 | + pass one of the variables at https://cmake.org/cmake/help/v3.0/module/GNUInstallDirs.html |
| 70 | + to cmake. For example: |
| 71 | + |
| 72 | + $ cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DLLVM_TARGETS_TO_BUILD="AArch64, X86" -G "Unix Makefiles" .. |
| 73 | + $ make -j8 |
| 74 | + |
| 75 | + |
| 76 | +3. Right after building, install Keystone. |
| 77 | + |
| 78 | + $ sudo make install |
| 79 | + |
| 80 | + Keystone is installed in '/usr/local', depending on your distribution (eg. Ubuntu) you might |
| 81 | + need to add '/usr/local/lib' to '/etc/ld.so.conf'. Then update the dynamic linker |
| 82 | + with: |
| 83 | + |
| 84 | + $ sudo ldconfig |
| 85 | + |
| 86 | + Besides the libraries & C header files under thedirectory "include/keystone", |
| 87 | + this step also installs a tool named "kstool" on the system. |
| 88 | + (The source of "kstool" is in the directory "kstool/kstool") |
| 89 | + |
| 90 | + |
| 91 | +4. Test Keystone with "kstool" like below. |
| 92 | + |
| 93 | + $ kstool x32 "add eax, ebx" |
| 94 | + |
| 95 | + Run "kstool" without any option to find out how to use this handy tool. |
| 96 | + |
| 97 | + |
| 98 | +5. Learn more on how to code your own tools with our samples. |
| 99 | + |
| 100 | + For C sample code, see code in directory samples/ |
| 101 | + |
| 102 | + For Python sample code, see code in directory bindings/python/ |
0 commit comments