Hash :
1574cfad
Author :
Thomas de Grivel
Date :
2023-11-19T13:03:40
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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
#!/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
cd "$(dirname "$0")"
echo "$PWD/$(basename "$0")"
c_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/'
}
c_ext_rule() {
c_o_rule "$2" | sed -e "s/[.]o:/$1:/"
}
c_lo_rule() {
c_ext_rule .lo "$1"
}
c_prog_rule() {
{ c_o_rule "$1" || exit 1; } | sed -e 's/[.]o:/:/'
}
c2ext() {
EXT="$1"; shift
echo "$@" | sed -e "s/[.]c$/${EXT}/" -e "s/[.]c /${EXT} /g"
}
c2la() {
c2ext .la "$@"
}
c2lo() {
c2ext .lo "$@"
}
c2o() {
c2ext .o "$@"
}
c2prog() {
echo "$@" | sed -e 's/[.]c$//' -e 's/[.]c / /g'
}
config_asan() {
echo "int main (void) { 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
echo "HAVE_ASAN = $HAVE_ASAN" >> ${CONFIG_MK}
}
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 (void) { return 0; }" >> "$OUT_C"
if ${CC} ${CPPFLAGS} ${CFLAGS} "$OUT_C" -o "$OUT" >/dev/null 2>&1; then
echo "#define $1 1" >> "${CONFIG_H}"
eval "$1=Yes"
else
echo "#define $1 0" >> "${CONFIG_H}"
eval "$1=No"
fi
rm -f "$OUT_C"
rm -f "$OUT"
}
config_lib_have() {
NAME="$1"
shift
OUT_C=".config_$NAME.c"
OUT=".config_$NAME"
echo "/* generated by configure */" > "$OUT_C"
echo "int main (void) { return 0; }" >> "$OUT_C"
if ${CC} ${CPPFLAGS} ${CFLAGS} "$OUT_C" ${LIBS} $@ -o "$OUT"; then
eval "HAVE_$NAME=true"
echo "HAVE_$NAME = true" >> ${CONFIG_MK}
else
eval "HAVE_$NAME=false"
echo "HAVE_$NAME = false" >> ${CONFIG_MK}
fi
rm -f "$OUT" "$OUT_C"
}
config_lib() {
NAME="$1"
shift
OUT_C=".config_$NAME.c"
OUT=".config_$NAME"
echo "/* generated by configure */" > "$OUT_C"
echo "int main (void) { return 0; }" >> "$OUT_C"
if ${CC} ${CPPFLAGS} ${CFLAGS} "$OUT_C" ${LIBS} $@ -o "$OUT"; then
LIBS="$LIBS $@"
fi
rm -f "$OUT" "$OUT_C"
}
env_reset() {
CPPFLAGS="$ENV_CPPFLAGS"
CFLAGS="$ENV_CFLAGS"
LDFLAGS="$ENV_LDFLAGS"
LIBS="$ENV_LIBS"
}
objc_o_rule() {
echo "$1" | sed -e 's/^\(.*\)\.m$/\1.o: \1.m/'
echo "$1" | sed -e 's/^\(.*\)\.m$/\1.o: Makefile config.mk/'
}
objc_ext_rule() {
objc_o_rule "$2" | sed -e "s/[.]o:/$1:/"
}
objc2ext() {
EXT="$1"; shift
echo "$@" | sed -e "s/[.]m$/${EXT}/" -e "s/[.]m /${EXT} /g"
}
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}
}
swift_o_rule() {
echo "$1" | sed -e 's/^\(.*\)\.swift$/\1.o: \1.c/'
echo "$1" | sed -e 's/^\(.*\)\.swift$/\1.o: Makefile config.mk/'
}
swift_ext_rule() {
swift_o_rule "$2" | sed -e "s/[.]o:/$1:/"
}
swift2ext() {
EXT="$1"; shift
echo "$@" | sed -e "s/[.]swift$/${EXT}/" -e "s/[.]swift /${EXT} /g"
}
update_config_h() {
echo "#endif" >> "${CONFIG_H}"
if ! cmp "${CONFIG_H}" config.h >/dev/null 2>&1; then
mv "${CONFIG_H}" config.h
echo "-> ${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 "-> ${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 "-> ${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 "-> ${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}
ENV_CPPFLAGS="$CPPFLAGS"
ENV_CFLAGS="$CFLAGS"
ENV_LDFLAGS="$LDFLAGS"
ENV_LIBS="$LIBS"
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 >/dev/null 2>&1; 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}
#if [ "x$SWIFTC" = "x" ]; then
# if test -x "$(which swiftc 2>/dev/null)"; then
# SWIFTC="$(which swiftc)"
# HAVE_SWIFT=true
# else
# HAVE_SWIFT=false
# fi
#else
# HAVE_SWIFT=true
#fi
#echo "SWIFTC = $SWIFTC" >> ${CONFIG_MK}
#echo "HAVE_SWIFT = $HAVE_SWIFT" >> ${CONFIG_MK}
if [ "x$OBJCC" = "x" ]; then
if test -x "$(which clang 2>/dev/null)"; then
OBJCC="$(which clang)"
else
OBJCC=clang
fi
fi
echo "OBJCC = $OBJCC" >> ${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}