comparison test/dynload_plain/Makefile.generic @ 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
comparison
equal deleted inserted replaced
569:7e00c173519d 570:3155ccc33cae
1 # path to default libc.so file, easier to do via shell than in code (see main() in dynload_plain.c)
2 # for compat: first gmake style, then assignment op which will use ! as part of var name on gmake<4
3 # and thus not override previously set var; in a similar vein, the :sh line works on
4 # sun make flavors and sets the var using sunOS specific deduction if not already set
5 # (:sh also works on bmake, but != already sets the var)
6 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)
7 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
8 DEF_C_DYLIB:sh=[ -z "${DEF_C_DYLIB}" ] && ls /lib/`isainfo -b`/libc.so || echo "${DEF_C_DYLIB}"
9
10 APP = dynload_plain 1 APP = dynload_plain
11 OBJS = dynload_plain.o 2 OBJS = dynload_plain.o
3 TEST_C_LD = dynload_plain_c_ld # helper to deduce default c lib apps are linked with
12 TEST_U8_SO = dynload_plain_ß_test # @@@ unsure if every platform handles ß, here (ANSI, UTF-8, ...) 4 TEST_U8_SO = dynload_plain_ß_test # @@@ unsure if every platform handles ß, here (ANSI, UTF-8, ...)
13 SRCTOP = ${VPATH}/../.. 5 SRCTOP = ${VPATH}/../..
14 BLDTOP = ../.. 6 BLDTOP = ../..
15 CFLAGS += -I${SRCTOP}/dynload -DDEF_C_DYLIB=\"${DEF_C_DYLIB}\" 7 CFLAGS += -I${SRCTOP}/dynload -DDEF_C_DYLIB=\"${DEF_C_DYLIB}\"
16 LDLIBS_D += -L${BLDTOP}/dynload -ldynload_s 8 LDLIBS_D += -L${BLDTOP}/dynload -ldynload_s
17 9
18 # Works on: Darwin, NetBSD.
19 # Linux: add '-ldl'
20 .PHONY: all clean install 10 .PHONY: all clean install
21 all: ${APP} ${TEST_U8_SO} 11 all: ${TEST_C_LD} ${TEST_U8_SO}
12 # deduce path to default libc.so file, easier to do via shell than in code
13 # (see main() in dynload_plain.c); get from what ${TEST_C_LD} is linked
14 # against, then reinvoke make with actual build
15 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`; \
16 ${MAKE} DEF_C_DYLIB="$$X" ${APP}
17 ${TEST_C_LD}:
18 # dummy bin built with same toolchain and flags to deduce default c lib this is linked with
19 echo 'int main() { return 0; }' | ${CC} -x c ${CFLAGS} ${LDFLAGS} -o ${TEST_C_LD} -
22 ${APP}: ${OBJS} 20 ${APP}: ${OBJS}
23 ${CC} ${CFLAGS} ${LDFLAGS} ${OBJS} ${LDLIBS_D} ${LDLIBS} -o ${APP} 21 ${CC} ${CFLAGS} ${LDFLAGS} ${OBJS} ${LDLIBS_D} ${LDLIBS} -o ${APP}
24 ${TEST_U8_SO}: 22 ${TEST_U8_SO}:
25 echo 'int dynload_plain_testfunc() { return 5; }' | ${CC} -`[ \`uname\` = Darwin ] && echo dynamiclib || echo shared` -x c - -o ${TEST_U8_SO} 23 echo 'int dynload_plain_testfunc() { return 5; }' | ${CC} -`[ \`uname\` = Darwin ] && echo dynamiclib || echo shared` -x c - -o ${TEST_U8_SO}
26 clean: 24 clean:
27 rm -f ${APP} ${OBJS} ${TEST_U8_SO} 25 rm -f ${APP} ${OBJS} ${TEST_C_LD} ${TEST_U8_SO}
28 install: 26 install:
29 mkdir -p ${PREFIX}/test 27 mkdir -p ${PREFIX}/test
30 cp ${APP} ${TEST_U8_SO} ${PREFIX}/test 28 cp ${APP} ${TEST_U8_SO} ${PREFIX}/test
31 29