Hash :
396ebad7
Author :
Thomas de Grivel
Date :
2023-10-21T15:21:20
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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
#!/bin/sh
## c3
## Copyright 2022,2023 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
echo "$(basename "$PWD")/$(basename "$0")"
o_rule() {
"$CC" $CPPFLAGS $CFLAGS -M "$1" || { echo "$1" | sed -e 's/^\(.*\)\.c$/\1.o: \1.c/'; }
echo "$1" | sed -e 's/^\(.*\)\.c$/\1.o: Makefile config.mk/'
}
ext_rule() {
o_rule "$2" | sed -e "s/[.]o:/$1:/"
}
lo_rule() {
ext_rule .lo "$1"
}
prog_rule() {
{ o_rule "$1" || exit 1; } | sed -e 's/[.]o:/:/'
}
c2prog() {
echo "$@" | sed -e 's/[.]c$//' -e 's/[.]c / /g'
}
c2ext() {
EXT="$1"; shift
echo "$@" | sed -e "s/[.]c$/${EXT}/" -e "s/[.]c /${EXT} /g"
}
c2o() {
c2ext .o "$@"
}
c2lo() {
c2ext .lo "$@"
}
c2la() {
c2ext .la "$@"
}
config_asan() {
echo "int main() { return 0; }" > .config_asan.c
if $CC $CFLAGS .config_asan.c $LDFLAGS -lasan -o /dev/null 2>/dev/null; then
HAVE_ASAN=true
else
HAVE_ASAN=false
fi
rm .config_asan.c
}
config_define () {
echo "#define $1 $2" >> "${CONFIG_H}"
}
config_gnu() {
if grep -q _GNU_SOURCE /usr/include/features.h 2>/dev/null; then
CFLAGS="$CFLAGS -D_GNU_SOURCE"
fi
}
config_include() {
OUT=".config_$1"
OUT_C=".config_$1.c"
shift
echo "/* generated by configure */" > "$OUT_C"
while [ $# -gt 1 ]; do
echo "#include <$1>" >> "$OUT_C"
shift
done
echo "int main () { return 0; }" >> "$OUT_C"
if ${CC} ${CPPFLAGS} ${CFLAGS} "$OUT_C" -o "$OUT"; then
echo "#define $1 1" >> "${CONFIG_H}"
eval "$1=Yes"
else
echo "#define $1 0" >> "${CONFIG_H}"
eval "$1=No"
fi
rm "$OUT_C"
rm "$OUT"
}
config_lib() {
LIBS_SAVE="$LIBS"
OUT=".config_$1.c"
shift
echo "/* generated by configure */" > "$OUT"
echo "int main () { return 0; }" >> "$OUT"
LIBS="${LIBS} $@"
if ${CC} ${CPPFLAGS} ${CFLAGS} "$OUT" ${LIBS} -o /dev/null; then
:
else
LIBS="${LIBS_SAVE}"
fi
rm "$OUT"
}
pkg_config() {
if pkg-config "$1"; then
CFLAGS="$CFLAGS $(pkg-config --cflags "$1")"
LIBS="$LIBS $(pkg-config --libs "$1")"
fi
}
require_pkg_config() {
if ! which pkg-config >/dev/null; then
echo "please install pkg-config" >&2
exit 1
fi
}
sources() {
echo "$1 = \\
$(echo "$2" | sed -e 's/^\(.*\)$/ \1 \\\\/')
" >> ${SOURCES_MK}
echo "$1='$(echo "$2" | tr '\n' ' ')'" >> ${SOURCES_SH}
}
update_config_h() {
echo "#endif" >> "${CONFIG_H}"
if ! cmp "${CONFIG_H}" config.h >/dev/null 2>&1; then
mv "${CONFIG_H}" config.h
echo "-> $(basename "$PWD")/config.h"
else
rm "${CONFIG_H}"
fi
}
update_config_mk() {
if ! cmp "${CONFIG_MK}" config.mk >/dev/null 2>&1; then
mv "${CONFIG_MK}" config.mk
echo "-> $(basename "$PWD")/config.mk"
else
rm "${CONFIG_MK}"
fi
}
update_sources_mk() {
if ! cmp "${SOURCES_MK}" sources.mk >/dev/null 2>&1; then
mv "${SOURCES_MK}" sources.mk
echo "-> $(basename "$PWD")/sources.mk"
else
rm "${SOURCES_MK}"
fi
}
update_sources_sh() {
if ! cmp "${SOURCES_SH}" sources.sh >/dev/null 2>&1; then
mv "${SOURCES_SH}" sources.sh
echo "-> $(basename "$PWD")/sources.sh"
else
rm "${SOURCES_SH}"
fi
}
CONFIG_H=config.h
CONFIG_H=".config.h.tmp"
echo "/* config.h generated by configure */" > ${CONFIG_H}
echo "#ifndef CONFIG_H" >> "${CONFIG_H}"
echo "#define CONFIG_H" >> "${CONFIG_H}"
CONFIG_MK=config.mk
CONFIG_MK=".config.mk.tmp"
echo "# config.mk generated by configure" > ${CONFIG_MK}
SOURCES_MK=sources.mk
SOURCES_MK=".sources.mk.tmp"
SOURCES_SH=sources.sh
SOURCES_SH=".sources.sh.tmp"
VER=0.1
echo "VER = $VER" >> ${CONFIG_MK}
echo "SRC_TOP = $SRC_TOP" >> ${CONFIG_MK}
if [ "x$CC" = "x" ]; then
if test -n $(which cc); then
CC=cc
elif test -n $(which gcc); then
CC=gcc
fi
fi
echo "CC = $CC" >> ${CONFIG_MK}
CC_TARGET=$(LC_ALL=C cc -v 2>&1 | grep 'Target: ' | cut -c 9-)
echo "CC_TARGET = $CC_TARGET" >> ${CONFIG_MK}
if [ "x$GCOV" = "x" ]; then
if which gcov >/dev/null 2>&1; then
GCOV=gcov
HAVE_GCOV=true
elif which egcov >/dev/null 2>&1; then
GCOV=egcov
HAVE_GCOV=true
fi
HAVE_GCOV=false
else
HAVE_GCOV=true
fi
echo "HAVE_GCOV = $HAVE_GCOV" >> ${CONFIG_MK}
if ${HAVE_GCOV}; then
echo "GCOV = $GCOV" >> ${CONFIG_MK}
fi
if [ "x$GMAKE" = "x" ]; then
if which gmake 2>/dev/null; then
GMAKE=gmake
else
GMAKE=make
fi
fi
echo "GMAKE = $GMAKE" >> ${CONFIG_MK}
if [ "x$INSTALL" = "x" ]; then
if test -x "$(which install)"; then
INSTALL=install
fi
fi
echo "INSTALL = $INSTALL" >> ${CONFIG_MK}
if [ "x$LIBTOOL" = "x" ]; then
if test -x "$(which glibtool 2>/dev/null)"; then
LIBTOOL="$(which glibtool)"
elif test -x "/usr/local/bin/libtool"; then
LIBTOOL="/usr/local/bin/libtool"
elif test -x "$(which libtool 2>/dev/null)"; then
LIBTOOL="$(which libtool)"
else
LIBTOOL=libtool
fi
fi
echo "LIBTOOL = $LIBTOOL" >> ${CONFIG_MK}
PREFIX="${PREFIX:-/usr/local}"
echo "PREFIX = $PREFIX" >> ${CONFIG_MK}
echo "DESTDIR ?=" >> ${CONFIG_MK}
echo "prefix ?= ${DESTDIR}${PREFIX}" >> ${CONFIG_MK}
if [ "x$OWNER" = "x" ]; then
OWNER="$(ls -ld "$PREFIX" | tr -s ' ' | cut -d ' ' -f 3)"
fi
echo "OWNER = $OWNER" >> ${CONFIG_MK}
if [ "x$GROUP" = "x" ]; then
GROUP="$(ls -ld "$PREFIX" | tr -s ' ' | cut -d ' ' -f 4)"
fi
echo "GROUP = $GROUP" >> ${CONFIG_MK}
if [ "x$BINDIR" = "x" ]; then
BINDIR="${PREFIX}/bin"
fi
echo "BINDIR = $BINDIR" >> ${CONFIG_MK}
if [ "x$LIBDIR" = "x" ]; then
LIBDIR="${PREFIX}/lib"
fi
echo "LIBDIR = $LIBDIR" >> ${CONFIG_MK}