-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.plain
executable file
·408 lines (352 loc) · 9.68 KB
/
configure.plain
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#!/bin/sh
#
# Guess values for system-dependent variables and create Makefiles.
#
# Copyright (C) 2017-2020 Zhang Maiyun
#
# This file is part of the slib.
# The slib is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
srcdir="$(dirname "$0")"
export CONFIGROOT="$srcdir/cmake"
# shellcheck source=cmake/acconf.sh
. "$srcdir/cmake/acconf.sh"
# Kept for no reason
# Plus which, cc, ar and sh, these are minimal requirement to build this project
check_progs cat mkdir cut sed expr find tr grep uname install ln make
# Default/init value of variables
prefix="/usr/local"
bindir=""
libdir=""
includedir=""
cross=""
cc="${CC}"
ar="${AR}"
rm="rm"
# shellcheck disable=SC2153 # CFLAGS is external
cflags="${CFLAGS} ${CPPFLAGS} -Wall -Wextra -pedantic -O2 -DHAVE_CONFIG_H -I${srcdir}/include -I."
# shellcheck disable=SC2153 # LDFLAGS is external
ldflags="-lm ${LDFLAGS}"
soflags=""
cfiles="$(
cd "${srcdir}" || exit 1
find src -name '*.c' -type f | tr '\n' ' '
)"
hfiles="$(find "${srcdir}/include" -name '*.h' -type f | tr '\n' ' ')"
exesuf=""
sosuf=""
disable_abort=""
enable_dmalloc=""
# Get constants defined in CMakeLists.txt
name="libsbl"
ver_major="$(grep SBLLIB_VERSION "${srcdir}/include/slib/general.h" | cut -f3 -d\ )"
ver_minor="$(grep SBLLIB_MINOR "${srcdir}/include/slib/general.h" | cut -f3 -d\ )"
ver_pl="$(grep SBLLIB_PATCHLEVEL "${srcdir}/include/slib/general.h" | cut -f3 -d\ )"
version="${ver_major}.${ver_minor}.${ver_pl}"
description="$(grep PROJECT_DESCRIPTION "${srcdir}/CMakeLists.txt" | cut -d\" -f2)"
# Help
help_me()
{
cat <<EON
Usage: ${srcdir}/configure [option=<value> | --help]
Options:
--prefix=PREFIX set prefix [/usr/local]
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]
--target=TARGET unused
--rm=RM file unlinking program(Should support \`-f') [rm]
--sosuffix=EXT_WITH_A_DOT set extension of shared objects
--exesuffix=EXT_WITH_A_DOT set extension of executables
--soflags=SOFLAGS set CFLAGS for shared objects
--*dir=DIR set bindir, libdir, includedir, mandir, infodir
--help,-h display this help information
Optional Features:
--disable-abort disable abort on memory failure [enabled]
--enable-dmalloc enable dmalloc for debug [disabled]
Some influential environment variables:
AR libmaker
CC C compiler
CFLAGS C flags
LDFLAGS LD flags
Project maintained by Zhang Maiyun <[email protected]>.
EON
exit 0
}
# Parse arguments
for opt
do
eval opt=\""${opt}"\"
case "${opt}" in
--prefix=*)
prefix=$(echo "${opt}" | cut -d '=' -f 2)
;;
--host=*)
cross=$(echo "${opt}" | cut -d '=' -f 2)
;;
--build=* | --target=*) ;;
--rm=*)
rm=$(echo "${opt}" | cut -d '=' -f 2)
;;
--sosuffix=*)
sosuf=$(echo "${opt}" | cut -d '=' -f 2)
;;
--exesuffix=*)
exesuf=$(echo "${opt}" | cut -d '=' -f 2)
;;
--bindir=*)
bindir=$(echo "${opt}" | cut -d '=' -f 2)
;;
--libdir=*)
libdir=$(echo "${opt}" | cut -d '=' -f 2)
;;
--includedir=*)
includedir=$(echo "${opt}" | cut -d '=' -f 2)
;;
--soflags=*)
soflags="${soflags} $(echo "${opt}" | cut -d '=' -f 2)"
;;
--disable-abort)
disable_abort=on
;;
--enable-abort)
disable_abort=""
;;
--disable-dmalloc)
enable_dmalloc=""
;;
--enable-dmalloc)
enable_dmalloc=on
;;
--help | -h)
help_me
;;
*)
echo configure: Warning: unrecognized option "${opt}"
;;
esac
done
if [ "$enable_dmalloc" = "on" ]
then
ldflags="${ldflags} -ldmalloc"
fi
echo "Starting configuration for host $(get_proper_triplet "$cross")"
# Check for C compiler
if [ "$cc" = "" ]
then
check_cc "$cross"
fi
# exesuf also determined here
check_cc_works
# Check for ar
if [ "$ar" = "" ]
then
check_ar "$cross"
fi
# For sosuf
check_shared_works "$cross" "$version"
if [ "$append_version" = "true" ]
then
if [ "$sosuf" = ".so" ]
then
acsosuf=${sosuf}.${ver_major}
else
acsosuf=.${ver_major}${sosuf}
fi
fi
if check_header "alloca.h"
then
alloca_h=1
else
alloca_h=0
fi
if check_header "fcntl.h"
then
fcntl_h=1
else
fcntl_h=0
fi
if check_header "stdbool.h"
then
stdbool_h=1
else
stdbool_h=0
fi
if check_header "stdint.h"
then
stdint_h=1
else
stdint_h=0
fi
if check_header "termios.h"
then
termios_h=1
else
termios_h=0
fi
if check_header "unistd.h"
then
unistd_h=1
else
unistd_h=0
fi
if check_type "size_t"
then
size_t=0
else
size_t=1
fi
if check_type "intptr_t"
then
intptr_t=0
else
intptr_t=1
fi
if [ "$libdir" = "" ]
then
libdir="$prefix/lib"
fi
if [ "$bindir" = "" ]
then
bindir="$prefix/bin"
fi
if [ "$includedir" = "" ]
then
includedir="$prefix/include"
fi
# Write output
mkdir -p src
echo Generating Makefile
cat >Makefile <<ACEOF
# Makefile generated by configure
OBJECTS_SHARED=$(echo "${cfiles}" | sed s/\\.c/.c.shared.o/g)
OBJECTS_STATIC=$(echo "${cfiles}" | sed s/\\.c/.c.static.o/g)
CC=${cc}
CFLAGS=${cflags}
LDFLAGS=${ldflags}
all: libsbl${acsosuf} libsbl.a sbltool${exesuf}
libsbl${acsosuf}: \$(OBJECTS_SHARED)
\$(CC) ${soflags} \$(OBJECTS_SHARED) -o \$@ \$(LDFLAGS)
libsbl.a: \$(OBJECTS_STATIC)
${ar} rcs ./libsbl.a \$(OBJECTS_STATIC)
sbltool${exesuf}: libsbl${acsosuf} ${srcdir}/sbltool.c
\$(CC) \$(CFLAGS) -o \$@ ${srcdir}/sbltool.c -L. -lsbl \$(LDFLAGS)
install: all
install -c -d -m 755 ${bindir} ${libdir} ${includedir} ${includedir}/slib
install -c -p -m 644 ${srcdir}/include/slib.h ${includedir}
install -c -p -m 644 ${srcdir}/include/slib/*.h ${includedir}/slib
install -c -p -m 644 sbl.pc ${libdir}/pkgconfig
install -c -p -m 644 libsbl.a ${libdir}
install -c -p -m 755 libsbl${acsosuf} ${libdir}
ln libsbl${acsosuf} ${libdir}/libsbl${sosuf}
install -c -p -m 755 sbltool${exesuf} ${bindir}
# The test, always ensure the built version is used
test: testdrv.exe
./testdrv.exe
.PHONY: clean
clean:
${rm} -rf libsbl.*dylib libsbl.dll libsbl.*so* sbltool sbltool.exe testdrv.exe *.o */*.o *.a
distclean: clean
-rmdir src testbin 2>/dev/null
${rm} -f Makefile config.mk config.h sbl.pc testdrv.h
# Everything below is the same, you will not like to read it line by line
ACEOF
tmp=''
includes=''
entries='{'
for file in "$srcdir"/test/*-test.c
do
tmp="${tmp} ${file}"
testname=$(echo "${file}" | sed s,.*/,, | cut -f1 -d-)
entries="${entries}{\"${testname}\", ${testname}_main}, "
includes="${includes}#include \"${testname}-test.c\"\\n"
done
echo Generating testdrv.h
entries="${entries}{NULL, NULL}}"
# shellcheck disable=SC2059 # the escapes need to be interpreted
printf "${includes}" >testdrv.h
sed "s/@TESTS@/${entries}/;s,@TFILES@,," "${srcdir}/test/testdrv.h.in" >>testdrv.h
{
echo testdrv.exe: "${srcdir}/test/testdrv.c" testdrv.h "${tmp}" libsbl.a
echo " \$(CC) \$(CFLAGS) -I${srcdir}/test -I. -o \$@ ${srcdir}/test/testdrv.c libsbl.a \$(LDFLAGS)"
} >>Makefile
for file in $cfiles
do
echo "${file}.shared.o: ${srcdir}/${file} ${hfiles}"
echo " \$(CC) \$(CFLAGS) -fPIC -Dsbl_EXPORTS -c -o \$@ ${srcdir}/${file}"
echo "${file}.static.o: ${srcdir}/${file} ${hfiles}"
echo " \$(CC) \$(CFLAGS) -c -o \$@ ${srcdir}/${file}"
done >> Makefile
echo Generating sbl.pc
sed "s,@CMAKE_INSTALL_PREFIX@,${prefix},;\
s,@CMAKE_INSTALL_LIBDIR@,lib,;\
s,@CMAKE_INSTALL_INCLUDEDIR@,include,;\
s,@PROJECT_NAME@,${name},;\
s,@PROJECT_DESCRIPTION@,${description},;\
s,@PROJECT_VERSION@,${version},;" \
"${srcdir}/sbl.pc.in" >sbl.pc
echo Generating config.h
if [ $alloca_h -eq 1 ]
then
echo "#define HAVE_ALLOCA_H 1" >config.h
else
echo "#undef HAVE_ALLOCA_H" >config.h
fi
if [ $fcntl_h -eq 1 ]
then
echo "#define HAVE_FCNTL_H 1" >>config.h
else
echo "#undef HAVE_FCNTL_H" >>config.h
fi
if [ $stdbool_h -eq 1 ]
then
echo "#define HAVE_STDBOOL_H 1" >>config.h
else
echo "#undef HAVE_STDBOOL_H" >>config.h
fi
if [ $stdint_h -eq 1 ]
then
echo "#define HAVE_STDINT_H 1" >>config.h
else
echo "#undef HAVE_STDINT_H" >>config.h
fi
if [ $termios_h -eq 1 ]
then
echo "#define HAVE_TERMIOS_H 1" >>config.h
else
echo "#undef HAVE_TERMIOS_H" >>config.h
fi
if [ $unistd_h -eq 1 ]
then
echo "#define HAVE_UNISTD_H 1" >>config.h
else
echo "#undef HAVE_UNISTD_H" >>config.h
fi
if [ $size_t -eq 0 ]
then
echo "#define size_t unsigned int" >>config.h
fi
if [ $intptr_t -eq 0 ]
then
echo "#define intptr_t long int" >>config.h
fi
if [ "$disable_abort" = "on" ]
then
echo "#define S_NOABRT 1" >>config.h
fi
if [ "$enable_dmalloc" = "on" ]
then
echo "#define DMALLOC" >>config.h
echo "#define DMALLOC_FUNC_CHECK" >>config.h
fi
echo "#define sbl_LIBRARY" >>config.h