From e329b402982228e56775796c7816320362fb3398 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 17 Apr 2022 05:11:47 +0300
Subject: [PATCH 58/58] macOS: Add hbinstall.sh script

For installing homebrew environment for building macOS .app

See osdn #44400

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 Makefile.am                 |  1 +
 macOS/homebrew/hbinstall.sh | 84 +++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+)
 create mode 100755 macOS/homebrew/hbinstall.sh

diff --git a/Makefile.am b/Makefile.am
index 0157042ec2..8447758b1f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -28,6 +28,7 @@ docs =			\
 
 EXTRA_DIST =	autogen.sh 			\
 		configure.ac			\
+		macOS/homebrew/hbinstall.sh	\
 		m4/ax_cxx_compile_stdcxx.m4	\
 		m4/c99.m4			\
 		m4/c11.m4			\
diff --git a/macOS/homebrew/hbinstall.sh b/macOS/homebrew/hbinstall.sh
new file mode 100755
index 0000000000..487e30f665
--- /dev/null
+++ b/macOS/homebrew/hbinstall.sh
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+# Install homebrew for building MacOS freeciv .app
+# WIP
+
+# Can be "master", if you want development version
+HBVER="3.4.6"
+
+if test "$1" = "" ; then
+  echo "No installation directory given." >&2
+  exit 1
+fi
+
+MAINDIR="$1"
+
+if ! mkdir -p "${MAINDIR}/Contents" ; then
+  echo "Failed to create \"${MAINDIR}/Contents\"" >&2
+  exit 1
+fi
+
+if ! mkdir -p "${MAINDIR}/Resources" ; then
+  echo "Failed to create \"${MAINDIR}/Resources\"" >&2
+  exit 1
+fi
+
+if ! mkdir -p "${MAINDIR}/MacOS" ; then
+  echo "Failed to create \"${MAINDIR}/MacOS\"" >&2
+  exit 1
+fi
+
+if ! curl -L "https://github.com/Homebrew/brew/tarball/${HBVER}" |
+     tar xz --strip 1 -C "${MAINDIR}/Resources"
+then
+  echo "Homebrew install failed" >&2
+  exit 1
+fi
+
+eval "$("${MAINDIR}/Resources/bin/brew" shellenv)"
+
+# Packages that we temporarily take from HEAD
+# - shared-mime-info : current version available from homebrew does not build with recent meson
+# - meson : version available from homebrew fails building latest gtk+3
+HEAD_PACKAGES="\
+ meson \
+ shared-mime-info \
+"
+
+PACKAGES="\
+ lua@5.4 \
+ autoconf \
+ automake \
+ gettext \
+ libtool \
+ pkg-config \
+ atk \
+ freetype \
+ gettext \
+ glib \
+ gtk+3 \
+ icu4c \
+ pango \
+ sdl2_gfx \
+ sdl2_image \
+ sdl2_mixer \
+ sdl2_ttf \
+ qt@6 \
+"
+
+if test "$HEAD_PACKAGES" != "" ; then
+  if ! brew install --HEAD $HEAD_PACKAGES ; then
+    echo "Homebrew install of HEAD packages failed" >&2
+    exit 1
+  fi
+fi
+
+if ! brew fetch $PACKAGES ; then
+  echo "Homebrew fetching packages failed." >&2
+  exit 1
+fi
+
+if ! brew install $PACKAGES ; then
+  echo "Homebrew packages installation failed." >&2
+  exit 1
+fi
-- 
2.35.1