pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 1 | #!/bin/sh |
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 |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 4 | # By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 |
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 | |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 8 | MAKE_JOBS=$((${MAKE_JOBS}+0)) |
| 9 | [ ${MAKE_JOBS} -lt 1 ] && \ |
| 10 | MAKE_JOBS=4 |
Nguyen Anh Quynh | 50ebb68 | 2014-03-31 21:15:29 +0800 | [diff] [blame] | 11 | |
| 12 | # build iOS lib for all iDevices, or only specific device |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 13 | build_iOS() { |
| 14 | ${MAKE} clean |
| 15 | IOS_SDK=`xcrun --sdk iphoneos --show-sdk-path` |
| 16 | IOS_CC=`xcrun --sdk iphoneos -f clang` |
| 17 | IOS_CFLAGS="-Os -Wimplicit -isysroot $IOS_SDK" |
| 18 | IOS_LDFLAGS="-isysroot $IOS_SDK" |
| 19 | if [ -z "$1" ]; then |
| 20 | # build for all iDevices |
| 21 | IOS_ARCHS="armv7 armv7s arm64" |
| 22 | else |
| 23 | IOS_ARCHS="$1" |
| 24 | fi |
| 25 | CC="$IOS_CC" \ |
| 26 | CFLAGS="$IOS_CFLAGS" \ |
| 27 | LDFLAGS="$IOS_LDFLAGS" \ |
| 28 | LIBARCHS="$IOS_ARCHS" \ |
| 29 | ${MAKE} |
Nguyen Anh Quynh | 50ebb68 | 2014-03-31 21:15:29 +0800 | [diff] [blame] | 30 | } |
| 31 | |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 32 | build() { |
| 33 | [ "$UNAME" = Darwin ] && LIBARCHS="i386 x86_64" |
| 34 | ${MAKE} clean |
| 35 | ${MAKE} |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 36 | } |
| 37 | |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 38 | install() { |
| 39 | # Mac OSX needs to find the right directory for pkgconfig |
| 40 | if [ "$UNAME" = Darwin ]; then |
| 41 | # we are going to install into /usr/local, so remove old installs under /usr |
| 42 | rm -rf /usr/lib/libcapstone.* |
| 43 | rm -rf /usr/include/capstone |
| 44 | # install into /usr/local |
| 45 | PREFIX=/usr/local |
pancake | d1af4dd | 2015-03-02 10:55:55 +0100 | [diff] [blame] | 46 | if [ "${HOMEBREW_CAPSTONE}" != 1 ]; then |
| 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)" |
| 49 | fi |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 50 | ${MAKE} install |
| 51 | else # not OSX |
| 52 | test -d /usr/lib64 && ${MAKE} LIBDIRARCH=lib64 |
| 53 | ${MAKE} install |
| 54 | fi |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 55 | } |
| 56 | |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 57 | uninstall() { |
| 58 | # Mac OSX needs to find the right directory for pkgconfig |
| 59 | if [ "$UNAME" = "Darwin" ]; then |
| 60 | # find the directory automatically, so we can support both Macport & Brew |
| 61 | PKGCFGDIR="$(pkg-config --variable pc_path pkg-config | cut -d ':' -f 1)" |
| 62 | PREFIX=/usr/local |
| 63 | ${MAKE} uninstall |
| 64 | else # not OSX |
| 65 | test -d /usr/lib64 && LIBDIRARCH=lib64 |
| 66 | ${MAKE} uninstall |
| 67 | fi |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 68 | } |
| 69 | |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 70 | if [ "$UNAME" = SunOS ]; then |
| 71 | [ -z "${MAKE}" ] && MAKE=gmake |
| 72 | INSTALL_BIN=ginstall |
| 73 | CC=gcc |
Nguyen Anh Quynh | d3b3071 | 2014-01-17 21:25:18 +0800 | [diff] [blame] | 74 | fi |
| 75 | |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 76 | if [ -n "`echo "$UNAME" | grep BSD`" ]; then |
| 77 | MAKE=gmake |
| 78 | PREFIX=/usr/local |
Nguyen Anh Quynh | f63db27 | 2014-01-17 22:12:35 +0800 | [diff] [blame] | 79 | fi |
| 80 | |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 81 | [ -z "${UNAME}" ] && UNAME=$(uname) |
| 82 | [ -z "${MAKE}" ] && MAKE=make |
| 83 | [ -n "${MAKE_JOBS}" ] && MAKE="$MAKE -j${MAKE_JOBS}" |
radare | 796f1d4 | 2015-03-07 11:40:19 +0100 | [diff] [blame^] | 84 | export CC INSTALL_BIN PREFIX PKGCFGDIR LIBDIRARCH LIBARCHS CFLAGS LDFLAGS |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 85 | |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 86 | case "$1" in |
| 87 | "" ) build;; |
| 88 | "default" ) build;; |
| 89 | "install" ) install;; |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 90 | "uninstall" ) uninstall;; |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 91 | "nix32" ) CFLAGS=-m32 LDFLAGS=-m32 build;; |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 92 | "cross-win32" ) CROSS=i686-w64-mingw32- build;; |
| 93 | "cross-win64" ) CROSS=x86_64-w64-mingw32- build;; |
| 94 | "cygwin-mingw32" ) CROSS=i686-pc-mingw32- build;; |
| 95 | "cygwin-mingw64" ) CROSS=x86_64-w64-mingw32- build;; |
Nguyen Anh Quynh | f08ed97 | 2014-04-07 22:13:56 +0800 | [diff] [blame] | 96 | "cross-android" ) CROSS=arm-linux-androideabi- build;; |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 97 | "clang" ) CC=clang build;; |
| 98 | "gcc" ) CC=gcc build;; |
Nguyen Anh Quynh | 50ebb68 | 2014-03-31 21:15:29 +0800 | [diff] [blame] | 99 | "ios" ) build_iOS;; |
| 100 | "ios_armv7" ) build_iOS armv7;; |
| 101 | "ios_armv7s" ) build_iOS armv7s;; |
| 102 | "ios_arm64" ) build_iOS arm64;; |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 103 | * ) |
| 104 | echo "Usage: $0 ["`grep '^ "' $0 | cut -d '"' -f 2 | tr "\\n" "|"`"]" |
| 105 | exit 1;; |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 106 | esac |