-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·220 lines (200 loc) · 5.79 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
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
#!/bin/sh
CC="cc"
# Always enabled and cannot be disabled. If your code depends on these features it's either C89 or you have a massive skill issue
CFLAGS="-std=c11 -Werror=implicit-function-declaration -Werror=implicit-int"
AR="ar"
RANLIB="ranlib"
prefix="/usr/local"
exec_prefix="$prefix"
bindir="$exec_prefix/bin"
libdir="$prefix/lib"
includedir="$prefix/include"
platform="c"
indev=0
fatal_error(){
echo "Error: $@!"
echo "Notice: If you're not a project maintainer, this is a bug. Please report this to the project maintainers."
exit 1
}
update_prefixes(){
if [ "$1" = "" ]; then
exec_prefix="$prefix"
fi
bindir="$exec_prefix/bin"
libdir="$prefix/lib"
includedir="$prefix/include"
}
generate_config(){
if [ ! -f ./defaults.conf ]; then
fatal_error "Defaults file is missing"
fi
. ./defaults.conf
if [ "$main_project" = "" ]; then
fatal_error "Main project field is empty"
elif [ $(echo "$main_project" | grep -c '|') -lt 1 ]; then
fatal_error "Invalid main project field"
fi
prefix=$(echo "$prefix" | sed "s/~/$(echo $HOME | sed 's/\//\\\//g')/g")
exec_prefix=$(echo "$exec_prefix" | sed "s/~/$(echo $HOME | sed 's/\//\\\//g')/g")
bindir=$(echo "$bindir" | sed "s/~/$(echo $HOME | sed 's/\//\\\//g')/g")
libdir=$(echo "$libdir" | sed "s/~/$(echo $HOME | sed 's/\//\\\//g')/g")
includedir=$(echo "$includedir" | sed "s/~/$(echo $HOME | sed 's/\//\\\//g')/g")
echo "Checking install prefix...$prefix"
echo "Checking executable install prefix...$exec_prefix"
echo "Checking binary install prefix...$bindir"
echo "Checking library install prefix...$libdir"
echo "Checking headers install prefix...$includedir"
printf "Detecting target system..."
if [ "$target" = "" ]; then
echo "native."
else
echo "$target."
fi
printf "Detecting C compiler..."
compiler_check="$(realpath $(command -v $CC))"
if [ $(echo "$compiler_check" | grep clang -c) -ne 0 ]; then
echo "clang"
if [ "$target" != "" ]; then
CFLAGS="--target=$target $CFLAGS"
fi
elif [ $(echo "$compiler_check" | grep gcc -c) -ne 0 ]; then
echo "gcc"
if [ $(echo $(basename $CC) | grep "$target" -c) -eq 0 ]; then
compile_dir="$(dirname $CC)"
compile_name="$(basename $CC)"
if [ "$compile_dir" != "." ]; then
CC="$compile_dir/"
else
CC=""
fi
CC="$CC$target-$compile_name"
fi
else
echo "$CC"
fi
echo "Compiler flags set...$CFLAGS"
if [ "$LDFLAGS" != "" ]; then
echo "Linker flags set...$LDFLAGS"
fi
compile_config_str="CC=\"$CC\"\nCFLAGS=\"$CFLAGS\"\nAR=\"$AR\"\nRANLIB=\"$RANLIB\"\n"
install_config_str="prefix=\"$prefix\"\nexec_prefix=\"$exec_prefix\"\nbindir=\"$bindir\"\nlibdir=\"$libdir\"\nincludedir=\"$includedir\"\n"
if [ "$LDFLAGS" != "" ]; then
compile_config_str="LDFLAGS=\"$LDFLAGS\"\n$compile_config_str"
fi
if [ $indev -eq 1 ]; then
src="$src $src_indev"
fi
printf "$compile_config_str\n$install_config_str\n" > ./.config
printf "main_project=\"$main_project\"\n\n" >> ./.config
if [ -f ./custom.conf ]; then
cat custom.conf >> ./.config
fi
}
update_prefixes
while [ $# -ne 0 ]; do
case $1 in
--prefix | --prefix=*)
if [ $(echo $1 | grep "=" -c) -ne 0 ]; then
prefix="$(echo $1 | cut -d= -f2)"
else
prefix="$2"
shift
fi
update_prefixes
;;
--exec-prefix | --exec-prefix=*)
if [ $(echo $1 | grep "=" -c) -ne 0 ]; then
exec_prefix="$(echo $1 | cut -d= -f2)"
else
exec_prefix="$2"
shift
fi
update_prefixes exec
;;
--bindir | --bindir=*)
if [ $(echo $1 | grep "=" -c) -ne 0 ]; then
bindir="$(echo $1 | cut -d= -f2)"
else
bindir="$2"
shift
fi
;;
--libdir | --libdir=*)
if [ $(echo $1 | grep "=" -c) -ne 0 ]; then
libdir="$(echo $1 | cut -d= -f2)"
else
libdir="$2"
shift
fi
;;
--includedir | --includedir=*)
if [ $(echo $1 | grep "=" -c) -ne 0 ]; then
includedir="$(echo $1 | cut -d= -f2)"
else
includedir="$2"
shift
fi
;;
--target | --target=*)
if [ $(echo $1 | grep "=" -c) -ne 0 ]; then
target="$(echo $1 | cut -d= -f2)"
else
target="$2"
shift
fi
;;
--enable-indev)
indev=1
;;
--enable-w*)
CFLAGS="$CFLAGS -Wall"
if [ "$1" = "--enable-wextra" ] || [ "$1" = "--enable-werror" ]; then
CFLAGS="$CFLAGS -Wextra"
fi
if [ "$1" = "--enable-werror" ]; then
CFLAGS="$CFLAGS -Werror"
fi
;;
--help | --*)
printf "CinnamonWolfy's Generic C11 Configure System v0.06\n\n"
printf "Usage: $0 [OPTIONS]...\n\n"
echo "Install Options"
echo "--prefix=DIR Set install path (default=/usr/local)"
echo "--exec-prefix=DIR Sets executable install path (default=prefix)"
echo "--bindir=DIR Set binary install path (default=exec_prefix/bin)"
echo "--libdir=DIR Set library install path (default=prefix/lib)"
echo "--includedir=DIR Set include headers install path (default=prefix/include)"
printf "\nCompile Options\n"
echo "--target=TARGET Set the target system"
echo "--enable-nonportable Compile platform-specific modules/source files"
echo "--enable-indev Compile incomplete modules/source files"
echo "--enable-wall Compile with -Wall"
echo "--enable-wextra Compile with -Wextra (enables -Wall)"
echo "--enable-werror Compile with -Werror (enables -Wall -Wextra)"
printf "\nInfluential Environment Variables\n"
echo " CC C compiler"
echo " CFLAGS Flags passed to the C compiler"
echo " LDFLAGS FLags passed to the linker"
echo " AR Archival tool for creating static libraries"
echo " RANLIB Like AR, but indexes symbols in an AR archive"
exit 0
;;
CC=*)
CC=$(echo $1 | cut -d= -f2)
;;
CFLAGS=*)
CFLAGS="$CFLAGS $(echo $1 | cut -d= -f2-)"
;;
LDFLAGS=*)
LDFLAGS="$(echo $1 | cut -d= -f2-)"
;;
AR=*)
AR=$(echo $1 | cut -d= -f2)
;;
RANLIB=*)
RANLIB=$(echo $1 | cut -d= -f2)
;;
esac
shift
done
generate_config