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