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 | |
Nguyen Anh Quynh | 6023ef7 | 2014-04-29 11:21:04 +0800 | [diff] [blame] | 3 | # Capstone Disassembly Engine |
| 4 | # By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 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 |
Ole André Vadla Ravnås | 6583f06 | 2014-07-04 23:09:19 +0200 | [diff] [blame] | 12 | IOS_SDK=`xcrun --sdk iphoneos --show-sdk-path` |
| 13 | IOS_CC=`xcrun --sdk iphoneos -f clang` |
| 14 | IOS_CFLAGS="-Os -Wimplicit -isysroot $IOS_SDK" |
| 15 | IOS_LDFLAGS="-isysroot $IOS_SDK" |
Nguyen Anh Quynh | 50ebb68 | 2014-03-31 21:15:29 +0800 | [diff] [blame] | 16 | if (( $# == 0 )); then |
| 17 | # build for all iDevices |
Ole André Vadla Ravnås | 6583f06 | 2014-07-04 23:09:19 +0200 | [diff] [blame] | 18 | IOS_ARCHS="armv7 armv7s arm64" |
Nguyen Anh Quynh | 50ebb68 | 2014-03-31 21:15:29 +0800 | [diff] [blame] | 19 | else |
Ole André Vadla Ravnås | 6583f06 | 2014-07-04 23:09:19 +0200 | [diff] [blame] | 20 | IOS_ARCHS="$1" |
Nguyen Anh Quynh | 50ebb68 | 2014-03-31 21:15:29 +0800 | [diff] [blame] | 21 | fi |
Ole André Vadla Ravnås | 174f9bb | 2014-07-05 20:29:50 +0200 | [diff] [blame] | 22 | CC="$IOS_CC" CFLAGS="$IOS_CFLAGS" LDFLAGS="$IOS_LDFLAGS" LIBARCHS="$IOS_ARCHS" ${MAKE} |
Nguyen Anh Quynh | 50ebb68 | 2014-03-31 21:15:29 +0800 | [diff] [blame] | 23 | } |
| 24 | |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 25 | function build { |
Ole André Vadla Ravnås | 39edca1 | 2014-07-05 20:31:30 +0200 | [diff] [blame] | 26 | if [ $(uname -s) = Darwin ]; then |
| 27 | export LIBARCHS="i386 x86_64" |
| 28 | fi |
| 29 | |
Nguyen Anh Quynh | af87393 | 2014-01-28 11:14:55 +0800 | [diff] [blame] | 30 | ${MAKE} clean |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 31 | |
| 32 | if [ ${CC}x != x ]; then |
| 33 | ${MAKE} CC=$CC |
| 34 | else |
| 35 | ${MAKE} |
| 36 | fi |
| 37 | } |
| 38 | |
| 39 | function install { |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 40 | # Mac OSX needs to find the right directory for pkgconfig |
| 41 | if [ "$(uname)" == "Darwin" ]; then |
Nguyen Anh Quynh | bcc6e53 | 2014-07-07 11:42:25 +0800 | [diff] [blame] | 42 | # we are going to install into /usr/local, so remove old installs under /usr |
| 43 | rm -rf /usr/lib/libcapstone.* |
| 44 | rm -rf /usr/include/capstone |
| 45 | # install into /usr/local |
| 46 | export PREFIX=/usr/local |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 47 | # find the directory automatically, so we can support both Macport & Brew |
| 48 | 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] | 49 | # set PKGCFGDIR only in non-Brew environment & pkg-config is available |
| 50 | if [ "$HOMEBREW_CAPSTONE" != "1" ] && [ ${PKGCFGDIR}x != x ]; then |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 51 | if [ ${CC}x != x ]; then |
| 52 | ${MAKE} CC=$CC PKGCFGDIR=$PKGCFGDIR install |
| 53 | else |
| 54 | ${MAKE} PKGCFGDIR=$PKGCFGDIR install |
| 55 | fi |
| 56 | else |
| 57 | if [ ${CC}x != x ]; then |
| 58 | ${MAKE} CC=$CC install |
| 59 | else |
| 60 | ${MAKE} install |
| 61 | fi |
| 62 | fi |
Nguyen Anh Quynh | 360bf1e | 2014-04-14 13:36:46 +0800 | [diff] [blame] | 63 | else # not OSX |
| 64 | if test -d /usr/lib64; then |
| 65 | if [ ${CC}x != x ]; then |
| 66 | ${MAKE} LIBDIRARCH=lib64 CC=$CC install |
| 67 | else |
| 68 | ${MAKE} LIBDIRARCH=lib64 install |
| 69 | fi |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 70 | else |
Nguyen Anh Quynh | 360bf1e | 2014-04-14 13:36:46 +0800 | [diff] [blame] | 71 | if [ ${CC}x != x ]; then |
| 72 | ${MAKE} CC=$CC install |
| 73 | else |
| 74 | ${MAKE} install |
| 75 | fi |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 76 | fi |
| 77 | fi |
| 78 | } |
| 79 | |
| 80 | function uninstall { |
| 81 | # Mac OSX needs to find the right directory for pkgconfig |
| 82 | if [ "$(uname)" == "Darwin" ]; then |
| 83 | # find the directory automatically, so we can support both Macport & Brew |
| 84 | PKGCFGDIR="$(pkg-config --variable pc_path pkg-config | cut -d ':' -f 1)" |
Nguyen Anh Quynh | cf86270 | 2014-07-22 21:19:02 +0800 | [diff] [blame] | 85 | export PREFIX=/usr/local |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 86 | if [ ${PKGCFGDIR}x != x ]; then |
| 87 | ${MAKE} PKGCFGDIR=$PKGCFGDIR uninstall |
| 88 | else |
| 89 | ${MAKE} uninstall |
| 90 | fi |
Nguyen Anh Quynh | 360bf1e | 2014-04-14 13:36:46 +0800 | [diff] [blame] | 91 | else # not OSX |
| 92 | if test -d /usr/lib64; then |
| 93 | ${MAKE} LIBDIRARCH=lib64 uninstall |
| 94 | else |
| 95 | ${MAKE} uninstall |
| 96 | fi |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 97 | fi |
| 98 | } |
| 99 | |
Nguyen Anh Quynh | af87393 | 2014-01-28 11:14:55 +0800 | [diff] [blame] | 100 | MAKE=make |
Nguyen Anh Quynh | d3b3071 | 2014-01-17 21:25:18 +0800 | [diff] [blame] | 101 | if [ "$(uname)" == "SunOS" ]; then |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 102 | export MAKE=gmake |
| 103 | export INSTALL_BIN=ginstall |
| 104 | export CC=gcc |
Nguyen Anh Quynh | d3b3071 | 2014-01-17 21:25:18 +0800 | [diff] [blame] | 105 | fi |
| 106 | |
Nguyen Anh Quynh | f63db27 | 2014-01-17 22:12:35 +0800 | [diff] [blame] | 107 | if [[ "$(uname)" == *BSD* ]]; then |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 108 | export MAKE=gmake |
| 109 | export PREFIX=/usr/local |
Nguyen Anh Quynh | f63db27 | 2014-01-17 22:12:35 +0800 | [diff] [blame] | 110 | fi |
| 111 | |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 112 | case "$1" in |
| 113 | "" ) build;; |
| 114 | "default" ) build;; |
| 115 | "install" ) install;; |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 116 | "uninstall" ) uninstall;; |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 117 | "nix32" ) CFLAGS=-m32 LDFLAGS=-m32 build;; |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 118 | "cross-win32" ) CROSS=i686-w64-mingw32- build;; |
| 119 | "cross-win64" ) CROSS=x86_64-w64-mingw32- build;; |
| 120 | "cygwin-mingw32" ) CROSS=i686-pc-mingw32- build;; |
| 121 | "cygwin-mingw64" ) CROSS=x86_64-w64-mingw32- build;; |
Nguyen Anh Quynh | f08ed97 | 2014-04-07 22:13:56 +0800 | [diff] [blame] | 122 | "cross-android" ) CROSS=arm-linux-androideabi- build;; |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 123 | "clang" ) CC=clang build;; |
| 124 | "gcc" ) CC=gcc build;; |
Nguyen Anh Quynh | 50ebb68 | 2014-03-31 21:15:29 +0800 | [diff] [blame] | 125 | "ios" ) build_iOS;; |
| 126 | "ios_armv7" ) build_iOS armv7;; |
| 127 | "ios_armv7s" ) build_iOS armv7s;; |
| 128 | "ios_arm64" ) build_iOS arm64;; |
Nguyen Anh Quynh | f08ed97 | 2014-04-07 22:13:56 +0800 | [diff] [blame] | 129 | * ) 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] | 130 | esac |