Skip to content

Commit

Permalink
Support static compilation on Mac
Browse files Browse the repository at this point in the history
  • Loading branch information
Timmmm committed Dec 2, 2024
1 parent b73a799 commit 6803144
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,28 @@ SOFTFLOAT_FLAGS = -I $(SOFTFLOAT_INCDIR)
SOFTFLOAT_LIBS = $(SOFTFLOAT_LIBDIR)/softfloat.a
SOFTFLOAT_SPECIALIZE_TYPE = RISCV

UNAME_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')

STATIC_GMP_A :=
STATIC_B_STATIC :=

ifneq (,$(STATIC))
ifeq ($(UNAME_S),Darwin)
STATIC_GMP_A := 1
else
STATIC_B_STATIC := 1
endif
endif

GMP_FLAGS = $(shell pkg-config --cflags gmp)
# N.B. GMP does not have pkg-config metadata on Ubuntu 18.04 so default to -lgmp
GMP_LIBS = $(shell pkg-config --libs gmp || echo -lgmp)
ifneq (,$(STATIC_GMP_A))
GMP_LIBS = $(shell pkg-config --variable=libdir gmp)/libgmp.a
else
# N.B. GMP does not have pkg-config metadata on Ubuntu 18.04 so default to -lgmp
GMP_LIBS = $(shell pkg-config --libs gmp || echo -lgmp)
endif

# TODO: Remove Zlib when upgrading to Sail 0.19; it is no longer a requirement.
ZLIB_FLAGS = $(shell pkg-config --cflags zlib)
ZLIB_LIBS = $(shell pkg-config --libs zlib)

Expand Down Expand Up @@ -193,8 +212,9 @@ endif

# Optional link C_LIBS statically. Unlike -static this will not
# link glibc statically which is generally a bad idea.
ifneq (,$(STATIC))
C_LIBS_WRAPPED = -Wl,-Bstatic $(C_LIBS) -Wl,-Bdynamic
# Unfortunately the Mac linker does not support -Bstatic.
ifneq (,$(STATIC_B_STATIC))
C_LIBS_WRAPPED = -Wl,--push-state,-Bstatic $(C_LIBS) -Wl,--pop-state
else
C_LIBS_WRAPPED = $(C_LIBS)
endif
Expand Down

0 comments on commit 6803144

Please sign in to comment.