From 1489635e20f35236840fb3701dc74de718bd12ce Mon Sep 17 00:00:00 2001
From: midipix <writeonce@midipix.org>
Date: Tue, 25 Dec 2018 13:00:09 -0500
Subject: project: custom config: support --with[out]-pycompile,
 --with[out]-pydebug.

---
 project/config/cfgdefs.in |  3 ++-
 project/config/cfgdefs.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

(limited to 'project/config')

diff --git a/project/config/cfgdefs.in b/project/config/cfgdefs.in
index fa42373..7239352 100644
--- a/project/config/cfgdefs.in
+++ b/project/config/cfgdefs.in
@@ -3,5 +3,6 @@ PYTHON_VER               = @python_ver@
 PYTHON_MAJOR             = @python_major@
 PYTHON_MINOR             = @python_minor@
 PYTHON_MICRO             = @python_micro@
-PYTHON_SOABI             = cpython-$(PYTHON_MAJOR)$(PYTHON_MINOR)-$(CCHOST)
+PYTHON_ABIFL             = @python_abifl@
+PYTHON_SOABI             = cpython-$(PYTHON_MAJOR)$(PYTHON_MINOR)$(PYTHON_ABIFL)-$(CCHOST)
 
diff --git a/project/config/cfgdefs.sh b/project/config/cfgdefs.sh
index cde8eb6..ecb0625 100644
--- a/project/config/cfgdefs.sh
+++ b/project/config/cfgdefs.sh
@@ -19,8 +19,23 @@
 . "$mb_project_dir/sofort/cfgtest/cfgtest.sh"
 
 
+pycfg_pydebug=
+pycfg_pymalloc=
+
 for arg ; do
 	case "$arg" in
+		--with-pydebug )
+			pycfg_pydebug='d' ;;
+
+		--without-pydebug )
+			pycfg_pydebug= ;;
+
+		--with-pymalloc )
+			pycfg_pymalloc='m' ;;
+
+		--without-pymalloc )
+			pycfg_pymalloc= ;;
+
 		*)
 			error_msg ${arg#}: "unsupported config argument."
 			exit 2
@@ -64,6 +79,24 @@ cfgdefs_detect_python_version()
 }
 
 
+cfgdefs_set_option_variables()
+{
+	python_abifl=$pycfg_pydebug$pycfg_pymalloc
+}
+
+
+cfgdefs_output_options()
+{
+	if [ -n "$pycfg_pydebug" ]; then
+		cfgtest_cflags_append '-DPy_DEBUG'
+	fi
+
+	if [ -n "$pycfg_pymalloc" ]; then
+		cfgtest_cflags_append '-DWITH_PYMALLOC'
+	fi
+}
+
+
 cfgdefs_output_custom_defs()
 {
 	sed \
@@ -71,6 +104,7 @@ cfgdefs_output_custom_defs()
 			-e 's/@python_major@/'"$python_major"'/g'   \
 			-e 's/@python_minor@/'"$python_minor"'/g'   \
 			-e 's/@python_micro@/'"$python_micro"'/g'   \
+			-e 's/@python_abifl@/'"$python_abifl"'/g'   \
 		"$mb_project_dir/project/config/cfgdefs.in"         \
 			>> "$mb_pwd/cfgdefs.mk"
 }
@@ -377,6 +411,11 @@ cfgdefs_perform_target_tests()
 	[ $python_major = '3' ] && \
 	cfgtest_makevar_append '-Wl,--as-needed -llzma         -Wl,--no-as-needed'
 
+	# options
+	cfgtest_newline
+	cfgtest_comment 'target options'
+	cfgdefs_output_options
+
 	# pretty cfgdefs.mk
 	cfgtest_newline
 }
@@ -393,6 +432,11 @@ cfgdefs_perform_native_tests()
 	# ncurses libs
 	cfgtest_ldflags_append $mb_ncurses_libs
 
+	# options
+	cfgtest_newline
+	cfgtest_comment '(native) pycompile options'
+	cfgdefs_output_options
+
 	# pretty cfgdefs.mk
 	cfgtest_newline
 }
@@ -404,6 +448,9 @@ cfgdefs_set_cfghost_flavors
 # python version info
 cfgdefs_detect_python_version
 
+# python-specific configuration
+cfgdefs_set_option_variables
+
 # cfgdefs.in --> cfgdefs.mk
 cfgdefs_output_custom_defs
 
-- 
cgit v1.2.3