Skip to content

Commit

Permalink
Merge pull request #153 from h0tw1r3/feature/packaging
Browse files Browse the repository at this point in the history
Packaging
  • Loading branch information
mickelson committed Sep 23, 2015
2 parents 334b2ec + 172768a commit 313fb60
Show file tree
Hide file tree
Showing 14 changed files with 301 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ datadir=$(datarootdir)
exec_prefix=$(prefix)
bindir=$(exec_prefix)/bin

DATA_PATH=$(datadir)/attract/
DATA_PATH:=$(datadir)/attract/
EXE_BASE=attract
EXE_EXT=
OBJ_DIR=obj
Expand Down Expand Up @@ -363,7 +363,7 @@ EXPATOBJS = \
$(EXPAT_OBJ_DIR)/xmlrole.o \
$(EXPAT_OBJ_DIR)/xmltok.o

$(OBJ_DIR)/libexpat.a: $(EXPATOBJS) | $(OBJ_DIR)
$(OBJ_DIR)/libexpat.a: $(EXPATOBJS) | $(EXPAT_OBJ_DIR)
$(AR) $(ARFLAGS) $@ $(EXPATOBJS)

$(EXPAT_OBJ_DIR)/%.o: $(EXTLIBS_DIR)/expat/%.c | $(EXPAT_OBJ_DIR)
Expand Down
3 changes: 2 additions & 1 deletion src/fe_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <SFML/Window/VideoMode.hpp>
#include <SFML/System/Vector2.hpp>

