diff --git a/.gitignore b/.gitignore index 79079cea..49a27453 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ src/wx/cmd-evtable.h src/wx/cmdhandlers.h src/wx/cmdtab.cpp src/wx/wxvbam.xrs -build* +build/* # vim swap files *.sw? diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ad859b2..27f1faf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -291,7 +291,7 @@ IF(WIN32) find_package(Git) if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") set(git_checkout TRUE) - execute_process(COMMAND "${GIT_EXECUTABLE}" submodule update --remote --recursive RESULT_VARIABLE git_status) + execute_process(COMMAND "${GIT_EXECUTABLE}" submodule update --remote --recursive RESULT_VARIABLE git_status WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") endif() if(NOT (git_checkout AND git_status EQUAL 0)) diff --git a/cmake/GitTagVersion.cmake b/cmake/GitTagVersion.cmake index f6487ad5..6eb25b3a 100644 --- a/cmake/GitTagVersion.cmake +++ b/cmake/GitTagVersion.cmake @@ -6,7 +6,7 @@ function(git_version version revision version_release) find_package(Git) if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") # get latest version from tag history - execute_process(COMMAND "${GIT_EXECUTABLE}" tag "--format=%(align:width=20)%(refname:short)%(end)%(if)%(*objectname)%(then)%(*objectname)%(else)%(objectname)%(end)" --sort=-creatordate OUTPUT_VARIABLE tags OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND "${GIT_EXECUTABLE}" tag "--format=%(align:width=20)%(refname:short)%(end)%(if)%(*objectname)%(then)%(*objectname)%(else)%(objectname)%(end)" --sort=-creatordate OUTPUT_VARIABLE tags OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") # if no tags (e.g. shallow clone) do nothing if(tags STREQUAL "") @@ -16,7 +16,7 @@ function(git_version version revision version_release) # convert to list of the form [tag0, ref0, tag1, ref1, ...] string(REGEX REPLACE "[ \n]+" ";" tags "${tags}") - execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD OUTPUT_VARIABLE current_ref OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD OUTPUT_VARIABLE current_ref OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") # if cannot get current ref, do nothing if(current_ref STREQUAL "") @@ -53,7 +53,7 @@ function(git_version version revision version_release) if(NOT "${${version_release}}" AND "${${revision}}" STREQUAL "") # dev version, use short sha for ref - execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD OUTPUT_VARIABLE short_sha OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD OUTPUT_VARIABLE short_sha OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") set(${revision} "${short_sha}" CACHE STRING "Latest Git Tag Revision" FORCE) endif() endif() diff --git a/src/common/ConfigManager.cpp b/src/common/ConfigManager.cpp index e2db1c9b..3cc21c95 100644 --- a/src/common/ConfigManager.cpp +++ b/src/common/ConfigManager.cpp @@ -15,6 +15,7 @@ extern "C" { #include #include #include +#include #include "../common/Patch.h" #include "../common/ConfigManager.h" diff --git a/tools/osx/builder b/tools/osx/builder new file mode 100755 index 00000000..b5f52e3a --- /dev/null +++ b/tools/osx/builder @@ -0,0 +1,276 @@ +#!/bin/sh + +set -e + +BUILD_ROOT=$HOME/vbam-build + +# build env +export MACOSX_DEPLOYMENT_TARGET=10.7 +export CFLAGS="-I$BUILD_ROOT/root/include" +export CPPFLAGS="-I$BUILD_ROOT/root/include" +export CXXFLAGS="-I$BUILD_ROOT/root/include -std=c++11 -stdlib=libc++" +export OBJCXXFLAGS="-I$BUILD_ROOT/root/include -std=c++11 -stdlib=libc++" +export LDFLAGS="-L$BUILD_ROOT/root/lib" +export CMAKE_PREFIX_PATH="$BUILD_ROOT/root" +export PKG_CONFIG_PATH="$BUILD_ROOT/root/lib/pkgconfig" +export PATH="$BUILD_ROOT/root/bin:$PATH" + +DISTS=' + gettext http://ftp.gnu.org/pub/gnu/gettext/gettext-latest.tar.xz libintl.a + openssl https://www.openssl.org/source/openssl-1.0.2l.tar.gz libssl.a + libpng https://download.sourceforge.net/libpng/libpng-1.6.32.tar.xz libpng.a + libjpeg-turbo https://github.com/libjpeg-turbo/libjpeg-turbo/archive/1.5.2.tar.gz libjpeg.a + libtiff http://dl.maptools.org/dl/libtiff/tiff-3.8.2.tar.gz libtiff.a + sdl2 https://www.libsdl.org/release/SDL2-2.0.6.tar.gz libSDL2.a + sfml https://www.sfml-dev.org/files/SFML-2.4.2-sources.zip libsfml-system-s.a + wxwidgets https://github.com/wxWidgets/wxWidgets/releases/download/v3.0.3/wxWidgets-3.0.3.tar.bz2 libwx_baseu-3.0.a + ffmpeg http://ffmpeg.org/releases/ffmpeg-3.3.4.tar.xz libavformat.a +' + +CONFIGURE_ARGS="--disable-shared --enable-static --prefix=$BUILD_ROOT/root" +CMAKE_ARGS="-DCMAKE_PREFIX_PATH=$BUILD_ROOT/root -DCMAKE_INSTALL_PREFIX=$BUILD_ROOT/root" + +DIST_OVERRIDES=" + openssl darwin64-x86_64-cc no-shared --prefix=$BUILD_ROOT/root +" + +DIST_ARGS=" + sfml -DBUILD_SHARED_LIBS=NO + wxwidgets --with-macosx-version-min=$MACOSX_DEPLOYMENT_TARGET --enable-stl LDFLAGS=-stdlib=libc++ +" + +main() { + setup + download_dists + build_dists + build_project +} + +setup() { + mkdir -p "$BUILD_ROOT" + + i=0 + DIST_NAMES= + for item in $DISTS; do + if [ $((i % 3)) -eq 0 ]; then + DIST_NAMES="$DIST_NAMES $item" + fi + i=$((i + 1)) + done + + i=0 + DIST_TARGETS= + for item in $DISTS; do + if [ $((i % 3)) -eq 2 ]; then + DIST_TARGETS="$DIST_TARGETS $item" + fi + i=$((i + 1)) + done + + NUM_CPUS=$(sysctl -n hw.ncpu) + + CHECKOUT=$(find_checkout) +} + +download_dists() { + mkdir -p "$BUILD_ROOT/dists" + + i=0 + for item in $DISTS; do + if [ $((i % 3)) -eq 0 ]; then + dist_name=$item + elif [ $((i % 3)) -eq 1 ]; then + dist_url=$item + dist_file="$BUILD_ROOT/dists/${dist_url##*/}" + + cd "$BUILD_ROOT/dists" + if [ ! -e "$dist_file" ]; then + echo "\nFetching $dist_name: $dist_url\n" + curl -LO "$dist_url" + fi + + dist_dir="$BUILD_ROOT/libs/$dist_name" + + if [ ! -d "$dist_dir" ]; then + mkdir -p "$dist_dir" + + tmp_dir="$BUILD_ROOT/libs/tmp" + mkdir -p "$tmp_dir" + cd "$tmp_dir" + + case "$dist_file" in + *.tar.gz) + 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" + fi + fi + + i=$((i + 1)) + done +} + +build_dists() { + cd "$BUILD_ROOT/libs" + + i=0 + for dist in $DIST_NAMES; do + target_lib="$BUILD_ROOT/root/lib/$(list_get $i $DIST_TARGETS)" + + if [ ! -e "$target_lib" ]; then + cd "$dist" + + if [ -e configure -o -e configure.ac -o -e configure.in -o -e Makefile.am ]; then + echo "\nBuilding $dist\n" + + if [ ! -e configure ]; then + aclocal + glibtoolize + autoheader + autoconf + [ -e Makefile.am ] && automake --add-missing + fi + + ./configure $(dist_args "$dist" autoconf) + make -j$NUM_CPUS + make install prefix=$BUILD_ROOT/root + + echo "\nDone!!!\n" + elif [ -e CMakeLists.txt ]; then + echo "\nBuilding $dist\n" + + mkdir -p build + cd build + + cmake .. $(dist_args "$dist" cmake) + make -j$NUM_CPUS + rm -rf destdir + mkdir destdir + make install DESTDIR="$PWD/destdir" + + cd "$PWD/destdir/$BUILD_ROOT/root" + find . ! -type d | (cd "$BUILD_ROOT/root"; IFS=' +'; while read f; do + mkdir -p "${f%/*}" + cp -a "$BUILD_ROOT/libs/$dist/build/destdir/$BUILD_ROOT/root/$f" "$f" + done) + + cd "$BUILD_ROOT/libs/$dist" + + echo "\nDone!!!\n" + fi + + cd .. + fi + + i=$((i + 1)) + done +} + +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 name required' + buildsys=$2 + [ "$buildsys" = autoconf -o "$buildsys" = cmake ] || \ + error "buildsystem type required, must be 'autoconf' or 'cmake'" + + 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")" + ;; + esac + fi + + echo "$args" + + return 0 +} + +table_line() { + name=$1 + [ -n "$name" ] || error 'item name required' + table=$2 + [ -n "$table" ] || error 'table string required' + + 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" -DENABLE_FFMPEG=OFF -DSFML_STATIC_LIBRARIES=TRUE + make -j$NUM_CPUS + + echo "\nBuild Successful!!!\n\nBuild results can be found in: $BUILD_ROOT/project\n" +} + +main "$@"