visualboyadvance-m/tools/osx/builder

580 lines
21 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
set -e
BUILD_ROOT=$HOME/vbam-build
build_env() {
cat <<EOF
export MACOSX_DEPLOYMENT_TARGET=10.7
export CFLAGS="-I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -framework Carbon -Wno-unused-command-line-argument -arch x86_64"
export CPPFLAGS="-I$BUILD_ROOT/root/include"
export CXXFLAGS="-I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -std=c++11 -stdlib=libc++ -framework Carbon -Wno-unused-command-line-argument -arch x86_64"
export OBJCXXFLAGS="-I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -std=c++11 -stdlib=libc++ -framework Carbon -Wno-unused-command-line-argument -arch x86_64"
export LDFLAGS="-L$BUILD_ROOT/root/lib -framework Carbon -Wno-unused-command-line-argument -arch x86_64"
export CMAKE_PREFIX_PATH="$BUILD_ROOT/root"
export PKG_CONFIG_PATH="$BUILD_ROOT/root/lib/pkgconfig"
export PERL_MB_OPT='--install_base $BUILD_ROOT/root/perl5'
export PERL_MM_OPT='INSTALL_BASE=$BUILD_ROOT/root/perl5'
export PERL5LIB="$BUILD_ROOT/root/perl5/lib/perl5"
export PERL_LOCAL_LIB_ROOT="$BUILD_ROOT/root/perl5"
export PATH="$BUILD_ROOT/root/bin:$BUILD_ROOT/root/perl5/bin:$PATH"
EOF
}
eval "$(build_env)"
DISTS='
nasm http://www.nasm.us/pub/nasm/releasebuilds/2.13.01/nasm-2.13.01.tar.xz bin/nasm
yasm http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz bin/yasm
zlib https://zlib.net/zlib-1.2.11.tar.gz lib/libz.a
xz https://tukaani.org/xz/xz-5.2.3.tar.xz lib/liblzma.a
bzip2 http://bzip.org/1.0.6/bzip2-1.0.6.tar.gz lib/libbz2.a
pcre https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.bz2 lib/libpcre.a
libffi ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz lib/libffi.a
libiconv https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz lib/libiconv.a
gettext http://ftp.gnu.org/pub/gnu/gettext/gettext-0.19.8.1.tar.xz lib/libintl.a
glib http://mirror.umd.edu/gnome/sources/glib/2.54/glib-2.54.1.tar.xz lib/libglib-2.0.a
openssl https://www.openssl.org/source/openssl-1.0.2l.tar.gz lib/libssl.a
libpng https://download.sourceforge.net/libpng/libpng-1.6.32.tar.xz lib/libpng.a
libjpeg-turbo https://github.com/libjpeg-turbo/libjpeg-turbo/archive/1.5.2.tar.gz lib/libjpeg.a
libtiff http://dl.maptools.org/dl/libtiff/tiff-3.8.2.tar.gz lib/libtiff.a
sdl2 https://www.libsdl.org/release/SDL2-2.0.6.tar.gz lib/libSDL2.a
sfml https://github.com/SFML/SFML/archive/2.4.2.tar.gz lib/libsfml-system-s.a
wxwidgets https://github.com/wxWidgets/wxWidgets/releases/download/v3.0.3/wxWidgets-3.0.3.tar.bz2 lib/libwx_baseu-3.0.a
xvidcore http://downloads.xvid.org/downloads/xvidcore-1.3.4.tar.bz2 lib/libxvidcore.a
fribidi http://fribidi.org/download/fribidi-0.19.7.tar.bz2 lib/libfribidi.a
libass https://github.com/libass/libass/releases/download/0.13.7/libass-0.13.7.tar.xz lib/libass.a
libgsm http://www.quut.com/gsm/gsm-1.0.17.tar.gz lib/libgsm.a
libmodplug https://github.com/Konstanty/libmodplug/archive/5a39f5913d07ba3e61d8d5afdba00b70165da81d.tar.gz lib/libmodplug.a
libopencore-amrnb https://downloads.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.5.tar.gz lib/libopencore-amrnb.a
opus https://archive.mozilla.org/pub/opus/opus-1.2.1.tar.gz lib/libopus.a
snappy https://github.com/google/snappy/archive/1.1.7.tar.gz lib/libsnappy.a
libsoxr https://downloads.sourceforge.net/project/soxr/soxr-0.1.2-Source.tar.xz lib/libsoxr.a
speex http://downloads.us.xiph.org/releases/speex/speex-1.2.0.tar.gz lib/libspeex.a
libvorbis https://github.com/xiph/vorbis/archive/v1.3.5.tar.gz lib/libvorbis.a
libogg http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.xz lib/libogg.a
libtheora https://github.com/Distrotech/libtheora/archive/17b02c8c564475bb812e540b551219fc42b1f75f.tar.gz lib/libtheora.a
vidstab https://github.com/georgmartius/vid.stab/archive/v1.1.0.tar.gz lib/libvidstab.a
libvo-amrwbenc https://github.com/mstorsjo/vo-amrwbenc/archive/v0.1.3.tar.gz lib/libvo-amrwbenc.a
mp3lame https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz lib/libmp3lame.a
libxml2 ftp://xmlsoft.org/libxml2/libxml2-2.9.6.tar.gz lib/libxml2.a
XML-NamespaceSupport https://cpan.metacpan.org/authors/id/P/PE/PERIGRIN/XML-NamespaceSupport-1.12.tar.gz perl5/lib/perl5/XML/NamespaceSupport.pm
XML-SAX-Base https://cpan.metacpan.org/authors/id/G/GR/GRANTM/XML-SAX-Base-1.09.tar.gz perl5/lib/perl5/XML/SAX/Base.pm
XML-SAX https://cpan.metacpan.org/authors/id/G/GR/GRANTM/XML-SAX-0.99.tar.gz perl5/lib/perl5/XML/SAX.pm
docbook2x https://downloads.sourceforge.net/project/docbook2x/docbook2x/0.8.8/docbook2X-0.8.8.tar.gz bin/docbook2man
expat https://github.com/libexpat/libexpat/archive/R_2_2_4.tar.gz lib/libexpat.a
graphite2 https://github.com/silnrsi/graphite/releases/download/1.3.10/graphite2-1.3.10.tgz lib/libgraphite2.a
freetype http://download.savannah.gnu.org/releases/freetype/freetype-2.8.tar.bz2 lib/libfreetype.a
harfbuzz https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-1.6.0.tar.bz2 lib/libharfbuzz.a
fontconfig https://www.freedesktop.org/software/fontconfig/release/fontconfig-2.12.6.tar.bz2 lib/libfontconfig.a
libbluray ftp://ftp.videolan.org/pub/videolan/libbluray/1.0.0/libbluray-1.0.0.tar.bz2 lib/libbluray.a
libvpx http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.6.1.tar.bz2 lib/libvpx.a
libwavpack http://www.wavpack.com/wavpack-5.1.0.tar.bz2 lib/libwavpack.a
libx264 ftp://ftp.videolan.org/pub/videolan/x264/snapshots/last_stable_x264.tar.bz2 lib/libx264.a
libx265 https://bitbucket.org/multicoreware/x265/downloads/x265_2.5.tar.gz lib/libx265.a
libxavs https://github.com/Distrotech/xavs/archive/distrotech-xavs-git.tar.gz lib/libxavs.a
libzmq https://github.com/zeromq/libzmq/releases/download/v4.2.2/zeromq-4.2.2.tar.gz lib/libzmq.a
# libzvbi https://downloads.sourceforge.net/project/zapping/zvbi/0.2.35/zvbi-0.2.35.tar.bz2 lib/libzvbi.a
ffmpeg http://ffmpeg.org/releases/ffmpeg-3.3.4.tar.xz lib/libavformat.a
'
CONFIGURE_ARGS="--disable-shared --enable-static --prefix=$BUILD_ROOT/root"
CMAKE_ARGS="-DBUILD_SHARED_LIBS=NO -DENABLE_SHARED=NO -DCMAKE_PREFIX_PATH=$BUILD_ROOT/root -DCMAKE_INSTALL_PREFIX=$BUILD_ROOT/root -DCMAKE_BUILD_TYPE=Release"
DIST_PATCHES='
docbook2x https://sourceforge.net/p/docbook2x/bugs/_discuss/thread/0cfa4055/f6a5/attachment/docbook2x.patch
graphite2 https://gist.githubusercontent.com/rkitover/418600634d7cf19e2bf1c3708b50c042/raw/b5e9ee6c237a588157a754de6705a56fc315b00a/graphite2-static.patch
'
DIST_PRE_BUILD="
expat cd expat; sed -i .bak 's/cp \\\$</mv \$</' doc/doc.mk
libmodplug sed -i .bak '/-mmacosx-version-min=/d' configure.ac; sed -i .bak 's/-lstdc++/-lc++/g' libmodplug.pc.in; rm -f configure
libzmq sed -i .bak 's/-lstdc++/-lc++/g' src/libzmq.pc.in
xvidcore cd build/generic; sed -i .bak '/^all:/{ s/ *\\\$(SHARED_LIB)//; }; /^install:/{ s, *\\\$(BUILD_DIR)/\\\$(SHARED_LIB),,; }; s/\\\$(INSTALL).*\\\$(SHARED_LIB).*/:/; s/\\\$(LN_S).*\\\$(SHARED_LIB).*/:/' Makefile
libx265 cd source
ffmpeg sed -i .bak 's/-lstdc++/-lc++/g' configure
"
DIST_POST_BUILD="
"
DIST_OVERRIDES="
zlib --static --prefix=$BUILD_ROOT/root
openssl darwin64-x86_64-cc no-shared --prefix=$BUILD_ROOT/root
"
DIST_ARGS="
pcre --enable-utf8 --enable-pcre8 --enable-pcre16 --enable-pcre32 --enable-unicode-properties --enable-pcregrep-libz --enable-pcregrep-libbz2 --enable-jit
libmodplug CC=clang++ CXX=clang++
freetype --with-harfbuzz=no
harfbuzz --with-cairo=no
libvpx --disable-unit-tests --disable-tools --disable-docs --disable-examples
libxavs --disable-asm
libzvbi --without-x --without-doxygen
libxml2 --without-python
wxwidgets --with-macosx-version-min=$MACOSX_DEPLOYMENT_TARGET --enable-stl LDFLAGS='$LDFLAGS -stdlib=libc++' --disable-precomp-headers
libbluray --disable-bdjava
libopencore-amrnb --disable-compile-c
vidstab -DUSE_OMP=NO
ffmpeg --extra-ldflags='-framework CoreText' --pkg-config-flags=--static --enable-nonfree --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-version3 --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzmq --enable-openssl --enable-lzma
#
# TODO: add these if possible (from brew) --enable-indev=qtkit --enable-securetransport --enable-chromaprint --enable-ffplay --enable-frei0r --enable-libbs2b --enable-libcaca --enable-libfdk-aac --enable-libgme --enable-libgsm --enable-librtmp --enable-librubberband --enable-libssh --enable-libtesseract --enable-libtwolame --enable-webp --enable-libzimg
#
# Possibly also: --enable-libzvbi
# I could not get libzvbi to build
#
# these require > 10.7:
# --enable-opencl # requires 10.8
# --enable-videotoolbox # requires 10.8
"
DIST_MAKE_ARGS="
expat DOCBOOK_TO_MAN=docbook2man
"
main() {
read_command_line "$@"
setup
delete_outdated_dists
download_dists
build_dists
build_project
}
read_command_line() {
case "$1" in
--env)
build_env
exit 0
;;
esac
}
setup() {
mkdir -p "$BUILD_ROOT/root/include"
[ -e "$BUILD_ROOT/root/inc" ] || ln -s "$BUILD_ROOT/root/include" "$BUILD_ROOT/root/inc"
DIST_NAMES=$( table_column 0 3 "$DISTS")
DIST_URLS=$( table_column 1 3 "$DISTS")
DIST_TARGETS=$(table_column 2 3 "$DISTS")
DISTS_NUM=$(table_rows "$DISTS")
NUM_CPUS=$(sysctl -n hw.ncpu)
CHECKOUT=$(find_checkout)
}
delete_outdated_dists() {
[ ! -d "$BUILD_ROOT/downloads" ] && return 0
files=
i=0
for dist in $DIST_NAMES; do
dist_url=$(list_get $i $DIST_URLS)
dist_file="$BUILD_ROOT/downloads/$dist-${dist_url##*/}"
files="$files $dist_file"
i=$((i + 1))
done
OLDIFS=$IFS
IFS='
'; find "$BUILD_ROOT/downloads" -type f -maxdepth 1 -not -name '.*' | \
while read -r file; do
IFS=$OLDIFS
if ! list_contains "$file" $files; then
echo "\nDeleting outdated dist: $file\n"
rm -f "$file"
fi
done
IFS=$OLDIFS
}
download_dists() {
mkdir -p "$BUILD_ROOT/downloads"
i=0
while [ $i -lt $DISTS_NUM ]; do
dist_name=$(list_get $i $DIST_NAMES)
dist_url=$( list_get $i $DIST_URLS)
orig_dist_file="$BUILD_ROOT/downloads/${dist_url##*/}"
dist_file="$BUILD_ROOT/downloads/$dist_name-${dist_url##*/}"
dist_dir="$BUILD_ROOT/dists/$dist_name"
cd "$BUILD_ROOT/downloads"
if [ ! -e "$dist_file" ]; then
echo "\nFetching $dist_name: $dist_url\n"
curl -LO "$dist_url"
mv -f "$orig_dist_file" "$dist_file"
# force rebuild for new dist file
rm -f "$BUILD_ROOT/root/$(list_get $i $DIST_TARGETS)"
rm -rf "$dist_dir"
fi
if [ ! -d "$dist_dir" ]; then
mkdir -p "$dist_dir"
tmp_dir="$BUILD_ROOT/dists/tmp"
mkdir -p "$tmp_dir"
cd "$tmp_dir"
case "$dist_file" in
*.tar)
tar xf "$dist_file"
;;
*.tar.gz|*.tgz)
tar zxf "$dist_file"
;;
*.tar.xz)
xzcat "$dist_file" | tar xf -
;;
*.tar.bz2)
bzcat "$dist_file" | tar xf -
;;
*.zip)
unzip -q "$dist_file"
;;
esac
mv */* "$dist_dir"
rm -rf "$tmp_dir"
# force rebuild if dist dir was deleted
rm -f "$BUILD_ROOT/root/$(list_get $i $DIST_TARGETS)"
fi
i=$((i + 1))
done
}
build_dists() {
i=0
while [ $i -lt $DISTS_NUM ]; do
install_artifact="$BUILD_ROOT/root/$(list_get $i $DIST_TARGETS)"
if [ ! -e "$install_artifact" ]; then
build_dist $(list_get $i $DIST_NAMES)
fi
i=$((i + 1))
done
}
build_dist() {
dist=$1
[ -n "$1" ] || error 'build_dist: dist name required'
shift
extra_dist_args=$@
cd "$BUILD_ROOT/dists/$dist"
echo "\nBuilding $dist\n"
ORIG_LDFLAGS=$LDFLAGS
# have to make sure C++ flags are passed when linking, but only for C++ and **NOT** C
# this fails if there are any .c files in the project
if [ "$(find . -name '*.cpp' -o -name '*.cc' | wc -l)" -ne 0 -a "$(find . -name '*.c' | wc -l)" -eq 0 ]; then
export LDFLAGS="$CXXFLAGS $LDFLAGS"
fi
dist_patch "$dist"
dist_pre_build "$dist"
if [ -e configure -o -e configure.ac -o -e configure.in -o -e Makefile.am ]; then
if [ ! -e configure ]; then
if [ -e autogen.sh ]; then
sh autogen.sh
elif [ -e buildconf.sh ]; then
sh buildconf.sh
else
if [ -d m4 ]; then
aclocal -I m4
else
aclocal
fi
if command -v glibtoolize >/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 "$@"