1 dnl Process this file with autoconf to produce a configure script.
2 dnl
3 dnl This is the foobar configure script.
4 dnl
5 dnl Copyright (C) 2011 Sebastian 'tokkee' Harl <sh@tokkee.org>
6 dnl
7 dnl This program is free software; you can redistribute it and/or modify it
8 dnl under the terms of the GNU General Public License as published by the
9 dnl Free Software Foundation; only version 2 of the License is applicable.
10 dnl
11 dnl This program is distributed in the hope that it will be useful, but
12 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 dnl General Public License for more details.
15 dnl
16 dnl You should have received a copy of the GNU General Public License along
17 dnl with this program; if not, write to the Free Software Foundation, Inc.,
18 dnl 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 dnl OR:
20 dnl All rights reserved.
21 dnl
22 dnl Redistribution and use in source and binary forms, with or without
23 dnl modification, are permitted provided that the following conditions
24 dnl are met:
25 dnl 1. Redistributions of source code must retain the above copyright
26 dnl notice, this list of conditions and the following disclaimer.
27 dnl 2. Redistributions in binary form must reproduce the above copyright
28 dnl notice, this list of conditions and the following disclaimer in the
29 dnl documentation and/or other materials provided with the distribution.
30 dnl
31 dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 dnl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
33 dnl TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 dnl PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
35 dnl CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36 dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37 dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38 dnl OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40 dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 dnl ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 AC_INIT([foobar full name],[m4_esyscmd(./version-gen.sh)],
44 [Sebastian 'tokkee' Harl <sh@tokkee.org>],
45 [foobar],
46 [http://git.tokkee.org/?p=template.git])
47 AC_CONFIG_SRCDIR([src/foobar.c])
48 AC_CONFIG_HEADERS([src/config.h])
49 AC_PREFIX_DEFAULT([/opt/foobar])
51 AM_INIT_AUTOMAKE([foreign -Wall])
53 AC_LANG(C)
55 AC_SYS_LARGEFILE
57 AC_PROG_CC
58 AC_PROG_CPP
59 AC_PROG_INSTALL
60 AC_PROG_LN_S
61 AC_PROG_MAKE_SET
63 AM_PROG_CC_C_O
65 m4_ifdef([LT_INIT],
66 [
67 LT_INIT
68 ],
69 # else
70 # (older libtools)
71 [
72 AC_PROG_LIBTOOL
73 ]
74 )
76 test_cc_flags() {
77 AC_LANG_CONFTEST([AC_LANG_PROGRAM([[ ]], [[ ]])])
78 $CC -c conftest.c $CFLAGS $@ > /dev/null 2> /dev/null
79 ret=$?
80 rm -f conftest.o
81 return $ret
82 }
84 m4_divert_once([HELP_ENABLE], [
85 Build options:])
87 dnl Optionally stick to standard C99 and POSIX:2001 as close as possible.
88 AC_ARG_ENABLE([standards],
89 AS_HELP_STRING([--enable-standards],
90 [C99 / POSIX standards compliance mode @<:@default=no@:>@]),
91 [enable_standards="$enableval"],
92 [enable_standards="no"])
94 if test "x$enable_standards" = "xyes"; then
95 AC_DEFINE([_ISOC99_SOURCE], 1,
96 [Define to enforce ISO/IEC 9899:1999 (C99) compliance.])
97 AC_DEFINE([_POSIX_C_SOURCE], 200112L,
98 [Define to enforce IEEE 1003.1-2001 (POSIX:2001) compliance.])
99 AC_DEFINE([_XOPEN_SOURCE], 600,
100 [Define to enforce X/Open 6 (XSI) compliance.])
101 AC_DEFINE([_REENTRANT], 1,
102 [Define to enable reentrant interfaces.])
103 AC_DEFINE([_THREAD_SAFE], 1,
104 [Define to enable reentrant interfaces.])
106 for flag in -std=c99 -pedantic; do
107 AC_MSG_CHECKING([whether $CC accepts $flag])
109 if test_cc_flags $flag; then
110 CFLAGS="$CFLAGS $flag"
111 AC_MSG_RESULT([yes])
112 else
113 AC_MSG_RESULT([no])
114 fi
115 done
116 fi
118 dnl Hardening (see e.g. http://wiki.debian.org/Hardening for a motivation).
119 AC_DEFINE([_FORTIFY_SOURCE], 2,
120 [Define to enable protection against static sized buffer overflows.])
121 AC_ARG_ENABLE([hardening],
122 AS_HELP_STRING([--disable-hardening],
123 [hardening options @<:@default=yes@:>@]),
124 [enable_hardening="$enableval"],
125 [enable_hardening="yes"])
127 if test "x$enable_hardening" = "xyes"; then
128 hardening=0
129 hardening_tests=0
130 for flag in -Wformat -Wformat-security; do
131 hardening_tests=$(($hardening_tests + 1))
132 AC_MSG_CHECKING([whether $CC accepts $flag])
134 if test_cc_flags $flag; then
135 CFLAGS="$CFLAGS $flag"
136 hardening=$(($hardening + 1))
137 AC_MSG_RESULT([yes])
138 else
139 AC_MSG_RESULT([no])
140 fi
141 done
142 if test $hardening -ne $hardening_tests; then
143 AC_MSG_WARN(
144 [Some hardening options are not supported by your compiler!])
145 fi
146 fi
148 dnl Strict checking for potential problems.
149 AC_ARG_ENABLE([strict-checks],
150 AS_HELP_STRING([--disable-strict-checks],
151 [strict compiler checks @<:@default=yes@:>@]),
152 [enable_strict_checks="$enableval"],
153 [enable_strict_checks="yes"])
155 STRICT_CFLAGS=""
156 for flag in -Wall -Werror; do
157 AC_MSG_CHECKING([whether $CC accepts $flag])
159 if test_cc_flags $flag; then
160 STRICT_CFLAGS="$STRICT_CFLAGS $flag"
161 AC_MSG_RESULT([yes])
162 else
163 AC_MSG_RESULT([no])
164 fi
165 done
167 if test "x$enable_strict_checks" = "xyes"; then
168 for flag in -Wextra \
169 -Wbad-function-cast \
170 -Wcast-align \
171 -Wcast-qual \
172 -Wconversion \
173 -Wdeclaration-after-statement \
174 -Wmissing-prototypes \
175 -Wpointer-arith \
176 -Wshadow \
177 -Wstrict-prototypes \
178 -Wunreachable-code; do
179 AC_MSG_CHECKING([whether $CC accepts $flag])
181 if test_cc_flags $flag; then
182 STRICT_CFLAGS="$STRICT_CFLAGS $flag"
183 AC_MSG_RESULT([yes])
184 else
185 AC_MSG_RESULT([no])
186 fi
187 done
188 fi
189 AC_SUBST([STRICT_CFLAGS])
191 AC_CHECK_HEADERS(libgen.h)
193 AC_CONFIG_FILES([Makefile src/Makefile])
194 AC_OUTPUT
196 cat <<EOF;
198 $PACKAGE_NAME has been configured successfully.
200 Run 'make' to compile the software and use 'make install' to
201 install the package into $prefix.
203 Configuration summary:
205 package version: $PACKAGE_VERSION
206 build date: `date --utc '+%F %T'` (UTC)
208 Please report bugs to $PACKAGE_BUGREPORT.
210 EOF