changeset 2688:102a7498752d draft

(svn r3230) -Feature: [OSX] OSX builds can now change where it searches for dynamic libs and can move libs into the bundle This is not a fix for the issues with static linking, more like a workaround. Static linking still got issues Apple recommends to use dynamic linking anyway, so I guess this doesn't matter much
author bjarni <bjarni@openttd.org>
date Wed, 23 Nov 2005 12:21:54 +0000
parents 91b598992565
children a18e6976c98c
files Makefile makefiledir/Makefile.config_writer makefiledir/Makefile.libdetection os/macosx/Makefile
diffstat 4 files changed, 105 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile
+++ b/Makefile
@@ -73,6 +73,9 @@
 # do `make install', the game won't be able to find it's files (so you should
 # also define all the following paths before building).
 #
+# OSX specific paths are set in os/macosx/Makefile
+# MAKEMOVEABLE moves the dynamic libs into the bundle to make the app independent from end user's libs (OSX only)
+#
 # So, the following paths should be defined if INSTALL is defined.
 # None of these paths have to end with /
 # PREFIX:	Normally /usr/local
@@ -197,14 +200,6 @@
 endif
 endif
 
-ifdef RELEASE
-ifdef OSX
-ifndef STATIC
-$(error do not make dynamically linked releases. Most users can't use those)
-endif
-endif
-endif
-
 # Force SDL on UNIX platforms
 ifndef WITH_SDL
 ifdef UNIX
@@ -492,6 +487,9 @@
 
 # OSX specific setup
 ifdef OSX
+	# ensure that changing libpathnames will not overwrite anything in the binary
+	LDFLAGS += -headerpad_max_install_names
+
 	ifndef DEDICATED
 		LIBS += -framework QuickTime
 	endif
@@ -798,18 +796,9 @@
 	@echo '===> Linking $@'
 	$(Q)$(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS) $(LIBS) -o $@
 
-$(OSX): $(TTD)
-	$(Q)rm -fr "$(OSXAPP)"
-	$(Q)mkdir -p "$(OSXAPP)"/Contents/MacOS
-	$(Q)mkdir -p "$(OSXAPP)"/Contents/Resources
-	$(Q)mkdir -p "$(OSXAPP)"/Contents/Data
-	$(Q)mkdir -p "$(OSXAPP)"/Contents/Lang
-	$(Q)echo "APPL????" > "$(OSXAPP)"/Contents/PkgInfo
-	$(Q)cp os/macosx/openttd.icns "$(OSXAPP)"/Contents/Resources/openttd.icns
-	$(Q)os/macosx/plistgen.sh "$(OSXAPP)" "$(REV)"
-	$(Q)cp data/* "$(OSXAPP)"/Contents/Data/
-	$(Q)cp lang/*.lng "$(OSXAPP)"/Contents/Lang/
-	$(Q)cp $(TTD) "$(OSXAPP)"/Contents/MacOS/$(TTD)
+ifdef OSX
+-include os/macosx/Makefile
+endif
 
 $(STRGEN): strgen/strgen.c endian_host.h
 	@echo '===> Compiling and Linking $@'
@@ -862,43 +851,6 @@
 .PHONY: release
 endif
 
-ifdef OSX
-release: all
-	$(Q)mkdir -p "OpenTTD $(RELEASE)"
-	$(Q)mkdir -p "OpenTTD $(RELEASE)"/docs
-	$(Q)mkdir -p "OpenTTD $(RELEASE)"/scenario
-	$(Q)cp -R $(OSXAPP) "OpenTTD $(RELEASE)"/
-	$(Q)cp docs/OSX_where_did_the_package_go.txt "OpenTTD $(RELEASE)"/Where\ did\ the\ package\ go.txt
-	$(Q)cp readme.txt "OpenTTD $(RELEASE)"/docs/
-	$(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD $(RELEASE)"/docs/readme\ if\ crashed\ on\ OSX.txt
-	$(Q)cp docs/console.txt "OpenTTD $(RELEASE)"/docs/
-	$(Q)cp COPYING "OpenTTD $(RELEASE)"/docs/
-	$(Q)cp changelog.txt "OpenTTD $(RELEASE)"/docs/
-	$(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD $(RELEASE)"/docs/
-	$(Q)cp os/macosx/*.webloc "OpenTTD $(RELEASE)"
-	$(Q)cp known-bugs.txt "OpenTTD $(RELEASE)"/known-bugs.txt
-	$(Q)cp scenario/* "OpenTTD $(RELEASE)"/scenario/
-	$(Q)/usr/bin/hdiutil create -ov -format UDZO -srcfolder "OpenTTD $(RELEASE)" openttd-"$(RELEASE)"-osx.dmg
-	$(Q)rm -fr "OpenTTD $(RELEASE)"
-
-nightly_build: all
-	$(Q)mkdir -p "OpenTTD_nightly_$(DATE)"
-	$(Q)mkdir -p "OpenTTD_nightly_$(DATE)"/docs
-	$(Q)cp -R $(OSXAPP) "OpenTTD_nightly_$(DATE)"/
-	$(Q)cp docs/OSX_where_did_the_package_go.txt "OpenTTD_nightly_$(DATE)"/Where\ did\ the\ package\ go.txt
-	$(Q)cp readme.txt "OpenTTD_nightly_$(DATE)"/docs/
-	$(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD_nightly_$(DATE)"/docs/readme\ if\ crashed\ on\ OSX.txt
-	$(Q)cp docs/console.txt "OpenTTD_nightly_$(DATE)"/docs/
-	$(Q)cp COPYING "OpenTTD_nightly_$(DATE)"/docs/
-	$(Q)cp revisionlog.txt "OpenTTD_nightly_$(DATE)"/revisionlog.txt
-	$(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD_nightly_$(DATE)"/docs/
-	$(Q)cp os/macosx/*.webloc "OpenTTD_nightly_$(DATE)"/
-	$(Q)/usr/bin/hdiutil create -ov -format UDZO -srcfolder "OpenTTD_nightly_$(DATE)" openttd-nightly-"$(DATE)".dmg
-	$(Q)rm -fr "OpenTTD_nightly_$(DATE)"
-
-.PHONY: release nightly_build
-endif
-
 rev.c: FORCE
 	@# setting the revision number in a place, there the binary can read it
 	@echo 'const char _openttd_revision[] = "$(REV)";' >>rev.c.new
--- a/makefiledir/Makefile.config_writer
+++ b/makefiledir/Makefile.config_writer
@@ -74,6 +74,12 @@
 	$(call CONFIG_LINE,STATIC_ZLIB_PATH:=$(STATIC_ZLIB_PATH))
 	$(call CONFIG_LINE,)
 
+	$(call CONFIG_LINE,\# Lib paths for OSX. If you do not know what they do, do not touch them)
+	$(call CONFIG_LINE,OSX_LIB_PATH:=$(OSX_LIB_PATH))
+	$(call CONFIG_LINE,OSX_LOCAL_LIB_PATH:=$(OSX_LOCAL_LIB_PATH))
+	$(call CONFIG_LINE,OSX_CHANGE_LIB_PATH:=$(OSX_CHANGE_LIB_PATH))
+	$(call CONFIG_LINE,)
+
 	$(call CONFIG_LINE,\# OS flags)
 	$(call CONFIG_LINE,WIN32:=$(WIN32))
 	$(call CONFIG_LINE,UNIX:=$(UNIX))
--- a/makefiledir/Makefile.libdetection
+++ b/makefiledir/Makefile.libdetection
@@ -23,8 +23,6 @@
 OSX:=1
 # OSX uses the unix setup too
 UNIX:=1
-# OSX generally uses static since so few computers actually have all the libs installed in unix style
-STATIC:=1
 endif
 
 # Automatically recognize if building on MorphOS
new file mode 100644
--- /dev/null
+++ b/os/macosx/Makefile
@@ -0,0 +1,90 @@
+# $Id: Makefile 3214 2005-11-17 19:43:37Z bjarni $
+# This makefile is not a standalone makefile, but is called from the general one
+# it contains targets specific to MacOS X
+
+# it's possible to link OpenTTD dynamically and move the needed libs into the bundle
+# this way it's possible to move the app around without thinking about libs on the computer it runs on
+# dynamic linking is recommended for several reasons, specially because static linking makes issues with OpenTTD
+# to setup the lib paths, a few flags needs to be set (default setup should work if the libs were installed with fink)
+#
+# OSX_LIB_PATH: this is the path to where the lib files are located on the compiling computer. (default /sw/lib/)
+# OSX_LOCAL_LIB_PATH: is the path that the binary will use to search for the libs.
+#	it's always an absolute path except when the keyword @executable_path is used, then it's the binary
+#	it's important to remember that it's the binary and not the bundle, so to get the bundle path, use @executable_path/../../../
+
+
+ifdef RELEASE
+	CONVERT_LIB_PATH:=convert_OSX_lib_path
+endif
+
+ifdef OSX_CHANGE_LIB_PATH
+	CONVERT_LIB_PATH:=convert_OSX_lib_path
+endif
+
+ifndef OSX_LIB_PATH
+	OSX_LIB_PATH:=/sw/lib/
+endif
+
+ifndef OSX_LOCAL_LIB_PATH
+	OSX_LOCAL_LIB_PATH:=@executable_path/../lib/
+endif
+
+ifdef MAKEMOVEABLE
+	CONVERT_LIB_PATH:=convert_OSX_lib_path
+	OSX_LOCAL_LIB_PATH:=@executable_path/../lib/
+	MOVE_LIB_INTO_BUNDLE:=move_lib_into_bundle
+endif
+
+# the rest is the targets. If more than one is called, they need to be called in the order they are written
+
+# build the bundle. OSX wants to keep apps in bundles, so we will give it one
+# the good thing about bundles is that you can keep extra files in them, so we keep lng files and a data dir in it
+build_OSX_bundle:
+	$(Q)rm -fr "$(OSXAPP)"
+	$(Q)mkdir -p "$(OSXAPP)"/Contents/MacOS
+	$(Q)mkdir -p "$(OSXAPP)"/Contents/Resources
+	$(Q)mkdir -p "$(OSXAPP)"/Contents/Data
+	$(Q)mkdir -p "$(OSXAPP)"/Contents/Lang
+	$(Q)echo "APPL????" > "$(OSXAPP)"/Contents/PkgInfo
+	$(Q)cp os/macosx/openttd.icns "$(OSXAPP)"/Contents/Resources/openttd.icns
+	$(Q)os/macosx/plistgen.sh "$(OSXAPP)" "$(REV)"
+	$(Q)cp data/* "$(OSXAPP)"/Contents/Data/
+	$(Q)cp lang/*.lng "$(OSXAPP)"/Contents/Lang/
+	$(Q)cp $(TTD) "$(OSXAPP)"/Contents/MacOS/$(TTD)
+
+
+# set the path that OpenTTD will use to search for dynamic libraries
+$(CONVERT_LIB_PATH):
+	$(Q)install_name_tool -change $(OSX_LIB_PATH)libSDL-1.2.0.dylib $(OSX_LOCAL_LIB_PATH)libSDL-1.2.0.dylib "$(OSXAPP)"/Contents/MacOS/$(TTD)
+	$(Q)install_name_tool -change $(OSX_LIB_PATH)libpng12.0.dylib $(OSX_LOCAL_LIB_PATH)libpng12.0.dylib "$(OSXAPP)"/Contents/MacOS/$(TTD)
+
+
+# copies the lib files into the bundle. This way you can move the bundle around like if it were statically linked
+$(MOVE_LIB_INTO_BUNDLE):
+	$(Q)mkdir -p "$(OSXAPP)"/Contents/lib/
+	$(Q)cp -RH $(OSX_LIB_PATH)libSDL-1.2.0.dylib "$(OSXAPP)"/Contents/lib/libSDL-1.2.0.dylib
+	$(Q)cp -RH $(OSX_LIB_PATH)libpng12.0.dylib "$(OSXAPP)"/Contents/lib/libpng12.0.dylib
+
+
+# make the release disk image. Should only be used with releases and is a good and fast way to make sure to remember all the needed files
+release: all
+	$(Q)mkdir -p "OpenTTD $(RELEASE)"
+	$(Q)mkdir -p "OpenTTD $(RELEASE)"/docs
+	$(Q)mkdir -p "OpenTTD $(RELEASE)"/scenario
+	$(Q)cp -R $(OSXAPP) "OpenTTD $(RELEASE)"/
+	$(Q)cp docs/OSX_where_did_the_package_go.txt "OpenTTD $(RELEASE)"/Where\ did\ the\ package\ go.txt
+	$(Q)cp readme.txt "OpenTTD $(RELEASE)"/docs/
+	$(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD $(RELEASE)"/docs/readme\ if\ crashed\ on\ OSX.txt
+	$(Q)cp docs/console.txt "OpenTTD $(RELEASE)"/docs/
+	$(Q)cp COPYING "OpenTTD $(RELEASE)"/docs/
+	$(Q)cp changelog.txt "OpenTTD $(RELEASE)"/docs/
+	$(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD $(RELEASE)"/docs/
+	$(Q)cp os/macosx/*.webloc "OpenTTD $(RELEASE)"
+	$(Q)cp known-bugs.txt "OpenTTD $(RELEASE)"/known-bugs.txt
+	$(Q)cp scenario/* "OpenTTD $(RELEASE)"/scenario/
+	$(Q)/usr/bin/hdiutil create -ov -format UDZO -srcfolder "OpenTTD $(RELEASE)" openttd-"$(RELEASE)"-osx.dmg
+	$(Q)rm -fr "OpenTTD $(RELEASE)"
+
+$(OSX): $(TTD) build_OSX_bundle $(CONVERT_LIB_PATH)
+
+.PHONY: release $(CONVERT_LIB_PATH) $(MOVE_LIB_INTO_BUNDLE) build_OSX_bundle