Commit b14289380cb0b6493e38ac1a3565d95f45e442c0

Thomas de Grivel 2024-03-24T17:57:47

wip config.subr clean build prog

diff --git a/config.subr b/config.subr
index 89a5d5e..299404a 100644
--- a/config.subr
+++ b/config.subr
@@ -57,6 +57,26 @@ build_lo() {
     done
 }
 
+build_prog() {
+    echo >> ${CONFIG_MK}
+    echo "$PROG_ASAN: $LOCAL_LIBS_ASAN $OBJECTS_ASAN .build/ld_asan" >> ${CONFIG_MK}
+    echo "	.build/ld_asan $PROG_ASAN" >> ${CONFIG_MK}
+
+    if $HAVE_GCOV; then
+        echo >> ${CONFIG_MK}
+        echo "$PROG_COV: $LOCAL_LIBS_COV $OBJECTS_COV .build/ld_cov" >> ${CONFIG_MK}
+        echo "	.build/ld_cov $PROG_COV" >> ${CONFIG_MK}
+    fi
+
+    echo >> ${CONFIG_MK}
+    echo "$PROG_DEBUG: $LOCAL_LIBS_DEBUG $OBJECTS_DEBUG .build/ld_debug" >> ${CONFIG_MK}
+    echo "	.build/ld_debug $PROG_DEBUG" >> ${CONFIG_MK}
+
+    echo >> ${CONFIG_MK}
+    echo "$PROG: $LOCAL_LIBS $OBJECTS .build/ld_main" >> ${CONFIG_MK}
+    echo "	.build/ld_main $PROG" >> ${CONFIG_MK}
+}
+
 c_o_rule() {
     "$CC" $CPPFLAGS $CFLAGS -M "$1" || { echo "$1" | sed -e 's/^\(.*\)\.c$/\1.o: \1.c/'; }
     echo "$1: $2" | sed -e 's/^\(.*\)\.c:/\1.o:/'
@@ -463,6 +483,58 @@ update_build_lib() {
     update_and_chmod 755 ${LD_MAIN} .build/ld_main
 }
 
+update_build_prog() {
+    LD_MAIN=.build/ld_main.tmp
+    LD_ASAN=.build/ld_asan.tmp
+    LD_COV=.build/ld_cov.tmp
+    LD_DEBUG=.build/ld_debug.tmp
+    mkdir -p .build
+
+    echo "#!/bin/sh" >> ${LD_ASAN}
+    echo "# gen by configure" >> ${LD_ASAN}
+    echo "CC=\"${CC}\"" >> ${LD_ASAN}
+    echo "CFLAGS=\"${CFLAGS_ASAN}\"" >> ${LD_ASAN}
+    echo "LDFLAGS=\"${LDFLAGS_ASAN}\"" >> ${LD_ASAN}
+    echo "OBJECTS=\"${OBJECTS_ASAN}\"" >> ${LD_ASAN}
+    echo "LIBS=\"${LIBS_ASAN}\"" >> ${LD_ASAN}
+    echo >> ${LD_ASAN}
+    echo "${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS} \${LDFLAGS} \${OBJECTS} \${LIBS} -o \"\$1\" >> .build/log 2>&1" >> ${LD_ASAN}
+    update_and_chmod 755 ${LD_ASAN} .build/ld_asan
+
+    echo "#!/bin/sh" >> ${LD_COV}
+    echo "# gen by configure" >> ${LD_COV}
+    echo "CC=\"${CC}\"" >> ${LD_COV}
+    echo "CFLAGS=\"${CFLAGS_ASAN}\"" >> ${LD_COV}
+    echo "LDFLAGS=\"${LDFLAGS_COV}\"" >> ${LD_COV}
+    echo "OBJECTS=\"${OBJECTS_COV}\"" >> ${LD_COV}
+    echo "LIBS=\"${LIBS_COV}\"" >> ${LD_COV}
+    echo >> ${LD_COV}
+    echo "${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS} \${LDFLAGS} \${OBJECTS} \${LIBS} -o \"\$1\" >> .build/log 2>&1" >> ${LD_COV}
+    update_and_chmod 755 ${LD_COV} .build/ld_cov
+
+    echo "#!/bin/sh" >> ${LD_DEBUG}
+    echo "# gen by configure" >> ${LD_DEBUG}
+    echo "CC=\"${CC}\"" >> ${LD_DEBUG}
+    echo "CFLAGS=\"${CFLAGS_DEBUG}\"" >> ${LD_DEBUG}
+    echo "LDFLAGS=\"${LDFLAGS_DEBUG}\"" >> ${LD_DEBUG}
+    echo "OBJECTS=\"${OBJECTS_DEBUG}\"" >> ${LD_DEBUG}
+    echo "LIBS=\"${LIBS_DEBUG}\"" >> ${LD_DEBUG}
+    echo >> ${LD_DEBUG}
+    echo "${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS} \${LDFLAGS} \${OBJECTS} \${LIBS} -o \"\$1\" >> .build/log 2>&1" >> ${LD_DEBUG}
+    update_and_chmod 755 ${LD_DEBUG} .build/ld_debug
+
+    echo "#!/bin/sh" >> ${LD_MAIN}
+    echo "# gen by configure" >> ${LD_MAIN}
+    echo "CC=\"${CC}\"" >> ${LD_MAIN}
+    echo "CFLAGS=\"${CFLAGS_DEBUG}\"" >> ${LD_MAIN}
+    echo "LDFLAGS=\"${LDFLAGS}\"" >> ${LD_MAIN}
+    echo "OBJECTS=\"${OBJECTS}\"" >> ${LD_MAIN}
+    echo "LIBS=\"${LIBS}\"" >> ${LD_MAIN}
+    echo >> ${LD_MAIN}
+    echo "${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS} \${LDFLAGS} \${OBJECTS} \${LIBS} -o \"\$1\" >> .build/log 2>&1" >> ${LD_MAIN}
+    update_and_chmod 755 ${LD_MAIN} .build/ld_main
+}
+
 update_file() {
     if ! cmp "$1" "$2" >/dev/null 2>&1; then
         mv "$1" "$2"
diff --git a/test/configure b/test/configure
index 74653d9..12c6d41 100755
--- a/test/configure
+++ b/test/configure
@@ -39,7 +39,7 @@ OBJECTS_DEBUG="$(c2ext .debug.lo "$SOURCES")"
 echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
 
 # Common config for all targets
-CFLAGS="$CFLAGS -W -Wall -Werror -std=c11 -pedantic -fPIC"
+CFLAGS="$CFLAGS -W -Wall -Werror -std=c11 -pedantic -pipe"
 LDFLAGS="$LDFLAGS -rdynamic"
 config_asan
 config_gnu
@@ -54,28 +54,32 @@ LIBS="$LIBS -pthread -lm"
 CFLAGS_ASAN="$CFLAGS -fsanitize=address -O1 -fno-omit-frame-pointer -g"
 LDFLAGS_ASAN="$LDFLAGS"
 LIBC3_ASAN=../libc3/libc3_asan.la
-LIBS_ASAN="$LIBC3_ASAN $LIBS"
+LOCAL_LIBS_ASAN="$LIBC3_ASAN"
+LIBS_ASAN="$LOCAL_LIBS_ASAN $LIBS"
 
 # Coverage config
 CFLAGS_COV="$CFLAGS --coverage"
 LDFLAGS_COV="$LDFLAGS"
 LIBC3_COV=../libc3/libc3_cov.la
-LIBS_COV="$LIBC3_COV $LIBS"
+LOCAL_LIBS_COV="$LIBC3_COV"
+LIBS_COV="$LOCAL_LIBS_COV $LIBS"
 
 # Debug config
 CFLAGS_DEBUG="$CFLAGS -DDEBUG -O0 -g"
 LDFLAGS_DEBUG="$LDFLAGS"
 LIBC3_DEBUG=../libc3/libc3_debug.la
-LIBS_DEBUG="$LIBC3_DEBUG $LIBS"
+LOCAL_LIBS_DEBUG="$LIBC3_DEBUG"
+LIBS_DEBUG="$LOCAL_LIBS_DEBUG $LIBS"
 
 # Main config
-DEFAULT_CFLAGS="-O2 -pipe"
+DEFAULT_CFLAGS="-O2 -pipe -fPIC"
 if [ "x$ENV_CFLAGS" = "x" ]; then
     CFLAGS="$CFLAGS $DEFAULT_CFLAGS"
 fi
 CFLAGS="$CFLAGS -DNDEBUG"
 LIBC3=../libc3/libc3.la
-LIBS="$LIBC3 $LIBS"
+LOCAL_LIBS="$LIBC3"
+LIBS="$LOCAL_LIBS $LIBS"
 
 echo "HAVE_ASAN = $HAVE_ASAN" >> ${CONFIG_MK}
 echo "CPPFLAGS = $CPPFLAGS" >> ${CONFIG_MK}
@@ -86,57 +90,19 @@ echo >> ${CONFIG_MK}
 echo "CFLAGS_ASAN = $CFLAGS_ASAN" >> ${CONFIG_MK}
 echo "LDFLAGS_ASAN = $LDFLAGS_ASAN" >> ${CONFIG_MK}
 echo "LIBS_ASAN = $LIBS_ASAN" >> ${CONFIG_MK}
-if $HAVE_GCOV; then
-    echo >> ${CONFIG_MK}
-    echo "CFLAGS_COV = $CFLAGS_COV" >> ${CONFIG_MK}
-    echo "LDFLAGS_COV = $LDFLAGS_COV" >> ${CONFIG_MK}
-    echo "LIBS_COV = $LIBS_COV" >> ${CONFIG_MK}
-fi
+echo >> ${CONFIG_MK}
+echo "CFLAGS_COV = $CFLAGS_COV" >> ${CONFIG_MK}
+echo "LDFLAGS_COV = $LDFLAGS_COV" >> ${CONFIG_MK}
+echo "LIBS_COV = $LIBS_COV" >> ${CONFIG_MK}
 echo >> ${CONFIG_MK}
 echo "CFLAGS_DEBUG = $CFLAGS_DEBUG" >> ${CONFIG_MK}
 echo "LDFLAGS_DEBUG = $LDFLAGS_DEBUG" >> ${CONFIG_MK}
 echo "LIBS_DEBUG = $LIBS_DEBUG" >> ${CONFIG_MK}
 
-echo >> ${CONFIG_MK}
-echo "$PROG: $LIBC3 $OBJECTS" >> ${CONFIG_MK}
-echo "	${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS} \${LDFLAGS} ${OBJECTS} ${LIBS} -o $PROG" >> ${CONFIG_MK}
-
-echo >> ${CONFIG_MK}
-echo "$PROG_ASAN: $LIBC3_ASAN $OBJECTS_ASAN" >> ${CONFIG_MK}
-echo "	${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS_ASAN} \${LDFLAGS_ASAN} ${OBJECTS_ASAN} ${LIBS_ASAN} -o $PROG_ASAN" >> ${CONFIG_MK}
+update_build
+update_build_prog
 
-if $HAVE_GCOV; then
-    echo >> ${CONFIG_MK}
-    echo "$PROG_COV: $LIBC3_COV $OBJECTS_COV" >> ${CONFIG_MK}
-    echo "	${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS_COV} \${LDFLAGS_COV} ${OBJECTS_COV} ${LIBS_COV} -o $PROG_COV" >> ${CONFIG_MK}
-fi
-
-echo >> ${CONFIG_MK}
-echo "$PROG_DEBUG: $LIBC3_DEBUG $OBJECTS_DEBUG" >> ${CONFIG_MK}
-echo "	${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS_DEBUG} \${LDFLAGS_DEBUG} ${OBJECTS_DEBUG} ${LIBS_DEBUG} -o $PROG_DEBUG" >> ${CONFIG_MK}
-
-for SRC in $SOURCES; do
-    echo >> ${CONFIG_MK}
-    SRC_LO="$(c2ext .main.lo "$SRC")"
-    c_ext_rule .main.lo "$SRC" >> ${CONFIG_MK}
-    echo "	${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS} -c $SRC -o $SRC_LO" >> ${CONFIG_MK}
-
-    echo >> ${CONFIG_MK}
-    SRC_ASAN_LO="$(c2ext .asan.lo "$SRC")"
-    c_ext_rule .asan.lo "$SRC" >> ${CONFIG_MK}
-    echo "	${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_ASAN} -c $SRC -o $SRC_ASAN_LO" >> ${CONFIG_MK}
-
-    if $HAVE_GCOV; then
-        echo >> ${CONFIG_MK}
-        SRC_COV_LO="$(c2ext .cov.lo "$SRC")"
-        c_ext_rule .cov.lo "$SRC" >> ${CONFIG_MK}
-        echo "	${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_COV} -c $SRC -o $SRC_COV_LO" >> ${CONFIG_MK}
-    fi
-
-    echo >> ${CONFIG_MK}
-    SRC_DEBUG_LO="$(c2ext .debug.lo "$SRC")"
-    c_ext_rule .debug.lo "$SRC" >> ${CONFIG_MK}
-    echo "	${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_DEBUG} -c $SRC -o $SRC_DEBUG_LO" >> ${CONFIG_MK}
-done
+build_lo
+build_prog
 
 update_config_mk