From 75e9ca47a52e9fd269e7471d0bcbf43bcfc61e60 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Thu, 20 Dec 2018 17:02:51 -0500 Subject: [PATCH 1/8] GEN-403 Fix linux build, stub in Raspberry Pi This is the first cut of a build for the Raspberry Pi. I worked this up on a Raspberry Pi 2 Model B, using Raspbian GNU/Linux 9.6 (stretch). It requires that we build cmake from source since the version included in stretch is too old. diff --git a/scripts/build.sh b/scripts/build.sh index a71a1ef..3d444be 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -10,7 +10,7 @@ set -o functrace IFS=$'\n\t' # Enable for enhanced debugging -#set -vx +${DEBUG:-false} && set -vx # Credit to https://stackoverflow.com/a/17805088 and http://wiki.bash-hackers.org/scripting/debuggingtips @@ -66,9 +66,9 @@ elif [ "$OS" == "Darwin" ]; then brew upgrade cmake || true elif [ "$(cut -c1-5 <<<"$OS")" == "Linux" ]; then # Do something under GNU/Linux platform - if ! command -v apt-get >/dev/null 2>&1; then + if command -v apt-get >/dev/null 2>&1; then ensure_debian_devtools_installed - elif ! command -v pacman >/dev/null 2>&1; then + elif command -v pacman >/dev/null 2>&1; then ensure_arch_devtools_installed else echo "Only debian/ubuntu and arch Linux are supported targets, sorry." diff --git a/scripts/common.sh b/scripts/common.sh index d79fdd0..853ae0b 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -39,14 +39,25 @@ function ensure_cmake { local cmake version=3.12 build=3 + arch=$(arch) tmpdir=$(mktemp -d) - cmake="cmake-$version.$build-Linux-x86_64" - cd "$tmpdir" || exit 1 - curl -sSO "https://cmake.org/files/v$version/$cmake.sh" - $SUDO mkdir /opt/cmake - yes | $SUDO sh "$cmake.sh" --prefix=/opt/cmake || true # exits 141 on success for some reason - $SUDO rm -f /usr/local/bin/cmake - $SUDO ln -s "/opt/cmake/$cmake/bin/cmake" /usr/local/bin/cmake + cmake="cmake-$version.$build-Linux-$arch" + cd "$tmpdir" + curl -fsSO "https://cmake.org/files/v$version/$cmake.sh" + if [[ -f "$cmake" ]]; then + $SUDO mkdir -p /opt/cmake + yes | $SUDO sh "$cmake.sh" --prefix=/opt/cmake || true # exits 141 on success for some reason + $SUDO rm -f /usr/local/bin/cmake + $SUDO ln -s "/opt/cmake/$cmake/bin/cmake" /usr/local/bin/cmake + else + cmake="cmake-$version.$build" + curl -fsSO "https://cmake.org/files/v$version/$cmake.tar.gz" + tar xfz "$cmake.tar.gz" + cd "$cmake" + ./configure + make + $SUDO make install + fi rm -rf "$tmpdir" } k --- scripts/build.sh | 6 +++--- scripts/common.sh | 25 ++++++++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index a71a1ef..3d444be 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -10,7 +10,7 @@ set -o functrace IFS=$'\n\t' # Enable for enhanced debugging -#set -vx +${DEBUG:-false} && set -vx # Credit to https://stackoverflow.com/a/17805088 # and http://wiki.bash-hackers.org/scripting/debuggingtips @@ -66,9 +66,9 @@ elif [ "$OS" == "Darwin" ]; then brew upgrade cmake || true elif [ "$(cut -c1-5 <<<"$OS")" == "Linux" ]; then # Do something under GNU/Linux platform - if ! command -v apt-get >/dev/null 2>&1; then + if command -v apt-get >/dev/null 2>&1; then ensure_debian_devtools_installed - elif ! command -v pacman >/dev/null 2>&1; then + elif command -v pacman >/dev/null 2>&1; then ensure_arch_devtools_installed else echo "Only debian/ubuntu and arch Linux are supported targets, sorry." diff --git a/scripts/common.sh b/scripts/common.sh index d79fdd0..853ae0b 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -39,14 +39,25 @@ function ensure_cmake { local cmake version=3.12 build=3 + arch=$(arch) tmpdir=$(mktemp -d) - cmake="cmake-$version.$build-Linux-x86_64" - cd "$tmpdir" || exit 1 - curl -sSO "https://cmake.org/files/v$version/$cmake.sh" - $SUDO mkdir /opt/cmake - yes | $SUDO sh "$cmake.sh" --prefix=/opt/cmake || true # exits 141 on success for some reason - $SUDO rm -f /usr/local/bin/cmake - $SUDO ln -s "/opt/cmake/$cmake/bin/cmake" /usr/local/bin/cmake + cmake="cmake-$version.$build-Linux-$arch" + cd "$tmpdir" + curl -fsSO "https://cmake.org/files/v$version/$cmake.sh" + if [[ -f "$cmake" ]]; then + $SUDO mkdir -p /opt/cmake + yes | $SUDO sh "$cmake.sh" --prefix=/opt/cmake || true # exits 141 on success for some reason + $SUDO rm -f /usr/local/bin/cmake + $SUDO ln -s "/opt/cmake/$cmake/bin/cmake" /usr/local/bin/cmake + else + cmake="cmake-$version.$build" + curl -fsSO "https://cmake.org/files/v$version/$cmake.tar.gz" + tar xfz "$cmake.tar.gz" + cd "$cmake" + ./configure + make + $SUDO make install + fi rm -rf "$tmpdir" } From 6ea1363753a7ce844172c637a29d6953bb5f4260 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Thu, 20 Dec 2018 18:50:08 -0500 Subject: [PATCH 2/8] GEN-403 Go faster on Raspberry Pi. Disable removal of tmp dir temporarily to aid debugging. --- .gitignore | 1 + scripts/common.sh | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index b4c575a..c4103c5 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,4 @@ src/Resources.h sdkconfig sdkconfig.old *.store +*.tmp diff --git a/scripts/common.sh b/scripts/common.sh index 853ae0b..e24d926 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -40,8 +40,9 @@ function ensure_cmake { version=3.12 build=3 arch=$(arch) + uname=$(uname -s) tmpdir=$(mktemp -d) - cmake="cmake-$version.$build-Linux-$arch" + cmake="cmake-$version.$build-$uname-$arch" cd "$tmpdir" curl -fsSO "https://cmake.org/files/v$version/$cmake.sh" if [[ -f "$cmake" ]]; then @@ -55,10 +56,11 @@ function ensure_cmake { tar xfz "$cmake.tar.gz" cd "$cmake" ./configure - make + make -j $(nproc --all) $SUDO make install fi - rm -rf "$tmpdir" + # TODO: re-enable after cmake source build works + # rm -rf "$tmpdir" } function ensure_debian_devtools_installed { From 4eb45777786d95d33eb272f9fa06ec462b90e329 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Thu, 20 Dec 2018 19:03:33 -0500 Subject: [PATCH 3/8] GEN-403 "make -j" had no effect, backing it out --- scripts/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/common.sh b/scripts/common.sh index e24d926..686fcef 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -56,7 +56,7 @@ function ensure_cmake { tar xfz "$cmake.tar.gz" cd "$cmake" ./configure - make -j $(nproc --all) + make $SUDO make install fi # TODO: re-enable after cmake source build works From c3b9e804ce1aafef3a5d8cebc2a1947147b38b0b Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Fri, 21 Dec 2018 00:54:34 -0500 Subject: [PATCH 4/8] GEN-403 Improve cmake detection + install This now works correctly to install cmake from source on the Raspberry Pi running Raspbian 9.6 (stretch). --- scripts/common.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index 686fcef..c3a312a 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -30,7 +30,7 @@ function ensure_homebrew_installed { function ensure_cmake { # Adapted from https://askubuntu.com/questions/355565/how-do-i-install-the-latest-version-of-cmake-from-the-command-line - if [[ -d /opt/cmake ]]; then + if [[ -x /usr/local/bin/cmake ]]; then return fi local version @@ -44,8 +44,7 @@ function ensure_cmake { tmpdir=$(mktemp -d) cmake="cmake-$version.$build-$uname-$arch" cd "$tmpdir" - curl -fsSO "https://cmake.org/files/v$version/$cmake.sh" - if [[ -f "$cmake" ]]; then + if curl -fsSO "https://cmake.org/files/v$version/$cmake.sh"; then $SUDO mkdir -p /opt/cmake yes | $SUDO sh "$cmake.sh" --prefix=/opt/cmake || true # exits 141 on success for some reason $SUDO rm -f /usr/local/bin/cmake From ed3d1701a84e66dee96996d1bcc96a334a24a1cf Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Fri, 21 Dec 2018 01:07:26 -0500 Subject: [PATCH 5/8] GEN-403 clean up temp directory, add docs --- scripts/common.sh | 71 ++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index c3a312a..216f26b 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -45,21 +45,22 @@ function ensure_cmake { cmake="cmake-$version.$build-$uname-$arch" cd "$tmpdir" if curl -fsSO "https://cmake.org/files/v$version/$cmake.sh"; then + # Install binary package if we could retrieve it $SUDO mkdir -p /opt/cmake yes | $SUDO sh "$cmake.sh" --prefix=/opt/cmake || true # exits 141 on success for some reason $SUDO rm -f /usr/local/bin/cmake $SUDO ln -s "/opt/cmake/$cmake/bin/cmake" /usr/local/bin/cmake else + # Install from source (on Raspberry Pi with Rasbian 9.6 (stretch) for example. cmake="cmake-$version.$build" curl -fsSO "https://cmake.org/files/v$version/$cmake.tar.gz" tar xfz "$cmake.tar.gz" cd "$cmake" ./configure - make + make $SUDO make install fi - # TODO: re-enable after cmake source build works - # rm -rf "$tmpdir" + rm -rf "$tmpdir" } function ensure_debian_devtools_installed { @@ -148,7 +149,7 @@ function clean { } # TODO: Use otool -L and some foo to find the dependencies -# The sentinel is "/usr/local/opt" +# The sentinel is "/usr/local/opt" function copy_sdl2_libs_to_app { if [[ "$OS" == "Darwin" ]]; then export APP_DIR="$BASE_DIR/build/genus.app" @@ -156,8 +157,8 @@ function copy_sdl2_libs_to_app { export APP_RES_DIR="$APP_CNT_DIR/Resources" export APP_MACOSX_DIR="$APP_CNT_DIR/MacOS" if [[ -d "$APP_DIR" ]]; then - rm -rf "$APP_MACOSX_DIR/libs" - mkdir -p "$APP_MACOSX_DIR/libs" + rm -rf "$APP_MACOSX_DIR/libs" + mkdir -p "$APP_MACOSX_DIR/libs" cp /usr/local/opt/sdl2/lib/libSDL2.dylib "$APP_MACOSX_DIR/libs/" cp /usr/local/opt/sdl2_image/lib/libSDL2_image.dylib "$APP_MACOSX_DIR/libs/" @@ -169,49 +170,49 @@ function copy_sdl2_libs_to_app { # FIX Genus install_name_tool -change \ - /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib \ - ./libs/libSDL2.dylib \ - "$APP_MACOSX_DIR/genus" + /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib \ + ./libs/libSDL2.dylib \ + "$APP_MACOSX_DIR/genus" install_name_tool -change \ - /usr/local/opt/sdl2_image/lib/libSDL2_image-2.0.0.dylib \ - ./libs/libSDL2_image.dylib \ - "$APP_MACOSX_DIR/genus" + /usr/local/opt/sdl2_image/lib/libSDL2_image-2.0.0.dylib \ + ./libs/libSDL2_image.dylib \ + "$APP_MACOSX_DIR/genus" # FIX SDL2_image install_name_tool -change \ - /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib \ - ./libs/libSDL2.dylib \ - "$APP_MACOSX_DIR/libs/libSDL2_image.dylib" + /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib \ + ./libs/libSDL2.dylib \ + "$APP_MACOSX_DIR/libs/libSDL2_image.dylib" install_name_tool -change \ - /usr/local/opt/libpng/lib/libpng16.16.dylib \ - ./libs/libpng.dylib \ - "$APP_MACOSX_DIR/libs/libSDL2_image.dylib" - install_name_tool -change \ - /usr/local/opt/jpeg/lib/libjpeg.9.dylib \ - ./libs/libjpeg.dylib \ - "$APP_MACOSX_DIR/libs/libSDL2_image.dylib" + /usr/local/opt/libpng/lib/libpng16.16.dylib \ + ./libs/libpng.dylib \ + "$APP_MACOSX_DIR/libs/libSDL2_image.dylib" + install_name_tool -change \ + /usr/local/opt/jpeg/lib/libjpeg.9.dylib \ + ./libs/libjpeg.dylib \ + "$APP_MACOSX_DIR/libs/libSDL2_image.dylib" install_name_tool -change \ - /usr/local/opt/libtiff/lib/libtiff.5.dylib \ - ./libs/libtiff.dylib \ - "$APP_MACOSX_DIR/libs/libSDL2_image.dylib" + /usr/local/opt/libtiff/lib/libtiff.5.dylib \ + ./libs/libtiff.dylib \ + "$APP_MACOSX_DIR/libs/libSDL2_image.dylib" install_name_tool -change \ - /usr/local/opt/webp/lib/libwebp.7.dylib \ - ./libs/libwebp.dylib \ - "$APP_MACOSX_DIR/libs/libSDL2_image.dylib" + /usr/local/opt/webp/lib/libwebp.7.dylib \ + ./libs/libwebp.dylib \ + "$APP_MACOSX_DIR/libs/libSDL2_image.dylib" # FIX TIFF install_name_tool -change \ - /usr/local/opt/jpeg/lib/libjpeg.9.dylib \ - ./libs/libjpeg.dylib \ - "$APP_MACOSX_DIR/libs/libtiff.dylib" + /usr/local/opt/jpeg/lib/libjpeg.9.dylib \ + ./libs/libjpeg.dylib \ + "$APP_MACOSX_DIR/libs/libtiff.dylib" # CREATE WRAPPER mv "$APP_MACOSX_DIR/genus" "$APP_MACOSX_DIR/genus.bin" tee "$APP_MACOSX_DIR/genus" <<-"EOF" - #!/usr/bin/env bash - MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd )" - (cd $MY_DIR && ./genus.bin) - EOF + #!/usr/bin/env bash + MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd )" + (cd $MY_DIR && ./genus.bin) + EOF chmod 0755 "$BASE_DIR/build/genus.app/Contents/MacOS/genus" # INSTALL APP.PLIST & ETC From 1563f90a6bc417079138807d22f44314907921e9 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Tue, 22 Jan 2019 15:11:35 -0500 Subject: [PATCH 6/8] Fix docker build issues with ssl --- scripts/common.sh | 2 +- scripts/docker-build.sh | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index 216f26b..683852f 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -65,7 +65,7 @@ function ensure_cmake { function ensure_debian_devtools_installed { $SUDO apt-get -qq update - $SUDO apt-get -qq install --no-install-recommends build-essential git libsdl2-dev libsdl2-image-dev curl doxygen imagemagick + $SUDO apt-get -qq install --no-install-recommends build-essential git libsdl2-dev libsdl2-image-dev curl doxygen imagemagick ca-certificates openssl # Ubuntu 18.04 has an old cmake (3.9) so install a newer one from binaries from cmake ensure_cmake } diff --git a/scripts/docker-build.sh b/scripts/docker-build.sh index d04c825..599247a 100755 --- a/scripts/docker-build.sh +++ b/scripts/docker-build.sh @@ -9,7 +9,8 @@ set -euo pipefail IFS=$'\n\t' # Enable for enhanced debugging -#set -vx +DEBUG=${DEBUG:-/bin/false} +"$DEBUG" && set -vx # Credit to https://stackoverflow.com/a/17805088 # and http://wiki.bash-hackers.org/scripting/debuggingtips @@ -44,5 +45,5 @@ if [[ -L creative-engine ]]; then cp -a "$CREATIVE_ENGINE_DIR" . fi #shellcheck disable=SC2086,SC2048 -docker build . -t genus -f "$DIR/Dockerfile" +docker build -t genus -f "$DIR/Dockerfile" . From 7b42e412decdedd03e6b5b59688f29d40d53241f Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Tue, 22 Jan 2019 15:20:00 -0500 Subject: [PATCH 7/8] Improve Docker packaging on arm and x86_64 --- scripts/Dockerfile | 6 +++++- scripts/docker-build.sh | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/Dockerfile b/scripts/Dockerfile index 70671dd..5c67463 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -5,4 +5,8 @@ RUN /bin/bash /opt/genus/scripts/docker-install-debian-prerequisites.sh RUN rm -rf /opt/genus/scripts COPY . /opt/genus RUN ln -s /opt/genus/creative-engine /opt/creative-engine -RUN /bin/bash /opt/genus/scripts/build.sh docker-build +RUN /bin/bash /opt/genus/scripts/build.sh docker-build && \ + mkdir -p /opt/genus/bin && \ + mv /opt/genus/build/genus /opt/genus/bin && \ + rm -rf $(ls /opt/genus | grep -v ^bin$) +ENTRYPOINT /opt/genus/bin/genus diff --git a/scripts/docker-build.sh b/scripts/docker-build.sh index 599247a..654c646 100755 --- a/scripts/docker-build.sh +++ b/scripts/docker-build.sh @@ -45,5 +45,19 @@ if [[ -L creative-engine ]]; then cp -a "$CREATIVE_ENGINE_DIR" . fi #shellcheck disable=SC2086,SC2048 -docker build -t genus -f "$DIR/Dockerfile" . +case $(arch) in + armv7l) + DOCKERFILE="$DIR/Dockerfile-arm.tmp" + sed -e 's/ubuntu:18.04/schachr\/raspbian-stretch:latest/' < "$DIR/Dockerfile" >"$DOCKERFILE" + ;; + x86_64) + DOCKERFILE="$DIR/Dockerfile" + ;; + *) + echo "Unsupported architecture $(arch)" + exit 1 + ;; +esac + +docker build -t genus -f "$DOCKERFILE" . From f2bb26a119d2d79861e07d52669221af7f49c63d Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Tue, 22 Jan 2019 16:58:17 -0500 Subject: [PATCH 8/8] Fix up shellcheck fails --- scripts/common.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index 1273687..1cb0956 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -43,7 +43,7 @@ function ensure_cmake { uname=$(uname -s) tmpdir=$(mktemp -d) cmake="cmake-$version.$build-$uname-$arch" - cd "$tmpdir" + cd "$tmpdir" || exit 1 if curl -fsSO "https://cmake.org/files/v$version/$cmake.sh"; then # Install binary package if we could retrieve it $SUDO mkdir -p /opt/cmake @@ -56,7 +56,7 @@ function ensure_cmake { cmake="cmake-$version.$build" curl -fsSO "https://cmake.org/files/v$version/$cmake.tar.gz" tar xfz "$cmake.tar.gz" - cd "$cmake" + cd "$cmake" || exit 1 ./configure make $SUDO make install @@ -210,10 +210,10 @@ function copy_sdl2_libs_to_app { # CREATE WRAPPER mv "$APP_MACOSX_DIR/genus" "$APP_MACOSX_DIR/genus.bin" tee "$APP_MACOSX_DIR/genus" <<-"EOF" - #!/usr/bin/env bash - MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd )" - (cd $MY_DIR && ./genus.bin) - EOF + #!/usr/bin/env bash + MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd )" + (cd $MY_DIR && ./genus.bin) + EOF chmod 0755 "$BASE_DIR/build/genus.app/Contents/MacOS/genus" # INSTALL APP.PLIST & ETC