254580cf2e4ac6b86331e5ff62ee300ae58d87e7
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) 2010 Sebastian 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],[m4_esyscmd(./version-gen.sh)],
44 [Sebastian Harl <sh@tokkee.org>])
45 AC_CONFIG_SRCDIR([src/foobar.c])
46 AC_CONFIG_HEADERS([src/config.h])
47 AC_PREFIX_DEFAULT([/opt/foobar])
49 AM_INIT_AUTOMAKE([foreign -Wall])
51 AC_LANG(C)
53 AC_SYS_LARGEFILE
55 AC_PROG_CC
56 AC_PROG_CPP
57 AC_PROG_INSTALL
58 AC_PROG_LN_S
59 AC_PROG_MAKE_SET
61 AM_PROG_CC_C_O
63 m4_ifdef([LT_INIT],
64 [
65 LT_INIT
66 ],
67 # else
68 # (older libtools)
69 [
70 AC_PROG_LIBTOOL
71 ]
72 )
74 test_cc_flags() {
75 AC_LANG_CONFTEST([int main() {}])
76 $CC -c conftest.c $CFLAGS $@ > /dev/null 2> /dev/null
77 ret=$?
78 rm -f conftest.o
79 return $ret
80 }
82 m4_divert_once([HELP_ENABLE], [
83 Build options:])
85 dnl Optionally stick to standard C99 and POSIX:2001 as close as possible.
86 AC_ARG_ENABLE([standards],
87 AS_HELP_STRING([--enable-standards],
88 [C99 / POSIX standards compliance mode @<:@default=no@:>@]),
89 [enable_standards="$enableval"],
90 [enable_standards="no"])
92 if test "x$enable_standards" = "xyes"; then
93 AC_DEFINE([_ISOC99_SOURCE], 1,
94 [Define to enforce ISO/IEC 9899:1999 (C99) compliance.])
95 AC_DEFINE([_POSIX_C_SOURCE], 200112L,
96 [Define to enforce IEEE 1003.1-2001 (POSIX:2001) compliance.])
97 AC_DEFINE([_XOPEN_SOURCE], 600,
98 [Define to enforce X/Open 6 (XSI) compliance.])
99 AC_DEFINE([_REENTRANT], 1,
100 [Define to enable reentrant interfaces.])
101 AC_DEFINE([_THREAD_SAFE], 1,
102 [Define to enable reentrant interfaces.])
104 for flag in -std=c99 -pedantic; do
105 AC_MSG_CHECKING([whether $CC accepts $flag])
107 if test_cc_flags $flag; then
108 CFLAGS="$CFLAGS $flag"
109 AC_MSG_RESULT([yes])
110 else
111 AC_MSG_RESULT([no])
112 fi
113 done
114 fi
116 dnl Hardening (see e.g. http://wiki.debian.org/Hardening for a motivation).
117 AC_DEFINE([_FORTIFY_SOURCE], 2,
118 [Define to enable protection against static sized buffer overflows.])
119 AC_ARG_ENABLE([hardening],
120 AS_HELP_STRING([--disable-hardening],
121 [hardening options @<:@default=yes@:>@]),
122 [enable_hardening="$enableval"],
123 [enable_hardening="yes"])
125 if test "x$enable_hardening" = "xyes"; then
126 hardening=0
127 hardening_tests=0
128 for flag in -Wformat -Wformat-security; do
129 hardening_tests=$(($hardening_tests + 1))
130 AC_MSG_CHECKING([whether $CC accepts $flag])
132 if test_cc_flags $flag; then
133 CFLAGS="$CFLAGS $flag"
134 hardening=$(($hardening + 1))
135 AC_MSG_RESULT([yes])
136 else
137 AC_MSG_RESULT([no])
138 fi
139 done
140 if test $hardening -ne $hardening_tests; then
141 AC_MSG_WARN(
142 [Some hardening options are not supported by your compiler!])
143 fi
144 fi
146 dnl Strict checking for potential problems.
147 AC_ARG_ENABLE([strict-checks],
148 AS_HELP_STRING([--disable-strict-checks],
149 [strict compiler checks @<:@default=yes@:>@]),
150 [enable_strict_checks="$enableval"],
151 [enable_strict_checks="yes"])
153 STRICT_CFLAGS=""
154 for flag in -Wall -Werror; do
155 AC_MSG_CHECKING([whether $CC accepts $flag])
157 if test_cc_flags $flag; then
158 STRICT_CFLAGS="$STRICT_CFLAGS $flag"
159 AC_MSG_RESULT([yes])
160 else
161 AC_MSG_RESULT([no])
162 fi
163 done
165 if test "x$enable_strict_checks" = "xyes"; then
166 for flag in -Wextra \
167 -Wbad-function-cast \
168 -Wcast-align \
169 -Wcast-qual \
170 -Wconversion \
171 -Wdeclaration-after-statement \
172 -Wmissing-prototypes \
173 -Wpointer-arith \
174 -Wshadow \
175 -Wstrict-prototypes \
176 -Wunreachable-code; do
177 AC_MSG_CHECKING([whether $CC accepts $flag])
179 if test_cc_flags $flag; then
180 STRICT_CFLAGS="$STRICT_CFLAGS $flag"
181 AC_MSG_RESULT([yes])
182 else
183 AC_MSG_RESULT([no])
184 fi
185 done
186 fi
187 AC_SUBST([STRICT_CFLAGS])
189 AC_CHECK_HEADERS(libgen.h)
191 AC_CONFIG_FILES([Makefile src/Makefile])
192 AC_OUTPUT
194 cat <<EOF;
196 $PACKAGE_NAME has been configured successfully.
198 Run 'make' to compile the software and use 'make install' to
199 install the package into $prefix.
201 Configuration summary:
203 package version: $PACKAGE_VERSION
204 build date: `date --utc '+%F %T'` (UTC)
206 Please report bugs to $PACKAGE_BUGREPORT.
208 EOF