From 4b0dd3c009869ee21b065afb6609861fb0a98fbf Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Tue, 20 Feb 2024 09:54:44 +0100 Subject: [PATCH] automatically build dependencies --- scripts/formulas/msdf-atlas-gen.sh | 102 +++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/scripts/formulas/msdf-atlas-gen.sh b/scripts/formulas/msdf-atlas-gen.sh index d0bc9bd..23594c5 100644 --- a/scripts/formulas/msdf-atlas-gen.sh +++ b/scripts/formulas/msdf-atlas-gen.sh @@ -74,6 +74,51 @@ VER=1.2.2 GIT_URL=https://github.com/Chlumsky/msdf-atlas-gen.git GIT_TAG="v${VER}" +# bash utilities +YES=0 +NO=1 +PROBABLY_YES=$YES +PROBABLY_NOT=$NO +REMEMBORY_AUTOPILOT=$NO +THIRDPARTY_BUILD_DIRECTORY="thirdparty" + +decision() { + # get default + if [ "$2" = "$YES" ]; then + default="yes" + else + default="no" + fi + + # should we go autopilot + if [ "${REMEMBORY_AUTOPILOT}" = "$YES" ]; + then + echo "$1? -> $default" + return $2 + fi + + echo "" + echo "$0 NEEDS A DECISION" + echo "" + echo "> $1?" + read -r -p "> Do you want? [y]es / [n]o / [d]efault ($default): " input + + case $input in + [yY][eE][sS]|[yY]) + return $YES + ;; + [nN][oO]|[nN]) + return $NO + ;; + [dD]) + return "$2" = "$YES" + ;; + *) + return $NO + ;; + esac +} + # download the source code and unpack it into LIB_NAME function download() { echo "download msdf-atlas-gen" @@ -86,6 +131,63 @@ function download() { # prepare the build environment, executed inside the lib src dir function prepare() { mkdir -p lib/$TYPE + + PREV_DIR="$(pwd)" + + if [ "$TYPE" == "emscripten" ] ; then + echo "preparing $TYPE thirdparty dependencies" + if decision "download, build and install all thirdparty dependencies" $PROBABLY_YES; then + REMEMBORY_AUTOPILOT=$YES + fi + if decision "download and build tinyxml2 for $TYPE" $PROBABLY_YES; then + mkdir -p "thirdparty" + cd "thirdparty" + if [ -d "tinyxml2" ] ; then + echo "apparently already done" + else + git clone --depth=1 https://github.com/leethomason/tinyxml2.git + cd tinyxml2 + mkdir build && cd build + emcmake cmake .. + emmake make + emmake make install + fi + cd "$PREV_DIR" + fi + if decision "download and build zlib for $TYPE" $PROBABLY_YES; then + mkdir -p "thirdparty" + cd "thirdparty" + if [ -d "zlib" ] ; then + echo "apparently already done" + else + wget https://pointer.click/files/zlib-1.3.1.tar.gz + mkdir -p zlib + tar -xzf zlib-1.3.1.tar.gz -C zlib --strip-components=1 + cd zlib + mkdir build && cd build + emcmake cmake .. + emmake make + emmake make install + fi + cd "$PREV_DIR" + fi + if decision "download and build libpng for $TYPE" $PROBABLY_YES; then + mkdir -p "thirdparty" + cd "thirdparty" + if [ -d "libpng-1.6.39" ] ; then + echo "apparently already done" + else + wget https://sourceforge.net/projects/libpng/files/libpng16/1.6.39/libpng-1.6.39.tar.xz/download -O libpng-1.6.39.tar.xz + tar -xf libpng-1.6.39.tar.xz + cd libpng-1.6.39 + mkdir build && cd build + emcmake cmake .. + emmake make + emmake make install + fi + cd "$PREV_DIR" + fi + fi } # executed inside the lib src dir