From 25c1472a95390a6203d4a8a3f4482c4d9f1a8e9d Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 23 Aug 2021 13:38:52 +0200 Subject: [PATCH] Fix sys/static.sh on iOS/macOS targets ##build --- libr/util/sys.c | 13 ++++--------- sys/static.sh | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/libr/util/sys.c b/libr/util/sys.c index d9f4d736e3..acf31e536f 100644 --- a/libr/util/sys.c +++ b/libr/util/sys.c @@ -537,21 +537,16 @@ R_API bool r_sys_getenv_asbool(const char *key) { return res; } -#if __vinix__ -#define USE_GLIBC 0 -#else -#define USE_GLIBC 1 -#endif - R_API char *r_sys_getdir(void) { #if __WINDOWS__ return _getcwd (NULL, 0); #else -#if USE_GLIBC +#ifdef __GLIBC__ return getcwd (NULL, 0); #else - char *res = calloc (1024, 1); - char *cwd = getcwd (res, 1024); + const size_t maxpathlen = 4096; + char *res = calloc (maxpathlen, 1); + char *cwd = getcwd (res, maxpathlen); if (!cwd) { free (res); } diff --git a/sys/static.sh b/sys/static.sh index 2d6369c439..3e7e67b43e 100755 --- a/sys/static.sh +++ b/sys/static.sh @@ -2,6 +2,17 @@ [ -z "${STATIC_BINS}" ] && STATIC_BINS=0 +if [ "$1" = "--help" ]; then + echo "Usage: sys/static.sh [--help,--meson]" + exit 0 +fi + +if [ "$1" = "--meson" ]; then + CFLAGS="-static" LDFLAGS="-static" meson --prefix=${HOME}/.local --buildtype release --default-library static build + ninja -C build && ninja -C build install + exit $? +fi + case "$(uname)" in Linux) LDFLAGS="${LDFLAGS} -lpthread -ldl -lutil -lm" @@ -12,13 +23,16 @@ Linux) if [ -n "`gcc -v 2>&1 | grep gcc`" ]; then export AR=gcc-ar fi + CFLAGS_STATIC=-static ;; Darwin) CFLAGS="${CFLAGS} -flto" LDFLAGS="${LDFLAGS} -flto" + CFLAGS_STATIC="" ;; DragonFly|OpenBSD) LDFLAGS="${LDFLAGS} -lpthread -lkvm -lutil -lm" + CFLAGS_STATIC=-static ;; esac MAKE=make @@ -61,7 +75,7 @@ fi ${MAKE} -j 8 || exit 1 BINS="rarun2 rasm2 radare2 ragg2 rabin2 rax2 rahash2 rafind2 r2agent radiff2 r2r" # shellcheck disable=SC2086 -export CFLAGS="-static ${CFLAGS}" +export CFLAGS="${CFLAGS_STATIC} ${CFLAGS}" for a in ${BINS} ; do ( cd binr/$a @@ -70,7 +84,7 @@ for a in ${BINS} ; do ${MAKE} -j4 || exit 1 else if [ "${STATIC_BINS}" = 1 ]; then - CFLAGS=-static LDFLAGS=-static ${MAKE} -j4 || exit 1 + CFLAGS=${CFLAGS_STATIC} LDFLAGS=${CFLAGS_STATIC} ${MAKE} -j4 || exit 1 else ${MAKE} -j4 || exit 1 fi