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 | |
Nguyen Anh Quynh | fc3b138 | 2015-06-22 12:51:21 +0800 | [diff] [blame] | 12 | # build Android lib for only one supported architecture |
radare | 71fd42d | 2015-07-28 16:49:00 +0200 | [diff] [blame] | 13 | build_android() { |
Nguyen Anh Quynh | fc3b138 | 2015-06-22 12:51:21 +0800 | [diff] [blame] | 14 | if [ -z "$NDK" ]; then |
| 15 | echo "ERROR! Please set \$NDK to point at your Android NDK directory." |
| 16 | exit 1 |
| 17 | fi |
| 18 | HOSTOS=$(uname -s | tr 'LD' 'ld') |
| 19 | HOSTARCH=$(uname -m) |
| 20 | |
| 21 | TARGARCH="$1" |
| 22 | shift |
| 23 | |
| 24 | case "$TARGARCH" in |
| 25 | arm) |
| 26 | [ -n "$APILEVEL" ] || APILEVEL="android-14" # default to ICS |
| 27 | [ -n "$GCCVER" ] || GCCVER="4.8" |
| 28 | CROSS=arm-linux-androideabi- |
| 29 | ;; |
| 30 | arm64) |
| 31 | [ -n "$APILEVEL" ] || APILEVEL="android-21" # first with arm64 |
| 32 | [ -n "$GCCVER" ] || GCCVER="4.9" |
| 33 | CROSS=aarch64-linux-android- |
| 34 | ;; |
| 35 | |
| 36 | *) |
| 37 | echo "ERROR! Building for Android on $1 is not currently supported." |
| 38 | exit 1 |
| 39 | ;; |
| 40 | esac |
| 41 | |
| 42 | TOOLCHAIN="$NDK/toolchains/$CROSS$GCCVER/prebuilt/$HOSTOS-$HOSTARCH" |
| 43 | PLATFORM="$NDK/platforms/$APILEVEL/arch-$TARGARCH" |
| 44 | |
| 45 | ${MAKE} clean |
| 46 | |
| 47 | CROSS="$TOOLCHAIN/bin/$CROSS" CFLAGS="--sysroot=$PLATFORM" LDFLAGS="--sysroot=$PLATFORM" ${MAKE} $* |
| 48 | } |
| 49 | |
Nguyen Anh Quynh | 50ebb68 | 2014-03-31 21:15:29 +0800 | [diff] [blame] | 50 | # build iOS lib for all iDevices, or only specific device |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 51 | build_iOS() { |
| 52 | ${MAKE} clean |
| 53 | IOS_SDK=`xcrun --sdk iphoneos --show-sdk-path` |
| 54 | IOS_CC=`xcrun --sdk iphoneos -f clang` |
| 55 | IOS_CFLAGS="-Os -Wimplicit -isysroot $IOS_SDK" |
| 56 | IOS_LDFLAGS="-isysroot $IOS_SDK" |
| 57 | if [ -z "$1" ]; then |
| 58 | # build for all iDevices |
| 59 | IOS_ARCHS="armv7 armv7s arm64" |
| 60 | else |
| 61 | IOS_ARCHS="$1" |
| 62 | fi |
| 63 | CC="$IOS_CC" \ |
| 64 | CFLAGS="$IOS_CFLAGS" \ |
| 65 | LDFLAGS="$IOS_LDFLAGS" \ |
| 66 | LIBARCHS="$IOS_ARCHS" \ |
| 67 | ${MAKE} |
Nguyen Anh Quynh | 50ebb68 | 2014-03-31 21:15:29 +0800 | [diff] [blame] | 68 | } |
| 69 | |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 70 | build() { |
| 71 | [ "$UNAME" = Darwin ] && LIBARCHS="i386 x86_64" |
| 72 | ${MAKE} clean |
Nguyen Anh Quynh | fc3b138 | 2015-06-22 12:51:21 +0800 | [diff] [blame] | 73 | ${MAKE} $* |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 74 | } |
| 75 | |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 76 | install() { |
| 77 | # Mac OSX needs to find the right directory for pkgconfig |
| 78 | if [ "$UNAME" = Darwin ]; then |
| 79 | # we are going to install into /usr/local, so remove old installs under /usr |
| 80 | rm -rf /usr/lib/libcapstone.* |
| 81 | rm -rf /usr/include/capstone |
| 82 | # install into /usr/local |
| 83 | PREFIX=/usr/local |
pancake | d1af4dd | 2015-03-02 10:55:55 +0100 | [diff] [blame] | 84 | if [ "${HOMEBREW_CAPSTONE}" != 1 ]; then |
| 85 | # find the directory automatically, so we can support both Macport & Brew |
| 86 | PKGCFGDIR="$(pkg-config --variable pc_path pkg-config | cut -d ':' -f 1)" |
| 87 | fi |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 88 | ${MAKE} install |
| 89 | else # not OSX |
| 90 | test -d /usr/lib64 && ${MAKE} LIBDIRARCH=lib64 |
| 91 | ${MAKE} install |
| 92 | fi |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 93 | } |
| 94 | |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 95 | uninstall() { |
| 96 | # Mac OSX needs to find the right directory for pkgconfig |
| 97 | if [ "$UNAME" = "Darwin" ]; then |
| 98 | # find the directory automatically, so we can support both Macport & Brew |
| 99 | PKGCFGDIR="$(pkg-config --variable pc_path pkg-config | cut -d ':' -f 1)" |
| 100 | PREFIX=/usr/local |
| 101 | ${MAKE} uninstall |
| 102 | else # not OSX |
| 103 | test -d /usr/lib64 && LIBDIRARCH=lib64 |
| 104 | ${MAKE} uninstall |
| 105 | fi |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 106 | } |
| 107 | |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 108 | if [ "$UNAME" = SunOS ]; then |
| 109 | [ -z "${MAKE}" ] && MAKE=gmake |
| 110 | INSTALL_BIN=ginstall |
| 111 | CC=gcc |
Nguyen Anh Quynh | d3b3071 | 2014-01-17 21:25:18 +0800 | [diff] [blame] | 112 | fi |
| 113 | |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 114 | if [ -n "`echo "$UNAME" | grep BSD`" ]; then |
| 115 | MAKE=gmake |
| 116 | PREFIX=/usr/local |
Nguyen Anh Quynh | f63db27 | 2014-01-17 22:12:35 +0800 | [diff] [blame] | 117 | fi |
| 118 | |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 119 | [ -z "${UNAME}" ] && UNAME=$(uname) |
| 120 | [ -z "${MAKE}" ] && MAKE=make |
| 121 | [ -n "${MAKE_JOBS}" ] && MAKE="$MAKE -j${MAKE_JOBS}" |
radare | 796f1d4 | 2015-03-07 11:40:19 +0100 | [diff] [blame] | 122 | export CC INSTALL_BIN PREFIX PKGCFGDIR LIBDIRARCH LIBARCHS CFLAGS LDFLAGS |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 123 | |
Nguyen Anh Quynh | fc3b138 | 2015-06-22 12:51:21 +0800 | [diff] [blame] | 124 | TARGET="$1" |
radare | 71fd42d | 2015-07-28 16:49:00 +0200 | [diff] [blame] | 125 | [ -n "$TARGET" ] && shift |
Nguyen Anh Quynh | fc3b138 | 2015-06-22 12:51:21 +0800 | [diff] [blame] | 126 | |
| 127 | case "$TARGET" in |
| 128 | "" ) build $*;; |
| 129 | "default" ) build $*;; |
| 130 | "debug" ) CAPSTONE_USE_SYS_DYN_MEM=yes CAPSTONE_STATIC=yes CFLAGS='-O0 -g -fsanitize=address' LDFLAGS='-fsanitize=address' build $*;; |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 131 | "install" ) install;; |
Nguyen Anh Quynh | af0e937 | 2014-04-12 23:10:46 +0800 | [diff] [blame] | 132 | "uninstall" ) uninstall;; |
Nguyen Anh Quynh | fc3b138 | 2015-06-22 12:51:21 +0800 | [diff] [blame] | 133 | "nix32" ) CFLAGS=-m32 LDFLAGS=-m32 build $*;; |
| 134 | "cross-win32" ) CROSS=i686-w64-mingw32- build $*;; |
| 135 | "cross-win64" ) CROSS=x86_64-w64-mingw32- build $*;; |
| 136 | "cygwin-mingw32" ) CROSS=i686-pc-mingw32- build $*;; |
| 137 | "cygwin-mingw64" ) CROSS=x86_64-w64-mingw32- build $*;; |
| 138 | "cross-android" ) build_android $*;; |
| 139 | "cross-android64" ) CROSS=aarch64-linux-gnu- build $*;; # Linux cross build |
| 140 | "clang" ) CC=clang build $*;; |
| 141 | "gcc" ) CC=gcc build $*;; |
| 142 | "ios" ) build_iOS $*;; |
| 143 | "ios_armv7" ) build_iOS armv7 $*;; |
| 144 | "ios_armv7s" ) build_iOS armv7s $*;; |
| 145 | "ios_arm64" ) build_iOS arm64 $*;; |
Pb | 2769c77 | 2015-11-06 14:44:55 +0100 | [diff] [blame] | 146 | "osx-kernel" ) CAPSTONE_USE_SYS_DYN_MEM=yes CAPSTONE_HAS_OSXKERNEL=yes CAPSTONE_ARCHS=x86 CAPSTONE_SHARED=no CAPSTONE_BUILD_CORE_ONLY=yes build $*;; |
pancake | 63414a4 | 2015-02-27 17:57:53 +0100 | [diff] [blame] | 147 | * ) |
| 148 | echo "Usage: $0 ["`grep '^ "' $0 | cut -d '"' -f 2 | tr "\\n" "|"`"]" |
| 149 | exit 1;; |
Nguyen Anh Quynh | 64d4083 | 2014-01-17 20:55:21 +0800 | [diff] [blame] | 150 | esac |