diff --git a/Makefile b/Makefile index 8f12d4ab9..09f881536 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -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