OSX: Build with statically linked libraries !

tested on OS X Mavericks 10.9.5 with macports
This commit is contained in:
Thomas BERNARD 2018-11-27 12:55:13 +01:00 committed by Thomas Bernard
parent d91290f63f
commit 2bee52b9af
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
2 changed files with 51 additions and 4 deletions

View File

@ -135,6 +135,8 @@ else
else else
ifeq ($(PLATFORM),Darwin) # 2 ifeq ($(PLATFORM),Darwin) # 2
#Mac OS X specific #Mac OS X specific
# to statically link non system libraries
OSX_STATIC ?= 1
# Darwin / OS X versions : # Darwin / OS X versions :
# 6 => 10.2 ppc only # 6 => 10.2 ppc only
@ -196,17 +198,33 @@ endif
endif endif
ifeq ($(API),sdl2) ifeq ($(API),sdl2)
SDLCOPT = $(shell sdl2-config --cflags) SDLCOPT = $(shell sdl2-config --cflags)
#TTFCOPT = $(shell pkg-config --cflags SDL2_ttf)
ifeq ($(OSX_STATIC), 1)
SDLLOPT = $(shell sdl2-config --static-libs | sed 's/-lSDL2//' | sed 's/-L[^ ]*//')
SDLLIBDIR = $(shell pkg-config --variable=libdir SDL2_image)
SDLLOPT += $(SDLLIBDIR)/libSDL2.a
# trick to get all dependencies
SDLLOPT += $(addsuffix .a, $(shell ../tools/osx_find_dependencies.sh $(SDLLIBDIR)/libSDL2_image.dylib $(SDLLIBDIR)/libSDL2_ttf.dylib | grep -v SDL2 | cut -d'.' -f 1))
SDLLOPT += $(SDLLIBDIR)/libSDL2_image.a
TTFLOPT =
SDLLOPT += $(shell pkg-config --variable=libdir SDL2_ttf)/libSDL2_ttf.a
else
SDLLOPT = $(shell sdl2-config --libs) $(shell pkg-config --libs SDL2_image) SDLLOPT = $(shell sdl2-config --libs) $(shell pkg-config --libs SDL2_image)
SDLLOPT += -Wl,-framework,Cocoa SDLLOPT += -Wl,-framework,Cocoa
#TTFCOPT = $(shell pkg-config --cflags SDL2_ttf)
TTFLOPT = $(shell pkg-config --libs SDL2_ttf) TTFLOPT = $(shell pkg-config --libs SDL2_ttf)
endif
endif endif
# these are for use with macports # these are for use with macports
LUAPKG := $(shell for p in lua5.3 lua-5.3 lua53 lua5.2 lua-5.2 lua52 lua5.1 lua-5.1 lua51 lua ; do pkg-config --exists $$p && echo $$p && break ; done) LUAPKG := $(shell for p in lua5.3 lua-5.3 lua53 lua5.2 lua-5.2 lua52 lua5.1 lua-5.1 lua51 lua ; do pkg-config --exists $$p && echo $$p && break ; done)
ifneq ($(LUAPKG), ) ifneq ($(LUAPKG), )
LUACOPT = $(shell pkg-config $(LUAPKG) --cflags) ifeq ($(OSX_STATIC),1)
LUALOPT = $(shell pkg-config $(LUAPKG) --libs) LUACOPT = $(shell pkg-config $(LUAPKG) --cflags | sed 's/-I/-idirafter/')
LUALOPT = $(shell pkg-config $(LUAPKG) --variable=libdir)/liblua.a
else
LUACOPT = $(shell pkg-config $(LUAPKG) --cflags)
LUALOPT = $(shell pkg-config $(LUAPKG) --libs)
endif
else else
# these are for use with Mac OS X native frameworks # these are for use with Mac OS X native frameworks
LUACOPT = -I$(FWDIR)/Lua.framework/Headers LUACOPT = -I$(FWDIR)/Lua.framework/Headers
@ -226,11 +244,15 @@ ifdef MACOSX_LION
LOPT = $(SDLLOPT) $(LUALOPT) -framework libpng14 -lz LOPT = $(SDLLOPT) $(LUALOPT) -framework libpng14 -lz
else else
LOPT = $(SDLLOPT) $(LUALOPT) LOPT = $(SDLLOPT) $(LUALOPT)
LOPT += $(TTFLOPT) ifneq ($(OSX_STATIC), 1)
LOPT += $(TTFLOPT)
endif
LIBPNGCONFIG := $(shell libpng-config) LIBPNGCONFIG := $(shell libpng-config)
ifneq ($(LIBPNGCONFIG), ) ifneq ($(LIBPNGCONFIG), )
COPT += $(shell libpng-config --cflags) COPT += $(shell libpng-config --cflags)
ifneq ($(OSX_STATIC), 1)
LOPT += $(shell libpng-config --ldflags) LOPT += $(shell libpng-config --ldflags)
endif
else else
LOPT += -lpng LOPT += -lpng
endif endif

25
tools/osx_find_dependencies.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/sh
# no argument : error
if [ ! -f $1 ] ; then
exit 1
fi
# more than one argument : iterate
if [ $# -ne 1 ] ; then
for arg in $@ ; do
$0 $arg
done | sort | uniq
exit 0
fi
#list=$(otool -L $1 | sed '1d' | grep -v libSystem.B | grep -v /System/Library | grep -v $1 | cut -f 2 | cut -d' ' -f 1)
list=$(otool -L $1 | sed '1d' | grep -v /usr/lib/lib | grep -v /System/Library | grep -v $1 | cut -f 2 | cut -d' ' -f 1)
#echo "$1 => $list" >&2
# recursive calls
for lib in $list ; do
echo $lib
$0 $lib
done | sort | uniq