#!/bin/sh set -e BUILD_ROOT=$HOME/vbam-build build_env() { cat </dev/null; then glibtoolize else libtoolize fi autoheader || : autoconf [ -e Makefile.am ] && automake --add-missing fi fi eval "set -- $(dist_args "$dist" autoconf) $extra_dist_args" ./configure "$@" eval "set -- $(dist_make_args "$dist")" make -j$NUM_CPUS "$@" make install prefix=$BUILD_ROOT/root elif [ -e CMakeLists.txt ]; then mkdir -p build cd build eval "set -- $(dist_args "$dist" cmake) $extra_dist_args" cmake .. "$@" eval "set -- $(dist_make_args "$dist")" make -j$NUM_CPUS "$@" rm -rf destdir mkdir destdir make install DESTDIR="$PWD/destdir" cd "destdir/$BUILD_ROOT/root" OLDPWD=$PWD find . ! -type d | (cd "$BUILD_ROOT/root";IFS=' '; while read f; do mkdir -p "${f%/*}" cp -a "$OLDPWD/$f" "$f" done) elif [ -e Makefile.PL ]; then eval "set -- $(dist_args "$dist" perl) $extra_dist_args" perl Makefile.PL "$@" eval "set -- $(dist_make_args "$dist")" make -j$NUM_CPUS "$@" make install elif [ -e Makefile ]; then eval "set -- $(dist_make_args "$dist")" make -j$NUM_CPUS "$@" make install PREFIX="$BUILD_ROOT/root" INSTALL_ROOT="$BUILD_ROOT/root" else error "don't know how to build $dist" fi dist_post_build "$dist" export LDFLAGS=$ORIG_LDFLAGS echo "\nDone!!!\n" } list_get() { i=0 n=${1:=0} shift for item; do if [ $i -eq $n ]; then echo "$item" return 0 fi i=$((i + 1)) done } dist_args() { dist=$1 [ -n "$dist" ] || error 'dist_args: dist name required' buildsys=$2 case "$buildsys" in autoconf|cmake|perl) ;; *) error "dist_args: buildsystem type required, must be 'autoconf', 'cmake' or 'perl'" ;; esac args=$(table_line "$dist" "$DIST_OVERRIDES") if [ -z "$args" ]; then case "$buildsys" in autoconf) args="$CONFIGURE_ARGS $(table_line "$dist" "$DIST_ARGS")" ;; cmake) args="$CMAKE_ARGS $(table_line "$dist" "$DIST_ARGS")" ;; perl) args="$(table_line "$dist" "$DIST_ARGS")" ;; esac fi echo "$args" return 0 } dist_make_args() { dist=$1 [ -n "$dist" ] || error 'dist_make_args: dist name required' echo "$(table_line "$dist" "$DIST_MAKE_ARGS")" return 0 } dist_patch() { [ -n "$1" ] || error 'dist_patch: dist name required' _patch_url="$(table_line "$1" "$DIST_PATCHES")" [ -n "$_patch_url" ] || return 0 echo "\nApplying patch $_patch_url to $1\n" curl -LO "$_patch_url" patch -p1 < "${_patch_url##*/}" echo "\nDone!!!\n" } dist_pre_build() { [ -n "$1" ] || error 'dist_pre_build: dist name required' _cmd=$(table_line "$1" "$DIST_PRE_BUILD") [ -n "$_cmd" ] || return 0 echo "\nRunning pre-build for: $dist:\n$_cmd\n" eval "$_cmd" } dist_post_build() { [ -n "$1" ] || error 'dist_post_build: dist name required' _cmd=$(table_line "$1" "$DIST_POST_BUILD") [ -n "$_cmd" ] || return 0 if [ -z "$IN_DIST_POST_BUILD" ]; then IN_DIST_POST_BUILD=1 echo "\nRunning post-build for: $dist:\n$_cmd\n" eval "$_cmd" IN_DIST_POST_BUILD= fi } table_line() { name=$1 [ -n "$name" ] || error 'item name required' table=$2 [ -n "$table" ] || error 'table string required' table=$(echo "$table" | grep -Ev '^ *#') OLDIFS=$IFS IFS=' ' for line in $table; do IFS=$OLDIFS set -- $line if [ "$1" = "$name" ]; then shift echo "$@" return 0 fi done IFS=$OLDIFS } find_checkout() { ( cd "$(dirname "$0")" while [ "$PWD" != / ]; do if [ -e src/version.h.in ]; then echo "$PWD" exit 0 fi cd .. done exit 1 ) || error 'cannot find project checkout' } error() { printf >&2 '\nERROR: %s\n\n' "$1" [ -z "$2" ] && exit 1 } build_project() { echo "\nBuilding project: $CHECKOUT\n" mkdir -p "$BUILD_ROOT/project" cd "$BUILD_ROOT/project" cmake "$CHECKOUT" -DCMAKE_PREFIX_PATH="$BUILD_ROOT/root" -DCMAKE_BUILD_TYPE=Release -DSFML_STATIC_LIBRARIES=TRUE -DENABLE_FFMPEG=ON -DFFMPEG_STATIC=TRUE make -j$NUM_CPUS codesign -s "Developer ID Application" --deep ./visualboyadvance-m.app || : rm -f ./visualboyadvance-m-Mac.zip zip -9r ./visualboyadvance-m-Mac.zip ./visualboyadvance-m.app echo "\nBuild Successful!!!\n\nBuild results can be found in: $BUILD_ROOT/project\n" } table_column() { col=$1 [ -n "$col" ] || error 'table_column: column required' row_size=$2 [ -n "$row_size" ] || error 'table_column: row_size required' table=$3 [ -n "$table" ] || error 'table_column: table required' table=$(echo "$table" | grep -Ev '^ *#') i=0 res= for item in $table; do if [ $((i % row_size)) -eq "$col" ]; then res="$res $item" fi i=$((i + 1)) done echo $res return 0 } table_rows() { table=$1 [ -n "$table" ] || error 'table_rows: table required' table=$(echo "$table" | grep -Ev '^ *#') i=0 OLDIFS=$IFS IFS=' '; for line in $table; do i=$((i + 1)) done IFS=$OLDIFS echo $i return 0 } list_contains() { _item=$1 [ -n "$_item" ] || error 'list_contains: item required' shift for _pos; do [ "$_item" = "$_pos" ] && return 0 done return 1 } main "$@"