blob: 4a8cdf1058fdf476af2fca8b3d092be65e1d0473 [file] [log] [blame]
Nguyen Anh Quynhc3fd5272014-03-31 16:05:25 +08001#!/usr/bin/env bash
Nguyen Anh Quynh64d40832014-01-17 20:55:21 +08002
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 Quynh50ebb682014-03-31 21:15:29 +08008
9# build iOS lib for all iDevices, or only specific device
10function 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 Quynh64d40832014-01-17 20:55:21 +080024function build {
Nguyen Anh Quynhaf873932014-01-28 11:14:55 +080025 ${MAKE} clean
Nguyen Anh Quynh64d40832014-01-17 20:55:21 +080026
27 if [ ${CC}x != x ]; then
28 ${MAKE} CC=$CC
29 else
30 ${MAKE}
31 fi
32}
33
34function install {
Nguyen Anh Quynhaf0e9372014-04-12 23:10:46 +080035 # 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)"
39 if [ ${PKGCFGDIR}x != x ]; then
40 if [ ${CC}x != x ]; then
41 ${MAKE} CC=$CC PKGCFGDIR=$PKGCFGDIR install
42 else
43 ${MAKE} PKGCFGDIR=$PKGCFGDIR install
44 fi
45 else
46 if [ ${CC}x != x ]; then
47 ${MAKE} CC=$CC install
48 else
49 ${MAKE} install
50 fi
51 fi
Nguyen Anh Quynh64d40832014-01-17 20:55:21 +080052 else
Nguyen Anh Quynhaf0e9372014-04-12 23:10:46 +080053 if [ ${CC}x != x ]; then
54 ${MAKE} CC=$CC install
55 else
56 ${MAKE} install
57 fi
58 fi
59}
60
61function uninstall {
62 # Mac OSX needs to find the right directory for pkgconfig
63 if [ "$(uname)" == "Darwin" ]; then
64 # find the directory automatically, so we can support both Macport & Brew
65 PKGCFGDIR="$(pkg-config --variable pc_path pkg-config | cut -d ':' -f 1)"
66 if [ ${PKGCFGDIR}x != x ]; then
67 ${MAKE} PKGCFGDIR=$PKGCFGDIR uninstall
68 else
69 ${MAKE} uninstall
70 fi
71 else
72 ${MAKE} uninstall
Nguyen Anh Quynh64d40832014-01-17 20:55:21 +080073 fi
74}
75
Nguyen Anh Quynhaf873932014-01-28 11:14:55 +080076MAKE=make
Nguyen Anh Quynhd3b30712014-01-17 21:25:18 +080077if [ "$(uname)" == "SunOS" ]; then
Nguyen Anh Quynhaf0e9372014-04-12 23:10:46 +080078 export MAKE=gmake
79 export INSTALL_BIN=ginstall
80 export CC=gcc
Nguyen Anh Quynhd3b30712014-01-17 21:25:18 +080081fi
82
Nguyen Anh Quynhf63db272014-01-17 22:12:35 +080083if [[ "$(uname)" == *BSD* ]]; then
Nguyen Anh Quynhaf0e9372014-04-12 23:10:46 +080084 export MAKE=gmake
85 export PREFIX=/usr/local
Nguyen Anh Quynhf63db272014-01-17 22:12:35 +080086fi
87
Nguyen Anh Quynh64d40832014-01-17 20:55:21 +080088case "$1" in
89 "" ) build;;
90 "default" ) build;;
91 "install" ) install;;
Nguyen Anh Quynhaf0e9372014-04-12 23:10:46 +080092 "uninstall" ) uninstall;;
Nguyen Anh Quynh64d40832014-01-17 20:55:21 +080093 "nix32" ) CFLAGS=-m32 LDFLAGS=-m32 build;;
Nguyen Anh Quynh64d40832014-01-17 20:55:21 +080094 "cross-win32" ) CROSS=i686-w64-mingw32- build;;
95 "cross-win64" ) CROSS=x86_64-w64-mingw32- build;;
96 "cygwin-mingw32" ) CROSS=i686-pc-mingw32- build;;
97 "cygwin-mingw64" ) CROSS=x86_64-w64-mingw32- build;;
Nguyen Anh Quynhf08ed972014-04-07 22:13:56 +080098 "cross-android" ) CROSS=arm-linux-androideabi- build;;
Nguyen Anh Quynh64d40832014-01-17 20:55:21 +080099 "clang" ) CC=clang build;;
100 "gcc" ) CC=gcc build;;
Nguyen Anh Quynh50ebb682014-03-31 21:15:29 +0800101 "ios" ) build_iOS;;
102 "ios_armv7" ) build_iOS armv7;;
103 "ios_armv7s" ) build_iOS armv7s;;
104 "ios_arm64" ) build_iOS arm64;;
Nguyen Anh Quynhf08ed972014-04-07 22:13:56 +0800105 * ) 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 Quynh64d40832014-01-17 20:55:21 +0800106esac