changeset 570:3155ccc33cae

- test/dynload_plain: simplify makefile based build by deducing default c lib to test with from a simple helper build
author Tassilo Philipp
date Sun, 04 Sep 2022 15:57:28 +0200
parents 7e00c173519d
children 996424e8a5fc
files test/dynload_plain/Makefile.embedded test/dynload_plain/Makefile.generic
diffstat 2 files changed, 21 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/test/dynload_plain/Makefile.embedded	Sun Sep 04 15:28:13 2022 +0200
+++ b/test/dynload_plain/Makefile.embedded	Sun Sep 04 15:57:28 2022 +0200
@@ -1,12 +1,3 @@
-# path to default libc.so file, easier to do via shell than in code (see main() in dynload_plain.c)
-# for compat: first gmake style, then assignment op which will use ! as part of var name on gmake<4
-#             and thus not override previously set var; in a similar vein, the :sh line works on
-#             sun make flavors and sets the var using sunOS specific deduction if not already set
-#             (:sh also works on bmake, but != already sets the var)
-DEF_C_DYLIB=$(shell ((ldd `which [` | grep -o '/.*/libc.so[^ ]*' || ls /lib*/libc.so* || ls /usr/lib/libc.so*) | grep -v '\.a$$' | (sort -V -r || sort -t . -n -k 2)) 2>/dev/null | head -1)
-DEF_C_DYLIB!=((ldd `which [` | grep -o '/.*/libc.so[^ ]*' || ls /lib*/libc.so* || ls /usr/lib/libc.so*) | grep -v '\.a$$' | (sort -V -r || sort -t . -n -k 2)) 2>/dev/null | head -1
-DEF_C_DYLIB:sh=[ -z "${DEF_C_DYLIB}" ] && ls /lib/`isainfo -b`/libc.so || echo "${DEF_C_DYLIB}"
-
 APP = dynload_plain
 OBJS = dynload_plain.o
 TEST_U8_SO = dynload_plain_ß_test # @@@ unsure if every platform handles ß, here (ANSI, UTF-8, ...)
@@ -18,10 +9,19 @@
 # Works on: Darwin, NetBSD.
 # Linux: add '-ldl'
 
-all: ${APP} ${TEST_U8_SO}
+all: ${TEST_C_LD} ${TEST_U8_SO}
+	# deduce path to default libc.so file, easier to do via shell than in code
+	# (see main() in dynload_plain.c); get from what ${TEST_C_LD} is linked
+	# against, then reinvoke make with actual build
+	export X=`((ldd ${TEST_C_LD} | grep -o '/.*/libc.so[^ ]*' || ls /lib*/libc.so* || ls /usr/lib/libc.so*) | grep -v '\.a$$' | (sort -V -r || sort -t . -n -k 2)) 2>/dev/null | head -1`; \
+	${MAKE} DEF_C_DYLIB="$$X" ${APP}
 
 .PHONY: all clean
 
+${TEST_C_LD}:
+	# dummy bin built with same toolchain and flags to deduce default c lib this is linked with
+	echo 'int main() { return 0; }' | ${CC} -x c ${CFLAGS} ${LDFLAGS} -o ${TEST_C_LD} -
+
 ${APP}: ${OBJS}
 	${CC} ${CFLAGS} ${LDFLAGS} ${OBJS} ${LDLIBS} -o $@
 
--- a/test/dynload_plain/Makefile.generic	Sun Sep 04 15:28:13 2022 +0200
+++ b/test/dynload_plain/Makefile.generic	Sun Sep 04 15:57:28 2022 +0200
@@ -1,30 +1,28 @@
-# path to default libc.so file, easier to do via shell than in code (see main() in dynload_plain.c)
-# for compat: first gmake style, then assignment op which will use ! as part of var name on gmake<4
-#             and thus not override previously set var; in a similar vein, the :sh line works on
-#             sun make flavors and sets the var using sunOS specific deduction if not already set
-#             (:sh also works on bmake, but != already sets the var)
-DEF_C_DYLIB=$(shell ((ldd `which [` | grep -o '/.*/libc.so[^ ]*' || ls /lib*/libc.so* || ls /usr/lib/libc.so*) | grep -v '\.a$$' | (sort -V -r || sort -t . -n -k 2)) 2>/dev/null | head -1)
-DEF_C_DYLIB!=((ldd `which [` | grep -o '/.*/libc.so[^ ]*' || ls /lib*/libc.so* || ls /usr/lib/libc.so*) | grep -v '\.a$$' | (sort -V -r || sort -t . -n -k 2)) 2>/dev/null | head -1
-DEF_C_DYLIB:sh=[ -z "${DEF_C_DYLIB}" ] && ls /lib/`isainfo -b`/libc.so || echo "${DEF_C_DYLIB}"
-
 APP        = dynload_plain
 OBJS       = dynload_plain.o
+TEST_C_LD  = dynload_plain_c_ld   # helper to deduce default c lib apps are linked with
 TEST_U8_SO = dynload_plain_ß_test # @@@ unsure if every platform handles ß, here (ANSI, UTF-8, ...)
 SRCTOP     = ${VPATH}/../..
 BLDTOP     = ../..
 CFLAGS    += -I${SRCTOP}/dynload -DDEF_C_DYLIB=\"${DEF_C_DYLIB}\"
 LDLIBS_D  += -L${BLDTOP}/dynload -ldynload_s
 
-# Works on: Darwin, NetBSD.
-# Linux: add '-ldl'
 .PHONY: all clean install
-all: ${APP} ${TEST_U8_SO}
+all: ${TEST_C_LD} ${TEST_U8_SO}
+	# deduce path to default libc.so file, easier to do via shell than in code
+	# (see main() in dynload_plain.c); get from what ${TEST_C_LD} is linked
+	# against, then reinvoke make with actual build
+	export X=`((ldd ${TEST_C_LD} | grep -o '/.*/libc.so[^ ]*' || ls /lib*/libc.so* || ls /usr/lib/libc.so*) | grep -v '\.a$$' | (sort -V -r || sort -t . -n -k 2)) 2>/dev/null | head -1`; \
+	${MAKE} DEF_C_DYLIB="$$X" ${APP}
+${TEST_C_LD}:
+	# dummy bin built with same toolchain and flags to deduce default c lib this is linked with
+	echo 'int main() { return 0; }' | ${CC} -x c ${CFLAGS} ${LDFLAGS} -o ${TEST_C_LD} -
 ${APP}: ${OBJS}
 	${CC} ${CFLAGS} ${LDFLAGS} ${OBJS} ${LDLIBS_D} ${LDLIBS} -o ${APP}
 ${TEST_U8_SO}:
 	echo 'int dynload_plain_testfunc() { return 5; }' | ${CC} -`[ \`uname\` = Darwin ] && echo dynamiclib || echo shared` -x c - -o ${TEST_U8_SO}
 clean:
-	rm -f ${APP} ${OBJS} ${TEST_U8_SO}
+	rm -f ${APP} ${OBJS} ${TEST_C_LD} ${TEST_U8_SO}
 install:
 	mkdir -p ${PREFIX}/test
 	cp ${APP} ${TEST_U8_SO} ${PREFIX}/test