1#!/bin/sh
2
3MAKE=make
4gmake --help >/dev/null 2>&1
5[ $? = 0 ] && MAKE=gmake
6
7${MAKE} --help 2>&1 | grep -q gnu
8if [ $? != 0 ]; then
9	echo "You need GNU Make to build me"
10	exit 1
11fi
12
13# find root
14cd "$(dirname "$0")" ; cd ..
15
16export WITHOUT_PULL=0
17ROOT=
18
19while [ $# -gt 0 ]
20do
21	case "$1" in
22		"--without-pull")
23			WITHOUT_PULL=1
24			;;
25		"--install-path")
26			shift
27			if [ -n "$1" ]; then
28				ROOT="$1"
29				BINDIR="$1/bin"
30			else
31				echo "ERROR: install-path must not be empty"
32				exit 1
33			fi
34			;;
35		*)
36			echo "WARNING: unknown argument \"$1\""
37	esac
38	shift
39done
40
41# update
42if [ $WITHOUT_PULL -eq 0 ]; then
43	if [ -d .git ]; then
44		git branch | grep "^\* master" > /dev/null
45		if [ $? = 0 ]; then
46			echo "WARNING: Updating from remote repository"
47			git pull
48		fi
49	fi
50fi
51
52if [ -z "${ROOT}" ]; then
53	if [ -z "${HOME}" ]; then
54		echo "HOME not set"
55		exit 1
56	fi
57
58	if [ ! -d "${HOME}" ]; then
59		echo "HOME is not a directory"
60		exit 1
61	fi
62	ROOT="${HOME}/bin/prefix/radare2"
63	BINDIR="${HOME}/bin"
64fi
65
66mkdir -p "${ROOT}/lib"
67
68if [ "${M32}" = 1 ]; then
69	./sys/build-m32.sh "${ROOT}" && ${MAKE} symstall
70elif [ "${HARDEN}" = 1 ]; then
71	./sys/build-harden.sh "${ROOT}" && ${MAKE} symstall
72else
73	./sys/build.sh "${ROOT}" && ${MAKE} symstall
74fi
75if [ $? != 0 ]; then
76	echo "Oops"
77	exit 1
78fi
79${MAKE} user-install
80echo
81echo "radare2 is now installed in ${BINDIR}"
82echo
83echo "Now add ${BINDIR} to your PATH"
84echo
85