Skip to content

Commit

Permalink
c-lib: Use $(CC) -dumpmachine for platform detection, not uname
Browse files Browse the repository at this point in the history
  • Loading branch information
terryburton committed Apr 29, 2024
1 parent 7192929 commit d4ee778
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/c-lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ MINOR := 0
PATCH := 0
VERSION := $(MAJOR).$(MINOR).$(PATCH)

ARCH := $(shell $(CC) -dumpmachine)

NAME = gs1encoders

BUILD_DIR = build
Expand Down Expand Up @@ -81,13 +83,13 @@ ifeq ($(SANITIZE),yes)
CC=clang
SAN_LDFLAGS = -fuse-ld=lld

ifneq ($(shell uname -s),Darwin)
SAN_CFLAGS = -fsanitize=address,leak,undefined$(FUZZER_SAN_OPT) -fno-omit-frame-pointer -fno-optimize-sibling-calls -O1
SAN_ENV = ASAN_OPTIONS="symbolize=1 detect_leaks=1" LSAN_OPTIONS="fast_unwind_on_malloc=0:malloc_context_size=50" ASAN_SYMBOLIZER_PATH="$(shell which llvm-symbolizer)"
else
ifneq (, $(findstring darwin, $(ARCH)))
# Leak detection is not supported on MacOS builds of LLVM
SAN_CFLAGS = -fsanitize=address,undefined$(FUZZER_SAN_OPT) -fno-omit-frame-pointer -fno-optimize-sibling-calls -O1
SAN_ENV = ASAN_OPTIONS="symbolize=1" LSAN_OPTIONS="fast_unwind_on_malloc=0:malloc_context_size=50" MallocNanoZone=0 ASAN_SYMBOLIZER_PATH="$(shell which llvm-symbolizer)"
else
SAN_CFLAGS = -fsanitize=address,leak,undefined$(FUZZER_SAN_OPT) -fno-omit-frame-pointer -fno-optimize-sibling-calls -O1
SAN_ENV = ASAN_OPTIONS="symbolize=1 detect_leaks=1" LSAN_OPTIONS="fast_unwind_on_malloc=0:malloc_context_size=50" ASAN_SYMBOLIZER_PATH="$(shell which llvm-symbolizer)"
endif

endif
Expand All @@ -97,20 +99,21 @@ ifeq ($(SLOW_TESTS),yes)
SLOW_TESTS_CFLAGS=-DSLOW_TESTS
endif

ifneq ($(shell uname -s),Darwin)
LIB_DYN_SUFFIX = so
LIB_STATIC_SUFFIX = a
LDFLAGS = -Wl,--as-needed -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now $(SAN_LDFLAGS)
LDFLAGS_SO = -shared -Wl,-soname,lib$(NAME).$(LIB_DYN_SUFFIX).$(MAJOR)
CFLAGS_FORTIFY = -D_FORTIFY_SOURCE=2
NPROC = nproc
else

ifneq (, $(findstring darwin, $(ARCH)))
LIB_DYN_SUFFIX = dylib
LIB_STATIC_SUFFIX = a
LDFLAGS =
LDFLAGS_SO = -shared -Wl,-install_name,lib$(NAME).$(LIB_DYN_SUFFIX).$(MAJOR)
CFLAGS_FORTIFY =
NPROC = sysctl -n hw.ncpu
else
LIB_DYN_SUFFIX = so
LIB_STATIC_SUFFIX = a
LDFLAGS = -Wl,--as-needed -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now $(SAN_LDFLAGS)
LDFLAGS_SO = -shared -Wl,-soname,lib$(NAME).$(LIB_DYN_SUFFIX).$(MAJOR)
CFLAGS_FORTIFY = -D_FORTIFY_SOURCE=2
NPROC = nproc
endif

LDLIBS = -lc
Expand Down

0 comments on commit d4ee778

Please sign in to comment.