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} -Wno-unused-parameter -Wno-pointer-sign"
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 echo "pkg-config: found" 1>&2
132 echo "pkg-config: found" 1>&3
134 if extra="$(pkg-config --cflags x11 xinerama xft || true)"; then
135 echo "Adding to CFLAGS: $extra (pkg-config)"
136 CFLAGS="$extra ${CFLAGS}"
138 if extra="$(pkg-config --libs x11 xinerama xft || true)"; then
139 echo "Adding to LDFLAGS: $extra (pkg-config)"
140 LDFLAGS="$extra ${LDFLAGS}"
143 echo "pkg-config: not found" 1>&2
144 echo "pkg-config: not found" 1>&3
147 #----------------------------------------------------------------------
148 # Allow certain variables to be overriden on the command line.
149 #----------------------------------------------------------------------
153 key=`echo $keyvals | cut -s -d '=' -f 1`
156 echo "$0: invalid key-value: $keyvals" 1>&2
159 val=`echo $keyvals | cut -d '=' -f 2-`
184 echo "$0: invalid key: $key" 1>&2
190 #----------------------------------------------------------------------
191 # These are the values that will be pushed into config.h after we test
192 # for whether they're supported or not.
193 # Each of these must have a runtest(), below.
194 # Please sort by alpha, for clarity.
195 # You WANT to change this.
196 #----------------------------------------------------------------------
204 HAVE_PROGRAM_INVOCATION_SHORT_NAME=
210 #----------------------------------------------------------------------
211 # Allow configure.local to override all variables, default settings,
212 # command-line arguments, and tested features, above.
213 # You PROBABLY DO NOT want to change this.
214 #----------------------------------------------------------------------
216 if [ -r ./configure.local ]; then
217 echo "configure.local: reading..." 1>&2
218 echo "configure.local: reading..." 1>&3
219 cat ./configure.local 1>&3
222 echo "configure.local: no (fully automatic configuration)" 1>&2
223 echo "configure.local: no (fully automatic configuration)" 1>&3
228 #----------------------------------------------------------------------
229 # Infrastructure for running tests.
230 # These consists of a series of functions that will attempt to run the
231 # given test file and record its exit into a HAVE_xxx variable.
232 # You DO NOT want to change this.
233 #----------------------------------------------------------------------
235 COMP="${CC} ${CFLAGS} ${CPPFLAGS} -Wno-unused -Werror"
237 # Check whether this HAVE_ setting is manually overridden.
238 # If yes, use the override, if no, do not decide anything yet.
239 # Arguments: lower-case test name, manual value
242 [ -z "${3}" ] && return 1
243 echo "${1}: manual (HAVE_${2}=${3})" 1>&2
244 echo "${1}: manual (HAVE_${2}=${3})" 1>&3
249 # Run a single autoconfiguration test.
250 # In case of success, enable the feature.
251 # In case of failure, do not decide anything yet.
252 # Arguments: lower-case test name, upper-case test name, additional
253 # CFLAGS, additional LIBS.
257 cat 1>&3 << __HEREDOC__
259 ${COMP} ${3} -o test-${1} test-${1}.c ${LDFLAGS} ${4}
261 if ${COMP} ${3} -o "test-${1}" test-${1}.c ${LDFLAGS} ${4} 1>&3 2>&3; then
262 echo "${1}: ${CC} succeeded" 1>&3
264 if [ -n "${5}" ] ; then
265 echo "${1}: ${CC} failed with $? (retrying)" 1>&3
266 cat 1>&3 << __HEREDOC__
268 ${COMP} ${3} -o test-${1} test-${1}.c ${LDFLAGS} ${5}
270 if ${COMP} ${3} -o "test-${1}" test-${1}.c ${LDFLAGS} ${5} 1>&3 2>&3; then
271 echo "${1}: ${CC} succeeded" 1>&3
272 extralib="(with ${5})"
274 echo "${1}: ${CC} failed with $?" 1>&3
279 echo "${1}: ${CC} failed with $?" 1>&3
285 if [ -n "${extralib}" ]
287 eval "LDADD_${2}=\"${5}\""
290 eval "LDADD_${2}=\"${4}\""
293 echo "${1}: yes ${extralib}" 1>&2
294 echo "${1}: yes ${extralib}" 1>&3
301 # Run a complete autoconfiguration test, including the check for
302 # a manual override and disabling the feature on failure.
303 # Arguments: lower case name, upper case name, additional CFLAGS,
304 # additional LDADD, alternative LDADD.
307 eval _manual=\${HAVE_${2}}
308 ismanual "${1}" "${2}" "${_manual}" && return 0
309 singletest "${1}" "${2}" "${3}" "${4}" "${5}" && return 0
315 #----------------------------------------------------------------------
316 # Begin running the tests themselves.
317 # All of your tests must be defined here.
318 # Please sort as the HAVE_xxxx values were defined.
319 # You WANT to change this.
320 # It consists of the following columns:
324 # (3) argument to cc *before* -o
325 # (4) argument to cc *after*
326 # (5) alternative argument to cc *after*
327 #----------------------------------------------------------------------
329 runtest capsicum CAPSICUM || true
330 runtest err ERR || true
331 runtest getexecname GETEXECNAME || true
332 runtest getprogname GETPROGNAME || true
333 runtest landlock LANDLOCK || true
334 runtest lib_socket LIB_SOCKET "" "" "-lsocket -lnsl" || true
335 runtest pledge PLEDGE || true
336 runtest program_invocation_short_name PROGRAM_INVOCATION_SHORT_NAME || true
337 runtest reallocarray REALLOCARRAY || true
338 runtest recallocarray RECALLOCARRAY || true
339 runtest static STATIC "" "-static" || true
340 runtest strtonum STRTONUM || true
341 runtest x11 LIB_X11 "" "" "-lX11 -lXinerama -lXft" || true
342 runtest __progname __PROGNAME || true
344 if [ "${HAVE_LIB_X11}" -eq 0 ]; then
345 echo "FATAL: libx11 not found" 1>&2
346 echo "make sure to have libx11, libxinerama and libxft installed" 1>&2
347 echo "FATAL: libx11 not found" 1>&3
351 #----------------------------------------------------------------------
352 # Output writing: generate the config.h file.
353 # This file contains all of the HAVE_xxxx variables necessary for
354 # compiling your source.
355 # You must include "config.h" BEFORE any other variables.
356 # You WANT to change this.
357 #----------------------------------------------------------------------
361 # Start with prologue.
364 #ifndef OCONFIGURE_CONFIG_H
365 #define OCONFIGURE_CONFIG_H
368 # error "Do not use C++: this is a C application."
370 #if !defined(__GNUC__) || (__GNUC__ < 4)
371 # define __attribute__(x)
373 #if defined(__linux__) || defined(__MINT__)
374 # define _GNU_SOURCE /* memmem, memrchr, setresuid... */
375 # define _DEFAULT_SOURCE /* le32toh, crypt, ... */
377 #if defined(__NetBSD__)
378 # define _OPENBSD_SOURCE /* reallocarray, etc. */
381 # ifndef _XOPEN_SOURCE /* SunOS already defines */
382 # define _XOPEN_SOURCE /* XPGx */
384 # define _XOPEN_SOURCE_EXTENDED 1 /* XPG4v2 */
385 # ifndef __EXTENSIONS__ /* SunOS already defines */
386 # define __EXTENSIONS__ /* reallocarray, etc. */
389 #if !defined(__BEGIN_DECLS)
390 # define __BEGIN_DECLS
392 #if !defined(__END_DECLS)
398 # This is just for size_t, mode_t, and dev_t.
399 # Most of these functions, in the real world, pull in <string.h> or
400 # someting that pulls in support for size_t.
401 # Our function declarations are standalone, so specify them here.
403 if [ ${HAVE_REALLOCARRAY} -eq 0 -o \
404 ${HAVE_RECALLOCARRAY} -eq 0 ]
406 echo "#include <sys/types.h> /* size_t, mode_t, dev_t */ "
410 if [ ${HAVE_ERR} -eq 0 ]
412 echo "#include <stdarg.h> /* err(3) */"
416 # Now we handle our HAVE_xxxx values.
417 # Most will just be defined as 0 or 1.
421 * Results of configuration feature-testing.
423 #define HAVE_CAPSICUM ${HAVE_CAPSICUM}
424 #define HAVE_ERR ${HAVE_ERR}
425 #define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
426 #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
427 #define HAVE_LANDLOCK ${HAVE_LANDLOCK}
428 #define HAVE_PLEDGE ${HAVE_PLEDGE}
429 #define HAVE_PROGRAM_INVOCATION_SHORT_NAME ${HAVE_PROGRAM_INVOCATION_SHORT_NAME}
430 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
431 #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
432 #define HAVE_STRTONUM ${HAVE_STRTONUM}
433 #define HAVE___PROGNAME ${HAVE___PROGNAME}
437 # Now we do our function declarations for missing functions.
439 [ ${HAVE_ERR} -eq 0 ] && \
440 COBJ="compat_err.c ${COBJ}" && \
443 * Compatibility functions for err(3).
445 extern void err(int, const char *, ...) __attribute__((noreturn));
446 extern void errc(int, int, const char *, ...) __attribute__((noreturn));
447 extern void errx(int, const char *, ...) __attribute__((noreturn));
448 extern void verr(int, const char *, va_list) __attribute__((noreturn));
449 extern void verrc(int, int, const char *, va_list) __attribute__((noreturn));
450 extern void verrx(int, const char *, va_list) __attribute__((noreturn));
451 extern void warn(const char *, ...);
452 extern void warnx(const char *, ...);
453 extern void warnc(int, const char *, ...);
454 extern void vwarn(const char *, va_list);
455 extern void vwarnc(int, const char *, va_list);
456 extern void vwarnx(const char *, va_list);
459 [ ${HAVE_GETPROGNAME} -eq 0 ] && \
460 COBJ="compat_getprogname.c ${COBJ}" && \
463 * Compatibility for getprogname(3).
465 extern const char *getprogname(void);
469 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
470 COBJ="compat_reallocarray.c ${COBJ}" && \
473 * Compatibility for reallocarray(3).
475 extern void *reallocarray(void *, size_t, size_t);
479 [ ${HAVE_RECALLOCARRAY} -eq 0 ] && \
480 COBJ="compat_recallocarray.c ${COBJ}" && \
483 * Compatibility for recallocarray(3).
485 extern void *recallocarray(void *, size_t, size_t, size_t);
489 [ ${HAVE_STRTONUM} -eq 0 ] && \
490 COBJ="compat_strtonum.c ${COBJ}" && \
493 * Compatibility for strotnum(3).
495 extern long long strtonum(const char *, long long, long long, const char **);
503 #define VERSION "${MYMENU_VERSION}"
508 #endif /*!OCONFIGURE_CONFIG_H*/
511 echo "config.h: written" 1>&2
512 echo "config.h: written" 1>&3
514 #----------------------------------------------------------------------
515 # Now we go to generate our Makefile.configure.
516 # This file is simply a bunch of Makefile variables.
517 # They'll work in both GNUmakefile and BSDmakefile.
518 # You MIGHT want to change this.
519 #----------------------------------------------------------------------
521 exec > Makefile.configure
523 [ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
524 [ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin"
525 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include"
526 [ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib"
527 [ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man"
528 [ -z "${SHAREDIR}" ] && SHAREDIR="${PREFIX}/share"
530 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
531 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444"
532 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444"
533 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444"
536 VERSION = ${MYMENU_VERSION}
539 CPPFLAGS = ${CPPFLAGS}
541 LDADD_LIB_SOCKET = ${LDADD_LIB_SOCKET}
542 LDADD_STATIC = ${LDADD_STATIC}
543 LDADD_LIB_X11 = ${LDADD_LIB_X11}
548 SHAREDIR = ${SHAREDIR}
550 INCLUDEDIR = ${INCLUDEDIR}
554 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
555 INSTALL_LIB = ${INSTALL_LIB}
556 INSTALL_MAN = ${INSTALL_MAN}
557 INSTALL_DATA = ${INSTALL_DATA}
562 echo "Makefile.configure: written" 1>&2
563 echo "Makefile.configure: written" 1>&3