Hash :
6d602254
Author :
Thomas de Grivel
Date :
2022-12-27T00:27:26
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
#!/bin/sh
## c3
## Copyright 2022 kmx.io <contact@kmx.io>
##
## Permission is hereby granted to use this software excepted
## on Apple computers 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_gnu() {
if grep -q _GNU_SOURCE /usr/include/features.h 2>/dev/null; then
CFLAGS="$CFLAGS -D_GNU_SOURCE"
fi
}
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
}
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_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 "C3_TOP = $C3_TOP" >> ${CONFIG_MK}
if test -z "$CC"; then
if test -n $(which cc); then
CC=cc
elif test -n $(which gcc); then
CC=gcc
fi
fi
echo "CC = $CC" >> ${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 test -z "$INSTALL"; then
if test -x "$(which install)"; then
INSTALL=install
fi
fi
echo "INSTALL = $INSTALL" >> ${CONFIG_MK}
if test -z "$LIBTOOL"; 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 test -z "$PREFIX"; then
if test -d "$HOME/.c3"; then
PREFIX="$HOME/.c3"
elif test -d /usr/local; then
PREFIX=/usr/local
elif test -d /usr; then
PREFIX=/usr
elif test -d /opt/local; then
PREFIX=/opt/local
elif test -d /opt; then
PREFIX=/opt
fi
fi
echo "PREFIX = $PREFIX" >> ${CONFIG_MK}
if test -z "$OWNER"; then
OWNER="$(ls -ld "$PREFIX" | tr -s ' ' | cut -d ' ' -f 3)"
fi
echo "OWNER = $OWNER" >> ${CONFIG_MK}
if test -z "$GROUP"; then
GROUP="$(ls -ld "$PREFIX" | tr -s ' ' | cut -d ' ' -f 4)"
fi
echo "GROUP = $GROUP" >> ${CONFIG_MK}
if test -z "$BINDIR"; then
BINDIR=${PREFIX}/bin
fi
echo "BINDIR = $BINDIR" >> ${CONFIG_MK}
if test -z "$LIBDIR"; then
LIBDIR=${PREFIX}/lib
fi
echo "LIBDIR = $LIBDIR" >> ${CONFIG_MK}