-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·141 lines (120 loc) · 3.48 KB
/
configure
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
#!/bin/sh
# Parameters
CC=gcc
CFLAGS=
DEBUG=true
# Optimization is only relevant when not in debug mode; see DEBUGPARAMS below
# for the actual optimization setting then
OPTIMIZATION="-O3 -flto -Wl,-O1"
WARNINGS="-Wall -Wextra -Wundef -Wshadow -Wcast-align -Wjump-misses-init \
-Wstrict-prototypes -Wstrict-overflow=4 -Wwrite-strings \
-Waggregate-return -Wcast-qual -Wswitch-default -Wstrict-aliasing \
-Wconversion -Wunreachable-code -Wformat=2 -Winit-self -Wuninitialized \
-Wmissing-prototypes -Wold-style-definition -Wdouble-promotion \
-Wsuggest-attribute=noreturn -Wsuggest-attribute=format \
-Wdeclaration-after-statement -Wunsafe-loop-optimizations \
-Wmissing-declarations -Wmissing-field-initializers -Wredundant-decls \
-Winline -Wvla -Wdisabled-optimization -Wstack-protector \
-Wvector-operation-performance"
ERRS="-pedantic-errors -Werror -Wno-error=cast-align -Wno-error=cast-qual"
DEFS=
TESTDEFS=" \
TESTING=1 \
COLOR_RED='\"$(tput setaf 1)\"' \
COLOR_GREEN='\"$(tput setaf 2)\"' \
COLOR_YELLOW='\"$(tput setaf 3)\"' \
COLOR_RESET='\"$(tput sgr 0)\"'"
EXEC=test
LINKS=asan
SRCDIR=src
TESTDIR=tests
MAKEFILE=Makefile
EXT=c
CPARAMS="-std=c99 -Wl,-build-id=sha1 $WARNINGS $ERRS"
DEBUGPARAMS="-ggdb3 -O0 -Wl,-O0 -Wno-error=unreachable-code -ftrapv \
-fstack-check -fstack-protector-all -fverbose-asm -fbounds-check \
-fsanitize=address -fmessage-length=72"
# These could be useful but don't currently work (gcc 4.8.3):
# -fdiagnostics-color=auto
# -fsanitize=thread
# -fsanitize=undefined
# -fsanitize=float-divide-by-zero
MAINFILE=main
# Programmatically generated parameters
SRCS="$(find -wholename "./$SRCDIR/*.$EXT" | tr "\n" " ")"
TESTS="$(find -wholename "./$TESTDIR/*.$EXT" | tr "\n" " ")"
SRCS_NOMAIN="$(printf "%s\n" "$SRCS" | sed \
"s/[^ ]*$SRCDIR\/${MAINFILE}.$EXT//")"
if $DEBUG
then
CPARAMS="$CPARAMS -DDEBUG $DEBUGPARAMS"
LPARAMS="$LPARAMS $DEBUGPARAMS"
else
CPARAMS="$CPARAMS $OPTIMIZATION -DNDEBUG"
fi
for DEF in $DEFS
do
CPARAMS="$CPARAMS -D$DEF"
done
CPARAMS="$CPARAMS $CFLAGS"
LPARAMS=
LLINKS=
if ! $DEBUG
then
LPARAMS="$LPARAMS $OPTIMIZATION"
fi
for LINK in $LINKS
do
LLINKS="$LLINKS -l$LINK"
done
TPARAMS=
for TESTDEF in $TESTDEFS
do
TPARAMS="$TPARAMS -D$TESTDEF"
done
# Actually create the make file
printf "
SHELL = /bin/sh
SRCS = %s
SRCS_NOMAIN = %s
SRCOBJS = \$(SRCS:.%s=.o)
SRCOBJS_NOMAIN = \$(SRCS_NOMAIN:.%s=.o)
TESTS = %s
TESTOBJS = \$(TESTS:.%s=.o)
CFLAGS = %s
LDFLAGS = %s
LINKS = %s
TFLAGS = \$(CFLAGS) %s
%s: \$(SRCOBJS)
\t%s -o \$@ \$(LDFLAGS) \$^ \$(LINKS)
" "$SRCS" "$SRCS_NOMAIN" "$EXT" "$EXT" "$TESTS" "$EXT" "$CPARAMS" "$LPARAMS" \
"$LLINKS" "$TPARAMS" "$EXEC" "$CC" > "$MAKEFILE"
for SRC in $SRCS
do
printf "%s/%s\n\t%s -c -o \$@ \$(CFLAGS) \$<\n" \
"$SRCDIR" "$($CC -MM "$SRC")" "$CC" >> "$MAKEFILE"
done
printf "
.PHONY: check
check: \$(TESTOBJS) ;
" >> "$MAKEFILE"
for TEST in $TESTS
do
printf "%s/%s\n\t@%s -c -o \$@ \$(TFLAGS) \$< \
\n\t%s -o check \$(LDFLAGS) \$@ \$(SRCOBJS_NOMAIN) \$(LINKS) \
\n\t@if ! ./check; then echo; tput setaf 1; echo 'Check failed!'; \
tput sgr 0; exit 1; fi \
\n\t@echo \
\n\t@tput setaf 2 \
\n\t@echo 'Check succeeded!' \
\n\t@echo \
\n\t@tput sgr 0 \
\n\t@rm -f check \$@\n\n" \
"$TESTDIR" "$($CC -MM "$TEST")" "$CC" "$CC" >> "$MAKEFILE"
done
printf "\n
.PHONY: clean
clean:
\tfind -name '*.[ios]' -exec rm '{}' +
\trm -f check '%s'
" "$EXEC" >> "$MAKEFILE"