From 5361ff6f48c1fbf03c72ed9d9460c66ded9b2ac4 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 1 Apr 2023 07:39:38 +0300 Subject: [PATCH 23/23] emsbuild.sh: Add initial version See osdn #47470 Signed-off-by: Marko Lindqvist --- Makefile.am | 2 + platforms/emscripten/emsbuild.sh | 61 ++++++++++++++++++++++ platforms/emscripten/setups/cross-ems.tmpl | 10 ++++ 3 files changed, 73 insertions(+) create mode 100755 platforms/emscripten/emsbuild.sh create mode 100644 platforms/emscripten/setups/cross-ems.tmpl diff --git a/Makefile.am b/Makefile.am index 62cf00942a..f9ef1896e2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -84,6 +84,8 @@ EXTRA_DIST = autogen.sh \ m4/testmatic.m4 \ meson.build \ meson_options.txt \ + platforms/emscripten/emsbuild.sh \ + platforms/emscripten/setups/cross-ems.tmpl \ platforms/flatpak/build_flatpak.sh \ platforms/flatpak/org.freeciv.gtk322.yml \ platforms/flatpak/org.freeciv.gtk4.yml \ diff --git a/platforms/emscripten/emsbuild.sh b/platforms/emscripten/emsbuild.sh new file mode 100755 index 0000000000..8b5197f72a --- /dev/null +++ b/platforms/emscripten/emsbuild.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# emsbuild.sh: Build freeciv using emsdk +# +# (c) 2023 Freeciv team +# +# This script is licensed under Gnu General Public License version 2 or later. +# See COPYING available from the same location you got this script. + +if test "$1" = "" || test "$1" = "-h" || test "$1" = "--help" ; then + echo "Usage: $0 " + exit 1 +fi + +EMSDK_ROOT="$1" +BUILD_ROOT="$(pwd)" +PLATFORM_ROOT="$(cd $(dirname "$0") && pwd)" + +if test "${PLATFORM_ROOT}" = "${BUILD_ROOT}" ; then + echo "Run $0 from a separate build directory." >&2 + exit 1 +fi + +if ! test -f "${EMSDK_ROOT}/emsdk_env.sh" ; then + echo "No environment setup script emsdk_env.sh in \"${EMSDK_ROOT}\"" >&2 + exit 1 +fi + +# Sometimes emsdk environment setup script requires +# cwd to be it's own directory. +cd "${EMSDK_ROOT}" || exit 1 +if ! . "./emsdk_env.sh" ; then + echo "Sourcing \"${EMSDK_ROOT}/emsdk_env.sh\" failed!" >&2 + exit 1 +fi +cd "${BUILD_ROOT}" || exit 1 + +# Add more emsdk directories to PATH +export PATH="${EMSDK_ROOT}/upstream/emscripten:$PATH" + +sed -e "s,,${EMSDK_ROOT}," \ + "${PLATFORM_ROOT}/setups/cross-ems.tmpl" > cross.txt + +if ! CC=emcc CXX=em++ AR=emar meson setup \ + --cross-file=cross.txt \ + -Ddefault_library=static \ + -Ddebug=true \ + -Dmwand=false \ + -Druledit=false \ + -Dclients=sdl2,stub \ + -Dfcmp=[] \ + "${PLATFORM_ROOT}/../../" +then + echo "Setup with meson failed!" >&2 + exit 1 +fi + +if ! ninja ; then + echo "Build with ninja failed!" >&2 + exit 1 +fi diff --git a/platforms/emscripten/setups/cross-ems.tmpl b/platforms/emscripten/setups/cross-ems.tmpl new file mode 100644 index 0000000000..a5bdf09596 --- /dev/null +++ b/platforms/emscripten/setups/cross-ems.tmpl @@ -0,0 +1,10 @@ +[binaries] +cc = '/upstream/emscripten/emcc' +cpp = '/upstream/emscripten/em++' +ar = '/upstream/emscripten/emar' +strip = '/upstream/emscripten/emstrip' + +[properties] +cross_inc_path = '/upstream/emscripten/system/include' +cross_lib_path = '/upstream/emscripten/system/lib' +crosser = false -- 2.39.2