-
Notifications
You must be signed in to change notification settings - Fork 65
/
configure
executable file
·281 lines (231 loc) · 7.32 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
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
#!/bin/sh
#
# Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@openbsd.org>
# Copyright (c) 2018 Jan Stary <hans@stare.cz>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
set -e
[ -w config.log ] && mv config.log config.log.old
[ -w config.h ] && mv config.h config.h.old
# Output file descriptor usage:
# 1 (stdout): config.h, Makefile.local
# 2 (stderr): original stderr, usually to the console
# 3: config.log
exec 3> config.log
echo "config.log: writing..."
# --- default settings -------------------------------------------------
SOURCEDIR=`dirname "$0"`
CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make -sf -`
CFLAGS="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings"
CFLAGS="${CFLAGS} -Wno-unused-parameter"
LDFLAGS=
LDADD=
HAVE_ERR=
HAVE_GETOPT=
HAVE_GETIMEOFDAY=
HAVE_PROGNAME=
HAVE_STRTONUM=
#HAVE_NTOHL=
#HAVE_PATH_MAX=
#HAVE_REALLOCARRAY=
#HAVE_RECALLOCARRAY=
#HAVE_STRCASESTR=
#HAVE_STRINGLIST=
#HAVE_STRLCAT=
#HAVE_STRLCPY=
#HAVE_STRNDUP=
HAVE_LNSL=
HAVE_LSOCKET=
HAVE_BIGENDIAN=
HAVE_MSGCONTROL=
INSTALL="install"
PREFIX="/usr/local"
BINDIR=
MANDIR=
# --- manual settings from configure.local -----------------------------
if [ -r ./configure.local ]; then
echo "configure.local: reading..." 1>&2
echo "configure.local: reading..." 1>&3
cat ./configure.local 1>&3
. ./configure.local
else
echo "configure.local: no (fully automatic configuration)" 1>&2
echo "configure.local: no (fully automatic configuration)" 1>&3
fi
echo 1>&3
# --- tests for config.h ----------------------------------------------
COMP="${CC} ${CFLAGS} -Wno-unused -Werror"
# Check whether this HAVE_ setting is manually overridden.
# If yes, use the override, if no, do not decide anything yet.
# Arguments: lower-case test name, manual value
ismanual() {
[ -z "${3}" ] && return 1
echo "${1}: manual (HAVE_${2}=${3})" 1>&2
echo "${1}: manual (HAVE_${2}=${3})" 1>&3
echo 1>&3
return 0
}
# Run a single autoconfiguration test.
# In case of success, enable the feature.
# In case of failure, do not decide anything yet.
# Arguments: lower-case test name, upper-case test name, additional CFLAGS
singletest() {
cat 1>&3 << __HEREDOC__
${1}${3}: testing...
${COMP} -o have-${1} have-${1}.c ${3}
__HEREDOC__
if ${COMP} -o "have-${1}" "${SOURCEDIR}/have-${1}.c" ${3} 1>&3 2>&3
then
echo "${1}${3}: ${CC} succeeded" 1>&3
else
echo "${1}${3}: ${CC} failed with $?" 1>&3
echo 1>&3
return 1
fi
if ./have-${1} 1>&3 2>&3; then
echo "${1}${3}: yes" 1>&2
echo "${1}${3}: yes" 1>&3
echo 1>&3
eval HAVE_${2}=1
rm "have-${1}"
return 0
else
echo "${1}${3}: execution failed with $?" 1>&3
echo 1>&3
rm "have-${1}"
return 1
fi
}
# Run a complete autoconfiguration test, including the check for
# a manual override and disabling the feature on failure.
# Arguments: lower case name, upper case name, additional CFLAGS
runtest() {
eval _manual=\${HAVE_${2}}
ismanual "${1}" "${2}" "${_manual}" && return 0
singletest "${1}" "${2}" "${3}" && return 0
echo "${1}${3}: no" 1>&2
eval HAVE_${2}=0
return 1
}
# --- run the tests ---
# functions
runtest err ERR || true
runtest getopt GETOPT || true
runtest gettimeofday GETTIMEOFDAY || true
runtest progname PROGNAME || true
runtest strtonum STRTONUM || true
#runtest ntohl NTOHL || true
#runtest PATH_MAX PATH_MAX || true
#runtest reallocarray REALLOCARRAY || true
#runtest recallocarray RECALLOCARRAY || true
#runtest strcasestr STRCASESTR || true
#runtest stringlist STRINGLIST || true
#runtest strlcat STRLCAT || true
#runtest strlcpy STRLCPY || true
#runtest strndup STRNDUP || true
# structures
runtest bigendian BIGENDIAN || true
runtest msgcontrol MSGCONTROL || true
# extra libs needed
runtest gethostbyname LNSL -lnsl || true
runtest socket LSOCKET -lsocket|| true
runtest windows WINDOWS || true
# --- write config.h ---
exec > config.h
cat << __HEREDOC__
#ifdef __cplusplus
#error "Do not use C++"
#endif
#if !defined(__GNUC__) || (__GNUC__ < 4)
#define __attribute__(x)
#endif
#if defined(__linux__) || defined(__MINT__)
#define _GNU_SOURCE /* See have-*.c for what needs this. */
#endif
__HEREDOC__
#[ ${HAVE_REALLOCARRAY} -eq 0 -o ${HAVE_RECALLOCARRAY} -eq 0 -o \
#${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 -o \
#${HAVE_STRNDUP} -eq 0 ] \
#&& echo "#include <sys/types.h>"
#echo
#[ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096"
cat << __HEREDOC__
#define HAVE_ERR ${HAVE_ERR}
#define HAVE_GETOPT ${HAVE_GETOPT}
#define HAVE_GETTIMEOFDAY ${HAVE_GETTIMEOFDAY}
#define HAVE_PROGNAME ${HAVE_PROGNAME}
#define HAVE_STRTONUM ${HAVE_STRTONUM}
/*
#define HAVE_NTOHL ${HAVE_NTOHL}
#define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
#define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
#define HAVE_STRCASESTR ${HAVE_STRCASESTR}
#define HAVE_STRINGLIST ${HAVE_STRINGLIST}
#define HAVE_STRLCAT ${HAVE_STRLCAT}
#define HAVE_STRLCPY ${HAVE_STRLCPY}
#define HAVE_STRNDUP ${HAVE_STRNDUP}
*/
#define RTP_BIG_ENDIAN ${HAVE_BIGENDIAN}
#define HAVE_MSGCONTROL ${HAVE_MSGCONTROL}
__HEREDOC__
if [ ${HAVE_ERR} -eq 0 ]; then
echo "extern void err(int, const char *, ...);"
echo "extern void errx(int, const char *, ...);"
echo "extern void warn(const char *, ...);"
echo "extern void warnx(const char *, ...);"
fi
if [ ${HAVE_PROGNAME} -eq 0 ]; then
echo "extern const char *getprogname(void);"
echo "extern void setprogname(const char *);"
fi
[ ${HAVE_STRTONUM} -eq 0 ] && \
echo "extern long long strtonum(const char *, long long, long long, const char **);"
#[ ${HAVE_REALLOCARRAY} -eq 0 ] && \
#echo "extern void *reallocarray(void *, size_t, size_t);"
#
#[ ${HAVE_RECALLOCARRAY} -eq 0 ] && \
#echo "extern void *recallocarray(void *, size_t, size_t, size_t);"
#
#[ ${HAVE_STRCASESTR} -eq 0 ] && \
#echo "extern char *strcasestr(const char *, const char *);"
#
#[ ${HAVE_STRLCAT} -eq 0 ] && \
#echo "extern size_t strlcat(char *, const char *, size_t);"
#
#[ ${HAVE_STRLCPY} -eq 0 ] && \
#echo "extern size_t strlcpy(char *, const char *, size_t);"
#
#[ ${HAVE_STRNDUP} -eq 0 ] && \
#echo "extern char *strndup(const char *, size_t);"
echo "config.h: written" 1>&2
echo "config.h: written" 1>&3
# --- tests for Makefile.local -----------------------------------------
exec > Makefile.local
[ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
[ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man"
[ ${HAVE_LNSL} -eq 1 ] && LDADD="${LDADD} -lnsl"
[ ${HAVE_LSOCKET} -eq 1 ] && LDADD="${LDADD} -lsocket"
[ ${HAVE_WINDOWS} -eq 1 ] && LDADD="${LDADD} -lws2_32"
cat << __HEREDOC__
CC = ${CC}
CFLAGS = ${CFLAGS}
LDFLAGS = ${LDFLAGS}
LDADD = ${LDADD}
PREFIX = ${PREFIX}
BINDIR = ${BINDIR}
MANDIR = ${MANDIR}
INSTALL = ${INSTALL}
__HEREDOC__
echo "Makefile.local: written" 1>&2
echo "Makefile.local: written" 1>&3
exit 0