scdoc2mdoc

A fork of scdoc to output mdoc(7)
git clone git://git.sgregoratto.me/scdoc2mdoc
Log | Files | Refs | README | LICENSE

configure (12018B)


      1 #! /bin/sh
      2 #
      3 # Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
      4 # Copyright (c) 2017, 2018 Kristaps Dzonsons <kristaps@bsd.lv>
      5 #
      6 # Permission to use, copy, modify, and distribute this software for any
      7 # purpose with or without fee is hereby granted, provided that the above
      8 # copyright notice and this permission notice appear in all copies.
      9 #
     10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     17 
     18 OCONFIGURE_VERSION="0.1.8"
     19 
     20 #
     21 # This script outputs two files: config.h and Makefile.configure.
     22 # It tries to read from configure.local, which contains predefined
     23 # values we won't autoconfigure.
     24 #
     25 # If you want to use configure with your project, have your GNUmakefile
     26 # or BSDmakefile---whichever---try to import/include Makefile.configure
     27 # at the beginning of the file.
     28 #
     29 # Like so (note no quotes, no period, etc.):
     30 #
     31 #   include Makefile.configure
     32 #
     33 # If it exists, configure was run; otherwise, it wasn't.
     34 #
     35 # You'll probably want to change parts of this file.  I've noted the
     36 # parts that you'll probably change in the section documentation.
     37 #
     38 # See https://github.com/kristapsdz/oconfigure for more.
     39 
     40 set -e
     41 
     42 #----------------------------------------------------------------------
     43 # Prepare for running: move aside previous configure runs.
     44 # Output file descriptor usage:
     45 #  1 (stdout): config.h or Makefile.configure
     46 #  2 (stderr): original stderr, usually to the console
     47 #  3: config.log
     48 # You DO NOT want to change this.
     49 #----------------------------------------------------------------------
     50 
     51 [ -w config.log ] && mv config.log config.log.old
     52 [ -w config.h   ] && mv config.h config.h.old
     53 
     54 exec 3> config.log
     55 echo "config.log: writing..."
     56 
     57 #----------------------------------------------------------------------
     58 # Initialize all variables here such that nothing can leak in from the
     59 # environment except for CC and CFLAGS, which we might have passed in.
     60 #----------------------------------------------------------------------
     61 
     62 CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make -sf -`
     63 CFLAGS=`printf "all:\\n\\t@echo \\\$(CFLAGS)\\n" | make -sf -`
     64 CFLAGS="${CFLAGS} -g -W -Wall -Wextra -Werror -Wno-unused-parameter"
     65 LDADD=
     66 CPPFLAGS=
     67 LDFLAGS=
     68 DESTDIR=
     69 PREFIX="/usr/local"
     70 BINDIR=
     71 SBINDIR=
     72 INCLUDEDIR=
     73 LIBDIR=
     74 MANDIR=
     75 SHAREDIR=
     76 PCDIR=
     77 INSTALL="install"
     78 INSTALL_PROGRAM=
     79 INSTALL_LIB=
     80 INSTALL_MAN=
     81 INSTALL_DATA=
     82 
     83 #----------------------------------------------------------------------
     84 # Allow certain variables to be overriden on the command line.
     85 #----------------------------------------------------------------------
     86 
     87 for keyvals in "$@"
     88 do
     89 	key=`echo $keyvals | cut -s -d '=' -f 1`
     90 	if [ -z "$key" ]
     91 	then
     92 		echo "$0: invalid key-value: $keyvals" 1>&2
     93 		exit 1
     94 	fi
     95 	val=`echo $keyvals | cut -d '=' -f 2-`
     96 	case "$key" in
     97 	LDADD)
     98 		LDADD="$val" ;;
     99 	LDFLAGS)
    100 		LDFLAGS="$val" ;;
    101 	CPPFLAGS)
    102 		CPPFLAGS="$val" ;;
    103 	DESTDIR)
    104 		DESTDIR="$val" ;;
    105 	PREFIX)
    106 		PREFIX="$val" ;;
    107 	MANDIR)
    108 		MANDIR="$val" ;;
    109 	LIBDIR)
    110 		LIBDIR="$val" ;;
    111 	BINDIR)
    112 		BINDIR="$val" ;;
    113 	SHAREDIR)
    114 		SHAREDIR="$val" ;;
    115 	PCDIR)
    116 		PCDIR="$val" ;;
    117 	SBINDIR)
    118 		SBINDIR="$val" ;;
    119 	INCLUDEDIR)
    120 		INCLUDEDIR="$val" ;;
    121 	*)
    122 		echo "$0: invalid key: $key" 1>&2
    123 		exit 1
    124 	esac
    125 done
    126 
    127 
    128 #----------------------------------------------------------------------
    129 # These are the values that will be pushed into config.h after we test
    130 # for whether they're supported or not.
    131 # Each of these must have a runtest(), below.
    132 # Please sort by alpha, for clarity.
    133 # You WANT to change this.
    134 #----------------------------------------------------------------------
    135 
    136 HAVE_ERR=
    137 HAVE_GETPROGNAME=
    138 HAVE_PLEDGE=
    139 HAVE_PROGRAM_INVOCATION_SHORT_NAME=
    140 HAVE_REALLOCARRAY=
    141 HAVE_STRTONUM=
    142 HAVE___PROGNAME=
    143 
    144 #----------------------------------------------------------------------
    145 # Allow configure.local to override all variables, default settings,
    146 # command-line arguments, and tested features, above.
    147 # You PROBABLY DO NOT want to change this.
    148 #----------------------------------------------------------------------
    149 
    150 if [ -r ./configure.local ]; then
    151 	echo "configure.local: reading..." 1>&2
    152 	echo "configure.local: reading..." 1>&3
    153 	cat ./configure.local 1>&3
    154 	. ./configure.local
    155 else
    156 	echo "configure.local: no (fully automatic configuration)" 1>&2
    157 	echo "configure.local: no (fully automatic configuration)" 1>&3
    158 fi
    159 
    160 echo 1>&3
    161 
    162 #----------------------------------------------------------------------
    163 # Infrastructure for running tests.
    164 # These consists of a series of functions that will attempt to run the
    165 # given test file and record its exit into a HAVE_xxx variable.
    166 # You DO NOT want to change this.
    167 #----------------------------------------------------------------------
    168 
    169 COMP="${CC} ${CFLAGS} ${CPPFLAGS} -Wno-unused -Werror"
    170 
    171 # Check whether this HAVE_ setting is manually overridden.
    172 # If yes, use the override, if no, do not decide anything yet.
    173 # Arguments: lower-case test name, manual value
    174 
    175 ismanual() {
    176 	[ -z "${3}" ] && return 1
    177 	echo "${1}: manual (HAVE_${2}=${3})" 1>&2
    178 	echo "${1}: manual (HAVE_${2}=${3})" 1>&3
    179 	echo 1>&3
    180 	return 0
    181 }
    182 
    183 # Run a single autoconfiguration test.
    184 # In case of success, enable the feature.
    185 # In case of failure, do not decide anything yet.
    186 # Arguments: lower-case test name, upper-case test name, additional
    187 # CFLAGS, additional LIBS.
    188 
    189 singletest() {
    190 	extralib=""
    191 	cat 1>&3 << __HEREDOC__
    192 ${1}: testing...
    193 ${COMP} -DTEST_${2} ${3} -o test-${1} tests.c ${4}
    194 __HEREDOC__
    195 	if ${COMP} -DTEST_${2} ${3} -o "test-${1}" tests.c ${4} 1>&3 2>&3; then
    196 		echo "${1}: ${CC} succeeded" 1>&3
    197 	else 
    198 		if [ -n "${5}" ] ; then
    199 			echo "${1}: ${CC} failed with $? (retrying)" 1>&3
    200 			cat 1>&3 << __HEREDOC__
    201 ${1}: testing...
    202 ${COMP} -DTEST_${2} ${3} -o test-${1} tests.c ${5}
    203 __HEREDOC__
    204 			if ${COMP} -DTEST_${2} ${3} -o "test-${1}" tests.c ${5} 1>&3 2>&3; then
    205 				echo "${1}: ${CC} succeeded" 1>&3
    206 				extralib="(with ${5})"
    207 			else 
    208 				echo "${1}: ${CC} failed with $?" 1>&3
    209 				echo 1>&3
    210 				return 1
    211 			fi
    212 		else
    213 			echo "${1}: ${CC} failed with $?" 1>&3
    214 			echo 1>&3
    215 			return 1
    216 		fi
    217 	fi
    218 
    219 	echo "${1}: yes ${extralib}" 1>&2
    220 	echo "${1}: yes ${extralib}" 1>&3
    221 	echo 1>&3
    222 	eval HAVE_${2}=1
    223 	rm "test-${1}"
    224 	return 0
    225 
    226 	# Don't actually run the test: none of our tests check for
    227 	# run-time behaviour.
    228 	# if ./test-${1} 1>&3 2>&3; then
    229 	# 	echo "${1}: yes" 1>&2
    230 	# 	echo "${1}: yes" 1>&3
    231 	# 	echo 1>&3
    232 	# 	eval HAVE_${2}=1
    233 	# 	rm "test-${1}"
    234 	# 	return 0
    235 	# else
    236 	# 	echo "${1}: execution failed with $?" 1>&3
    237 	# 	echo 1>&3
    238 	# 	rm "test-${1}"
    239 	# 	return 1
    240 	# fi
    241 }
    242 
    243 # Run a complete autoconfiguration test, including the check for
    244 # a manual override and disabling the feature on failure.
    245 # Arguments: lower case name, upper case name, additional CFLAGS, 
    246 # additional LDADD, alternative LDADD.
    247 
    248 runtest() {
    249 	eval _manual=\${HAVE_${2}}
    250 	ismanual "${1}" "${2}" "${_manual}" && return 0
    251 	singletest "${1}" "${2}" "${3}" "${4}" "${5}" && return 0
    252 	echo "${1}: no" 1>&2
    253 	eval HAVE_${2}=0
    254 	return 1
    255 }
    256 
    257 #----------------------------------------------------------------------
    258 # Begin running the tests themselves.
    259 # All of your tests must be defined here.
    260 # Please sort as the HAVE_xxxx values were defined.
    261 # You WANT to change this.
    262 # It consists of the following columns:
    263 #    runtest
    264 #    (1) test file
    265 #    (2) macro to set
    266 #    (3) argument to cc *before* -o
    267 #    (4) argument to cc *after* 
    268 #    (5) alternative argument to cc *after* 
    269 #----------------------------------------------------------------------
    270 
    271 runtest err		ERR				  || true
    272 runtest getprogname	GETPROGNAME			  || true
    273 runtest pledge		PLEDGE				  || true
    274 runtest program_invocation_short_name	PROGRAM_INVOCATION_SHORT_NAME || true
    275 runtest reallocarray	REALLOCARRAY			  || true
    276 runtest strtonum	STRTONUM			  || true
    277 runtest __progname	__PROGNAME			  || true
    278 
    279 #----------------------------------------------------------------------
    280 # Output writing: generate the config.h file.
    281 # This file contains all of the HAVE_xxxx variables necessary for
    282 # compiling your source.
    283 # You must include "config.h" BEFORE any other variables.
    284 # You WANT to change this.
    285 #----------------------------------------------------------------------
    286 
    287 exec > config.h
    288 
    289 # Start with prologue.
    290 
    291 cat << __HEREDOC__
    292 #ifdef __cplusplus
    293 #error "Do not use C++: this is a C application."
    294 #endif
    295 #if !defined(__GNUC__) || (__GNUC__ < 4)
    296 #define __attribute__(x)
    297 #endif
    298 #if defined(__linux__) || defined(__MINT__)
    299 #define _GNU_SOURCE	/* See test-*.c what needs this. */
    300 #endif
    301 #if !defined(__BEGIN_DECLS)
    302 # define __BEGIN_DECLS
    303 #endif
    304 #if !defined(__END_DECLS)
    305 # define __END_DECLS
    306 #endif
    307 __HEREDOC__
    308 
    309 # For the function declaration variables...
    310 
    311 [ ${HAVE_REALLOCARRAY} -eq 0 ] \
    312 	&& echo "#include <sys/types.h>"
    313 
    314 [ ${HAVE_ERR} -eq 0 ] \
    315 	&& echo "#include <stdarg.h>"
    316 
    317 # Now we handle our HAVE_xxxx values.
    318 # Most will just be defined as 0 or 1.
    319 
    320 cat << __HEREDOC__
    321 #define HAVE_ERR ${HAVE_ERR}
    322 #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
    323 #define HAVE_PLEDGE ${HAVE_PLEDGE}
    324 #define HAVE_PROGRAM_INVOCATION_SHORT_NAME ${HAVE_PROGRAM_INVOCATION_SHORT_NAME}
    325 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
    326 #define HAVE_STRTONUM ${HAVE_STRTONUM}
    327 #define HAVE___PROGNAME ${HAVE___PROGNAME}
    328 __HEREDOC__
    329 
    330 # Now we do our function declarations for missing functions.
    331 
    332 if [ ${HAVE_ERR} -eq 0 ]; then
    333 	echo "extern void err(int, const char *, ...);"
    334 	echo "extern void errx(int, const char *, ...);"
    335 	echo "extern void warn(const char *, ...);"
    336 	echo "extern void warnx(const char *, ...);"
    337 	echo "extern void vwarn(const char *, va_list);"
    338 	echo "extern void vwarnx(const char *, va_list);"
    339 fi
    340 
    341 if [ ${HAVE_GETPROGNAME} -eq 0 ]; then
    342 	echo "extern const char *getprogname(void);"
    343 	if [ ${HAVE_PROGRAM_INVOCATION_SHORT_NAME} -eq 0 -o \
    344 	     ${HAVE___PROGNAME} -eq 0 ]; then
    345 		echo "extern void setprogname(const char *);"
    346 	fi
    347 fi
    348 
    349 if [ ${HAVE_REALLOCARRAY} -eq 0 ]; then
    350 	echo "extern void *reallocarray(void *, size_t, size_t);"
    351 fi
    352 
    353 if [ ${HAVE_STRTONUM} -eq 0 ]; then
    354 	echo "extern long long strtonum(const char *, long long, long long, const char **);"
    355 fi
    356 
    357 echo "config.h: written" 1>&2
    358 echo "config.h: written" 1>&3
    359 
    360 #----------------------------------------------------------------------
    361 # Now we go to generate our Makefile.configure.
    362 # This file is simply a bunch of Makefile variables.
    363 # They'll work in both GNUmakefile and BSDmakefile.
    364 # You MIGHT want to change this.
    365 #----------------------------------------------------------------------
    366 
    367 exec > Makefile.configure
    368 
    369 [ -z "${BINDIR}"     ] && BINDIR="${PREFIX}/bin"
    370 [ -z "${SBINDIR}"    ] && SBINDIR="${PREFIX}/sbin"
    371 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include"
    372 [ -z "${LIBDIR}"     ] && LIBDIR="${PREFIX}/lib"
    373 [ -z "${MANDIR}"     ] && MANDIR="${PREFIX}/man"
    374 [ -z "${SHAREDIR}"   ] && SHAREDIR="${PREFIX}/share"
    375 [ -z "${PCDIR}"   ]    && PCDIR="${PREFIX}/lib/pkgconfig"
    376 
    377 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
    378 [ -z "${INSTALL_LIB}"     ] && INSTALL_LIB="${INSTALL} -m 0444"
    379 [ -z "${INSTALL_MAN}"     ] && INSTALL_MAN="${INSTALL} -m 0444"
    380 [ -z "${INSTALL_DATA}"    ] && INSTALL_DATA="${INSTALL} -m 0444"
    381 
    382 cat << __HEREDOC__
    383 CC		= ${CC}
    384 CFLAGS		= ${CFLAGS}
    385 CPPFLAGS	= ${CPPFLAGS}
    386 LDADD		= ${LDADD}
    387 LDFLAGS		= ${LDFLAGS}
    388 STATIC		= ${STATIC}
    389 PREFIX		= ${PREFIX}
    390 BINDIR		= ${BINDIR}
    391 SHAREDIR	= ${SHAREDIR}
    392 SBINDIR		= ${SBINDIR}
    393 INCLUDEDIR	= ${INCLUDEDIR}
    394 LIBDIR		= ${LIBDIR}
    395 MANDIR		= ${MANDIR}
    396 PCDIR		= ${PCDIR}
    397 INSTALL		= ${INSTALL}
    398 INSTALL_PROGRAM	= ${INSTALL_PROGRAM}
    399 INSTALL_LIB	= ${INSTALL_LIB}
    400 INSTALL_MAN	= ${INSTALL_MAN}
    401 INSTALL_DATA	= ${INSTALL_DATA}
    402 __HEREDOC__
    403 
    404 echo "Makefile.configure: written" 1>&2
    405 echo "Makefile.configure: written" 1>&3
    406 
    407 exit 0