From 3ebdb87e21d25b865e5757d4b30297d02fff177a Mon Sep 17 00:00:00 2001
From: midipix <writeonce@midipix.org>
Date: Mon, 10 Dec 2018 22:54:57 -0500
Subject: config: handle all dependency-related logic at the project level.

---
 config/x86_64-linux/config.mk   | 24 ------------------------
 config/x86_64-midipix/config.mk | 24 ------------------------
 project/config/cfgdefs.sh       | 38 +++++++++++++++++++++++++++++++++++++-
 project/depends.mk              | 22 ++++++++++++++++++++++
 project/pycompile.mk            |  2 +-
 5 files changed, 60 insertions(+), 50 deletions(-)

diff --git a/config/x86_64-linux/config.mk b/config/x86_64-linux/config.mk
index b6f0aaf..f0d0dfa 100644
--- a/config/x86_64-linux/config.mk
+++ b/config/x86_64-linux/config.mk
@@ -26,29 +26,5 @@ PYEXT_STATIC = \
 	$(PYEXT_SUBSET_STATIC_LINUX_AUDIO)  \
 
 
-# shared extensions: dependency switches
-CFLAGS_NCURSES  = -I$(SYSROOT)/usr/local/include/ncurses -I$(SYSROOT)/usr/include/ncurses
-LDFLAGS_NCURSES = -Wl,--as-needed -lpanelw -lncursesw -Wl,--no-as-needed
-
-CFLAGS_SQLITE   = -I$(SYSROOT)/usr/local/include/sqlite3 -I$(SYSROOT)/usr/include/sqlite3
-CFLAGS_SQLITE  += -DMODULE_NAME=\"sqlite3\"
-CFLAGS_SQLITE  += -DSQLITE_OMIT_LOAD_EXTENSION
-LDFLAGS_SQLITE  = -lsqlite3
-
-CFLAGS_EXPAT    = -DXML_DEV_URANDOM
-LDFLAGS_EXPAT   = -lexpat
-
-CFLAGS_DBM      = -DHAVE_NDBM_H
-LDFLAGS_DBM     = -lgdbm_compat
-
-
-# static extensions: dependency switch
-LDFLAGS_PYEXT_STATIC	= -lssl -lcrypto -lreadline -lbz2 -lgdbm -lffi -lintl -lz
-LDFLAGS_NCURSES_STATIC	= $(LDFLAGS_NCURSES)
-LDFLAGS_SQLITE_STATIC	= $(LDFLAGS_SQLITE)
-LDFLAGS_EXPAT_STATIC	= $(LDFLAGS_EXPAT)
-LDFLAGS_DBM_STATIC	= $(LDFLAGS_DBM)
-
-
 # strict shared object generation
 LDFLAGS_STRICT += -Wl,-no-undefined
diff --git a/config/x86_64-midipix/config.mk b/config/x86_64-midipix/config.mk
index 6e727a5..72d86cc 100644
--- a/config/x86_64-midipix/config.mk
+++ b/config/x86_64-midipix/config.mk
@@ -22,29 +22,5 @@ PYEXT_STATIC = \
 	$(PYEXT_SUBSET_STATIC_ANYOS_CORE) \
 
 
-# shared extensions: dependency switches
-CFLAGS_NCURSES  = -I$(SYSROOT)/usr/local/include/ncurses -I$(SYSROOT)/usr/include/ncurses
-LDFLAGS_NCURSES = -Wl,--as-needed -lpanelw -lncursesw -ltinfo -Wl,--no-as-needed
-
-CFLAGS_SQLITE   = -I$(SYSROOT)/usr/local/include/sqlite3 -I$(SYSROOT)/usr/include/sqlite3
-CFLAGS_SQLITE  += -DMODULE_NAME=\"sqlite3\"
-CFLAGS_SQLITE  += -DSQLITE_OMIT_LOAD_EXTENSION
-LDFLAGS_SQLITE  = -lsqlite3
-
-CFLAGS_EXPAT    = -DXML_DEV_URANDOM
-LDFLAGS_EXPAT   = -lexpat
-
-CFLAGS_DBM      = -DHAVE_NDBM_H
-LDFLAGS_DBM     = -lgdbm_compat
-
-
-# static extensions: dependency switch
-LDFLAGS_PYEXT_STATIC	= -lssl -lcrypto -lreadline -lbz2 -lgdbm -lffi -lintl -lz
-LDFLAGS_NCURSES_STATIC	= $(LDFLAGS_NCURSES)
-LDFLAGS_SQLITE_STATIC	= $(LDFLAGS_SQLITE)
-LDFLAGS_EXPAT_STATIC	= $(LDFLAGS_EXPAT)
-LDFLAGS_DBM_STATIC	= $(LDFLAGS_DBM)
-
-
 # strict shared object generation
 LDFLAGS_STRICT += -Wl,-no-undefined
diff --git a/project/config/cfgdefs.sh b/project/config/cfgdefs.sh
index a8e4d53..c993def 100644
--- a/project/config/cfgdefs.sh
+++ b/project/config/cfgdefs.sh
@@ -73,7 +73,26 @@ printf 'void * addr = &X509_NAME_ENTRY_set;'           \
 		>> $mb_pwd/cfgdefs.mk
 
 # ncurses: python refers to the internals of typedef struct _win_st WINDOW
