2011-11-22 14:12:29 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2018-12-30 12:38:50 +00:00
|
|
|
[ -z "${STATIC_BINS}" ] && STATIC_BINS=0
|
|
|
|
|
2021-08-23 11:38:52 +00:00
|
|
|
if [ "$1" = "--help" ]; then
|
|
|
|
echo "Usage: sys/static.sh [--help,--meson]"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "--meson" ]; then
|
2024-03-27 21:30:58 +00:00
|
|
|
[ "`uname`" != Darwin ] && export CFLAGS="-static" LDFLAGS="-static"
|
|
|
|
meson --prefix=${HOME}/.local --buildtype release --default-library static build
|
2021-08-23 11:38:52 +00:00
|
|
|
ninja -C build && ninja -C build install
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
2018-10-20 17:58:20 +00:00
|
|
|
case "$(uname)" in
|
|
|
|
Linux)
|
2018-03-11 22:35:40 +00:00
|
|
|
LDFLAGS="${LDFLAGS} -lpthread -ldl -lutil -lm"
|
Fix the CI badge and fully rewrite all the workflows to make sense ##build
* Windows, Linux, Static, macOS, Android, iOS builds published for every commit
* Kept coverage, coverity, fuzzing tests, lgtm and -Werror jobs
* Kill the continuos, the over-engineered matrix and other empty or unnecessary tasks (250 vs 900LOC)
* Jobs TODO: fatmac, termux and rpm (centos) packages
2021-01-12 12:41:21 +00:00
|
|
|
if [ "$NOLTO" != 1 ]; then
|
|
|
|
CFLAGS="${CFLAGS} -flto"
|
|
|
|
LDFLAGS="${LDFLAGS} -flto"
|
|
|
|
fi
|
2020-08-13 05:55:39 +00:00
|
|
|
if [ -n "`gcc -v 2>&1 | grep gcc`" ]; then
|
|
|
|
export AR=gcc-ar
|
|
|
|
fi
|
2021-08-23 11:38:52 +00:00
|
|
|
CFLAGS_STATIC=-static
|
2020-08-13 05:55:39 +00:00
|
|
|
;;
|
|
|
|
Darwin)
|
|
|
|
CFLAGS="${CFLAGS} -flto"
|
|
|
|
LDFLAGS="${LDFLAGS} -flto"
|
2021-08-23 11:38:52 +00:00
|
|
|
CFLAGS_STATIC=""
|
2018-10-20 17:58:20 +00:00
|
|
|
;;
|
2020-08-17 04:43:10 +00:00
|
|
|
DragonFly|OpenBSD)
|
2018-10-20 17:58:20 +00:00
|
|
|
LDFLAGS="${LDFLAGS} -lpthread -lkvm -lutil -lm"
|
2021-08-23 11:38:52 +00:00
|
|
|
CFLAGS_STATIC=-static
|
2018-10-20 17:58:20 +00:00
|
|
|
;;
|
|
|
|
esac
|
2011-11-22 14:12:29 +00:00
|
|
|
MAKE=make
|
|
|
|
gmake --help >/dev/null 2>&1
|
|
|
|
[ $? = 0 ] && MAKE=gmake
|
|
|
|
|
|
|
|
# find root
|
2015-06-17 02:39:19 +00:00
|
|
|
cd "$(dirname "$PWD/$0")" ; cd ..
|
2011-11-22 14:12:29 +00:00
|
|
|
|
2021-05-14 19:34:21 +00:00
|
|
|
musl-gcc --help > /dev/null 2>&1
|
|
|
|
if [ $? = 0 ]; then
|
|
|
|
CFGARGS=--with-compiler=musl-gcc
|
|
|
|
export CC="musl-gcc"
|
|
|
|
fi
|
|
|
|
|
2011-11-22 14:12:29 +00:00
|
|
|
ccache --help > /dev/null 2>&1
|
|
|
|
if [ $? = 0 ]; then
|
|
|
|
[ -z "${CC}" ] && CC=gcc
|
|
|
|
CC="ccache ${CC}"
|
|
|
|
export CC
|
|
|
|
fi
|
2015-01-24 02:30:07 +00:00
|
|
|
if [ -n "$1" ]; then
|
|
|
|
PREFIX="$1"
|
2018-02-19 12:17:21 +00:00
|
|
|
else
|
|
|
|
PREFIX=/usr
|
2015-01-24 02:30:07 +00:00
|
|
|
fi
|
2021-05-14 19:34:21 +00:00
|
|
|
# CFGARGS=--disable-loadlibs
|
2022-11-30 18:15:59 +00:00
|
|
|
# CFGARGS=--without-openssl
|
2018-02-19 12:17:21 +00:00
|
|
|
DOCFG=1
|
|
|
|
if [ 1 = "${DOCFG}" ]; then
|
2015-01-24 20:18:26 +00:00
|
|
|
# build
|
|
|
|
if [ -f config-user.mk ]; then
|
|
|
|
${MAKE} mrproper > /dev/null 2>&1
|
|
|
|
fi
|
2018-03-11 22:35:40 +00:00
|
|
|
export CFLAGS="${CFLAGS} -fPIC"
|
2022-11-02 09:57:15 +00:00
|
|
|
export CFGARGS="$CFGARGS --with-static-themes"
|
Fix the CI badge and fully rewrite all the workflows to make sense ##build
* Windows, Linux, Static, macOS, Android, iOS builds published for every commit
* Kept coverage, coverity, fuzzing tests, lgtm and -Werror jobs
* Kill the continuos, the over-engineered matrix and other empty or unnecessary tasks (250 vs 900LOC)
* Jobs TODO: fatmac, termux and rpm (centos) packages
2021-01-12 12:41:21 +00:00
|
|
|
cp -f dist/plugins-cfg/plugins.static.nogpl.cfg plugins.cfg
|
2015-11-01 18:31:07 +00:00
|
|
|
./configure-plugins || exit 1
|
2022-11-02 16:38:54 +00:00
|
|
|
./configure --prefix="$PREFIX" --without-gpl --with-libr $CFGARGS || exit 1
|
2011-11-22 14:12:29 +00:00
|
|
|
fi
|
2015-11-01 09:26:38 +00:00
|
|
|
${MAKE} -j 8 || exit 1
|
2021-12-16 23:15:38 +00:00
|
|
|
BINS="rarun2 r2pm rasm2 radare2 ragg2 rabin2 rax2 rahash2 rafind2 r2agent radiff2 r2r"
|
2015-06-17 02:39:19 +00:00
|
|
|
# shellcheck disable=SC2086
|
2021-08-23 11:38:52 +00:00
|
|
|
export CFLAGS="${CFLAGS_STATIC} ${CFLAGS}"
|
2015-04-09 21:36:18 +00:00
|
|
|
for a in ${BINS} ; do
|
|
|
|
(
|
2015-07-22 23:19:10 +00:00
|
|
|
cd binr/$a
|
|
|
|
${MAKE} clean
|
2018-11-16 15:53:50 +00:00
|
|
|
if [ "`uname`" = Darwin ]; then
|
|
|
|
${MAKE} -j4 || exit 1
|
|
|
|
else
|
2018-12-30 12:38:50 +00:00
|
|
|
if [ "${STATIC_BINS}" = 1 ]; then
|
2021-08-23 11:38:52 +00:00
|
|
|
CFLAGS=${CFLAGS_STATIC} LDFLAGS=${CFLAGS_STATIC} ${MAKE} -j4 || exit 1
|
2018-12-30 12:38:50 +00:00
|
|
|
else
|
|
|
|
${MAKE} -j4 || exit 1
|
|
|
|
fi
|
2018-11-16 15:53:50 +00:00
|
|
|
fi
|
2015-04-09 21:36:18 +00:00
|
|
|
)
|
|
|
|
done
|
|
|
|
|
|
|
|
rm -rf r2-static
|
2015-11-01 18:31:07 +00:00
|
|
|
mkdir r2-static || exit 1
|
2018-02-19 12:17:21 +00:00
|
|
|
${MAKE} install DESTDIR="${PWD}/r2-static" || exit 1
|
|
|
|
|
2018-10-15 22:28:51 +00:00
|
|
|
echo "Using PREFIX ${PREFIX}"
|
|
|
|
|
2018-02-19 12:17:21 +00:00
|
|
|
# testing installation
|
|
|
|
cat > .test.c <<EOF
|
|
|
|
#include <r_core.h>
|
|
|
|
int main() {
|
|
|
|
RCore *core = r_core_new ();
|
|
|
|
r_core_free (core);
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
cat .test.c
|
|
|
|
if [ -z "${CC}" ]; then
|
2020-08-13 05:55:39 +00:00
|
|
|
gcc -v > /dev/null 2>&1 && CC=gcc
|
2018-02-19 12:17:21 +00:00
|
|
|
fi
|
2020-07-24 09:55:53 +00:00
|
|
|
|
|
|
|
# static pkg-config linking test
|
|
|
|
echo "[*] Static building with pkg-config..."
|
|
|
|
PKG_CONFIG_FLAGS=`
|
|
|
|
PKG_CONFIG_PATH="${PWD}/r2-static/usr/lib/pkgconfig" \
|
|
|
|
pkg-config \
|
|
|
|
--define-variable="libdir=${PWD}/r2-static/usr/lib" \
|
|
|
|
--define-variable="prefix=${PWD}/r2-static/usr" \
|
|
|
|
--static --cflags --libs r_core
|
|
|
|
`
|
|
|
|
|
|
|
|
set -x
|
|
|
|
${CC} .test.c ${PKG_CONFIG_FLAGS} -o r2-pkgcfg-static
|
|
|
|
res=$?
|
|
|
|
set +x
|
|
|
|
if [ $res = 0 ]; then
|
|
|
|
echo SUCCESS
|
2021-02-14 01:28:55 +00:00
|
|
|
rm -f a.out
|
2020-07-24 09:55:53 +00:00
|
|
|
else
|
|
|
|
echo FAILURE
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "[*] Static building with libr.a..."
|
2018-02-19 12:17:21 +00:00
|
|
|
${CC} .test.c \
|
2018-03-13 02:38:38 +00:00
|
|
|
${CFLAGS} \
|
2020-07-24 09:55:53 +00:00
|
|
|
-I ${PWD}/r2-static/usr/include/libr \
|
|
|
|
-I ${PWD}/r2-static/usr/include/libr/sdb \
|
2018-03-03 21:28:21 +00:00
|
|
|
r2-static/usr/lib/libr.a ${LDFLAGS}
|
2018-02-19 12:17:21 +00:00
|
|
|
res=$?
|
2021-02-14 01:28:55 +00:00
|
|
|
du -hs r2-static/usr/bin/radare2
|
|
|
|
du -hs a.out
|
2020-07-24 09:55:53 +00:00
|
|
|
set +x
|
2018-03-02 00:06:50 +00:00
|
|
|
if [ $res = 0 ]; then
|
2018-02-19 12:17:21 +00:00
|
|
|
echo SUCCESS
|
2021-02-14 01:28:55 +00:00
|
|
|
rm -f a.out
|
2018-02-19 12:17:21 +00:00
|
|
|
else
|
|
|
|
echo FAILURE
|
|
|
|
fi
|
|
|
|
|
2021-02-14 01:28:55 +00:00
|
|
|
rm -f .test.c
|
2018-02-19 12:17:21 +00:00
|
|
|
exit $res
|