View Issue Details

IDProjectCategoryView StatusLast Update
0009975Dwarf FortressTechnical -- Generalpublic2023-12-26 19:50
Reportersnoerr Assigned ToToady One  
PrioritylowSeverityminorReproducibilityN/A
Status acknowledgedResolutionopen 
PlatformMacOSMac OS X 
Product Version0.43.05 
Summary0009975: Contribution: script to bundle Mac app
DescriptionContributing this script, which will bundle the files from the distribution into a Mac OS X app bundle. All it's missing is an icon file (icns format). The script has a TODO for that.

Steps To ReproduceSteps to use:

- stick script into a file, say "build-mac-package.sh" - works with bash on Mac OS X
- create your usual distribution folder
- run script, substituting the actual version number for "0.43.06" and your distribution folder path: build-mac-package.sh distribution_folder DwarfFotress.app 0.43.06
Additional Information#!/bin/sh

if [ $# -ne 3 ]; then
        echo "Usage: $0 <source folder> <target app name> <version>"
        echo "Example: $0 DwarfFortress/43.05 bin/DwarfFortress 43.05"
        echo " will create a DwaarfFortress.app in the bin/ folder under cwd using the contents of DwarfFortress/43.05"
        exit 1
fi
              
SRC_FOLDER=$1
DEST_APP=$2.app
VERSION=$3

if [ -d "${DEST_APP}.bak" ]; then
        # Delete old backup
        /bin/rm -rf "${DEST_APP}.bak"
fi
if [ -d "${DEST_APP}" ]; then
        # Back up current app
        /bin/mv "${DEST_APP}" "${DEST_APP}.bak"
fi
/bin/mkdir -p "${DEST_APP}"
/bin/mkdir -p "${DEST_APP}/Contents/MacOS"

# Create Info.plist
/bin/cat > "${DEST_APP}/Contents/Info.plist" <<EOL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>CFBundleDevelopmentRegion</key>
        <string>English</string>
        <key>CFBundleExecutable</key>
        <string>df</string>
        <key>CFBundleIconFile</key>
        <string>dwarfort.icns</string>
        <key>CFBundleIdentifier</key>
        <string>com.bay12games.dwarfort</string>
        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>
        <key>CFBundleName</key>
        <string>Dwarf Fortress</string>
        <key>CFBundlePackageType</key>
        <string>APPL</string>
        <key>CFBundleShortVersionString</key>
        <string>${VERSION}</string>
        <key>CFBundleSignature</key>
        <string>xmmd</string>
        <key>CFBundleVersion</key>
        <string>${VERSION}</string>
        <key>NSAppleScriptEnabled</key>
        <string>NO</string>
</dict>
</plist>
EOL

# Copy the launcher wrapper script
cat >"${DEST_APP}/Contents/MacOS/df" <<EOL
#!/bin/sh

APPNAME=DwarfFortress
DIR=\$(cd "\$(dirname "\$0")"; pwd)
RESOURCES_DIR=\$(cd "\${DIR}/../Resources"; pwd)

#thanks to Iriel for figuring this out
OSREV=\`uname -r | cut -d. -f1\`
if [ "\$OSREV" -ge 11 ] ; then
    export DYLD_LIBRARY_PATH=\${DIR}:\${RESOURCES_DIR}/libs:/lib:/usr/lib
    export DYLD_FRAMEWORK_PATH=\${DIR}:\${RESOURCES_DIR}/libs:lib:/usr/lib
else
    export DYLD_FALLBACK_LIBRARY_PATH=\${DIR}:\${RESOURCES_DIR}/libs:/lib:/usr/lib
    export DYLD_FALLBACK_FRAMEWORK_PATH=\${DIR}:\${RESOURCES_DIR}/libs:/lib:/usr/lib
fi

LOG_FILE="\${HOME}/Library/Logs/\${APPNAME}/\${APPNAME}.log"
/bin/mkdir -p "\`dirname \"\${LOG_FILE}\"\`"
cd "\${RESOURCES_DIR}"
if grep -q '\[PRINT_MODE:TEXT\]' data/init/init.txt ; then
    \${DIR}/dwarfort.exe "\$@" 2>&1 > "\${LOG_FILE}"
else
    \${DIR}/dwarfort.exe "\$@" 2>&1 > "\${LOG_FILE}" &
fi
EOL

# make sure the launcher script is executable
/bin/chmod 755 "${DEST_APP}/Contents/MacOS/df"

# Copy the exe file into place
/bin/cp "${SRC_FOLDER}/dwarfort.exe" "${DEST_APP}/Contents/MacOS/"

# Create the Resources folder for all the data files
/bin/mkdir -p "${DEST_APP}/Contents/Resources"
# Copy the resources into place
# TODO: copy the icon file (dwarfort.icns) to the resources folder too
for f in "command line.txt" data "file changes.txt" libs raw README.osx readme.txt "release notes.txt" sdl; do
        /bin/cp -R "${SRC_FOLDER}/${f}" "${DEST_APP}/Contents/Resources/"
done


pushd "${DEST_APP}/Contents"
CONTENT_DIR=`pwd`
popd
#echo "CONTENT_DIR=${CONTENT_DIR}"
/usr/bin/defaults write "${CONTENT_DIR}/Info.plist" CFBundleShortVersionString ${VERSION}
/usr/bin/defaults write "${CONTENT_DIR}/Info.plist" CFBundleVersion ${VERSION}

## optional: uncomment to package up a dmg for distribution:
## Copy your app into "publish" (or rename the folder to whatever you like)
## This folder should contain DwarfFortress.app and whatever other resources you want in the DMG (README files etc)
#PUBLISH_FOLDER=publish
#/usr/bin/hdiutil create -volname DwarfFortress -srcfolder ${PUBLISH_FOLDER}/ -ov -format UDIF -fs HFS+ ./DwarfFortress_${VERSION}.dmg
TagsNo tags attached.

Activities

lethosor

2023-12-26 19:50

manager   ~0041993

Converting to public so that other people can find this issue by searching. I'm not seeing any personal information that should prevent this report from being publicly visible.

Add Note

Note

Issue History

Date Modified Username Field Change
2016-08-23 15:58 snoerr New Issue
2016-08-25 13:34 Loci Assigned To => Toady One
2016-08-25 13:34 Loci Status new => acknowledged
2023-12-26 19:50 lethosor Note Added: 0041993
2023-12-26 19:50 lethosor View Status private => public