Hash :
922894e2
Author :
Thomas de Grivel
Date :
2022-12-08T03:01:27
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
#!/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
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_libbsd() {
if pkg-config libbsd-overlay; then
CPPFLAGS="$CPPFLAGS -D_NOT_GNU_SOURCE -D_GNU_SOURCE"
CFLAGS="$CFLAGS $(pkg-config --cflags libbsd-overlay)"
LIBS="$LIBS $(pkg-config --libs libbsd-overlay) -lmd"
fi
}
config_libcrypto() {
if pkg-config libcrypto; then
CFLAGS="$CFLAGS $(pkg-config --cflags libcrypto)"
LIBS="$LIBS $(pkg-config --libs libcrypto)"
fi
}
config_libffi() {
if pkg-config libffi; then
CFLAGS="$CFLAGS $(pkg-config --cflags libffi)"
LIBS="$LIBS $(pkg-config --libs libffi)"
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 "$PWD/config.mk"
else
rm "${CONFIG_MK}"
fi
}
CONFIG_MK=config.mk
CONFIG_MK=".config.mk.tmp"
echo "# config.mk generated by configure" > ${CONFIG_MK}
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 test -z "$GCOV"; then
if test -x "$(which gcov)"; then
GCOV=gcov
elif test -x "$(which egcov)"; then
GCOV=egcov
else
GCOV=gcov
fi
fi
echo "GCOV = $GCOV" >> ${CONFIG_MK}
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}