Skip to content

Instantly share code, notes, and snippets.

@jessevanherk
Last active October 25, 2018 03:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jessevanherk/b805c2f67fd1124547493e2a87ba685f to your computer and use it in GitHub Desktop.
Save jessevanherk/b805c2f67fd1124547493e2a87ba685f to your computer and use it in GitHub Desktop.
A sample makefile and support files to build a love2d game for multiple platforms from linux
[Desktop Entry]
Name=PRETTYNAMEHERE
GenericName=PRETTYNAMEHERE
Comment=
Exec=LCNAMEHERE
Icon=LCNAMEHERE
Terminal=false
Type=Application
Categories=Game;
--- launcher.sh 2014-08-28 18:53:05.345816236 -0600
+++ launcher.sh.debian 2014-08-28 19:10:59.757848253 -0600
@@ -17,9 +17,9 @@
# Figure out where things are installed.
# these can be patched by your distro, or otherwise edited.
-BASE_DIR="${0%/*}"
+BASE_DIR=/usr
BIN_DIR="$BASE_DIR/bin"
-LIB_DIR="$BASE_DIR/lib"
+LIB_DIR="$BASE_DIR/lib/$GAME_LC_NAME"
# Add our local LIB path to be searched first. If something here doesn't work,
# you can replace the library files, or symlink them, or remove them entirely.
#!/bin/bash
# LOVE Game Launcher for Linux
# by Jesse van Herk <jesse@imaginaryrobots.net>
#
# based on:
# http://stackoverflow.com/questions/7099712/whats-the-accepted-method-for-deploying-a-linux-application-that-relies-on-shar
# this will be filled in by Makefile/patch.
GAME_NAME=FOOBAR
GAME_LC_NAME=`echo ${GAME_NAME} | tr '[:upper:]' '[:lower:]'`
# Figure out architecture
ARCH="x86"
if [ "$(uname -m)" == "x86_64" ]
then
ARCH="x86_64"
fi
# Figure out where things are installed.
# these can be patched by your distro, or otherwise edited.
BASE_DIR="${0%/*}"
BIN_DIR="$BASE_DIR/bin"
LIB_DIR="$BASE_DIR/lib"
# Add our local LIB path to be searched first. If something here doesn't work,
# you can replace the library files, or symlink them, or remove them entirely.
# Or if you have a working love 0.9 install, just comment this line out.
export LD_LIBRARY_PATH="$LIB_DIR/$ARCH:$LD_LIBRARY_PATH"
echo "Launching game..."
# Run the appropriate game executable, pass along arguments.
exec "$BIN_DIR/${GAME_NAME}.$ARCH" "$@"
# if none of that worked, just install love, and run the .love file manually.
exit $?
LOVE_BIN=/usr/bin/love
LOVE_DIR=./src/love
DIST_DIR=./src/dist
PATCH_DIR=./src/patch
BUILD_DIR=./build
BIN_DIR=./bin
LOVE_VERSION=0.9.1
GAME_NAME=MySampleGame
PRETTY_NAME=My Sample Game
GAME_IDENTIFIER=com.example.mysamplegame
GAME_COPYRIGHT=© 2016 Your Name Here
GAME_MAINTAINER=Your Name Here \<yourname@example.com\>
GAME_LC_NAME=$(shell echo ${GAME_NAME} | tr '[:upper:]' '[:lower:]')
GAME_VERSION=$(shell cat version.txt)
GAME_DOT_VERSION=$(shell echo ${GAME_VERSION} | tr '_' '.')
ZIP_IGNORE=$(addprefix -x , \*.swp .git/\* .bzr/\* *.log ${LOVE_DIR}/\* ${BUILD_DIR}/\* spec/\* .gitignore Makefile doc\/* src/\* ${BIN_DIR}/\*)
#EXTRA_FILES=README.md licenses.txt EULA.md version.txt
EXTRA_FILES=README.md version.txt
ICON_OPTIONS=-flatten -background transparent
all: clean windows osx linux
test:
busted
clean:
rm -rf -- ${BUILD_DIR}
mkdir -p ${BUILD_DIR}
icons:
# make different icon sizes, for OSX, windows, and Linux
mkdir -p ${BUILD_DIR}/icons
convert ${ICON_OPTIONS} -resize 16x16 src/images/game_icon.xcf ${BUILD_DIR}/icons/icon_16.png
convert ${ICON_OPTIONS} -resize 24x24 src/images/game_icon.xcf ${BUILD_DIR}/icons/icon_24.png
convert ${ICON_OPTIONS} -resize 32x32 src/images/game_icon.xcf ${BUILD_DIR}/icons/icon_32.png
convert ${ICON_OPTIONS} -resize 48x48 src/images/game_icon.xcf ${BUILD_DIR}/icons/icon_48.png
convert ${ICON_OPTIONS} -resize 128x128 src/images/game_icon.xcf ${BUILD_DIR}/icons/icon_128.png
convert ${ICON_OPTIONS} -resize 256x256 src/images/game_icon.xcf ${BUILD_DIR}/icons/icon_256.png
convert ${ICON_OPTIONS} -resize 512x512 src/images/game_icon.xcf ${BUILD_DIR}/icons/icon_512.png
# make OSX icon bundle. doesn't use every size!
png2icns ${BUILD_DIR}/icons/${GAME_NAME}.icns \
${BUILD_DIR}/icons/icon_16.png ${BUILD_DIR}/icons/icon_32.png \
${BUILD_DIR}/icons/icon_128.png ${BUILD_DIR}/icons/icon_256.png \
${BUILD_DIR}/icons/icon_512.png
lovefile:
mkdir -p ${BUILD_DIR}/
# create the .love file in the build dir.
zip -9 ${ZIP_IGNORE} -r ${BUILD_DIR}/${GAME_NAME}.love .
# magic rule to create an appropriate fused binary for windows.
%.exe: lovefile
$(eval BUILD_NAME=${GAME_NAME}-${GAME_VERSION}-$*)
mkdir -p ${BUILD_DIR}/${BUILD_NAME}
cat ${LOVE_DIR}/love-${LOVE_VERSION}-$*/love.exe ${BUILD_DIR}/${GAME_NAME}.love > ${BUILD_DIR}/${BUILD_NAME}/${GAME_NAME}.exe
# magic rule to make zipfiles appropriate for windows distribution.
%.zip: %.exe
$(eval BUILD_NAME=${GAME_NAME}-${GAME_VERSION}-$*)
# add DLLs
cp ${LOVE_DIR}/love-${LOVE_VERSION}-$*/*.dll ${BUILD_DIR}/${BUILD_NAME}/
# add extra files
cp ${EXTRA_FILES} ${BUILD_DIR}/${BUILD_NAME}/
# create output zip at main build/ folder
cd ${BUILD_DIR}/ && zip -r ${BUILD_NAME}.zip ${BUILD_NAME}/
# create bin files for linux
%.bin: lovefile
$(eval BUILD_NAME=${GAME_NAME}-${GAME_VERSION}-$*)
mkdir -p ${BUILD_DIR}/${BUILD_NAME}/bin
cat ${LOVE_DIR}/love-${LOVE_VERSION}-$*/love.x86 ${BUILD_DIR}/${GAME_NAME}.love > ${BUILD_DIR}/${BUILD_NAME}/bin/${GAME_NAME}.x86
cat ${LOVE_DIR}/love-${LOVE_VERSION}-$*/love.x86_64 ${BUILD_DIR}/${GAME_NAME}.love > ${BUILD_DIR}/${BUILD_NAME}/bin/${GAME_NAME}.x86_64
# set permissions
chmod 0755 ${BUILD_DIR}/${BUILD_NAME}/bin/${GAME_NAME}.x86
chmod 0755 ${BUILD_DIR}/${BUILD_NAME}/bin/${GAME_NAME}.x86_64
# create a tarball. Works similar to the OSX version.
%.tgz: %.bin icons
$(eval BUILD_NAME=${GAME_NAME}-${GAME_VERSION}-$*)
mkdir -p ${BUILD_DIR}/${BUILD_NAME}
# copy in dist files
cp -Rp ${DIST_DIR}/linux/* ${BUILD_DIR}/${BUILD_NAME}/
# add love file.
cp ${BUILD_DIR}/${GAME_NAME}.love ${BUILD_DIR}/${BUILD_NAME}/
# edit the game name in the launcher
sed --in-place -e "s/GAME_NAME=.*/GAME_NAME=${GAME_NAME}/" ${BUILD_DIR}/${BUILD_NAME}/launcher.sh
# rename the .desktop file
mv ${BUILD_DIR}/${BUILD_NAME}/game.desktop ${BUILD_DIR}/${BUILD_NAME}/${GAME_LC_NAME}.desktop
sed --in-place -e "s/PRETTYNAMEHERE/${PRETTY_NAME}/" ${BUILD_DIR}/${BUILD_NAME}/${GAME_LC_NAME}.desktop
sed --in-place -e "s/LCNAMEHERE/${GAME_LC_NAME}/" ${BUILD_DIR}/${BUILD_NAME}/${GAME_LC_NAME}.desktop
# update the name in the desktop file
# add RELATIVE symlink for game name.
ln -fs -- launcher.sh ${BUILD_DIR}/${BUILD_NAME}/${GAME_LC_NAME}
# add extra files
cp ${EXTRA_FILES} ${BUILD_DIR}/${BUILD_NAME}/
# create the tarball at main build/ folder.
tar czvf ${BUILD_DIR}/${BUILD_NAME}.tgz -C ${BUILD_DIR} ${BUILD_NAME}/
# install rule is basically just for checkinstall to generate a fake deb
# install intentionally doesn't do any building.
# DESTDIR is passed in when make is invoked - defaults to empty.
%.install:
$(eval BUILD_NAME=${GAME_NAME}-${GAME_VERSION}-$*)
# install libs
mkdir -p ${DESTDIR}/usr/lib/${GAME_LC_NAME}/
mkdir -p ${DESTDIR}/usr/lib/${GAME_LC_NAME}/x86/
mkdir -p ${DESTDIR}/usr/lib/${GAME_LC_NAME}/x86_64/
install -m644 --target-directory=${DESTDIR}/usr/lib/${GAME_LC_NAME}/x86 ${BUILD_DIR}/${BUILD_NAME}/lib/x86/*
install -m644 --target-directory=${DESTDIR}/usr/lib/${GAME_LC_NAME}/x86_64 ${BUILD_DIR}/${BUILD_NAME}/lib/x86_64/*
# patch launcher with debian/install version. Ignore errors if it's already been applied.
-patch -N -i ${PATCH_DIR}/launcher-debian.patch ${BUILD_DIR}/${BUILD_NAME}/launcher.sh
# install the main binaries
install --target-directory=${DESTDIR}/usr/bin/ ${BUILD_DIR}/${BUILD_NAME}/bin/*
# install the game launcher
install -D ${BUILD_DIR}/${BUILD_NAME}/${GAME_LC_NAME} ${DESTDIR}/usr/bin/${GAME_LC_NAME}
# create docs dir. use mkdir because "install -d" flakes out checkinstall.
mkdir -p ${DESTDIR}/usr/share/doc/${GAME_LC_NAME}/
install -m644 --target-directory=${DESTDIR}/usr/share/doc/${GAME_LC_NAME}/ ${EXTRA_FILES}
# install icons
install -m644 -D ${BUILD_DIR}/icons/icon_16.png /usr/share/icons/hicolor/16x16/apps/${GAME_LC_NAME}.png
install -m644 -D ${BUILD_DIR}/icons/icon_48.png /usr/share/icons/hicolor/48x48/apps/${GAME_LC_NAME}.png
install -m644 -D ${BUILD_DIR}/icons/icon_32.png /usr/share/icons/hicolor/32x32/apps/${GAME_LC_NAME}.png
install -m644 -D ${BUILD_DIR}/icons/icon_24.png /usr/share/icons/hicolor/24x24/apps/${GAME_LC_NAME}.png
install -m644 -D ${BUILD_DIR}/icons/icon_256.png /usr/share/icons/hicolor/256x256/apps/${GAME_LC_NAME}.png
install -m644 -D ${BUILD_DIR}/icons/icon_512.png /usr/share/icons/hicolor/512x512/apps/${GAME_LC_NAME}.png
# install desktop file.
install -m644 -D ${BUILD_DIR}/${BUILD_NAME}/${GAME_LC_NAME}.desktop /usr/share/applications/${GAME_LC_NAME}.desktop
# Rule to build OSX .app bundle
%.app: lovefile icons
$(eval BUILD_NAME=${GAME_NAME}-${GAME_VERSION}-$*)
mkdir -p ${BUILD_DIR}/${BUILD_NAME}
cp -Rp ${DIST_DIR}/love.app ${BUILD_DIR}/${BUILD_NAME}/${GAME_NAME}.app
# copy the love file in.
cp ${BUILD_DIR}/${GAME_NAME}.love ${BUILD_DIR}/${BUILD_NAME}/${GAME_NAME}.app/Contents/Resources/
# copy the icon file in.
cp ${BUILD_DIR}/icons/${GAME_NAME}.icns ${BUILD_DIR}/${BUILD_NAME}/${GAME_NAME}.app/Contents/Resources/
# patch the plist file, substituting variables first
sed -e "s/GAME_NAME/${GAME_NAME}/g" \
-e "s/PRETTY_NAME/${PRETTY_NAME}/g" \
-e "s/GAME_IDENTIFIER/${GAME_IDENTIFIER}/g" \
-e "s/GAME_DOT_VERSION/${GAME_DOT_VERSION}/g" \
-e "s/GAME_COPYRIGHT/${GAME_COPYRIGHT}/g" \
${PATCH_DIR}/plist-osx.patch | patch -N ${BUILD_DIR}/${BUILD_NAME}/${GAME_NAME}.app/Contents/Info.plist
# build a compressed .app for OSX
%.appzip: %.app
$(eval BUILD_NAME=${GAME_NAME}-${GAME_VERSION}-$*)
mkdir -p ${BUILD_DIR}/${BUILD_NAME}
# add extra files.
cp ${EXTRA_FILES} ${BUILD_DIR}/${BUILD_NAME}/
# change to the output dir and create the zip at the main build folder.
cd ${BUILD_DIR}/${BUILD_NAME} && zip -r ../${BUILD_NAME}.zip *
%.deb: linux.tgz
fakeroot checkinstall --pkgname ${GAME_LC_NAME} -y -D --install=no \
--fstrans=yes \
--nodoc --deldoc --deldesc --backup=no \
--requires love \
--maintainer "${GAME_MAINTAINER}" \
--pkgarch "$*" --pkggroup games --pkglicense="${GAME_COPYRIGHT}" \
--pakdir ${BUILD_DIR} --pkgversion ${GAME_DOT_VERSION} \
make install
win32: win32.zip
win64: win64.zip
windows: win32 win64
osx: osx.appzip
# no longer building an i386 deb file - they can use the generic linux one.
linux: linux.tgz amd64.deb
install: linux.install
--- Info.plist 2014-08-30 01:33:54.958688622 -0600
+++ Info.plist.local 2014-08-30 01:34:39.898689962 -0600
@@ -8,49 +8,23 @@
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
- <dict>
- <key>CFBundleTypeIconFile</key>
- <string>LoveDocument.icns</string>
- <key>CFBundleTypeName</key>
- <string>LÖVE Project</string>
- <key>CFBundleTypeRole</key>
- <string>Viewer</string>
- <key>LSHandlerRank</key>
- <string>Owner</string>
- <key>LSItemContentTypes</key>
- <array>
- <string>org.love2d.love-game</string>
- </array>
- </dict>
- <dict>
- <key>CFBundleTypeName</key>
- <string>Folder</string>
- <key>CFBundleTypeOSTypes</key>
- <array>
- <string>fold</string>
- </array>
- <key>CFBundleTypeRole</key>
- <string>Viewer</string>
- <key>LSHandlerRank</key>
- <string>None</string>
- </dict>
</array>
<key>CFBundleExecutable</key>
<string>love</string>
<key>CFBundleIconFile</key>
- <string>Love.icns</string>
+ <string>GAME_NAME.icns</string>
<key>CFBundleIdentifier</key>
- <string>org.love2d.love</string>
+ <string>GAME_IDENTIFIER</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
- <string>LÖVE</string>
+ <string>PRETTY_NAME</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
- <string>0.9.1</string>
+ <string>GAME_DOT_VERSION</string>
<key>CFBundleSignature</key>
- <string>LoVe</string>
+ <string>PRETTY_NAME</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
@@ -68,7 +42,7 @@
<key>LSApplicationCategoryType</key>
<string>public.app-category.games</string>
<key>NSHumanReadableCopyright</key>
- <string>© 2006-2014 LÖVE Development Team</string>
+ <string>GAME_COPYRIGHT</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>UTExportedTypeDeclarations</key>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment