From 656dd876d23dc34816b3ea8adb45cfe6e551abeb Mon Sep 17 00:00:00 2001 From: Dino Date: Mon, 13 Mar 2023 17:07:42 -0400 Subject: [PATCH] Ticket #46474 new files --- platforms/macos/MacAppREADME.txt | 53 +++++ platforms/macos/buildStandaloneApp.sh | 314 ++++++++++++++++++++++++++ 2 files changed, 367 insertions(+) create mode 100755 platforms/macos/MacAppREADME.txt create mode 100755 platforms/macos/buildStandaloneApp.sh diff --git a/platforms/macos/MacAppREADME.txt b/platforms/macos/MacAppREADME.txt new file mode 100755 index 0000000000..d1042f4fef --- /dev/null +++ b/platforms/macos/MacAppREADME.txt @@ -0,0 +1,53 @@ +Put "freeciv.app" into your Applications folder. It needs to be there, and +not re-named, in order to work. Because Macs are so paranoid, you may have a +hard time running it the first time. When you get the dlog that says it +cannot be opened because the developer cannot be verified, click cancel, then +open System Preferences, go to Security & Privacy and click the Open Anyway +button. That will save it as an exception to your security settings, and you +can open it in the future by double-clicking it. + +Tip - the save game files are in a folder named ".freeciv/saves" within your +home folder, AKA "/Users/{username}/.freeciv/saves". Your home folder is the +one with the house icon next to it in the favorites. In Unix-speak, it's +"~/.freeciv/saves". The finder won't normally show you folders that start +with ".", but you can toggle that by entering CMD+Shift+. while in a finder +window. While the hidden stuff is visible you can make an alias to the +".freeciv" folder which will always be visible. + +The default graphics client is qt. The gtk4 client is also included, they +look quite different but have mostly the same functionality. The qt client +has more zoom levels, and they both have their own little bugs. You can +switch clients by doing a little work. The Mac Finder shows apps like +freeciv.app as if it were a file, but once the drugs wear off it is actually +a folder. To peak inside, control+click (or right mouse button click) on the +app icon to get the pop-up menu and choose the menu item "Show Package +Contents". You will see a folder called "Contents", inside that is a file +called "Info.plist", which is a plain text file that controls what gets +executed. You can edit this file with the TextEdit app. There is a pair of +lines like this - + + CFBundleExecutable + ../bin/freeciv-qt + +Replace the string "../bin/freeciv-qt" with "../bin/freeciv-gtk4", and +save the file. The last step is to get the Finder to update its internal +database. Rename the "freeciv.app" to anything different (I like to add 'x' +to the end) and then rename it back to "freeciv.app". + +While you're in there, inside the "Contents" folder there's a folder called +"bin", which contains another executable file called "freeciv-mp-qt". This is +the modpack installer. You can double click on it and run it to install +modpacks. There is also a file "freeciv-server", which you can also double +click on and run if you want to set up a server for multi-player games. The +server does not have a GUI, it opens a terminal window where you can type in +interactive commands. For more details, see the wiki page +https://freeciv.fandom.com/wiki/Server_Manual + +The "bin" folder also contains a file "freeciv-ruleup", which can be used to +update a ruleset from the format of the previous freeciv version to the +current version. It does not have a GUI and needs to be run from a command line. +For more details, see the wiki page https://freeciv.org/wiki/Freeciv-ruleup + +The "bin" folder also contains a file "freeciv-ruledit", which can be used to +edit a ruleset. You can double click on it to run it, and it has a GUI, but is +lacking documentation. diff --git a/platforms/macos/buildStandaloneApp.sh b/platforms/macos/buildStandaloneApp.sh new file mode 100755 index 0000000000..1d02d47af3 --- /dev/null +++ b/platforms/macos/buildStandaloneApp.sh @@ -0,0 +1,314 @@ +#!/bin/bash + +# intended use - +# this file lives in {root of git branch}/platforms/macos +# > cd {root of git branch} +# > platforms/macos/buildStandaloneApp.sh +# after very lengthy successful run, folder {root of git branch}/platforms/macos +# will contain a zip file which can be put on https://www.freeciv.org/download.html + +ROOT=`pwd` +VSTRING=`./fc_version` +CONTENTSDIR="/Applications/Freeciv.app/Contents/" + +# create app bundle stuff +if ! [ -e "${CONTENTSDIR}" ] ; then + + if ! mkdir -p "${CONTENTSDIR}" ; then + echo "Failed to create \"${CONTENTSDIR}" >&2 + exit 1 + fi + + if ! mkdir -p "${CONTENTSDIR}Resources" ; then + echo "Failed to create directory \"${CONTENTSDIR}Resources\"" >&2 + exit 1 + fi + + if ! cp data/freeciv-client.icns "${CONTENTSDIR}Resources" ; then + echo "Failed to copy file \"freeciv-client.icns\"" >&2 + exit 1 + fi + + if ! mkdir -p "${CONTENTSDIR}MacOS" ; then + echo "Failed to create directory \"${CONTENTSDIR}MacOS\"" >&2 + exit 1 + fi + + # create the Info.plist file, with placeholder "VER" for version string + if ! echo " + + + LSEnvironment + + LD_LIBRARY_PATH + /Applications/Freeciv.app/Contents/lib + + CFBundleName + freeciv + CFBundleIdentifier + freeciv + CFBundleVersion + VER + CFBundleShortVersionString + VER + CFBundleExecutable + ../bin/freeciv-qt + CFBundleIconFile + freeciv-client.icns + CFBundleDevelopmentRegion + English + CFBundlePackageType + APPL + CFBundleSignature + ???? + CFBundleInfoDictionaryVersion + 6.0 + +" > "${CONTENTSDIR}Info.plist" ; then + echo "Failed to create file \"${CONTENTSDIR}Info.plist\"" >&2 + exit 1 + fi + + # substitute VSTRING into Info.plist + sed -i '' -e "s/VER/${VSTRING}/g" "${CONTENTSDIR}Info.plist" + + if ! echo -n "APPL????" > "${CONTENTSDIR}PkgInfo" ; then + echo "Failed to create file \"${CONTENTSDIR}PkgInfo\"" >&2 + exit 1 + fi + +fi + +echo "### freeciv.app directory created." +echo "### installing homebrew." + +# install homebrew +cd "${CONTENTSDIR}" +mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew + +BREW="${CONTENTSDIR}homebrew/bin/brew" + +$BREW developer off + +QTVER="qt5" # "=qt6" doesn't work yet +QT="qt@5" # "=qt@6" doesn't work yet + +# this list of top level packages results in many more +# dependent packages getting installed +HOMEBREW_PACKAGES="meson lua@5.4 jpeg-turbo gtk4 sdl2_mixer $QTVER" + +echo "### installing homebrew packages." + +# install packages +for pack in $HOMEBREW_PACKAGES +do + $BREW install $pack +done + +cd $ROOT + +# define the ENV VARS we need +export PATH="$($BREW --prefix $QT)/bin:${CONTENTSDIR}homebrew/bin/:$PATH" +export CXXFLAGS=-std=c++17 +export CPPFLAGS="-I$($BREW --prefix icu4c)/include \ +-I$($BREW --prefix readline)/include -I$($BREW --prefix gettext)/include \ +-I$($BREW --prefix $QT)/include \ +-I${CONTENTSDIR}homebrew/include" +export LDFLAGS="-L$($BREW --prefix icu4c)/lib -L$($BREW --prefix readline)/lib \ +-L$($BREW --prefix gettext)/lib \ +-L$($BREW --prefix sdl2)/lib -L$($BREW --prefix sdl2_mixer)/lib \ +-L$($BREW --prefix zstd)/lib -L$($BREW --prefix $QT)/lib" +export PKG_CONFIG_PATH="$($BREW --prefix icu4c)/lib/pkgconfig" + +# set up fresh build dir and cd to it +if [ -e build ] ; then + rm -R build +fi + +if ! mkdir build ; then + echo "Failed to create build directory" >&2 + exit 1 +fi + +cd build || exit 1 + +echo "### meson setup." + +# do the meson setup +if ! meson setup .. \ + -Dack_experimental=true \ + -Dsyslua=true \ + -Ddebug=false \ + -Dqtver=$QTVER \ + -Dclients=qt,gtk4 \ + -Dfcmp=qt \ + -Dprefix="$CONTENTSDIR" +then + echo "Meson setup failed!" >&2 + exit 1 +fi + +echo "### ninja build." + +# do the build +if ! ninja +then + echo "Build failed!" >&2 + exit 1 +fi + +echo "### ninja install." + +# do the install +if ! ninja install ; then + echo "Install failed!" >&2 + exit 1 +fi + +# the clean up strategy is to rename the "homebrew" folder to +# "homebrewSource" and create a new folder called "homebrew". +# Then we copy the needed items from $HBSOURCEDIR to $HBDESTDIR. +# Finally we delete the folder $HBSOURCEDIR, +# and some un-needed stuff in .../contents/share + +echo "### cleanup." + +HBSOURCEDIR="${CONTENTSDIR}homebrewSource/" +HBDESTDIR="${CONTENTSDIR}homebrew/" +SOURCE_CELLAR="${HBSOURCEDIR}Cellar/" +DEST_CELLAR="${HBDESTDIR}Cellar/" +SOURCE_LIB="${HBSOURCEDIR}lib/" +DEST_OPT="${HBDESTDIR}opt/" + +mv "${HBDESTDIR}" "${HBSOURCEDIR}" +mkdir "${HBDESTDIR}" +mkdir "${DEST_CELLAR}" +mkdir "${DEST_OPT}" + +# for the given package, clone the directory structure of the +# source Cellar to the dest Cellar, and copy the contained *.dylib +# files. Create symlink to the folder in the dest "opt" folder. +doPackage() +{ + package=$1 + if ! cd "${SOURCE_CELLAR}${package}/" ; then + echo "Homebrew package ${package} not found," + echo "list of PACKAGES=\"...\" needs to be updated." + exit 1 + fi + mkdir "${DEST_CELLAR}${package}" + vers_dir=`ls -t | head -n 1 ` + cd $vers_dir + mkdir "${DEST_CELLAR}${package}/$vers_dir" + mkdir "${DEST_CELLAR}${package}/${vers_dir}/lib" + cd lib + cp *.dylib "${DEST_CELLAR}${package}/${vers_dir}/lib" + ln -s "${DEST_CELLAR}${package}/${vers_dir}" "${DEST_OPT}$package" +} + + +# This is the most fragile part - homebrew package dependencies can change at +# any time, and there's no way to automatically track them. +# We want only the ones required at run-time, which is much fewer than the +# total which were originally installed. +# This is up-to-date as of 3/13/23 + +PACKAGES="cairo flac fluid-synth fontconfig freetype fribidi gdk-pixbuf \ +gettext glib graphene graphite2 gtk4 harfbuzz icu4c jpeg-turbo lame libepoxy libogg \ +libpng libsndfile libtiff libvorbis libx11 libxau libxcb libxdmcp libxext \ +libxmp libxrender lua lz4 lzo mpg123 opus opusfile pango pcre2 pixman portaudio \ +readline sdl2 sdl2_mixer sqlite xz zstd" + +# How to debug problems with the list PACKAGES="..." +# +# First, divide this script into 2 parts - part 1 which does initial setup, +# installs homebrew and packages, does the meson setup and ninja build and install. +# Part 2 is the cleanup. Copy the first 3 lines of part 1 to the top of part 2. +# Then run part 1, and make a backup copy of the resulting "freeciv.app". +# Then try running the part2 which has had the PACKAGES="..." list updated. If it succeeds +# and the resulting client runs OK, then the list is now OK. If not, delete the +# "freeciv.app", duplicate that backup copy and rename it "freeciv.app". Then you can +# try another iteration of running a newer part 2. Skipping re-running the part 1 will +# save many hours of elapsed time. +# +# If doPackage() gets an error and reports failing to find a package, +# that package needs to be removed from the list. +# Packages that need to be added to the list can only be found by trying to run +# the built client. When it crashes, a dialog will appear saying +# "Freeciv.app cannot be opened because of a problem." +# Click on the "Report..." button and another dlog appears that will have +# crash report info with stack frames, etc. Somewhere in there it will say something like +# "Library not loaded: /Applications/Freeciv.app/Contents/homebrew/opt/opusfile/lib/libopusfile.0.dylib" +# The string between "/opt/" and "/lib/" is the name of the missing package, +# add it to the list. +# Close the dlog by clicking on the "Don't Send" button, and you're ready for +# the next iteration. +# When the corrected list in part 2 is working OK, copy it back into this file, +# and this file needs to be committed to the git repo. + + +for pack in $PACKAGES +do + doPackage $pack +done + + +QT5PACKAGES="giflib webp" +QT6PACKAGES="assimp brotli dbus double-conversion hunspell jasper \ +libb2 libmng md4c webp" + +# if qt6 ever works, these next 3 lines can be modified to use qt6 +QTVER="qt5" # "=qt6" doesn't work yet +QT="qt@5" # "=qt@6" doesn't work yet +QTPACKS=$QT5PACKAGES + +for pack in $QTPACKS +do + doPackage $pack +done + +# qt stuff needs special handling +mkdir "${DEST_CELLAR}$QT" +cd "${SOURCE_CELLAR}$QT" +vers_dir=`ls -t | head -n 1 ` +cd $vers_dir +mkdir "${DEST_CELLAR}$QT/$vers_dir" +ln -s "${DEST_CELLAR}$QT/$vers_dir" "${DEST_OPT}/$QT" +mkdir "${DEST_CELLAR}$QT/${vers_dir}/lib" +mkdir "${DEST_CELLAR}$QT/${vers_dir}/plugins" +mkdir "${DEST_CELLAR}$QT/${vers_dir}/plugins/platforms" +cp plugins/platforms/libqcocoa.dylib "${DEST_CELLAR}$QT/$vers_dir/plugins/platforms" + + +doQTModule() +{ + mod=$1 + cp -R ${mod}.framework "${DEST_CELLAR}$QT/${vers_dir}/lib" +} + +QTMODS="QtCore QtGui QtWidgets QtDBus QtPrintSupport" + +cd lib +for module in $QTMODS +do + doQTModule $module +done + +# delete the folder $HBSOURCEDIR, +# and some un-needed stuff in .../contents/share + +rm -f -R ${HBSOURCEDIR} +rm -f -R "${CONTENTSDIR}share/applications" +rm -f -R "${CONTENTSDIR}share/doc" +rm -f -R "${CONTENTSDIR}share/metainfo" + +echo "### creating tar file." + +# make a tar file containing the app and the MacAppREADME.txt file +TARFNAME="$ROOT/platforms/macos/freeciv-${VSTRING}.tar.gz" +cd /Applications +cp $ROOT/platforms/macos/MacAppREADME.txt . +tar -czf $TARFNAME Freeciv.app MacAppREADME.txt + +echo "### Done." -- 2.31.0