Hash :
7f80441c
Author :
Thomas de Grivel
Date :
2022-11-16T18:44:38
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
#!/bin/sh
## c3
## Copyright 2022 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 C3_TOP="$(pwd)/.."
. ../config.subr
LIB=libc3.la
LIB_ASAN=libc3.asan.la
LIB_COV=libc3.cov.la
LIB_DEBUG=libc3.debug.la
SOURCES="$(ls *.c | tr '\n' ' ')"
echo "SOURCES = $SOURCES" >> ${CONFIG_MK}
LIBTOMMATH_SOURCES="$(ls ../libtommath/*.c | grep -v -e bn_mp_set_double.c -e bn_s_mp_rand_platform.c | tr '\n' ' ')"
LO_SOURCES="$SOURCES $LIBTOMMATH_SOURCES"
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")"
# Default config
CPPFLAGS="${CPPFLAGS:=}"
ENV_CFLAGS="${CFLAGS:=}"
DEFAULT_CFLAGS="-O2 -pipe -fPIC"
LDFLAGS="${LDFLAGS:=}"
LIBS="${LIBS:=-lm -lffi}"
# Common config for all targets
CFLAGS="$CFLAGS -W -Wall -Werror -Wno-empty-translation-unit -std=c99 -pedantic"
config_asan
config_libbsd
config_libcrypto
# Address Sanitizer config
CFLAGS_ASAN="$CFLAGS -fsanitize=address -O1 -fno-omit-frame-pointer -g"
LDFLAGS_ASAN="$LDFLAGS"
LIBS_ASAN="$LIBS"
# Coverage config
CFLAGS_COV="$CFLAGS -ftest-coverage -fprofile-arcs"
LDFLAGS_COV="$LDFLAGS"
LIBS_COV="$LIBS"
# Debug config
CFLAGS_DEBUG="$CFLAGS -DDEBUG -O0 -ggdb"
LDFLAGS_DEBUG="$LDFLAGS"
LIBS_DEBUG="$LIBS"
# Main config
if [ "x$ENV_CFLAGS" = "x" ]; then
CFLAGS="$CFLAGS $DEFAULT_CFLAGS"
fi
CFLAGS="$CFLAGS -DNDEBUG"
LIBS="$LIBS"
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 "CFLAGS_ASAN = $CFLAGS_ASAN" >> ${CONFIG_MK}
echo "LDFLAGS_ASAN = $LDFLAGS_ASAN" >> ${CONFIG_MK}
echo "LIBS_ASAN = $LIBS_ASAN" >> ${CONFIG_MK}
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}
for SRC in $SOURCES; do
echo >> ${CONFIG_MK}
SRC_LO="$(c2ext .main.lo "$SRC")"
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")"
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}
echo >> ${CONFIG_MK}
SRC_COV_LO="$(c2ext .cov.lo "$SRC")"
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}
echo >> ${CONFIG_MK}
SRC_DEBUG_LO="$(c2ext .debug.lo "$SRC")"
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
echo >> ${CONFIG_MK}
echo "$LIB: $OBJECTS" >> ${CONFIG_MK}
echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${LDFLAGS} ${OBJECTS} \${LIBS} -o ${LIB} -rpath ${LIBDIR}" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
echo "$LIB_ASAN: $OBJECTS_ASAN" >> ${CONFIG_MK}
echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${LDFLAGS_ASAN} ${OBJECTS_ASAN} \${LIBS_ASAN} -o ${LIB_ASAN}" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
echo "$LIB_COV: $OBJECTS_COV" >> ${CONFIG_MK}
echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${LDFLAGS_COV} ${OBJECTS_COV} \${LIBS_COV} -o ${LIB_COV}" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
echo "$LIB_DEBUG: $OBJECTS_DEBUG" >> ${CONFIG_MK}
echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${LDFLAGS_DEBUG} ${OBJECTS_DEBUG} \${LIBS_DEBUG} -o ${LIB_DEBUG}" >> ${CONFIG_MK}
echo >> ${CONFIG_MK}
echo "install: ${LIB}" >> ${CONFIG_MK}
echo " \${INSTALL} -o \${OWNER} -g \${GROUP} -m 0755 -d \${LIBDIR}" >> ${CONFIG_MK}
echo " \${LIBTOOL} --tag=CC --mode=install \${INSTALL} -o \${OWNER} -g \${GROUP} -m 0755 ${LIB} \${LIBDIR}" >> ${CONFIG_MK}
update_config_mk