From c6ecc3c813b615348ad6220288e551e53935534d Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Tue, 6 Dec 2022 01:58:51 +0100 Subject: [PATCH] Added build helper script for MacOS X. --- config.mk | 24 +++++++++++++++++++----- etc/utils/build-linux.sh | 8 ++++---- etc/utils/build-macos.sh | 19 +++++++++++++++++++ 3 files changed, 42 insertions(+), 9 deletions(-) create mode 100755 etc/utils/build-macos.sh diff --git a/config.mk b/config.mk index 6ba0250..4f03a5d 100644 --- a/config.mk +++ b/config.mk @@ -1,3 +1,8 @@ +UNAME := $(strip $(shell uname)) +ifeq ($(UNAME),) + $(error Operating system could not be detected!) +endif + DUMPMACHINE := $(strip $(shell $(CC) -dumpmachine)) ifeq ($(DUMPMACHINE),) $(error C compiler could not be detected!) @@ -20,16 +25,21 @@ else ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),) XCFLAGS += -march=pentiumpro -mtune=intel endif -ifeq ($(firstword $(filter %-mingw32 %-windows-gnu %-cygwin,$(DUMPMACHINE))),) - DLL_LDFLAGS = -shared - DLL_SUFFIX := .so -else +ifneq ($(firstword $(filter %-mingw32 %-windows-gnu %-cygwin,$(DUMPMACHINE))),) DLL_LDFLAGS = -shared -Wl,--out-implib,$@.a EXE_SUFFIX := .exe DLL_SUFFIX := .dll ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),) XLDFLAGS += -Wl,--large-address-aware endif +else +ifneq ($(findstring -apple-darwin,$(DUMPMACHINE)),) + DLL_LDFLAGS = -dynamiclib + DLL_SUFFIX := .dylib +else + DLL_LDFLAGS = -shared + DLL_SUFFIX := .so +endif endif ifneq ($(STATIC),) @@ -45,8 +55,12 @@ ifneq ($(STRIP),) DLL_LDFLAGS += -Wl,--strip-all endif -ifneq ($(firstword $(filter MINGW32_NT-% MINGW64_NT-% CYGWIN_NT-%,$(shell uname))),) +ifneq ($(firstword $(filter MINGW32_NT-% MINGW64_NT-% CYGWIN_NT-%,$(UNAME))),) ENV_LDPATH := PATH else +ifneq ($(firstword $(UNAME)),Darwin) ENV_LDPATH := LD_LIBRARY_PATH +else + ENV_LDPATH := DYLD_LIBRARY_PATH +endif endif diff --git a/etc/utils/build-linux.sh b/etc/utils/build-linux.sh index bbace4c..d0c324f 100755 --- a/etc/utils/build-linux.sh +++ b/etc/utils/build-linux.sh @@ -14,8 +14,8 @@ cp -rfv "libhashset/include/"*.h "out/include" case "${mode}" in gnu) - for target in i686 x86_64 aarch64; do - compiler="${target}-linux-gnu-gcc" + for cpu in i686 x86_64 aarch64; do + compiler="${cpu}-linux-gnu-gcc" target="$("${compiler}" -dumpmachine)" echo -e "--------------------------------\n${target}\n--------------------------------" make CC="${compiler}" STRIP=1 @@ -29,8 +29,8 @@ case "${mode}" in done ;; musl) - for target in i686 x86_64 arm64; do - compiler="/usr/local/musl/${target}/bin/musl-gcc" + for cpu in i686 x86_64 arm64; do + compiler="/usr/local/musl/${cpu}/bin/musl-gcc" target="$("${compiler}" -dumpmachine | sed 's/-gnu/-musl/i')" echo -e "--------------------------------\n${target}\n--------------------------------" make CC="${compiler}" STATIC=1 STRIP=1 diff --git a/etc/utils/build-macos.sh b/etc/utils/build-macos.sh new file mode 100755 index 0000000..d49335c --- /dev/null +++ b/etc/utils/build-macos.sh @@ -0,0 +1,19 @@ +#!/bin/zsh +set -e +cd -- "${0:a:h}/../../" + +mkdir -pv "out/include" +cp -rfv "libhashset/include/"*.h "out/include" + +for cpu in x86_64 aarch64; do + target="${cpu}-apple-darwin" + echo -e "--------------------------------\n${target}\n--------------------------------" + make CC="cc -target ${target}" + mkdir -pv "out/lib/${target}" "out/bin/${target}" + cp -rv "libhashset/lib/"* "out/lib/${target}" + for i in example test; do + for j in hash-set hash-map; do + cp -fv "${i}/${j}/bin/${i}-${j}" "out/bin/${target}" + done + done +done