Hash :
75270fe7
Author :
Thomas de Grivel
Date :
2024-03-24T14:53:08
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
#!/bin/sh
## c3
## Copyright 2022-2024 kmx.io <contact@kmx.io>
##
## Permission is hereby granted to use this software granted the above
## copyright notice and this permission paragraph are included in all
## copies and substantial portions of this software.
##
## THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
## PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
## THIS SOFTWARE.
set -e
export SRC_TOP="$(dirname "$PWD")"
CONFIG_H_PREFIX=LIBC3_
. ../config.subr
LIB=libc3.la
LIB_ASAN=libc3_asan.la
LIB_COV=libc3_cov.la
LIB_DEBUG=libc3_debug.la
echo "LIB = $LIB" >> ${CONFIG_MK}
echo "LIB_ASAN = $LIB_ASAN" >> ${CONFIG_MK}
echo "LIB_COV = $LIB_COV" >> ${CONFIG_MK}
echo "LIB_DEBUG = $LIB_DEBUG" >> ${CONFIG_MK}
. ./sources.sh
OBJECTS="$(c2ext .main.lo "$LO_SOURCES")"
echo "OBJECTS = $OBJECTS" >> ${CONFIG_MK}
OBJECTS_ASAN="$(c2ext .asan.lo "$LO_SOURCES")"
OBJECTS_COV="$(c2ext .cov.lo "$LO_SOURCES")"
OBJECTS_DEBUG="$(c2ext .debug.lo "$LO_SOURCES")"
# Common config for all targets
CFLAGS="$CFLAGS -W -Wall -Werror -std=c11 -pedantic -pipe"
LDFLAGS="--shared $LDFLAGS -rdynamic"
config_asan
config_gnu
pkg_config libbsd-overlay
pkg_config libffi
pkg_config libmd
config_lib libmd -lmd 2>/dev/null
config_lib dl -ldl 2>/dev/null
config_include sha_h sys/types.h sha.h HAVE_SHA_H
config_include sha1_h sys/types.h sha1.h HAVE_SHA1_H
config_define PREFIX "\"${PREFIX}\""
config_have_stat_mtim
update_config_h
LIBS="$LIBS -lm -pthread -rpath ${PREFIX}/lib"
if ! [ -f ../ucd2c/ucd.c ]; then
touch ../ucd2c/ucd.c
fi
# Address Sanitizer config
CFLAGS_ASAN="$CFLAGS -DDEBUG -O1 -g"
CFLAGS_ASAN="$CFLAGS_ASAN -fsanitize=address -fno-omit-frame-pointer"
LDFLAGS_ASAN="$LDFLAGS"
LIBS_ASAN="$LIBS"
# Coverage config
CFLAGS_COV="$CFLAGS --coverage"
LDFLAGS_COV="$LDFLAGS"
LIBS_COV="$LIBS -lgcov"
# Debug config
CFLAGS_DEBUG="$CFLAGS -DDEBUG -O0 -g"
LDFLAGS_DEBUG="$LDFLAGS"
LIBS_DEBUG="$LIBS"
# Main config
DEFAULT_CFLAGS="-O2 -fPIC"
if [ "x$ENV_CFLAGS" = "x" ]; then
CFLAGS="$CFLAGS $DEFAULT_CFLAGS"
fi
CFLAGS="$CFLAGS -DNDEBUG"
LIBS="$LIBS"
make -f gen.mk
echo "LIB = $LIB" >> ${CONFIG_MK}
echo "HAVE_ASAN = $HAVE_ASAN" >> ${CONFIG_MK}
echo "CPPFLAGS = $CPPFLAGS" >> ${CONFIG_MK}
echo "CFLAGS = $CFLAGS" >> ${CONFIG_MK}
echo "LDFLAGS = $LDFLAGS" >> ${CONFIG_MK}
echo "LIBS = $LIBS" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
echo "LIB_ASAN = $LIB_ASAN" >> ${CONFIG_MK}
echo "CFLAGS_ASAN = $CFLAGS_ASAN" >> ${CONFIG_MK}
echo "LDFLAGS_ASAN = $LDFLAGS_ASAN" >> ${CONFIG_MK}
echo "LIBS_ASAN = $LIBS_ASAN" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
echo "LIB_COV = $LIB_COV" >> ${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 "LIB_DEBUG = $LIB_DEBUG" >> ${CONFIG_MK}
echo "CFLAGS_DEBUG = $CFLAGS_DEBUG" >> ${CONFIG_MK}
echo "LDFLAGS_DEBUG = $LDFLAGS_DEBUG" >> ${CONFIG_MK}
echo "LIBS_DEBUG = $LIBS_DEBUG" >> ${CONFIG_MK}
echo "#!/bin/sh" >> ${CC_ASAN}
echo "# gen by libc3/configure" >> ${CC_ASAN}
echo "CC=\"${CC}\"" >> ${CC_ASAN}
echo "CPPFLAGS=\"${CPPFLAGS_ASAN}\"" >> ${CC_ASAN}
echo "CFLAGS=\"${CFLAGS_ASAN}\"" >> ${CC_ASAN}
echo "${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS} -c \"\$1\" -o \"\$2\" >> .cc/log 2>&1" >> ${CC_ASAN}
update_and_chmod 755 ${CC_ASAN} .build/cc_asan
echo "#!/bin/sh" >> ${CC_COV}
echo "# gen by libc3/configure" >> ${CC_COV}
echo "CC=\"${CC}\"" >> ${CC_COV}
echo "CPPFLAGS=\"${CPPFLAGS_COV}\"" >> ${CC_COV}
echo "CFLAGS=\"${CFLAGS_COV}\"" >> ${CC_COV}
echo "${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS} -c \"\$1\" -o \"\$2\" >> .build/log 2>&1" >> ${CC_COV}
update_and_chmod 755 ${CC_COV} .build/cc_cov
echo "#!/bin/sh" >> ${CC_DEBUG}
echo "# gen by libc3/configure" >> ${CC_DEBUG}
echo "CC=\"${CC}\"" >> ${CC_DEBUG}
echo "CPPFLAGS=\"${CPPFLAGS_DEBUG}\"" >> ${CC_DEBUG}
echo "CFLAGS=\"${CFLAGS_DEBUG}\"" >> ${CC_DEBUG}
echo "${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS} -c \"\$1\" -o \"\$2\" >> .build/log 2>&1" >> ${CC_DEBUG}
update_and_chmod 755 ${CC_DEBUG} .build/cc_debug
echo "#!/bin/sh" >> ${CC_MAIN}
echo "# gen by libc3/configure" >> ${CC_MAIN}
echo "CC=\"${CC}\"" >> ${CC_MAIN}
echo "CPPFLAGS=\"${CPPFLAGS}\"" >> ${CC_MAIN}
echo "CFLAGS=\"${CFLAGS}\"" >> ${CC_MAIN}
echo "${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS} -c \"\$1\" -o \"\$2\" >> .build/log 2>&1" >> ${CC_MAIN}
update_and_chmod 755 ${CC_MAIN} .build/cc_main
echo "#!/bin/sh" >> ${LD_ASAN}
echo "# gen by libc3/configure" >> ${LD_ASAN}
echo "CC=\"${CC}\"" >> ${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} -shared \${LDFLAGS} \${OBJECTS} \${LIBS} -rpath ${LIBDIR} -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 libc3/configure" >> ${LD_COV}
echo "CC=\"${CC}\"" >> ${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} -shared \${LDFLAGS} \${OBJECTS} \${LIBS} -rpath ${LIBDIR} -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 libc3/configure" >> ${LD_DEBUG}
echo "CC=\"${CC}\"" >> ${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} -shared \${LDFLAGS} \${OBJECTS} \${LIBS} -rpath ${LIBDIR} -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 libc3/configure" >> ${LD_MAIN}
echo "CC=\"${CC}\"" >> ${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} -shared \${LDFLAGS} \${OBJECTS} \${LIBS} -rpath ${LIBDIR} -o \"\$1\" >> .build/log 2>&1" >> ${LD_MAIN}
update_and_chmod 755 ${LD_MAIN} .build/ld_main
for SRC in $SOURCES; do
echo >> ${CONFIG_MK}
SRC_ASAN_LO="$(c2ext .asan.lo "$SRC")"
c_ext_rule .asan.lo "$SRC" .build/cc_asan >> ${CONFIG_MK}
echo " .build/cc_asan $SRC $SRC_ASAN_LO" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
SRC_COV_LO="$(c2ext .cov.lo "$SRC")"
c_ext_rule .cov.lo "$SRC" .build/cc_cov >> ${CONFIG_MK}
echo " .build/cc_cov $SRC $SRC_COV_LO" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
SRC_DEBUG_LO="$(c2ext .debug.lo "$SRC")"
c_ext_rule .debug.lo "$SRC" .build/cc_debug >> ${CONFIG_MK}
echo " .build/cc_debug $SRC $SRC_DEBUG_LO" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
SRC_LO="$(c2ext .main.lo "$SRC")"
c_ext_rule .main.lo "$SRC" .build/cc_main >> ${CONFIG_MK}
echo " .build/cc_main $SRC $SRC_LO" >> ${CONFIG_MK}
done
echo >> ${CONFIG_MK}
echo "$LIB: $OBJECTS .build/ld_main" >> ${CONFIG_MK}
echo " .build/ld_main $LIB" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
echo "$LIB_ASAN: $OBJECTS_ASAN .build/ld_asan" >> ${CONFIG_MK}
echo " .build/ld_asan $LIB_ASAN" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
echo "$LIB_COV: $OBJECTS_COV .build/ld_cov" >> ${CONFIG_MK}
echo " .build/ld_cov $LIB_COV" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
echo "$LIB_DEBUG: $OBJECTS_DEBUG .build/ld_debug" >> ${CONFIG_MK}
echo " .build/ld_debug $LIB_DEBUG" >> ${CONFIG_MK}
update_config_mk