Debian Codegraph @

make.sh

raw symbols SCIP
1 #!/bin/sh
2
3 # Capstone Disassembly Engine
4 # By Nguyen Anh Quynh <[email protected]>, 2013-2019
5
6 # Note: to cross-compile "nix32" on Linux, package gcc-multilib is required.
7
8 MAKE_JOBS=${MAKE_JOBS:-4}
9
10 # build Android lib for only one supported architecture
11 build_android() {
12 if [ -z "$NDK" ]; then
13 echo "ERROR! Please set \$NDK to point at your Android NDK directory."
14 exit 1
15 fi
16
17 HOSTOS=$(uname -s | tr 'LD' 'ld')
18 HOSTARCH=$(uname -m)
19
20 TARGARCH="$1"
21 shift
22
23 case "$TARGARCH" in
24 arm)
25 [ -n "$APILEVEL" ] || APILEVEL="android-14" # default to ICS
26 CROSS=arm-linux-androideabi
27 ;;
28 arm64)
29 [ -n "$APILEVEL" ] || APILEVEL="android-21" # first with arm64
30 CROSS=aarch64-linux-android
31 ;;
32
33 *)
34 echo "ERROR! Building for Android on $1 is not currently supported."
35 exit 1
36 ;;
37 esac
38
39 STANDALONE=`realpath android-ndk-${TARGARCH}-${APILEVEL}`
40
41 [ -d $STANDALONE ] || {
42 python ${NDK}/build/tools/make_standalone_toolchain.py \
43 --arch ${TARGARCH} \
44 --api ${APILEVEL##*-} \
45 --install-dir ${STANDALONE}
46 }
47
48 ANDROID=1 CROSS="${STANDALONE}/${CROSS}/bin" CFLAGS="--sysroot=${STANDALONE}/sysroot" ${MAKE} $*
49 }
50
51 # build iOS lib for all iDevices, or only specific device
52 build_iOS() {
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 export CC="$IOS_CC"
64 export LIBARCHS="$IOS_ARCHS"
65 CFLAGS="$IOS_CFLAGS" LDFLAGS="$IOS_LDFLAGS" MACOS_UNIVERSAL=yes ${MAKE}
66 }
67
68 install() {
69 # Mac OSX needs to find the right directory for pkgconfig
70 if [ "$UNAME" = Darwin ]; then
71 # we are going to install into /usr/local, so remove old installs under /usr
72 rm -rf /usr/lib/libcapstone.*
73 rm -rf /usr/include/capstone
74 if [ "${HOMEBREW_CAPSTONE}" != 1 ]; then
75 # find the directory automatically, so we can support both Macport & Brew
76 export PKGCFGDIR="$(pkg-config --variable pc_path pkg-config | cut -d ':' -f 1)"
77 fi
78 ${MAKE} install
79 else # not OSX
80 test -d /usr/lib64 && ${MAKE} LIBDIRARCH=lib64
81 ${MAKE} install
82 fi
83 }
84
85 uninstall() {
86 # Mac OSX needs to find the right directory for pkgconfig
87 if [ "$UNAME" = "Darwin" ]; then
88 # find the directory automatically, so we can support both Macport & Brew
89 export PKGCFGDIR="$(pkg-config --variable pc_path pkg-config | cut -d ':' -f 1)"
90 ${MAKE} uninstall
91 else # not OSX
92 test -d /usr/lib64 && LIBDIRARCH=lib64
93 ${MAKE} uninstall
94 fi
95 }
96
97 UNAME="${UNAME:-$(uname)}"
98
99 if [ "$UNAME" = SunOS ]; then
100 MAKE="${MAKE:-gmake}"
101 export INSTALL_BIN=ginstall
102 export CC=gcc
103 fi
104
105 MAKE="${MAKE:-make}"
106
107 if echo "$UNAME" | grep -q BSD; then
108 MAKE=gmake
109 export PREFIX=/usr/local
110 fi
111
112 MAKE="$MAKE -j${MAKE_JOBS}"
113
114 TARGET="$1"
115 [ $# -gt 0 ] && shift
116
117 case "$TARGET" in
118 "" | "default" ) ${MAKE} "$@";;
119 "debug" ) \
120 CAPSTONE_USE_SYS_DYN_MEM=yes \
121 CAPSTONE_STATIC=yes \
122 CFLAGS='-DCAPSTONE_DEBUG -O0 -g -fsanitize=address' \
123 LDFLAGS='-fsanitize=address' \
124 ${MAKE} "$@";;
125 "install" ) install;;
126 "uninstall" ) uninstall;;
127 "nix32" ) CFLAGS=-m32 LDFLAGS=-m32 ${MAKE} "$@";;
128 "cross-win32" ) CROSS=i686-w64-mingw32- ${MAKE} "$@";;
129 "cross-win64" ) CROSS=x86_64-w64-mingw32- ${MAKE} "$@";;
130 "cygwin-mingw32" ) CROSS=i686-pc-mingw32- ${MAKE} "$@";;
131 "cygwin-mingw64" ) CROSS=x86_64-w64-mingw32- ${MAKE} "$@";;
132 "cross-android" ) build_android "$@";;
133 "cross-android64" ) CROSS=aarch64-linux-gnu- ${MAKE} "$@";; # Linux cross build
134 "clang" ) CC=clang ${MAKE} "$@";;
135 "gcc" ) CC=gcc ${MAKE} "$@";;
136 "ios" ) build_iOS "$@";;
137 "ios_armv7" ) build_iOS armv7 "$@";;
138 "ios_armv7s" ) build_iOS armv7s "$@";;
139 "ios_arm64" ) build_iOS arm64 "$@";;
140 "osx-kernel" ) CAPSTONE_USE_SYS_DYN_MEM=yes \
141 CAPSTONE_HAS_OSXKERNEL=yes \
142 CAPSTONE_ARCHS=x86 \
143 CAPSTONE_SHARED=no \
144 CAPSTONE_BUILD_CORE_ONLY=yes \
145 ${MAKE} "$@";;
146 "mac-universal" ) MACOS_UNIVERSAL=yes ${MAKE} "$@";;
147 "mac-universal-no" ) MACOS_UNIVERSAL=no ${MAKE} "$@";;
148 "xlc31" ) CC=xlc CFLAGS=-q31 LDFLAGS=-q31 ${MAKE} "$@";;
149 "xlc32" ) CC=xlc CFLAGS=-q32 LDFLAGS=-q32 ${MAKE} "$@";;
150 "xlc64" ) CC=xlc CFLAGS=-q64 LDFLAGS=-q64 ${MAKE} "$@";;
151 * )
152 echo "Usage: $0 ["$(grep '^ "' $0 | cut -d '"' -f 2 | tr "\\n" "|")"]"
153 exit 1;;
154 esac