From fc7fad007e813adc04ebae28e3db4904f5d79a1e Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Fri, 30 Apr 2021 04:46:14 +0300
Subject: [PATCH 23/23] Generate separate configuration header to be used for
 in-tree liblua build

Definitions from full fc_config.h can cause trouble in liblua build.
Generate and use separate config header that has just the definitions
needed in liblua build.

Reported by jdlh

See osdn #42114

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 configure.ac                            |  2 +-
 dependencies/lua-5.3/src/localluaconf.h |  5 +--
 gen_headers/.gitignore                  |  1 +
 gen_headers/Makefile.am                 |  1 +
 gen_headers/liblua_config.h.in          | 47 +++++++++++++++++++++++++
 5 files changed, 51 insertions(+), 5 deletions(-)
 create mode 100644 gen_headers/liblua_config.h.in

diff --git a/configure.ac b/configure.ac
index f87c169052..bd99fd5e50 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11,7 +11,7 @@ AC_CONFIG_SRCDIR([common/game.c])
 AC_CONFIG_AUX_DIR(bootstrap) # This can't be quoted or automake will fail
 AC_CONFIG_MACRO_DIR([m4])
 ifdef([AC_CONFIG_MACRO_DIRS],[AC_CONFIG_MACRO_DIRS([dependencies/m4])])
-AC_CONFIG_HEADERS([gen_headers/fc_config.h gen_headers/freeciv_config.h])
+AC_CONFIG_HEADERS([gen_headers/fc_config.h gen_headers/freeciv_config.h gen_headers/liblua_config.h])
 AC_CANONICAL_HOST
 AC_USE_SYSTEM_EXTENSIONS
 AC_C_BIGENDIAN
diff --git a/dependencies/lua-5.3/src/localluaconf.h b/dependencies/lua-5.3/src/localluaconf.h
index dcbd0304de..684aa851ba 100644
--- a/dependencies/lua-5.3/src/localluaconf.h
+++ b/dependencies/lua-5.3/src/localluaconf.h
@@ -14,12 +14,9 @@
 #define FC__LOCALLUACONF_H
 
 #ifdef HAVE_CONFIG_H
-#include <fc_config.h>
+#include <liblua_config.h>
 #endif
 
-/* Lua headers want to define VERSION to lua version */
-#undef VERSION
-
 #if defined(HAVE_MKSTEMP) && defined(FREECIV_HAVE_UNISTD_H)
 #define LUA_USE_MKSTEMP
 #endif
diff --git a/gen_headers/.gitignore b/gen_headers/.gitignore
index 7cfc5a8a4d..0b798ea68e 100644
--- a/gen_headers/.gitignore
+++ b/gen_headers/.gitignore
@@ -1,5 +1,6 @@
 /Makefile.in
 /Makefile
+/liblua_config.h
 /fc_config.h
 /fc_config.h.in
 /freeciv_config.h
diff --git a/gen_headers/Makefile.am b/gen_headers/Makefile.am
index e0b50e2f2d..8eee950625 100644
--- a/gen_headers/Makefile.am
+++ b/gen_headers/Makefile.am
@@ -1,4 +1,5 @@
 ## Process this file with automake to produce Makefile.in
 
 EXTRA_DIST = \
+	liblua_config.h.in
 	freeciv_config.h.in
diff --git a/gen_headers/liblua_config.h.in b/gen_headers/liblua_config.h.in
new file mode 100644
index 0000000000..4740316f92
--- /dev/null
+++ b/gen_headers/liblua_config.h.in
@@ -0,0 +1,47 @@
+/***********************************************************************
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+/* This header is generated from gen_headers/liblua_config.h.in.
+   It includes definitions needed by the in-tree liblua compilation. */
+
+#ifndef FC__LIBLUA_CONFIG_H
+#define FC__LIBLUA_CONFIG_H
+
+/* mkstemp() available */
+#undef HAVE_MKSTEMP
+
+/* unistd.h available */
+#undef FREECIV_HAVE_UNISTD_H
+
+/* popen() available */
+#undef HAVE_POPEN
+
+/* pclose() available */
+#undef HAVE_PCLOSE
+
+/* _longjmp() available */
+#undef HAVE__LONGJMP
+
+/* _setjmp() available */
+#undef HAVE__SETJMP
+
+/* gmtime_r() available */
+#undef HAVE_GMTIME_R
+
+/* localtime_r() available */
+#undef HAVE_LOCALTIME_R
+
+/* fseeko() available */
+#undef HAVE_FSEEKO
+
+#endif /* FC__LIBLUA_CONFIG_H */
-- 
2.30.2