Blame


1 8951cb19 2022-07-01 op #! /bin/sh
2 8951cb19 2022-07-01 op #
3 8951cb19 2022-07-01 op # Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
4 8951cb19 2022-07-01 op # Copyright (c) 2017, 2018 Kristaps Dzonsons <kristaps@bsd.lv>
5 8951cb19 2022-07-01 op # Copyright (c) 2022 Omar Polo <op@omarpolo.com>
6 8951cb19 2022-07-01 op #
7 8951cb19 2022-07-01 op # Permission to use, copy, modify, and distribute this software for any
8 8951cb19 2022-07-01 op # purpose with or without fee is hereby granted, provided that the above
9 8951cb19 2022-07-01 op # copyright notice and this permission notice appear in all copies.
10 8951cb19 2022-07-01 op #
11 8951cb19 2022-07-01 op # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 8951cb19 2022-07-01 op # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 8951cb19 2022-07-01 op # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 8951cb19 2022-07-01 op # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 8951cb19 2022-07-01 op # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 8951cb19 2022-07-01 op # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 8951cb19 2022-07-01 op # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 8951cb19 2022-07-01 op
19 8951cb19 2022-07-01 op OCONFIGURE_VERSION="0.3.8"
20 db073704 2022-07-02 op MYMENU_VERSION="1.1"
21 8951cb19 2022-07-01 op
22 8951cb19 2022-07-01 op #
23 8951cb19 2022-07-01 op # This script outputs two files: config.h and Makefile.configure.
24 8951cb19 2022-07-01 op # It tries to read from configure.local, which contains predefined
25 8951cb19 2022-07-01 op # values we won't autoconfigure.
26 8951cb19 2022-07-01 op #
27 8951cb19 2022-07-01 op # If you want to use configure with your project, have your GNUmakefile
28 8951cb19 2022-07-01 op # or BSDmakefile---whichever---try to import/include Makefile.configure
29 8951cb19 2022-07-01 op # at the beginning of the file.
30 8951cb19 2022-07-01 op #
31 8951cb19 2022-07-01 op # Like so (note no quotes, no period, etc.):
32 8951cb19 2022-07-01 op #
33 8951cb19 2022-07-01 op # include Makefile.configure
34 8951cb19 2022-07-01 op #
35 8951cb19 2022-07-01 op # If it exists, configure was run; otherwise, it wasn't.
36 8951cb19 2022-07-01 op #
37 8951cb19 2022-07-01 op # You'll probably want to change parts of this file. I've noted the
38 8951cb19 2022-07-01 op # parts that you'll probably change in the section documentation.
39 8951cb19 2022-07-01 op #
40 8951cb19 2022-07-01 op # See https://github.com/kristapsdz/oconfigure for more.
41 8951cb19 2022-07-01 op
42 8951cb19 2022-07-01 op set -e
43 8951cb19 2022-07-01 op
44 8951cb19 2022-07-01 op #----------------------------------------------------------------------
45 8951cb19 2022-07-01 op # Prepare for running: move aside previous configure runs.
46 8951cb19 2022-07-01 op # Output file descriptor usage:
47 8951cb19 2022-07-01 op # 1 (stdout): config.h or Makefile.configure
48 8951cb19 2022-07-01 op # 2 (stderr): original stderr, usually to the console
49 8951cb19 2022-07-01 op # 3: config.log
50 8951cb19 2022-07-01 op # You DO NOT want to change this.
51 8951cb19 2022-07-01 op #----------------------------------------------------------------------
52 8951cb19 2022-07-01 op
53 8951cb19 2022-07-01 op [ -w config.log ] && mv config.log config.log.old
54 8951cb19 2022-07-01 op [ -w config.h ] && mv config.h config.h.old
55 8951cb19 2022-07-01 op
56 8951cb19 2022-07-01 op exec 3> config.log
57 8951cb19 2022-07-01 op echo "config.log: writing..."
58 8951cb19 2022-07-01 op
59 8951cb19 2022-07-01 op # GNU submake prints different output if invoked recursively, which
60 8951cb19 2022-07-01 op # messes up CC and CFLAGS detection. Pass --no-print-directory if
61 8951cb19 2022-07-01 op # we have a MAKELEVEL (GNU and FreeBSD make) and the argument is
62 8951cb19 2022-07-01 op # allowed.
63 8951cb19 2022-07-01 op
64 8951cb19 2022-07-01 op MAKE_FLAGS=""
65 8951cb19 2022-07-01 op
66 8951cb19 2022-07-01 op if [ -n "${MAKELEVEL}" ]; then
67 8951cb19 2022-07-01 op if [ "${MAKELEVEL}" -gt 0 ] ; then
68 8951cb19 2022-07-01 op MAKE_FLAGS="--no-print-directory"
69 8951cb19 2022-07-01 op echo "all:" | make ${MAKE_FLAGS} -sf - 2>/dev/null || MAKE_FLAGS=""
70 8951cb19 2022-07-01 op fi
71 8951cb19 2022-07-01 op fi
72 8951cb19 2022-07-01 op
73 8951cb19 2022-07-01 op if [ -n "$MAKE_FLAGS" ]; then
74 8951cb19 2022-07-01 op echo "GNU submake detected: using --no-print-directory" 1>&2
75 8951cb19 2022-07-01 op echo "GNU submake detected: using --no-print-directory" 1>&3
76 8951cb19 2022-07-01 op fi
77 8951cb19 2022-07-01 op
78 8951cb19 2022-07-01 op #----------------------------------------------------------------------
79 8951cb19 2022-07-01 op # Initialize all variables here such that nothing can leak in from the
80 8951cb19 2022-07-01 op # environment except for CC and CFLAGS, which we might have passed in.
81 8951cb19 2022-07-01 op #----------------------------------------------------------------------
82 8951cb19 2022-07-01 op
83 8951cb19 2022-07-01 op CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make ${MAKE_FLAGS} -sf -`
84 8951cb19 2022-07-01 op CFLAGS=`printf "all:\\n\\t@echo \\\$(CFLAGS)\\n" | make ${MAKE_FLAGS} -sf -`
85 a11fa527 2022-07-01 op CFLAGS="${CFLAGS} -g -W -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes"
86 92775bad 2022-07-02 op CFLAGS="${CFLAGS} -Wno-unused-parameter -Wno-pointer-sign"
87 8951cb19 2022-07-01 op LDADD=
88 8951cb19 2022-07-01 op LDADD_LIB_SOCKET=
89 8951cb19 2022-07-01 op LDADD_STATIC=
90 8951cb19 2022-07-01 op LDADD_LIB_X11=
91 8951cb19 2022-07-01 op CPPFLAGS=
92 8951cb19 2022-07-01 op LDFLAGS=
93 8951cb19 2022-07-01 op DESTDIR=
94 8951cb19 2022-07-01 op PREFIX="/usr/local"
95 8951cb19 2022-07-01 op BINDIR=
96 8951cb19 2022-07-01 op SBINDIR=
97 8951cb19 2022-07-01 op INCLUDEDIR=
98 8951cb19 2022-07-01 op LIBDIR=
99 8951cb19 2022-07-01 op MANDIR=
100 8951cb19 2022-07-01 op SHAREDIR=
101 8951cb19 2022-07-01 op INSTALL="install"
102 8951cb19 2022-07-01 op INSTALL_PROGRAM=
103 8951cb19 2022-07-01 op INSTALL_LIB=
104 8951cb19 2022-07-01 op INSTALL_MAN=
105 8951cb19 2022-07-01 op INSTALL_DATA=
106 8951cb19 2022-07-01 op
107 8951cb19 2022-07-01 op # compats needed
108 8951cb19 2022-07-01 op COBJ=
109 8951cb19 2022-07-01 op
110 8951cb19 2022-07-01 op # SunOS sets "cc", but this doesn't exist.
111 8951cb19 2022-07-01 op # It does have gcc, so try that instead.
112 8951cb19 2022-07-01 op # Prefer clang, though.
113 8951cb19 2022-07-01 op
114 8951cb19 2022-07-01 op command -v ${CC} 2>/dev/null 1>&2 || {
115 8951cb19 2022-07-01 op echo "${CC} not found: trying clang" 1>&2
116 8951cb19 2022-07-01 op echo "${CC} not found: trying clang" 1>&3
117 8951cb19 2022-07-01 op CC=clang
118 8951cb19 2022-07-01 op command -v ${CC} 2>/dev/null 1>&2 || {
119 8951cb19 2022-07-01 op echo "${CC} not found: trying gcc" 1>&2
120 8951cb19 2022-07-01 op echo "${CC} not found: trying gcc" 1>&3
121 8951cb19 2022-07-01 op CC=gcc
122 8951cb19 2022-07-01 op command -v ${CC} 2>/dev/null 1>&2 || {
123 8951cb19 2022-07-01 op echo "gcc not found: giving up" 1>&2
124 8951cb19 2022-07-01 op echo "gcc not found: giving up" 1>&3
125 8951cb19 2022-07-01 op exit 1
126 8951cb19 2022-07-01 op }
127 8951cb19 2022-07-01 op }
128 8951cb19 2022-07-01 op }
129 8951cb19 2022-07-01 op
130 f8d213f1 2022-07-01 op command -v pkg-config 2>/dev/null 1>&2 && {
131 a7de20a8 2022-07-02 op echo "pkg-config: found" 1>&2
132 a7de20a8 2022-07-02 op echo "pkg-config: found" 1>&3
133 a7de20a8 2022-07-02 op
134 f8d213f1 2022-07-01 op if extra="$(pkg-config --cflags x11 xinerama xft || true)"; then
135 f8d213f1 2022-07-01 op echo "Adding to CFLAGS: $extra (pkg-config)"
136 f8d213f1 2022-07-01 op CFLAGS="$extra ${CFLAGS}"
137 f8d213f1 2022-07-01 op fi
138 f8d213f1 2022-07-01 op if extra="$(pkg-config --libs x11 xinerama xft || true)"; then
139 f8d213f1 2022-07-01 op echo "Adding to LDFLAGS: $extra (pkg-config)"
140 f8d213f1 2022-07-01 op LDFLAGS="$extra ${LDFLAGS}"
141 f8d213f1 2022-07-01 op fi
142 a7de20a8 2022-07-02 op } || {
143 a7de20a8 2022-07-02 op echo "pkg-config: not found" 1>&2
144 a7de20a8 2022-07-02 op echo "pkg-config: not found" 1>&3
145 f8d213f1 2022-07-01 op }
146 8951cb19 2022-07-01 op
147 8951cb19 2022-07-01 op #----------------------------------------------------------------------
148 8951cb19 2022-07-01 op # Allow certain variables to be overriden on the command line.
149 8951cb19 2022-07-01 op #----------------------------------------------------------------------
150 8951cb19 2022-07-01 op
151 8951cb19 2022-07-01 op for keyvals in "$@"
152 8951cb19 2022-07-01 op do
153 8951cb19 2022-07-01 op key=`echo $keyvals | cut -s -d '=' -f 1`
154 8951cb19 2022-07-01 op if [ -z "$key" ]
155 8951cb19 2022-07-01 op then
156 8951cb19 2022-07-01 op echo "$0: invalid key-value: $keyvals" 1>&2
157 8951cb19 2022-07-01 op exit 1
158 8951cb19 2022-07-01 op fi
159 8951cb19 2022-07-01 op val=`echo $keyvals | cut -d '=' -f 2-`
160 8951cb19 2022-07-01 op case "$key" in
161 8951cb19 2022-07-01 op LDADD)
162 8951cb19 2022-07-01 op LDADD="$val" ;;
163 8951cb19 2022-07-01 op LDFLAGS)
164 8951cb19 2022-07-01 op LDFLAGS="$val" ;;
165 8951cb19 2022-07-01 op CPPFLAGS)
166 8951cb19 2022-07-01 op CPPFLAGS="$val" ;;
167 8951cb19 2022-07-01 op DESTDIR)
168 8951cb19 2022-07-01 op DESTDIR="$val" ;;
169 8951cb19 2022-07-01 op PREFIX)
170 8951cb19 2022-07-01 op PREFIX="$val" ;;
171 8951cb19 2022-07-01 op MANDIR)
172 8951cb19 2022-07-01 op MANDIR="$val" ;;
173 8951cb19 2022-07-01 op LIBDIR)
174 8951cb19 2022-07-01 op LIBDIR="$val" ;;
175 8951cb19 2022-07-01 op BINDIR)
176 8951cb19 2022-07-01 op BINDIR="$val" ;;
177 8951cb19 2022-07-01 op SHAREDIR)
178 8951cb19 2022-07-01 op SHAREDIR="$val" ;;
179 8951cb19 2022-07-01 op SBINDIR)
180 8951cb19 2022-07-01 op SBINDIR="$val" ;;
181 8951cb19 2022-07-01 op INCLUDEDIR)
182 8951cb19 2022-07-01 op INCLUDEDIR="$val" ;;
183 8951cb19 2022-07-01 op *)
184 8951cb19 2022-07-01 op echo "$0: invalid key: $key" 1>&2
185 8951cb19 2022-07-01 op exit 1
186 8951cb19 2022-07-01 op esac
187 8951cb19 2022-07-01 op done
188 8951cb19 2022-07-01 op
189 8951cb19 2022-07-01 op
190 8951cb19 2022-07-01 op #----------------------------------------------------------------------
191 8951cb19 2022-07-01 op # These are the values that will be pushed into config.h after we test
192 8951cb19 2022-07-01 op # for whether they're supported or not.
193 8951cb19 2022-07-01 op # Each of these must have a runtest(), below.
194 8951cb19 2022-07-01 op # Please sort by alpha, for clarity.
195 8951cb19 2022-07-01 op # You WANT to change this.
196 8951cb19 2022-07-01 op #----------------------------------------------------------------------
197 8951cb19 2022-07-01 op
198 8951cb19 2022-07-01 op HAVE_CAPSICUM=
199 8951cb19 2022-07-01 op HAVE_ERR=
200 8951cb19 2022-07-01 op HAVE_GETEXECNAME=
201 8951cb19 2022-07-01 op HAVE_GETPROGNAME=
202 8951cb19 2022-07-01 op HAVE_LANDLOCK=
203 8951cb19 2022-07-01 op HAVE_PLEDGE=
204 8951cb19 2022-07-01 op HAVE_PROGRAM_INVOCATION_SHORT_NAME=
205 8951cb19 2022-07-01 op HAVE_REALLOCARRAY=
206 8951cb19 2022-07-01 op HAVE_RECALLOCARRAY=
207 8951cb19 2022-07-01 op HAVE_STRTONUM=
208 8951cb19 2022-07-01 op HAVE___PROGNAME=
209 8951cb19 2022-07-01 op
210 8951cb19 2022-07-01 op #----------------------------------------------------------------------
211 8951cb19 2022-07-01 op # Allow configure.local to override all variables, default settings,
212 8951cb19 2022-07-01 op # command-line arguments, and tested features, above.
213 8951cb19 2022-07-01 op # You PROBABLY DO NOT want to change this.
214 8951cb19 2022-07-01 op #----------------------------------------------------------------------
215 8951cb19 2022-07-01 op
216 8951cb19 2022-07-01 op if [ -r ./configure.local ]; then
217 8951cb19 2022-07-01 op echo "configure.local: reading..." 1>&2
218 8951cb19 2022-07-01 op echo "configure.local: reading..." 1>&3
219 8951cb19 2022-07-01 op cat ./configure.local 1>&3
220 8951cb19 2022-07-01 op . ./configure.local
221 8951cb19 2022-07-01 op else
222 8951cb19 2022-07-01 op echo "configure.local: no (fully automatic configuration)" 1>&2
223 8951cb19 2022-07-01 op echo "configure.local: no (fully automatic configuration)" 1>&3
224 8951cb19 2022-07-01 op fi
225 8951cb19 2022-07-01 op
226 8951cb19 2022-07-01 op echo 1>&3
227 8951cb19 2022-07-01 op
228 8951cb19 2022-07-01 op #----------------------------------------------------------------------
229 8951cb19 2022-07-01 op # Infrastructure for running tests.
230 8951cb19 2022-07-01 op # These consists of a series of functions that will attempt to run the
231 8951cb19 2022-07-01 op # given test file and record its exit into a HAVE_xxx variable.
232 8951cb19 2022-07-01 op # You DO NOT want to change this.
233 8951cb19 2022-07-01 op #----------------------------------------------------------------------
234 8951cb19 2022-07-01 op
235 8951cb19 2022-07-01 op COMP="${CC} ${CFLAGS} ${CPPFLAGS} -Wno-unused -Werror"
236 8951cb19 2022-07-01 op
237 8951cb19 2022-07-01 op # Check whether this HAVE_ setting is manually overridden.
238 8951cb19 2022-07-01 op # If yes, use the override, if no, do not decide anything yet.
239 8951cb19 2022-07-01 op # Arguments: lower-case test name, manual value
240 8951cb19 2022-07-01 op
241 8951cb19 2022-07-01 op ismanual() {
242 8951cb19 2022-07-01 op [ -z "${3}" ] && return 1
243 8951cb19 2022-07-01 op echo "${1}: manual (HAVE_${2}=${3})" 1>&2
244 8951cb19 2022-07-01 op echo "${1}: manual (HAVE_${2}=${3})" 1>&3
245 8951cb19 2022-07-01 op echo 1>&3
246 8951cb19 2022-07-01 op return 0
247 8951cb19 2022-07-01 op }
248 8951cb19 2022-07-01 op
249 8951cb19 2022-07-01 op # Run a single autoconfiguration test.
250 8951cb19 2022-07-01 op # In case of success, enable the feature.
251 8951cb19 2022-07-01 op # In case of failure, do not decide anything yet.
252 8951cb19 2022-07-01 op # Arguments: lower-case test name, upper-case test name, additional
253 8951cb19 2022-07-01 op # CFLAGS, additional LIBS.
254 8951cb19 2022-07-01 op
255 8951cb19 2022-07-01 op singletest() {
256 8951cb19 2022-07-01 op extralib=""
257 8951cb19 2022-07-01 op cat 1>&3 << __HEREDOC__
258 8951cb19 2022-07-01 op ${1}: testing...
259 8951cb19 2022-07-01 op ${COMP} ${3} -o test-${1} test-${1}.c ${LDFLAGS} ${4}
260 8951cb19 2022-07-01 op __HEREDOC__
261 8951cb19 2022-07-01 op if ${COMP} ${3} -o "test-${1}" test-${1}.c ${LDFLAGS} ${4} 1>&3 2>&3; then
262 8951cb19 2022-07-01 op echo "${1}: ${CC} succeeded" 1>&3
263 8951cb19 2022-07-01 op else
264 8951cb19 2022-07-01 op if [ -n "${5}" ] ; then
265 8951cb19 2022-07-01 op echo "${1}: ${CC} failed with $? (retrying)" 1>&3
266 8951cb19 2022-07-01 op cat 1>&3 << __HEREDOC__
267 8951cb19 2022-07-01 op ${1}: testing...
268 8951cb19 2022-07-01 op ${COMP} ${3} -o test-${1} test-${1}.c ${LDFLAGS} ${5}
269 8951cb19 2022-07-01 op __HEREDOC__
270 8951cb19 2022-07-01 op if ${COMP} ${3} -o "test-${1}" test-${1}.c ${LDFLAGS} ${5} 1>&3 2>&3; then
271 8951cb19 2022-07-01 op echo "${1}: ${CC} succeeded" 1>&3
272 8951cb19 2022-07-01 op extralib="(with ${5})"
273 8951cb19 2022-07-01 op else
274 8951cb19 2022-07-01 op echo "${1}: ${CC} failed with $?" 1>&3
275 8951cb19 2022-07-01 op echo 1>&3
276 8951cb19 2022-07-01 op return 1
277 8951cb19 2022-07-01 op fi
278 8951cb19 2022-07-01 op else
279 8951cb19 2022-07-01 op echo "${1}: ${CC} failed with $?" 1>&3
280 8951cb19 2022-07-01 op echo 1>&3
281 8951cb19 2022-07-01 op return 1
282 8951cb19 2022-07-01 op fi
283 8951cb19 2022-07-01 op fi
284 8951cb19 2022-07-01 op
285 8951cb19 2022-07-01 op if [ -n "${extralib}" ]
286 8951cb19 2022-07-01 op then
287 8951cb19 2022-07-01 op eval "LDADD_${2}=\"${5}\""
288 8951cb19 2022-07-01 op elif [ -n "${4}" ]
289 8951cb19 2022-07-01 op then
290 8951cb19 2022-07-01 op eval "LDADD_${2}=\"${4}\""
291 8951cb19 2022-07-01 op fi
292 8951cb19 2022-07-01 op
293 8951cb19 2022-07-01 op echo "${1}: yes ${extralib}" 1>&2
294 8951cb19 2022-07-01 op echo "${1}: yes ${extralib}" 1>&3
295 8951cb19 2022-07-01 op echo 1>&3
296 8951cb19 2022-07-01 op eval HAVE_${2}=1
297 8951cb19 2022-07-01 op rm "test-${1}"
298 8951cb19 2022-07-01 op return 0
299 8951cb19 2022-07-01 op }
300 8951cb19 2022-07-01 op
301 8951cb19 2022-07-01 op # Run a complete autoconfiguration test, including the check for
302 8951cb19 2022-07-01 op # a manual override and disabling the feature on failure.
303 8951cb19 2022-07-01 op # Arguments: lower case name, upper case name, additional CFLAGS,
304 8951cb19 2022-07-01 op # additional LDADD, alternative LDADD.
305 8951cb19 2022-07-01 op
306 8951cb19 2022-07-01 op runtest() {
307 8951cb19 2022-07-01 op eval _manual=\${HAVE_${2}}
308 8951cb19 2022-07-01 op ismanual "${1}" "${2}" "${_manual}" && return 0
309 8951cb19 2022-07-01 op singletest "${1}" "${2}" "${3}" "${4}" "${5}" && return 0
310 8951cb19 2022-07-01 op echo "${1}: no" 1>&2
311 8951cb19 2022-07-01 op eval HAVE_${2}=0
312 8951cb19 2022-07-01 op return 1
313 8951cb19 2022-07-01 op }
314 8951cb19 2022-07-01 op
315 8951cb19 2022-07-01 op #----------------------------------------------------------------------
316 8951cb19 2022-07-01 op # Begin running the tests themselves.
317 8951cb19 2022-07-01 op # All of your tests must be defined here.
318 8951cb19 2022-07-01 op # Please sort as the HAVE_xxxx values were defined.
319 8951cb19 2022-07-01 op # You WANT to change this.
320 8951cb19 2022-07-01 op # It consists of the following columns:
321 8951cb19 2022-07-01 op # runtest
322 8951cb19 2022-07-01 op # (1) test file
323 8951cb19 2022-07-01 op # (2) macro to set
324 8951cb19 2022-07-01 op # (3) argument to cc *before* -o
325 8951cb19 2022-07-01 op # (4) argument to cc *after*
326 8951cb19 2022-07-01 op # (5) alternative argument to cc *after*
327 8951cb19 2022-07-01 op #----------------------------------------------------------------------
328 8951cb19 2022-07-01 op
329 8951cb19 2022-07-01 op runtest capsicum CAPSICUM || true
330 8951cb19 2022-07-01 op runtest err ERR || true
331 8951cb19 2022-07-01 op runtest getexecname GETEXECNAME || true
332 8951cb19 2022-07-01 op runtest getprogname GETPROGNAME || true
333 8951cb19 2022-07-01 op runtest landlock LANDLOCK || true
334 8951cb19 2022-07-01 op runtest lib_socket LIB_SOCKET "" "" "-lsocket -lnsl" || true
335 8951cb19 2022-07-01 op runtest pledge PLEDGE || true
336 8951cb19 2022-07-01 op runtest program_invocation_short_name PROGRAM_INVOCATION_SHORT_NAME || true
337 8951cb19 2022-07-01 op runtest reallocarray REALLOCARRAY || true
338 8951cb19 2022-07-01 op runtest recallocarray RECALLOCARRAY || true
339 8951cb19 2022-07-01 op runtest static STATIC "" "-static" || true
340 8951cb19 2022-07-01 op runtest strtonum STRTONUM || true
341 8951cb19 2022-07-01 op runtest x11 LIB_X11 "" "" "-lX11 -lXinerama -lXft" || true
342 8951cb19 2022-07-01 op runtest __progname __PROGNAME || true
343 8951cb19 2022-07-01 op
344 8951cb19 2022-07-01 op if [ "${HAVE_LIB_X11}" -eq 0 ]; then
345 8951cb19 2022-07-01 op echo "FATAL: libx11 not found" 1>&2
346 3bb820ca 2022-07-01 op echo "make sure to have libx11, libxinerama and libxft installed" 1>&2
347 8951cb19 2022-07-01 op echo "FATAL: libx11 not found" 1>&3
348 8951cb19 2022-07-01 op exit 1
349 8951cb19 2022-07-01 op fi
350 8951cb19 2022-07-01 op
351 8951cb19 2022-07-01 op #----------------------------------------------------------------------
352 8951cb19 2022-07-01 op # Output writing: generate the config.h file.
353 8951cb19 2022-07-01 op # This file contains all of the HAVE_xxxx variables necessary for
354 8951cb19 2022-07-01 op # compiling your source.
355 8951cb19 2022-07-01 op # You must include "config.h" BEFORE any other variables.
356 8951cb19 2022-07-01 op # You WANT to change this.
357 8951cb19 2022-07-01 op #----------------------------------------------------------------------
358 8951cb19 2022-07-01 op
359 8951cb19 2022-07-01 op exec > config.h
360 8951cb19 2022-07-01 op
361 8951cb19 2022-07-01 op # Start with prologue.
362 8951cb19 2022-07-01 op
363 8951cb19 2022-07-01 op cat << __HEREDOC__
364 8951cb19 2022-07-01 op #ifndef OCONFIGURE_CONFIG_H
365 8951cb19 2022-07-01 op #define OCONFIGURE_CONFIG_H
366 8951cb19 2022-07-01 op
367 8951cb19 2022-07-01 op #ifdef __cplusplus
368 8951cb19 2022-07-01 op # error "Do not use C++: this is a C application."
369 8951cb19 2022-07-01 op #endif
370 8951cb19 2022-07-01 op #if !defined(__GNUC__) || (__GNUC__ < 4)
371 8951cb19 2022-07-01 op # define __attribute__(x)
372 8951cb19 2022-07-01 op #endif
373 8951cb19 2022-07-01 op #if defined(__linux__) || defined(__MINT__)
374 8951cb19 2022-07-01 op # define _GNU_SOURCE /* memmem, memrchr, setresuid... */
375 8951cb19 2022-07-01 op # define _DEFAULT_SOURCE /* le32toh, crypt, ... */
376 8951cb19 2022-07-01 op #endif
377 8951cb19 2022-07-01 op #if defined(__NetBSD__)
378 8951cb19 2022-07-01 op # define _OPENBSD_SOURCE /* reallocarray, etc. */
379 8951cb19 2022-07-01 op #endif
380 8951cb19 2022-07-01 op #if defined(__sun)
381 8951cb19 2022-07-01 op # ifndef _XOPEN_SOURCE /* SunOS already defines */
382 8951cb19 2022-07-01 op # define _XOPEN_SOURCE /* XPGx */
383 8951cb19 2022-07-01 op # endif
384 8951cb19 2022-07-01 op # define _XOPEN_SOURCE_EXTENDED 1 /* XPG4v2 */
385 8951cb19 2022-07-01 op # ifndef __EXTENSIONS__ /* SunOS already defines */
386 8951cb19 2022-07-01 op # define __EXTENSIONS__ /* reallocarray, etc. */
387 8951cb19 2022-07-01 op # endif
388 8951cb19 2022-07-01 op #endif
389 8951cb19 2022-07-01 op #if !defined(__BEGIN_DECLS)
390 8951cb19 2022-07-01 op # define __BEGIN_DECLS
391 8951cb19 2022-07-01 op #endif
392 8951cb19 2022-07-01 op #if !defined(__END_DECLS)
393 8951cb19 2022-07-01 op # define __END_DECLS
394 8951cb19 2022-07-01 op #endif
395 8951cb19 2022-07-01 op
396 8951cb19 2022-07-01 op __HEREDOC__
397 8951cb19 2022-07-01 op
398 8951cb19 2022-07-01 op # This is just for size_t, mode_t, and dev_t.
399 8951cb19 2022-07-01 op # Most of these functions, in the real world, pull in <string.h> or
400 8951cb19 2022-07-01 op # someting that pulls in support for size_t.
401 8951cb19 2022-07-01 op # Our function declarations are standalone, so specify them here.
402 8951cb19 2022-07-01 op
403 8951cb19 2022-07-01 op if [ ${HAVE_REALLOCARRAY} -eq 0 -o \
404 8951cb19 2022-07-01 op ${HAVE_RECALLOCARRAY} -eq 0 ]
405 8951cb19 2022-07-01 op then
406 8951cb19 2022-07-01 op echo "#include <sys/types.h> /* size_t, mode_t, dev_t */ "
407 8951cb19 2022-07-01 op echo
408 8951cb19 2022-07-01 op fi
409 8951cb19 2022-07-01 op
410 8951cb19 2022-07-01 op if [ ${HAVE_ERR} -eq 0 ]
411 8951cb19 2022-07-01 op then
412 8951cb19 2022-07-01 op echo "#include <stdarg.h> /* err(3) */"
413 8951cb19 2022-07-01 op echo
414 8951cb19 2022-07-01 op fi
415 8951cb19 2022-07-01 op
416 8951cb19 2022-07-01 op # Now we handle our HAVE_xxxx values.
417 8951cb19 2022-07-01 op # Most will just be defined as 0 or 1.
418 8951cb19 2022-07-01 op
419 8951cb19 2022-07-01 op cat << __HEREDOC__
420 8951cb19 2022-07-01 op /*
421 8951cb19 2022-07-01 op * Results of configuration feature-testing.
422 8951cb19 2022-07-01 op */
423 8951cb19 2022-07-01 op #define HAVE_CAPSICUM ${HAVE_CAPSICUM}
424 8951cb19 2022-07-01 op #define HAVE_ERR ${HAVE_ERR}
425 8951cb19 2022-07-01 op #define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
426 8951cb19 2022-07-01 op #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
427 8951cb19 2022-07-01 op #define HAVE_LANDLOCK ${HAVE_LANDLOCK}
428 8951cb19 2022-07-01 op #define HAVE_PLEDGE ${HAVE_PLEDGE}
429 8951cb19 2022-07-01 op #define HAVE_PROGRAM_INVOCATION_SHORT_NAME ${HAVE_PROGRAM_INVOCATION_SHORT_NAME}
430 8951cb19 2022-07-01 op #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
431 8951cb19 2022-07-01 op #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
432 8951cb19 2022-07-01 op #define HAVE_STRTONUM ${HAVE_STRTONUM}
433 8951cb19 2022-07-01 op #define HAVE___PROGNAME ${HAVE___PROGNAME}
434 8951cb19 2022-07-01 op
435 8951cb19 2022-07-01 op __HEREDOC__
436 8951cb19 2022-07-01 op
437 8951cb19 2022-07-01 op # Now we do our function declarations for missing functions.
438 8951cb19 2022-07-01 op
439 8951cb19 2022-07-01 op [ ${HAVE_ERR} -eq 0 ] && \
440 8951cb19 2022-07-01 op COBJ="compat_err.c ${COBJ}" && \
441 8951cb19 2022-07-01 op cat << __HEREDOC__
442 8951cb19 2022-07-01 op /*
443 8951cb19 2022-07-01 op * Compatibility functions for err(3).
444 8951cb19 2022-07-01 op */
445 8951cb19 2022-07-01 op extern void err(int, const char *, ...) __attribute__((noreturn));
446 8951cb19 2022-07-01 op extern void errc(int, int, const char *, ...) __attribute__((noreturn));
447 8951cb19 2022-07-01 op extern void errx(int, const char *, ...) __attribute__((noreturn));
448 8951cb19 2022-07-01 op extern void verr(int, const char *, va_list) __attribute__((noreturn));
449 8951cb19 2022-07-01 op extern void verrc(int, int, const char *, va_list) __attribute__((noreturn));
450 8951cb19 2022-07-01 op extern void verrx(int, const char *, va_list) __attribute__((noreturn));
451 8951cb19 2022-07-01 op extern void warn(const char *, ...);
452 8951cb19 2022-07-01 op extern void warnx(const char *, ...);
453 8951cb19 2022-07-01 op extern void warnc(int, const char *, ...);
454 8951cb19 2022-07-01 op extern void vwarn(const char *, va_list);
455 8951cb19 2022-07-01 op extern void vwarnc(int, const char *, va_list);
456 8951cb19 2022-07-01 op extern void vwarnx(const char *, va_list);
457 8951cb19 2022-07-01 op __HEREDOC__
458 8951cb19 2022-07-01 op
459 8951cb19 2022-07-01 op [ ${HAVE_GETPROGNAME} -eq 0 ] && \
460 8951cb19 2022-07-01 op COBJ="compat_getprogname.c ${COBJ}" && \
461 8951cb19 2022-07-01 op cat << __HEREDOC__
462 8951cb19 2022-07-01 op /*
463 8951cb19 2022-07-01 op * Compatibility for getprogname(3).
464 8951cb19 2022-07-01 op */
465 8951cb19 2022-07-01 op extern const char *getprogname(void);
466 8951cb19 2022-07-01 op
467 8951cb19 2022-07-01 op __HEREDOC__
468 8951cb19 2022-07-01 op
469 8951cb19 2022-07-01 op [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
470 8951cb19 2022-07-01 op COBJ="compat_reallocarray.c ${COBJ}" && \
471 8951cb19 2022-07-01 op cat << __HEREDOC__
472 8951cb19 2022-07-01 op /*
473 8951cb19 2022-07-01 op * Compatibility for reallocarray(3).
474 8951cb19 2022-07-01 op */
475 8951cb19 2022-07-01 op extern void *reallocarray(void *, size_t, size_t);
476 8951cb19 2022-07-01 op
477 8951cb19 2022-07-01 op __HEREDOC__
478 8951cb19 2022-07-01 op
479 8951cb19 2022-07-01 op [ ${HAVE_RECALLOCARRAY} -eq 0 ] && \
480 8951cb19 2022-07-01 op COBJ="compat_recallocarray.c ${COBJ}" && \
481 8951cb19 2022-07-01 op cat << __HEREDOC__
482 8951cb19 2022-07-01 op /*
483 8951cb19 2022-07-01 op * Compatibility for recallocarray(3).
484 8951cb19 2022-07-01 op */
485 8951cb19 2022-07-01 op extern void *recallocarray(void *, size_t, size_t, size_t);
486 8951cb19 2022-07-01 op
487 8951cb19 2022-07-01 op __HEREDOC__
488 8951cb19 2022-07-01 op
489 8951cb19 2022-07-01 op [ ${HAVE_STRTONUM} -eq 0 ] && \
490 8951cb19 2022-07-01 op COBJ="compat_strtonum.c ${COBJ}" && \
491 8951cb19 2022-07-01 op cat << __HEREDOC__
492 8951cb19 2022-07-01 op /*
493 8951cb19 2022-07-01 op * Compatibility for strotnum(3).
494 8951cb19 2022-07-01 op */
495 8951cb19 2022-07-01 op extern long long strtonum(const char *, long long, long long, const char **);
496 8951cb19 2022-07-01 op
497 8951cb19 2022-07-01 op __HEREDOC__
498 8951cb19 2022-07-01 op
499 8951cb19 2022-07-01 op cat <<__HEREDOC__
500 8951cb19 2022-07-01 op /*
501 8951cb19 2022-07-01 op * mymenu version
502 8951cb19 2022-07-01 op */
503 8951cb19 2022-07-01 op #define VERSION "${MYMENU_VERSION}"
504 8951cb19 2022-07-01 op
505 8951cb19 2022-07-01 op __HEREDOC__
506 8951cb19 2022-07-01 op
507 8951cb19 2022-07-01 op cat << __HEREDOC__
508 8951cb19 2022-07-01 op #endif /*!OCONFIGURE_CONFIG_H*/
509 8951cb19 2022-07-01 op __HEREDOC__
510 8951cb19 2022-07-01 op
511 8951cb19 2022-07-01 op echo "config.h: written" 1>&2
512 8951cb19 2022-07-01 op echo "config.h: written" 1>&3
513 8951cb19 2022-07-01 op
514 8951cb19 2022-07-01 op #----------------------------------------------------------------------
515 8951cb19 2022-07-01 op # Now we go to generate our Makefile.configure.
516 8951cb19 2022-07-01 op # This file is simply a bunch of Makefile variables.
517 8951cb19 2022-07-01 op # They'll work in both GNUmakefile and BSDmakefile.
518 8951cb19 2022-07-01 op # You MIGHT want to change this.
519 8951cb19 2022-07-01 op #----------------------------------------------------------------------
520 8951cb19 2022-07-01 op
521 8951cb19 2022-07-01 op exec > Makefile.configure
522 8951cb19 2022-07-01 op
523 8951cb19 2022-07-01 op [ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
524 8951cb19 2022-07-01 op [ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin"
525 8951cb19 2022-07-01 op [ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include"
526 8951cb19 2022-07-01 op [ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib"
527 8951cb19 2022-07-01 op [ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man"
528 8951cb19 2022-07-01 op [ -z "${SHAREDIR}" ] && SHAREDIR="${PREFIX}/share"
529 8951cb19 2022-07-01 op
530 8951cb19 2022-07-01 op [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
531 8951cb19 2022-07-01 op [ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444"
532 8951cb19 2022-07-01 op [ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444"
533 8951cb19 2022-07-01 op [ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444"
534 8951cb19 2022-07-01 op
535 8951cb19 2022-07-01 op cat << __HEREDOC__
536 84d6b0f4 2022-07-02 op VERSION = ${MYMENU_VERSION}
537 8951cb19 2022-07-01 op CC = ${CC}
538 8951cb19 2022-07-01 op CFLAGS = ${CFLAGS}
539 8951cb19 2022-07-01 op CPPFLAGS = ${CPPFLAGS}
540 8951cb19 2022-07-01 op LDADD = ${LDADD}
541 8951cb19 2022-07-01 op LDADD_LIB_SOCKET = ${LDADD_LIB_SOCKET}
542 8951cb19 2022-07-01 op LDADD_STATIC = ${LDADD_STATIC}
543 8951cb19 2022-07-01 op LDADD_LIB_X11 = ${LDADD_LIB_X11}
544 8951cb19 2022-07-01 op LDFLAGS = ${LDFLAGS}
545 8951cb19 2022-07-01 op STATIC = ${STATIC}
546 8951cb19 2022-07-01 op PREFIX = ${PREFIX}
547 8951cb19 2022-07-01 op BINDIR = ${BINDIR}
548 8951cb19 2022-07-01 op SHAREDIR = ${SHAREDIR}
549 8951cb19 2022-07-01 op SBINDIR = ${SBINDIR}
550 8951cb19 2022-07-01 op INCLUDEDIR = ${INCLUDEDIR}
551 8951cb19 2022-07-01 op LIBDIR = ${LIBDIR}
552 8951cb19 2022-07-01 op MANDIR = ${MANDIR}
553 8951cb19 2022-07-01 op INSTALL = ${INSTALL}
554 8951cb19 2022-07-01 op INSTALL_PROGRAM = ${INSTALL_PROGRAM}
555 8951cb19 2022-07-01 op INSTALL_LIB = ${INSTALL_LIB}
556 8951cb19 2022-07-01 op INSTALL_MAN = ${INSTALL_MAN}
557 8951cb19 2022-07-01 op INSTALL_DATA = ${INSTALL_DATA}
558 8951cb19 2022-07-01 op
559 8951cb19 2022-07-01 op COBJ = ${COBJ}
560 8951cb19 2022-07-01 op __HEREDOC__
561 8951cb19 2022-07-01 op
562 8951cb19 2022-07-01 op echo "Makefile.configure: written" 1>&2
563 8951cb19 2022-07-01 op echo "Makefile.configure: written" 1>&3
564 8951cb19 2022-07-01 op
565 8951cb19 2022-07-01 op exit 0