Nguyen Anh Quynh | c3fd527 | 2014-03-31 16:05:25 +0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 2 | |
| 3 | # Capstone Disassembler Engine |
| 4 | # By Nguyen Anh Quynh <aquynh@gmail.com>, 2013> |
| 5 | |
| 6 | # Note: to cross-compile "nix32" on Linux, package gcc-multilib is required. |
| 7 | |
Nguyen Anh Quynh | 50ebb68 | 2014-03-31 21:15:29 +0800 | [diff] [blame] | 8 | |
| 9 | # build iOS lib for all iDevices, or only specific device |
| 10 | function build_iOS { |
| 11 | ${MAKE} clean |
| 12 | SDK=`xcrun --sdk iphoneos --show-sdk-path` |
| 13 | GCC_BIN=`xcrun --sdk iphoneos -f gcc` |
| 14 | GCC_BASE="$GCC_BIN -Os -Wimplicit -isysroot $SDK" |
| 15 | if (( $# == 0 )); then |
| 16 | # build for all iDevices |
| 17 | GCC="$GCC_BASE -arch armv7 -arch armv7s -arch arm64" |
| 18 | else |
| 19 | GCC="$GCC_BASE -arch $1" |
| 20 | fi |
| 21 | ${MAKE} CC="$GCC" |
| 22 | } |
| 23 | |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 24 | function build { |
Nguyen Anh Quynh | af87393 | 2014-01-28 11:14:55 +0800 | [diff] [blame] | 25 | ${MAKE} clean |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 26 | |
| 27 | if [ ${CC}x != x ]; then |
| 28 | ${MAKE} CC=$CC |
| 29 | else |
| 30 | ${MAKE} |
| 31 | fi |
| 32 | } |
| 33 | |
| 34 | function install { |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 35 | # Mac OSX needs to find the right directory for pkgconfig |
| 36 | if [ "$(uname)" == "Darwin" ]; then |
| 37 | # find the directory automatically, so we can support both Macport & Brew |
| 38 | PKGCFGDIR="$(pkg-config --variable pc_path pkg-config | cut -d ':' -f 1)" |
Nguyen Anh Quynh | ac673ae | 2014-04-14 23:58:28 +0800 | [diff] [blame^] | 39 | # set PKGCFGDIR only in non-Brew environment & pkg-config is available |
| 40 | if [ "$HOMEBREW_CAPSTONE" != "1" ] && [ ${PKGCFGDIR}x != x ]; then |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 41 | if [ ${CC}x != x ]; then |
| 42 | ${MAKE} CC=$CC PKGCFGDIR=$PKGCFGDIR install |
| 43 | else |
| 44 | ${MAKE} PKGCFGDIR=$PKGCFGDIR install |
| 45 | fi |
| 46 | else |
| 47 | if [ ${CC}x != x ]; then |
| 48 | ${MAKE} CC=$CC install |
| 49 | else |
| 50 | ${MAKE} install |
| 51 | fi |
| 52 | fi |
Nguyen Anh Quynh | 360bf1e | 2014-04-14 13:36:46 +0800 | [diff] [blame] | 53 | else # not OSX |
| 54 | if test -d /usr/lib64; then |
| 55 | if [ ${CC}x != x ]; then |
| 56 | ${MAKE} LIBDIRARCH=lib64 CC=$CC install |
| 57 | else |
| 58 | ${MAKE} LIBDIRARCH=lib64 install |
| 59 | fi |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 60 | else |
Nguyen Anh Quynh | 360bf1e | 2014-04-14 13:36:46 +0800 | [diff] [blame] | 61 | if [ ${CC}x != x ]; then |
| 62 | ${MAKE} CC=$CC install |
| 63 | else |
| 64 | ${MAKE} install |
| 65 | fi |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 66 | fi |
| 67 | fi |
| 68 | } |
| 69 | |
| 70 | function uninstall { |
| 71 | # Mac OSX needs to find the right directory for pkgconfig |
| 72 | if [ "$(uname)" == "Darwin" ]; then |
| 73 | # find the directory automatically, so we can support both Macport & Brew |
| 74 | PKGCFGDIR="$(pkg-config --variable pc_path pkg-config | cut -d ':' -f 1)" |
| 75 | if [ ${PKGCFGDIR}x != x ]; then |
| 76 | ${MAKE} PKGCFGDIR=$PKGCFGDIR uninstall |
| 77 | else |
| 78 | ${MAKE} uninstall |
| 79 | fi |
Nguyen Anh Quynh | 360bf1e | 2014-04-14 13:36:46 +0800 | [diff] [blame] | 80 | else # not OSX |
| 81 | if test -d /usr/lib64; then |
| 82 | ${MAKE} LIBDIRARCH=lib64 uninstall |
| 83 | else |
| 84 | ${MAKE} uninstall |
| 85 | fi |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 86 | fi |
| 87 | } |
| 88 | |
Nguyen Anh Quynh | af87393 | 2014-01-28 11:14:55 +0800 | [diff] [blame] | 89 | MAKE=make |
Nguyen Anh Quynh | d3b3071 | 2014-01-17 21:25:18 +0800 | [diff] [blame] | 90 | if [ "$(uname)" == "SunOS" ]; then |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 91 | export MAKE=gmake |
| 92 | export INSTALL_BIN=ginstall |
| 93 | export CC=gcc |
Nguyen Anh Quynh | d3b3071 | 2014-01-17 21:25:18 +0800 | [diff] [blame] | 94 | fi |
| 95 | |
Nguyen Anh Quynh | f63db27 | 2014-01-17 22:12:35 +0800 | [diff] [blame] | 96 | if [[ "$(uname)" == *BSD* ]]; then |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 97 | export MAKE=gmake |
| 98 | export PREFIX=/usr/local |
Nguyen Anh Quynh | f63db27 | 2014-01-17 22:12:35 +0800 | [diff] [blame] | 99 | fi |
| 100 | |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 101 | case "$1" in |
| 102 | "" ) build;; |
| 103 | "default" ) build;; |
| 104 | "install" ) install;; |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 105 | "uninstall" ) uninstall;; |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 106 | "nix32" ) CFLAGS=-m32 LDFLAGS=-m32 build;; |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 107 | "cross-win32" ) CROSS=i686-w64-mingw32- build;; |
| 108 | "cross-win64" ) CROSS=x86_64-w64-mingw32- build;; |
| 109 | "cygwin-mingw32" ) CROSS=i686-pc-mingw32- build;; |
| 110 | "cygwin-mingw64" ) CROSS=x86_64-w64-mingw32- build;; |
Nguyen Anh Quynh | f08ed97 | 2014-04-07 22:13:56 +0800 | [diff] [blame] | 111 | "cross-android" ) CROSS=arm-linux-androideabi- build;; |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 112 | "clang" ) CC=clang build;; |
| 113 | "gcc" ) CC=gcc build;; |
Nguyen Anh Quynh | 50ebb68 | 2014-03-31 21:15:29 +0800 | [diff] [blame] | 114 | "ios" ) build_iOS;; |
| 115 | "ios_armv7" ) build_iOS armv7;; |
| 116 | "ios_armv7s" ) build_iOS armv7s;; |
| 117 | "ios_arm64" ) build_iOS arm64;; |
Nguyen Anh Quynh | f08ed97 | 2014-04-07 22:13:56 +0800 | [diff] [blame] | 118 | * ) echo "Usage: make.sh [nix32|cross-win32|cross-win64|cygwin-mingw32|cygwin-mingw64|ios|ios_armv7|ios_armv7s|ios_arm64|cross-android|clang|gcc|install|uninstall]"; exit 1;; |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 119 | esac |