This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
make
executable file
·114 lines (97 loc) · 3.25 KB
/
make
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
#!/bin/sh -e
configure() {
CFLAGS="-Wall -Wextra -pedantic $CFLAGS"
CFLAGS="-std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 $CFLAGS"
CPPFLAGS="-Iinclude $CPPFLAGS"
_dep() {
pkg-config --libs --cflags "${static:+--static}" "$1" ||
printf '%s\n' "$2"
}
# Detect when '-static' is passed via LDFLAGS and handle things accordingly.
case " $LDFLAGS " in *" -static "*)
static=1
esac
# Download functionality. Setting the environment variable CURL to '0' will
# disable the package manager's ability to download sources. Git sources
# will continue to work as normal (so long as git does).
#
# NOTE: The package manager does not depend on a specific SSL library. It
# only directly depends on libcurl.
case ${CURL:=1} in 1)
LDFLAGS="$(_dep libcurl -lcurl) $LDFLAGS"
CFLAGS="-DDL_USE_CURL $CFLAGS"
esac
# Which sha256 implementation to use. If all options are '0', an internal
# sha256 implementation will be used. NOTE: Only one option may be enabled
# at a time.
{
# SHA256 external implementation. Setting the environment variable
# BEARSSL to '1' will cause the package manager to use sha256 from
# bearssl.
case ${BEARSSL:=0} in 1)
LDFLAGS="$(_dep bearssl '-lbearssl') $LDFLAGS"
CFLAGS="-DSHA256_USE_BEARSSL $CFLAGS"
esac
# SHA256 external implementation. Setting the environment variable
# OPENSSL to '1' will cause the package manager to use sha256 from
# openssl.
case ${OPENSSL:=0} in 1)
LDFLAGS="$(_dep openssl '-lssl -lcrypto') $LDFLAGS"
CFLAGS="-DSHA256_USE_OPENSSL $CFLAGS"
esac
}
# tar external implementation. Setting the environment variable
# LIBARCHIVE to '1' will cause the package manager to use tar from
# libarchive. If set to '0', the tar command will be executed.
case ${LIBARCHIVE:=0} in 1)
LDFLAGS="$(_dep libarchive '-larchive') $LDFLAGS"
CFLAGS="-DTAR_USE_LIBARCHIVE $CFLAGS"
esac
}
build() {
configure
_cc() {
printf '%s %s\n' "${CC:=cc}" "$*"
"$CC" "$@" || exit 1
}
for obj in src/[!k]*.c src/*/*.c; do
_cc $CFLAGS $CPPFLAGS -c -o "${obj%%.c}.o" "$obj"
done
for prog in src/kiss.c test/*.c; do
_cc $CFLAGS $CPPFLAGS -o "${prog%%.c}" "$prog" \
src/[!k]*.o src/*/*.o $LDFLAGS
done
}
check() {
export KISS_ROOT=$PWD/test/test_hier
export KISS_PATH=$KISS_ROOT/repo/core:$KISS_ROOT/repo/extra
export XDG_CACHE_HOME=$PWD/test/test_hier
command -v valgrind &&
set -- valgrind \
--leak-check=full \
--track-origins=yes \
--error-exitcode=1 \
--suppressions=test/valgrind/musl.supp \
--suppressions=test/valgrind/lzma.supp
for file in test/*.c; do
"$@" "${file%%.c}" || exit 1
done
}
compdb() {
configure
printf '[\n'
for obj in src/*.c src/*/*.c; do
cat <<EOF
{
"directory": "$PWD",
"command": "${CC:=cc} $CFLAGS $CPPFLAGS -c -o ${obj%%.c}.o $obj",
"file": "$obj"
},
EOF
done
printf ']\n'
} > compile_commands.json
"${1:-build}" || {
printf 'error during %s\n' "$action" >&2
exit 1
}