3 # Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
4 # Copyright (c) 2017, 2018 Kristaps Dzonsons <kristaps@bsd.lv>
5 # Copyright (c) 2022 Omar Polo <op@omarpolo.com>
7 # Permission to use, copy, modify, and distribute this software for any
8 # purpose with or without fee is hereby granted, provided that the above
9 # copyright notice and this permission notice appear in all copies.
11 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 OCONFIGURE_VERSION="0.3.8"
23 # This script outputs two files: config.h and Makefile.configure.
24 # It tries to read from configure.local, which contains predefined
25 # values we won't autoconfigure.
27 # If you want to use configure with your project, have your GNUmakefile
28 # or BSDmakefile---whichever---try to import/include Makefile.configure
29 # at the beginning of the file.
31 # Like so (note no quotes, no period, etc.):
33 # include Makefile.configure
35 # If it exists, configure was run; otherwise, it wasn't.
37 # You'll probably want to change parts of this file. I've noted the
38 # parts that you'll probably change in the section documentation.
40 # See https://github.com/kristapsdz/oconfigure for more.
44 #----------------------------------------------------------------------
45 # Prepare for running: move aside previous configure runs.
46 # Output file descriptor usage:
47 # 1 (stdout): config.h or Makefile.configure
48 # 2 (stderr): original stderr, usually to the console
50 # You DO NOT want to change this.
51 #----------------------------------------------------------------------
53 [ -w config.log ] && mv config.log config.log.old
54 [ -w config.h ] && mv config.h config.h.old
57 echo "config.log: writing..."
59 # GNU submake prints different output if invoked recursively, which
60 # messes up CC and CFLAGS detection. Pass --no-print-directory if
61 # we have a MAKELEVEL (GNU and FreeBSD make) and the argument is
66 if [ -n "${MAKELEVEL}" ]; then
67 if [ "${MAKELEVEL}" -gt 0 ] ; then
68 MAKE_FLAGS="--no-print-directory"
69 echo "all:" | make ${MAKE_FLAGS} -sf - 2>/dev/null || MAKE_FLAGS=""
73 if [ -n "$MAKE_FLAGS" ]; then
74 echo "GNU submake detected: using --no-print-directory" 1>&2
75 echo "GNU submake detected: using --no-print-directory" 1>&3
78 #----------------------------------------------------------------------
79 # Initialize all variables here such that nothing can leak in from the
80 # environment except for CC and CFLAGS, which we might have passed in.
81 #----------------------------------------------------------------------
83 CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make ${MAKE_FLAGS} -sf -`
84 CFLAGS=`printf "all:\\n\\t@echo \\\$(CFLAGS)\\n" | make ${MAKE_FLAGS} -sf -`
85 CFLAGS="${CFLAGS} -g -W -Wall -Wextra" # -Wmissing-prototypes -Wstrict-prototypes
86 #CFLAGS="${CFLAGS} -Wwrite-strings -Wno-unused-parameter"
110 # SunOS sets "cc", but this doesn't exist.
111 # It does have gcc, so try that instead.
112 # Prefer clang, though.
114 command -v ${CC} 2>/dev/null 1>&2 || {
115 echo "${CC} not found: trying clang" 1>&2
116 echo "${CC} not found: trying clang" 1>&3
118 command -v ${CC} 2>/dev/null 1>&2 || {
119 echo "${CC} not found: trying gcc" 1>&2
120 echo "${CC} not found: trying gcc" 1>&3
122 command -v ${CC} 2>/dev/null 1>&2 || {
123 echo "gcc not found: giving up" 1>&2
124 echo "gcc not found: giving up" 1>&3
130 command -v pkg-config 2>/dev/null 1>&2 && {
131 if extra="$(pkg-config --cflags x11 xinerama xft || true)"; then
132 echo "Adding to CFLAGS: $extra (pkg-config)"
133 CFLAGS="$extra ${CFLAGS}"
135 if extra="$(pkg-config --libs x11 xinerama xft || true)"; then
136 echo "Adding to LDFLAGS: $extra (pkg-config)"
137 LDFLAGS="$extra ${LDFLAGS}"
141 #----------------------------------------------------------------------
142 # Allow certain variables to be overriden on the command line.
143 #----------------------------------------------------------------------
147 key=`echo $keyvals | cut -s -d '=' -f 1`
150 echo "$0: invalid key-value: $keyvals" 1>&2
153 val=`echo $keyvals | cut -d '=' -f 2-`
178 echo "$0: invalid key: $key" 1>&2
184 #----------------------------------------------------------------------
185 # These are the values that will be pushed into config.h after we test
186 # for whether they're supported or not.
187 # Each of these must have a runtest(), below.
188 # Please sort by alpha, for clarity.
189 # You WANT to change this.
190 #----------------------------------------------------------------------
198 HAVE_PROGRAM_INVOCATION_SHORT_NAME=
204 #----------------------------------------------------------------------
205 # Allow configure.local to override all variables, default settings,
206 # command-line arguments, and tested features, above.
207 # You PROBABLY DO NOT want to change this.
208 #----------------------------------------------------------------------
210 if [ -r ./configure.local ]; then
211 echo "configure.local: reading..." 1>&2
212 echo "configure.local: reading..." 1>&3
213 cat ./configure.local 1>&3
216 echo "configure.local: no (fully automatic configuration)" 1>&2
217 echo "configure.local: no (fully automatic configuration)" 1>&3
222 #----------------------------------------------------------------------
223 # Infrastructure for running tests.
224 # These consists of a series of functions that will attempt to run the
225 # given test file and record its exit into a HAVE_xxx variable.
226 # You DO NOT want to change this.
227 #----------------------------------------------------------------------
229 COMP="${CC} ${CFLAGS} ${CPPFLAGS} -Wno-unused -Werror"
231 # Check whether this HAVE_ setting is manually overridden.
232 # If yes, use the override, if no, do not decide anything yet.
233 # Arguments: lower-case test name, manual value
236 [ -z "${3}" ] && return 1
237 echo "${1}: manual (HAVE_${2}=${3})" 1>&2
238 echo "${1}: manual (HAVE_${2}=${3})" 1>&3
243 # Run a single autoconfiguration test.
244 # In case of success, enable the feature.
245 # In case of failure, do not decide anything yet.
246 # Arguments: lower-case test name, upper-case test name, additional
247 # CFLAGS, additional LIBS.
251 cat 1>&3 << __HEREDOC__
253 ${COMP} ${3} -o test-${1} test-${1}.c ${LDFLAGS} ${4}
255 if ${COMP} ${3} -o "test-${1}" test-${1}.c ${LDFLAGS} ${4} 1>&3 2>&3; then
256 echo "${1}: ${CC} succeeded" 1>&3
258 if [ -n "${5}" ] ; then
259 echo "${1}: ${CC} failed with $? (retrying)" 1>&3
260 cat 1>&3 << __HEREDOC__
262 ${COMP} ${3} -o test-${1} test-${1}.c ${LDFLAGS} ${5}
264 if ${COMP} ${3} -o "test-${1}" test-${1}.c ${LDFLAGS} ${5} 1>&3 2>&3; then
265 echo "${1}: ${CC} succeeded" 1>&3
266 extralib="(with ${5})"
268 echo "${1}: ${CC} failed with $?" 1>&3
273 echo "${1}: ${CC} failed with $?" 1>&3
279 if [ -n "${extralib}" ]
281 eval "LDADD_${2}=\"${5}\""
284 eval "LDADD_${2}=\"${4}\""
287 echo "${1}: yes ${extralib}" 1>&2
288 echo "${1}: yes ${extralib}" 1>&3
295 # Run a complete autoconfiguration test, including the check for
296 # a manual override and disabling the feature on failure.
297 # Arguments: lower case name, upper case name, additional CFLAGS,
298 # additional LDADD, alternative LDADD.
301 eval _manual=\${HAVE_${2}}
302 ismanual "${1}" "${2}" "${_manual}" && return 0
303 singletest "${1}" "${2}" "${3}" "${4}" "${5}" && return 0
309 #----------------------------------------------------------------------
310 # Begin running the tests themselves.
311 # All of your tests must be defined here.
312 # Please sort as the HAVE_xxxx values were defined.
313 # You WANT to change this.
314 # It consists of the following columns:
318 # (3) argument to cc *before* -o
319 # (4) argument to cc *after*
320 # (5) alternative argument to cc *after*
321 #----------------------------------------------------------------------
323 runtest capsicum CAPSICUM || true
324 runtest err ERR || true
325 runtest getexecname GETEXECNAME || true
326 runtest getprogname GETPROGNAME || true
327 runtest landlock LANDLOCK || true
328 runtest lib_socket LIB_SOCKET "" "" "-lsocket -lnsl" || true
329 runtest pledge PLEDGE || true
330 runtest program_invocation_short_name PROGRAM_INVOCATION_SHORT_NAME || true
331 runtest reallocarray REALLOCARRAY || true
332 runtest recallocarray RECALLOCARRAY || true
333 runtest static STATIC "" "-static" || true
334 runtest strtonum STRTONUM || true
335 runtest x11 LIB_X11 "" "" "-lX11 -lXinerama -lXft" || true
336 runtest __progname __PROGNAME || true
338 if [ "${HAVE_LIB_X11}" -eq 0 ]; then
339 echo "FATAL: libx11 not found" 1>&2
340 echo "make sure to have libx11, libxinerama and libxft installed" 1>&2
341 echo "FATAL: libx11 not found" 1>&3
345 #----------------------------------------------------------------------
346 # Output writing: generate the config.h file.
347 # This file contains all of the HAVE_xxxx variables necessary for
348 # compiling your source.
349 # You must include "config.h" BEFORE any other variables.
350 # You WANT to change this.
351 #----------------------------------------------------------------------
355 # Start with prologue.
358 #ifndef OCONFIGURE_CONFIG_H
359 #define OCONFIGURE_CONFIG_H
362 # error "Do not use C++: this is a C application."
364 #if !defined(__GNUC__) || (__GNUC__ < 4)
365 # define __attribute__(x)
367 #if defined(__linux__) || defined(__MINT__)
368 # define _GNU_SOURCE /* memmem, memrchr, setresuid... */
369 # define _DEFAULT_SOURCE /* le32toh, crypt, ... */
371 #if defined(__NetBSD__)
372 # define _OPENBSD_SOURCE /* reallocarray, etc. */
375 # ifndef _XOPEN_SOURCE /* SunOS already defines */
376 # define _XOPEN_SOURCE /* XPGx */
378 # define _XOPEN_SOURCE_EXTENDED 1 /* XPG4v2 */
379 # ifndef __EXTENSIONS__ /* SunOS already defines */
380 # define __EXTENSIONS__ /* reallocarray, etc. */
383 #if !defined(__BEGIN_DECLS)
384 # define __BEGIN_DECLS
386 #if !defined(__END_DECLS)
392 # This is just for size_t, mode_t, and dev_t.
393 # Most of these functions, in the real world, pull in <string.h> or
394 # someting that pulls in support for size_t.
395 # Our function declarations are standalone, so specify them here.
397 if [ ${HAVE_REALLOCARRAY} -eq 0 -o \
398 ${HAVE_RECALLOCARRAY} -eq 0 ]
400 echo "#include <sys/types.h> /* size_t, mode_t, dev_t */ "
404 if [ ${HAVE_ERR} -eq 0 ]
406 echo "#include <stdarg.h> /* err(3) */"
410 # Now we handle our HAVE_xxxx values.
411 # Most will just be defined as 0 or 1.
415 * Results of configuration feature-testing.
417 #define HAVE_CAPSICUM ${HAVE_CAPSICUM}
418 #define HAVE_ERR ${HAVE_ERR}
419 #define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
420 #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
421 #define HAVE_LANDLOCK ${HAVE_LANDLOCK}
422 #define HAVE_PLEDGE ${HAVE_PLEDGE}
423 #define HAVE_PROGRAM_INVOCATION_SHORT_NAME ${HAVE_PROGRAM_INVOCATION_SHORT_NAME}
424 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
425 #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
426 #define HAVE_STRTONUM ${HAVE_STRTONUM}
427 #define HAVE___PROGNAME ${HAVE___PROGNAME}
431 # Now we do our function declarations for missing functions.
433 [ ${HAVE_ERR} -eq 0 ] && \
434 COBJ="compat_err.c ${COBJ}" && \
437 * Compatibility functions for err(3).
439 extern void err(int, const char *, ...) __attribute__((noreturn));
440 extern void errc(int, int, const char *, ...) __attribute__((noreturn));
441 extern void errx(int, const char *, ...) __attribute__((noreturn));
442 extern void verr(int, const char *, va_list) __attribute__((noreturn));
443 extern void verrc(int, int, const char *, va_list) __attribute__((noreturn));
444 extern void verrx(int, const char *, va_list) __attribute__((noreturn));
445 extern void warn(const char *, ...);
446 extern void warnx(const char *, ...);
447 extern void warnc(int, const char *, ...);
448 extern void vwarn(const char *, va_list);
449 extern void vwarnc(int, const char *, va_list);
450 extern void vwarnx(const char *, va_list);
453 [ ${HAVE_GETPROGNAME} -eq 0 ] && \
454 COBJ="compat_getprogname.c ${COBJ}" && \
457 * Compatibility for getprogname(3).
459 extern const char *getprogname(void);
463 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
464 COBJ="compat_reallocarray.c ${COBJ}" && \
467 * Compatibility for reallocarray(3).
469 extern void *reallocarray(void *, size_t, size_t);
473 [ ${HAVE_RECALLOCARRAY} -eq 0 ] && \
474 COBJ="compat_recallocarray.c ${COBJ}" && \
477 * Compatibility for recallocarray(3).
479 extern void *recallocarray(void *, size_t, size_t, size_t);
483 [ ${HAVE_STRTONUM} -eq 0 ] && \
484 COBJ="compat_strtonum.c ${COBJ}" && \
487 * Compatibility for strotnum(3).
489 extern long long strtonum(const char *, long long, long long, const char **);
497 #define VERSION "${MYMENU_VERSION}"
502 #endif /*!OCONFIGURE_CONFIG_H*/
505 echo "config.h: written" 1>&2
506 echo "config.h: written" 1>&3
508 #----------------------------------------------------------------------
509 # Now we go to generate our Makefile.configure.
510 # This file is simply a bunch of Makefile variables.
511 # They'll work in both GNUmakefile and BSDmakefile.
512 # You MIGHT want to change this.
513 #----------------------------------------------------------------------
515 exec > Makefile.configure
517 [ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
518 [ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin"
519 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include"
520 [ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib"
521 [ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man"
522 [ -z "${SHAREDIR}" ] && SHAREDIR="${PREFIX}/share"
524 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
525 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444"
526 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444"
527 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444"
532 CPPFLAGS = ${CPPFLAGS}
534 LDADD_LIB_SOCKET = ${LDADD_LIB_SOCKET}
535 LDADD_STATIC = ${LDADD_STATIC}
536 LDADD_LIB_X11 = ${LDADD_LIB_X11}
541 SHAREDIR = ${SHAREDIR}
543 INCLUDEDIR = ${INCLUDEDIR}
547 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
548 INSTALL_LIB = ${INSTALL_LIB}
549 INSTALL_MAN = ${INSTALL_MAN}
550 INSTALL_DATA = ${INSTALL_DATA}
555 echo "Makefile.configure: written" 1>&2
556 echo "Makefile.configure: written" 1>&3