-printf 'CFLAGS_CONFIG\t\t+= -DNCURSES_INTERNALS' >> $mb_pwd/cfgdefs.mk
+printf 'CFLAGS_CONFIG\t\t+= -DNCURSES_INTERNALS\n' >> $mb_pwd/cfgdefs.mk
+
+# ncurses: tinfo
+mb_ncurses_libs="-lpanelw -lncursesw"
+
+if [ $mb_disable_shared = 'yes' ]; then
+	printf 'int main(void){return 0;}'          \
+		| $mb_cfgdefs_cc $mb_cfgdefs_cflags \
+			-ltinfo -o a.out -xc -      \
+			< /dev/null 2>/dev/null     \
+		&& mb_ncurses_libs="$mb_ncurses_libs -ltinfo"
+else
+	$mb_cfgdefs_cc $mb_cfgdefs_cflags               \
+			-shared -ltinfo -o a.out -xc -  \
+			< /dev/null 2>/dev/null         \
+		&& mb_ncurses_libs="$mb_ncurses_libs -ltinfo"
+fi
+
+printf 'LDFLAGS_NCURSES_LIBS\t+= %s\n' "$mb_ncurses_libs" \
+	>> $mb_pwd/cfgdefs.mk
 
 
 # system tests: (native) pycompile
@@ -85,5 +104,22 @@ $mb_native_cc -E -xc -                     \
 		printf 'PYCOMPILE_CFLAGS\t+= -DHAVE_NO_STROPTS_H\n' \
 			>> $mb_pwd/cfgdefs.mk
 
+# ncurses: tinfo
+mb_ncurses_libs="-lpanelw -lncursesw"
+
+printf 'int main(void){return 0;}'        \
+	| $mb_native_cc                   \
+		-ltinfo -o a.out -xc -    \
+		< /dev/null 2>/dev/null   \
+	&& mb_ncurses_libs="$mb_ncurses_libs -ltinfo"
+
+printf 'PYCOMPILE_NCURSES_LIBS\t+= %s\n' "$mb_ncurses_libs" \
+	>> $mb_pwd/cfgdefs.mk
+
+
+# clean-up
+rm -f a.out
+
+
 # all done
 return 0
diff --git a/project/depends.mk b/project/depends.mk
index e69de29..ff056a1 100644
--- a/project/depends.mk
+++ b/project/depends.mk
@@ -0,0 +1,22 @@
+# shared extensions: dependency switches
+CFLAGS_NCURSES  = -I$(SYSROOT)/usr/local/include/ncurses -I$(SYSROOT)/usr/include/ncurses
+LDFLAGS_NCURSES = -Wl,--as-needed $(LDFLAGS_NCURSES_LIBS) -Wl,--no-as-needed
+
+CFLAGS_SQLITE   = -I$(SYSROOT)/usr/local/include/sqlite3 -I$(SYSROOT)/usr/include/sqlite3
+CFLAGS_SQLITE  += -DMODULE_NAME=\"sqlite3\"
+CFLAGS_SQLITE  += -DSQLITE_OMIT_LOAD_EXTENSION
+LDFLAGS_SQLITE  = -lsqlite3
+
+CFLAGS_EXPAT    = -DXML_DEV_URANDOM
+LDFLAGS_EXPAT   = -lexpat
+
+CFLAGS_DBM      = -DHAVE_NDBM_H
+LDFLAGS_DBM     = -lgdbm_compat
+
+
+# static extensions: dependency switch
+LDFLAGS_PYEXT_STATIC	= -lssl -lcrypto -lreadline -lbz2 -lgdbm -lffi -lintl -lz
+LDFLAGS_NCURSES_STATIC	= $(LDFLAGS_NCURSES)
+LDFLAGS_SQLITE_STATIC	= $(LDFLAGS_SQLITE)
+LDFLAGS_EXPAT_STATIC	= $(LDFLAGS_EXPAT)
+LDFLAGS_DBM_STATIC	= $(LDFLAGS_DBM)
diff --git a/project/pycompile.mk b/project/pycompile.mk
index b6b3ff2..20a042f 100644
--- a/project/pycompile.mk
+++ b/project/pycompile.mk
@@ -21,7 +21,7 @@ PYCOMPILE_CFLAGS	+= -DEXEC_PREFIX=\"$(PYCOMPILE_PREFIX)\"
 PYCOMPILE_CFLAGS	+= -DPYTHONPATH=\"$(PYCOMPILE_PATH)\"
 
 PYCOMPILE_LDFLAGS	+= -lreadline -lm -lutil -lpthread
-PYCOMPILE_LDFLAGS	+= $(LDFLAGS_NCURSES_STATIC)
+PYCOMPILE_LDFLAGS	+= $(PYCOMPILE_NCURSES_LIBS)
 PYCOMPILE_LDFLAGS	+= -lreadline -lm -lutil -lpthread
 
 $(PYCOMPILE_DIR)/tree.tag:
-- 
cgit v1.2.3