Expand Down Expand Up @@ -208,7 +209,7 @@ FeInputSource::FeInputSource( const sf::Event &e, const sf::IntRect &mc_rect, co
break;

case sf::Event::JoystickMoved:
if ( abs( e.joystickMove.position ) > joy_thresh )
if ( std::abs( e.joystickMove.position ) > joy_thresh )
{
m_type = (Type)(Joystick0 + e.joystickMove.joystickId);

Expand Down
3 changes: 2 additions & 1 deletion src/fe_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>
#include <cmath>

class FeConfigContextImp : public FeConfigContext
{
Expand Down Expand Up @@ -1024,7 +1025,7 @@ bool FeOverlay::event_loop( FeEventLoopCtx &ctx )
float pos = sf::Joystick::getAxisPosition(
ctx.move_event.joystickMove.joystickId,
ctx.move_event.joystickMove.axis );
if ( abs( pos ) > m_feSettings.get_joy_thresh() )
if ( std::abs( pos ) > m_feSettings.get_joy_thresh() )
cont=true;
}
break;
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "fe_vm.hpp"
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>

#ifndef NO_MOVIE
Expand Down Expand Up @@ -809,7 +810,7 @@ int main(int argc, char *argv[])
float pos = sf::Joystick::getAxisPosition(
move_event.joystickMove.joystickId,
move_event.joystickMove.axis );
if ( abs( pos ) > feSettings.get_joy_thresh() )
if ( std::abs( pos ) > feSettings.get_joy_thresh() )
cont=true;
}
break;
Expand Down
8 changes: 4 additions & 4 deletions util/create-windows-pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ fi
cp -r *.md *.txt config/* stage/
cp -r ../extras/* stage/

# output changelog
util/output-changelog-md.sh $1 > stage/Changelog.md

# Unix to Windows line endings
#
sed -i 's/$/\r/' `find stage/ -name '*.*' | grep -e .md -e .txt -e .cfg -e .nut -e .nutr -e .msg -e .frag`

# special case due to space in name
sed -i 's/$/\r/' "stage/layouts/particle animation/layout.nut"
find stage -type f -regextype posix-egrep -regex '.*\.(md|txt|cfg|nut|nutr|msg|frag)$' -print0 | xargs -0 sed -i 's/$/\r/'

# Build and zip 32-bit windows version
#
Expand Down
Binary file added util/osx/DS_Store
Binary file not shown.
30 changes: 30 additions & 0 deletions util/osx/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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>CFBundleIconFile</key>
<string>attract.icns</string>
<key>CFBundleExecutable</key>
<string>launch.sh</string>
<key>CFBundleIdentifier</key>
<string>org.attractmode.attract</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Attract</string>
<key>CFBundleDisplayName</key>
<string>AttradeMode</string>
<key>CFBundleSpokenName</key>
<string>Attract Mode</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>%%SHORTVERSION%%</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>%%BUNDLEVERSION%%</string>
</dict>
</plist>
Binary file added util/osx/VolumeIcon.icns
Binary file not shown.
Binary file added util/osx/attract.icns
Binary file not shown.
Binary file added util/osx/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions util/osx/bundlelibs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python
# coding: utf-8

# Recursively change dynamic library link paths for non-system libraries
# to be relative to the linked program and copy them to <program>/../libs
#
# TODO: parse individual architectures (necessary?)
# modify temp lib instead of assuming path changes work
#
# Gist: https://gist.github.com/h0tw1r3/b12752f8e33f70422fbe
# Copyright: © 2015 Jeffrey Clark
# License: GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)

import os, stat, sys, subprocess, re, shutil

toolchain = os.getenv('TOOLCHAIN')
if toolchain == None:
toolchain = ""
else:
toolchain += "-"
otool = toolchain + "otool"
install_name_tool = toolchain + "install_name_tool"

def runOtool(filename):
p = subprocess.Popen([otool, '-XL', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return iter(p.stdout.readline, b'')

def fixname(filename, old, new):
p = subprocess.Popen([install_name_tool, '-change', old, new, filename], stdout=subprocess.PIPE)
p.communicate()
return

def fixid(filename, newid):
p = subprocess.Popen([install_name_tool, '-id', '@loader_path/../libs/' + newid, filename], stdout=subprocess.PIPE)
p.communicate()
return

def cmd_exists(cmd):
return subprocess.call("type " + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0

def mainloop(filename):
for line in runOtool(filename):
m = re.search('\s+/((usr|opt)/local/.*) \(.*\)$', line)
if m and len(m.group(1)) != 0:
path = os.path.realpath( os.path.join(os.getenv('LIB_BASE_PATH','/'),m.group(1)) )
linkname = os.path.basename( path )
if os.path.isfile( '../libs/' + linkname ) is False:
try:
shutil.copy2(path, '../libs/')
os.chmod('../libs/' + linkname, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH )
fixid('../libs/' + linkname, linkname)
mainloop('../libs/' + linkname)
except IOError as e:
print e
continue
fixname( filename, '/' + m.group(1), '@loader_path/../libs/' + linkname )
else:
m = re.search('\s+(@rpath(.*)) \(.*\)$', line)
if m and len(m.group(2)) != 0:
path = os.path.realpath(os.path.join(os.getenv('LIB_BASE_PATH','/'), 'usr/local/lib', m.group(2)))
print path
linkname = os.path.basename(path)
fixname(filename, m.group(1), '@loader_path/../libs/' + linkname)

if (len(sys.argv) != 2):
print "Usage: " + os.path.basename(sys.argv[0]) + " executable"
sys.exit(1)
if (not cmd_exists(otool)):
raise ValueError('Unable to execute otool: ' + otool)
if (not cmd_exists(install_name_tool)):
raise ValueError('Unable to execute install_name_tool: ' + install_name_tool)
if (not os.path.isfile(sys.argv[1])):
raise ValueError('File does not exist: ' + sys.argv[1])
if (not os.access(sys.argv[1], os.W_OK)):
raise ValueError('Unable to write to file: ' + sys.argv[1])

mainloop(sys.argv[1])
121 changes: 121 additions & 0 deletions util/osx/create-pkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/env bash
#
# Copyright: © 2015 Jeffrey Clark
# License: GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)

### begin: init
set -o pipefail
set -o errtrace

error() {
echo "ERROR in $0 : line $1 exit code $2"
exit $2
}
trap 'error ${LINENO} ${?}' ERR

SCRIPT_PATH="${BASH_SOURCE[0]}";
if ([ -h "${SCRIPT_PATH}" ]) then
while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done
fi
pushd . > /dev/null
cd `dirname ${SCRIPT_PATH}` > /dev/null
SCRIPT_PATH=`pwd`;
cd ..
### end: init

LASTTAG=$(git describe --tag --abbrev=0)
VERSION=$(git describe --tag | sed 's/-[^-]*$//')
REVCOUNT=$(git rev-list HEAD --count)
BUNDLEVERSION=${VERSION//[v-]/.}; BUNDLEVERSION=${BUNDLEVERSION#"."}
SHORTVERSION=${LASTTAG//v/}

### begin: make
PLATFORM=$(uname)
MAKEOPTS=""

# osxcross auto-detect
if [[ "$PLATFORM" != "Darwin" ]]; then
! [ -x "$(command -v hfsplus)" ] && echo "FATAL: 'hfsplus' not found" && exit 1
! [ -x "$(command -v mkfs.hfsplus)" ] && echo "FATAL: 'mkfs.hfs' not found" && exit 1
! [ -x "$(command -v dmg)" ] && echo "FATAL: 'dmg' not found" && exit 1

if [[ -z ${OSXCROSS_TARGET_DIR} || -z ${OSXCROSS_TARGET} ]]; then
echo "osxcross not initialized. add osxcross-conf and osxcross-env to the current environment" && exit 1
fi

[[ -z ${TOOLCHAIN} ]] && export TOOLCHAIN=x86_64-apple-${OSXCROSS_TARGET}
[[ -z ${LIB_BASE_PATH} ]] && export LIB_BASE_PATH="$(realpath ${OSXCROSS_TARGET_DIR}/macports/pkgs)"

MAKEOPTS="$MAKEOPTS CROSS=1 TOOLCHAIN=${TOOLCHAIN} FE_MACOSX_COMPILE=1 EXTRA_CFLAGS=\"-arch i386 -arch x86_64\""
fi

NPROC=$(getconf _NPROCESSORS_ONLN)
LLIMIT=$(awk 'BEGIN{printf"%.1f",'${NPROC}'/2}')

make -C .. clean
eval make -C .. -j${NPROC} -l${LLIMIT} ${MAKEOPTS} DATA_PATH=../config/ $@
### end: make

function finish {
if [[ ! -z $SCRATCH && -d $SCRATCH ]] ; then
rm -rf "${SCRATCH}"
fi
}
trap finish EXIT

SCRATCH=$(mktemp -d -t package.XXXXXXXX)
APPCONTENT="${SCRATCH}"/disk/Attract.app/Contents

# Create bundle folder structure
mkdir -p "${APPCONTENT}"/{MacOS,Resources,libs}

cp -r ../config "${APPCONTENT}"/
[[ -d ../../extras ]] && cp -r ../../extras/* "${APPCONTENT}"/config/
cp -a ../attract "${APPCONTENT}"/MacOS/
cp -a "${SCRIPT_PATH}"/attract.icns "${APPCONTENT}"/Resources/
cp -a "${SCRIPT_PATH}"/launch.sh "${APPCONTENT}"/MacOS/

# Documentation
mkdir "${SCRATCH}/disk/Documentation"
cp -a ../License.txt ${SCRATCH}/disk/Documentation/
cp ../*.md "${SCRATCH}"/disk/Documentation/
./output-changelog-md.sh ${LASTTAG} > "${SCRATCH}"/disk/Documentation/Changelog.md

# convert markdown to html if possible
find "${SCRATCH}"/disk/Documentation/ -name '*.md' | while read f
do
fp="${X%.md}"
if ! [ -x "$(command -v pandoc)" ]; then
mv "${f}" "${fp}.txt"
else
pandoc -f markdown_github -t html5 "${f}" -o "${fp}.html" && rm "${f}"
fi
done

cat "${SCRIPT_PATH}"/Info.plist | sed 's/%%SHORTVERSION%%/'${SHORTVERSION}'/' | sed 's/%%BUNDLEVERSION%%/'${BUNDLEVERSION}'/' > "${APPCONTENT}"/Info.plist

cp osx/DS_Store "${SCRATCH}/disk/.DS_Store"
cp osx/VolumeIcon.icns "${SCRATCH}/disk/.VolumeIcon.icns"
mkdir "${SCRATCH}/disk/.background"
cp osx/background.png "${SCRATCH}/disk/.background/background.png"

# Copy extra libs to bundle and fix link path
pushd "${APPCONTENT}"/MacOS >/dev/null
${SCRIPT_PATH}/bundlelibs.py attract
popd >/dev/null

if [[ "$PLATFORM" != "Darwin" ]]; then
WORKDMG="${SCRATCH}/uncompressed.dmg"
dd if=/dev/zero of="${WORKDMG}" bs=1M count=128
mkfs.hfsplus -v "AttractMode" "${WORKDMG}"
hfsplus "${WORKDMG}" addall "${SCRATCH}/disk/"
hfsplus "${WORKDMG}" attr / C
hfsplus "${WORKDMG}" symlink " " /Applications
# TODO: genisoimage has drawbacks, but most people dont have libdmg-hfsplus built
# make conditional package based on best available tools.
# genisoimage -D -V "AttractMode ${VERSION#v}" -no-pad -r -apple -o ${SCRATCH}/uncompressed.dmg ${SCRATCH}/disk/
dmg dmg "${WORKDMG}" ../attract-${VERSION#v}.dmg
else
# TODO: mount dmg and set file attributes (volume icon) and create Application symlink
hdiutil create -volname "AttractMode" -srcfolder ${SCRATCH}/disk/ -ov -format UDBZ ../attract-${VERSION#v}.dmg
fi
3 changes: 3 additions & 0 deletions util/osx/launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
cd "${0%/*}"
./attract
58 changes: 58 additions & 0 deletions util/output-changelog-md.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
#
# Generate markdown format changelog
# from tag (default HEAD) to previous tag
# grouped by author
#
# Copyright: © 2015 Jeffrey Clark
# License: GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)

# set cwd
SCRIPT_PATH="${BASH_SOURCE[0]}";
if ([ -h "${SCRIPT_PATH}" ]) then
while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done
fi
pushd . > /dev/null
cd `dirname ${SCRIPT_PATH}` > /dev/null
SCRIPT_PATH=`pwd`;
cd ${SCRIPT_PATH}/..

if [ $# -eq 0 ] ; then
TAG=$(git describe --tag)
else
## Just for attractmode
if [[ $1 =~ ^v ]]; then
TAG=$1
else
TAG=v$1
fi
fi
PRETAG=$(git describe --tag --abbrev=0 ${TAG}^)

IFS=$'\r\n'

echo -e "# Changelog #"

RANGE="${TAG}..HEAD"
i=0
for author in $(git --no-pager log --no-merges --pretty=format:"%an" ${RANGE} | sort | uniq -c) ;
do
[ $i -eq 0 ] && echo -e "\n## Commits made after ${TAG} ##"
name=$(echo $author | sed 's/^\ *\([0-9]*\)\ \(.*\)$/\2/')
count=$(echo $author | sed 's/^\ *\([0-9]*\)\ \(.*\)$/\1/')
echo -e "\n### $name ($count commits)\n"
git --no-pager log --author="$name" --date=short --no-merges --pretty=format:"* %s" ${RANGE} | grep -v "(nw)\| NW\| nw"
(( i++ ))
done

RANGE="${PRETAG}..${TAG}"

echo -e "\n## Commits from ${PRETAG} to ${TAG}"

for author in $(git --no-pager log --no-merges --pretty=format:"%an" ${RANGE} | sort | uniq -c) ;
do
name=$(echo $author | sed 's/^\ *\([0-9]*\)\ \(.*\)$/\2/')
count=$(echo $author | sed 's/^\ *\([0-9]*\)\ \(.*\)$/\1/')
echo -e "\n### $name ($count commits)\n"
git --no-pager log --author="$name" --date=short --no-merges --pretty=format:"* %s" ${RANGE} | grep -v "(nw)\| NW\| nw"
done

0 comments on commit 313fb60

Please sign in to comment.