From 3fcaa5f40c0113bbe50ed0c2a480ace545bc8264 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Fri, 23 Sep 2022 00:10:07 +0200 Subject: [PATCH] Added build scripts for FreeBSD, Solaris and MacOS X platforms. --- etc/utils/freebsd/mk-release.sh | 21 +++++++++++++++++++ etc/utils/linux/{mk-musl.sh => mk-musl-libc.sh} | 0 etc/utils/macosx/hdiutil.txt | 1 + etc/utils/macosx/mk-release.sh | 21 +++++++++++++++++++ etc/utils/solaris/mk-release.sh | 21 +++++++++++++++++++ libslunkcrypt/src/junk.c | 27 ++++++++++++++++--------- mk-release.sh | 2 +- 7 files changed, 82 insertions(+), 11 deletions(-) create mode 100755 etc/utils/freebsd/mk-release.sh rename etc/utils/linux/{mk-musl.sh => mk-musl-libc.sh} (100%) create mode 100644 etc/utils/macosx/hdiutil.txt create mode 100755 etc/utils/macosx/mk-release.sh create mode 100755 etc/utils/solaris/mk-release.sh diff --git a/etc/utils/freebsd/mk-release.sh b/etc/utils/freebsd/mk-release.sh new file mode 100755 index 0000000..acf4f60 --- /dev/null +++ b/etc/utils/freebsd/mk-release.sh @@ -0,0 +1,21 @@ +#!/bin/sh +set -e +cd -- "$(dirname -- "${0}")/../../.." + +if [ -z "${cc_path}" ]; then + cc_path="/usr/local/bin/gcc12" +fi + +mk_slunk() { + gmake -B CC="${cc_path}" CPU=${1} MARCH=${3} MTUNE=${4} STATIC=1 STRIP=1 + cp -vf "frontend/bin/slunkcrypt" "out/slunkcrypt-${2}" +} + +rm -rf "out" && mkdir -p "out" + +gmake CC="${cc_path}" clean + +mk_slunk 32 "i686" "pentiumpro" "pentium3" +mk_slunk 64 "x86_64" "x86-64" "nocona" + +echo "Build completed successfully." diff --git a/etc/utils/linux/mk-musl.sh b/etc/utils/linux/mk-musl-libc.sh similarity index 100% rename from etc/utils/linux/mk-musl.sh rename to etc/utils/linux/mk-musl-libc.sh diff --git a/etc/utils/macosx/hdiutil.txt b/etc/utils/macosx/hdiutil.txt new file mode 100644 index 0000000..70d1d31 --- /dev/null +++ b/etc/utils/macosx/hdiutil.txt @@ -0,0 +1 @@ +sudo hdiutil create archive.dmg -ov -volname "CRC-64" -fs HFS+ -srcfolder out diff --git a/etc/utils/macosx/mk-release.sh b/etc/utils/macosx/mk-release.sh new file mode 100755 index 0000000..c5a9be6 --- /dev/null +++ b/etc/utils/macosx/mk-release.sh @@ -0,0 +1,21 @@ +#!/bin/zsh +set -e +cd -- "$(dirname -- "${(%):-%N}")/../../.." + +if [ -z "${cc_path}" ]; then + cc_path="/usr/bin/cc" +fi + +mk_slunk() { + make -B CC="${cc_path}" TARGET="${1}-apple-macos" FLTO=1 + strip -o "out/slunkcrypt-${1}" "frontend/bin/slunkcrypt" +} + +rm -rf "out" && mkdir -p "out" + +make CC="${cc_path}" clean + +mk_slunk "x86_64" +mk_slunk "arm64" + +echo "Build completed successfully." diff --git a/etc/utils/solaris/mk-release.sh b/etc/utils/solaris/mk-release.sh new file mode 100755 index 0000000..f772460 --- /dev/null +++ b/etc/utils/solaris/mk-release.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -e +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../../.." + +if [ -z "${cc_path}" ]; then + cc_path="/usr/gcc/11/bin/gcc" +fi + +mk_slunk() { + gmake -B CC="${cc_path}" CPU=${1} MARCH=${3} MTUNE=${4} FLTO=1 STRIP=1 + cp -f "frontend/bin/slunkcrypt" "out/slunkcrypt-${2}" +} + +rm -rf "out" && mkdir -p "out" + +gmake CC="${cc_path}" clean + +mk_slunk 32 "i686" "pentiumpro" "pentium3" +mk_slunk 64 "x86_64" "x86-64" "nocona" + +echo "Build completed successfully." diff --git a/libslunkcrypt/src/junk.c b/libslunkcrypt/src/junk.c index c33bec1..24b4822 100644 --- a/libslunkcrypt/src/junk.c +++ b/libslunkcrypt/src/junk.c @@ -32,6 +32,11 @@ static INLINE size_t MIN_SIZE(const size_t a, const size_t b) { return (a > b) ? #else # include # include +# include +#endif + +#if defined(__APPLE__) && defined(__MACH__) +# include #endif /* detect compiler destructor support */ @@ -45,7 +50,7 @@ static INLINE size_t MIN_SIZE(const size_t a, const size_t b) { return (a > b) ? #undef HAVE_WIN32RTLGENRANDOM #if defined(_WIN32) # define HAVE_WIN32RTLGENRANDOM 1 -#elif (defined(__linux__) && !defined(__UCLIBC__)) || (defined(__FreeBSD__) && (__FreeBSD__ >= 12)) || defined(__DragonFly__) || defined(__OpenBSD__) || (defined(__sun) && defined(__SVR4)) +#elif (defined(__linux__) && !defined(__UCLIBC__)) || (defined(__FreeBSD__) && (__FreeBSD__ >= 12)) || defined(__DragonFly__) || defined(__OpenBSD__) || (defined(__sun) && defined(__SVR4)) || (defined(__APPLE__) && defined(__MACH__)) # define HAVE_GETENTROPY 1 #else # pragma message("Function getentropy() is *not* available -> using fallback!") @@ -63,9 +68,9 @@ static INLINE size_t MIN_SIZE(const size_t a, const size_t b) { return (a > b) ? /* detect sched_yield() or Sleep() support */ #ifdef _WIN32 -# define SCHED_YIELD() Sleep(0) +# define THREAD_YIELD() Sleep(0) #else -# define SCHED_YIELD() sched_yield() +# define THREAD_YIELD() sched_yield() #endif // ========================================================================== @@ -74,27 +79,29 @@ static INLINE size_t MIN_SIZE(const size_t a, const size_t b) { return (a > b) ? /* atomic memory access */ #if defined(_MSC_VER) && (!defined(__GNUC__)) +# define ONCE_FLAG_T LONG # define ATOMIC_COMPARE_EXCHANGE(X,Y,Z) InterlockedCompareExchange((X),(Y),(Z)) # define ATOMIC_EXCHANGE(X,Y) InterlockedExchange((X),(Y)) #else +# define ONCE_FLAG_T int # define ATOMIC_COMPARE_EXCHANGE(X,Y,Z) __sync_val_compare_and_swap((X),(Z),(Y)) # define ATOMIC_EXCHANGE(X,Y) __sync_lock_test_and_set((X),(Y)) #endif -/* execute initialization function once */ -static INLINE void initialize_once(volatile long *const once_flag, void (*const init_routine)(void)) +/* execute init routine once */ +static INLINE void initialize_once(volatile ONCE_FLAG_T *const once_control, void (*const init_routine)(void)) { - long state; - while ((state = ATOMIC_COMPARE_EXCHANGE(once_flag, -1, 0)) != 0) + ONCE_FLAG_T state; + while ((state = ATOMIC_COMPARE_EXCHANGE(once_control, -1, 0)) != 0) { if (state > 0) { return; /*already initialized*/ } - SCHED_YIELD(); + THREAD_YIELD(); } init_routine(); - ATOMIC_EXCHANGE(once_flag, 1); + ATOMIC_EXCHANGE(once_control, 1); } // ========================================================================== @@ -104,7 +111,7 @@ static INLINE void initialize_once(volatile long *const once_flag, void (*const #define MAX_COUNT 1048576U /* Global state */ -static volatile long s_random_is_initialized = 0L; +static volatile ONCE_FLAG_T s_random_is_initialized = 0; #if defined(_WIN32) typedef BOOLEAN(WINAPI *ptr_genrandom_t)(void *buffer, ULONG length); static HMODULE s_advapi32 = NULL; diff --git a/mk-release.sh b/mk-release.sh index f77b570..17a3249 100755 --- a/mk-release.sh +++ b/mk-release.sh @@ -19,7 +19,7 @@ rm -rf "out" && mkdir -p "out" $BASH -x -c "make clean" mk_slunk "x86_64" "MARCH=x86-64 MTUNE=nocona" -mk_slunk "i686" "MARCH=pentiumpro MTUNE=pentium3" +mk_slunk "i686" "MARCH=pentiumpro MTUNE=pentium3" mk_slunk "armel" mk_slunk "armhf" mk_slunk "arm64" -- 2.11.4.GIT