From 2bee52b9af5db8682bc12fb11eb51c7038e0d8f2 Mon Sep 17 00:00:00 2001 From: Thomas BERNARD Date: Tue, 27 Nov 2018 12:55:13 +0100 Subject: [PATCH] OSX: Build with statically linked libraries ! tested on OS X Mavericks 10.9.5 with macports --- src/Makefile | 30 ++++++++++++++++++++++++++---- tools/osx_find_dependencies.sh | 25 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100755 tools/osx_find_dependencies.sh diff --git a/src/Makefile b/src/Makefile index 0a33c953..c1f5c9c0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -135,6 +135,8 @@ else else ifeq ($(PLATFORM),Darwin) # 2 #Mac OS X specific + # to statically link non system libraries + OSX_STATIC ?= 1 # Darwin / OS X versions : # 6 => 10.2 ppc only @@ -196,17 +198,33 @@ endif endif ifeq ($(API),sdl2) 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 += -Wl,-framework,Cocoa - #TTFCOPT = $(shell pkg-config --cflags SDL2_ttf) TTFLOPT = $(shell pkg-config --libs SDL2_ttf) + endif endif # 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) ifneq ($(LUAPKG), ) - LUACOPT = $(shell pkg-config $(LUAPKG) --cflags) - LUALOPT = $(shell pkg-config $(LUAPKG) --libs) + ifeq ($(OSX_STATIC),1) + 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 # these are for use with Mac OS X native frameworks LUACOPT = -I$(FWDIR)/Lua.framework/Headers @@ -226,11 +244,15 @@ ifdef MACOSX_LION LOPT = $(SDLLOPT) $(LUALOPT) -framework libpng14 -lz else LOPT = $(SDLLOPT) $(LUALOPT) - LOPT += $(TTFLOPT) + ifneq ($(OSX_STATIC), 1) + LOPT += $(TTFLOPT) + endif LIBPNGCONFIG := $(shell libpng-config) ifneq ($(LIBPNGCONFIG), ) COPT += $(shell libpng-config --cflags) + ifneq ($(OSX_STATIC), 1) LOPT += $(shell libpng-config --ldflags) + endif else LOPT += -lpng endif diff --git a/tools/osx_find_dependencies.sh b/tools/osx_find_dependencies.sh new file mode 100755 index 00000000..6052950a --- /dev/null +++ b/tools/osx_find_dependencies.sh @@ -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