From f967b5a25509d7495445b392307fdaa046e84be7 Mon Sep 17 00:00:00 2001
From: Kurtis Rader <krader@skepticism.us>
Date: Sun, 26 Jan 2020 21:00:50 -0800
Subject: [PATCH] Change default build type to "minsize"

People (and distros) have been building ksh from this project using the
default "debug" build type since we switched from Nmake to Meson. That
results in a ksh program whose performance is far from optimal. So change
the default build type. If a debugging enabled binary is needed, such as
in a CI environment, it must be requested explicitly.

Related #1449

(cherry picked from commit db54d369002a0e942d695838986af6bf8962d763)
---
 CHANGELOG.md               |  3 +++
 meson.build                | 11 ++++++++++-
 scripts/build-on-docker.sh |  2 +-
 scripts/build-on-macos.sh  |  2 +-
 4 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0e38b780456e..8657ab1a2a15 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,9 @@
 
 ## Notable fixes and improvements
 
+- The default build type is now "minsize" since that dramatically improves the
+  performance of ksh. You can still request a debug build via `meson
+  --buildtype=debug` (issue #1449).
 - Fix `history` command behavior when the *~/.sh_history* file has
   specific content (issue #1432).
 
diff --git a/meson.build b/meson.build
index 0e5dc2483fb1..aecfe737c3f1 100644
--- a/meson.build
+++ b/meson.build
@@ -1,4 +1,13 @@
-project('ksh93', 'c', default_options: ['b_lundef=false', 'default_library=static'])
+project('ksh9', 'c', default_options: [
+    # This is the optimal production build type for this project. If you need
+    # a debug build you must explicitly run `meson --buildtype=debug`. This
+    # helps ensure that each distro (or user) gets a performance optimized build
+    # even if they don't know to add the `--buildtype=minsize` option.
+    'buildtype=minsize',
+    'b_lundef=false',
+    'default_library=static',
+    'c_std=c99', # we require the C99 (aka ISO9899:1999) language standard
+])
 
 source_dir = meson.current_source_dir()
 cc = meson.get_compiler('c')
diff --git a/scripts/build-on-docker.sh b/scripts/build-on-docker.sh
index cd8138be9ab2..0b5af4a1d698 100755
--- a/scripts/build-on-docker.sh
+++ b/scripts/build-on-docker.sh
@@ -18,7 +18,7 @@ mkdir build
 cd build
 
 echo ==== Configuring the build
-if ! meson -Dwarnings-are-errors=true
+if ! meson -Dwarnings-are-errors=true --buildtype=debug
 then
     cat meson-logs/meson-log.txt
     exit 1
diff --git a/scripts/build-on-macos.sh b/scripts/build-on-macos.sh
index 2732e370f8d8..163195accfff 100755
--- a/scripts/build-on-macos.sh
+++ b/scripts/build-on-macos.sh
@@ -15,7 +15,7 @@ mkdir build
 cd build
 
 echo ==== Configuring the build
-if ! meson -Dwarnings-are-errors=true
+if ! meson -Dwarnings-are-errors=true --buildtype=debug
 then
     cat meson-logs/meson-log.txt
     exit 1
