view test/dynload_plain/Makefile.embedded @ 569:7e00c173519d

- test/dynload_plain: make build deduce native libc to use for testing from more elemental tool (using [(1) now instead of ls(1), reason is that on some x64 sunos platforms, ls is 32bit; yes, hacky fix)
author Tassilo Philipp
date Sun, 04 Sep 2022 15:28:13 +0200
parents 4a3fab7712fb
children 3155ccc33cae
line wrap: on
line source

# 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, ...)

TOP = ../..
CFLAGS  += -I${TOP}/dynload -DDEF_C_DYLIB=\"${DEF_C_DYLIB}\"
LDFLAGS += -L${TOP}/dynload
LDLIBS  += -ldynload_s
# Works on: Darwin, NetBSD.
# Linux: add '-ldl'

all: ${APP} ${TEST_U8_SO}

.PHONY: all clean

${APP}: ${OBJS}
	${CC} ${CFLAGS} ${LDFLAGS} ${OBJS} ${LDLIBS} -o $@

${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}