1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
#!/bin/sh
# find
cd "$(dirname $0)"/..
CWD="`pwd`"
sudosetup() {
export NOSUDO
if [ -w "${PREFIX}" ]; then
NOSUDO=1
fi
if [ -n "${NOSUDO}" ]; then
SUDO=""
else
type sudo > /dev/null 2>&1 || NOSUDO=1
SUDO=sudo
[ -n "${NOSUDO}" ] && SUDO=
fi
if [ "${NOSUDO}" != 1 ]; then
if [ "$(id -u)" = 0 ]; then
SUDO=""
else
if [ -d /system/bin ]; then
# This is an android
SUDO=""
else
[ -n "${NOSUDO}" ] && SUDO="echo NOTE: sudo not found. Please run as root: "
fi
fi
if [ "${USE_SU}" = 1 ]; then
SUDO="/bin/su -m root -c"
fi
fi
}
# if owner of sys/install.sh != uid && uid == 0 { exec sudo -u id -A $SUDO_UID sys/install.sh $* }
ARGS=""
while : ; do
[ -z "$1" ] && break
case "$1" in
--help)
./configure --help
echo
echo "NOTE: Use sys/install.sh --install to use 'cp' instead of 'ln'."
echo
exit 0
;;
"--with-capstone4")
export USE_CS5=1
;;
"--install")
export INSTALL_TARGET="install"
;;
"--without-pull")
export WITHOUT_PULL=1
;;
'--prefix='*)
PREFIX=`echo "$1" | cut -d = -f 2`
ARGS="${ARGS} $1"
;;
-*)
# just for the penguin face case
ARGS="${ARGS} $1"
;;
*)
ARGS="${ARGS} $1"
PREFIX="$1"
;;
esac
shift
done
sudosetup
echo "$CWD" | grep -q ' '
if [ $? = 0 ]; then
USEMESON=1
fi
if [ "$USEMESON" = 1 ]; then
rm -rf b
meson b
ninja -C b
${SUDO} make symstall PWD="$PWD/b" BTOP="$PWD/b/binr"
exit $RV
fi
export PAGER=cat
unset LINK
if command -v termux-setup-storage; then
echo "Termux environment detected. Installing necessary packages"
pkg update -y && pkg install git build-essential binutils pkg-config -y
${PWD}/sys/termux.sh
exit $?
fi
if [ "$(uname)" = "Haiku" ]; then
gcc-x86 --version > /dev/null 2>&1
if [ $? = 0 ]; then
export CC=gcc-x86
export HOST_CC=gcc-x86
export USERCC=gcc-x86
else
echo "If compilation fails, install gcc-x86 from depot"
fi
export PREFIX="${PWD}/prefix"
else
if [ "$(id -u)" = 0 ]; then
echo "[WW] Do not run this script as root!"
if [ -n "${SUDO_USER}" ]; then
echo "[--] Downgrading credentials to ${SUDO_USER}"
exec sudo -u "${SUDO_USER}" sys/install.sh $*
fi
fi
fi
echo "$PWD" | grep -q " "
if [ $? = 0 ]; then
echo "You can't build radare from a directory with spaces with make" >&2
echo "To solve this you must 'meson' instead" >&2
exit 1
fi
export WANT_V35=0
export USE_CS4=0
export USE_CSNEXT=0
if [ -z "${MAKE}" ]; then
MAKE=make
gmake --help >/dev/null 2>&1
[ $? = 0 ] && MAKE=gmake
${MAKE} --help 2>&1 | grep -q gnu
if [ $? != 0 ]; then
echo "You need GNU Make to build me"
exit 1
fi
export MAKE="$MAKE"
fi
[ -z "${INSTALL_TARGET}" ] && INSTALL_TARGET=symstall
# update
if [ -z "$WITHOUT_PULL" ]; then
# if .git is a directory, that's a clone, if it's a file it's a submodule
if [ -e .git ]; then
git branch | grep "^\* master" > /dev/null
if [ $? = 0 ]; then
echo "WARNING: Updating from remote repository"
# Attempt to update from an existing remote
UPSTREAM_REMOTE=$(git remote -v | grep 'radareorg/radare2\(\.git\)\? (fetch)' | cut -f1 | head -n1)
if [ -n "$UPSTREAM_REMOTE" ]; then
git pull "$UPSTREAM_REMOTE" master
else
git pull https://github.com/radareorg/radare2 master
fi
fi
fi
fi
umask 0002
${SHELL} --version 2> /dev/null | grep -q fish
if [ $? = 0 ]; then
SHELL=/bin/sh
else
# TCSH
${SHELL} --help 2>&1 | grep -q vfork
if [ $? = 0 ]; then
SHELL=/bin/sh
echo IS ASH
fi
fi
# handle home installations of capstone via r2pm
export PKG_CONFIG_PATH="${HOME}/.local/share/radare2/prefix/lib/pkgconfig/"
if [ -d "$HOME/.local/share/radare2/prefix/include/capstone" ]; then
# capstone's pkg-config is wrong :_____
# export CFLAGS="$(pkg-config --cflags capstone)"
# export LDFLAGS="$(pkg-config --libs capstone)"
export CFLAGS="-I$HOME/.local/share/radare2/prefix/include"
export LDFLAGS="-L$HOME/.local/share/radare2/prefix/lib"
fi
NEED_CAPSTONE=1
pkg-config --cflags capstone > /dev/null 2>&1
if [ $? = 0 ]; then
pkg-config --atleast-version=5.0.0 capstone >/dev/null 2>&1
if [ $? = 0 ]; then
pkg-config --variable=archs capstone 2> /dev/null | grep -q riscv
if [ $? = 0 ]; then
export CFGARG="--with-syscapstone"
NEED_CAPSTONE=0
echo "Note: Using system-wide-capstone"
else
echo "Warning: Your system-wide capstone dont have enough archs"
fi
else
echo "Warning: Your system-wide capstone is too old for me"
fi
else
echo "Warning: Cannot find system wide capstone"
fi
echo "ARGS=$ARGS"
if [ "${M32}" = 1 ]; then
${SHELL} ./sys/build-m32.sh ${ARGS} || exit 1
elif [ "${HARDEN}" = 1 ]; then
# shellcheck disable=SC2048
# shellcheck disable=SC2086
${SHELL} ./sys/build-harden.sh ${ARGS} || exit 1
else
# shellcheck disable=SC2048
# shellcheck disable=SC2086
echo ${SHELL} ./sys/build.sh ${ARGS}
pwd
${SHELL} ./sys/build.sh ${ARGS} || exit 1
fi
${SUDO} ${MAKE} ${INSTALL_TARGET} || exit 1
if [ -z "${NOSUDO}" ]; then
${SHELL} ./sys/ldconfig.sh
fi
|