Code

22214b49d3f15d77d885fa2200f91bda1d018e10
[template.git] / configure.ac
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 AC_PROG_LIBTOOL
65 test_cc_flags() {
66         AC_LANG_CONFTEST([int main() {}])
67         $CC -c conftest.c $CFLAGS $@ > /dev/null 2> /dev/null
68         ret=$?
69         rm -f conftest.o
70         return $ret
71 }
73 m4_divert_once([HELP_ENABLE], [
74 Build options:])
76 dnl Optionally stick to standard C99 and POSIX:2001 as close as possible.
77 AC_ARG_ENABLE([standards],
78                 AS_HELP_STRING([--enable-standards],
79                                 [C99 / POSIX standards compliance mode @<:@default=no@:>@]),
80                 [enable_standards="$enableval"],
81                 [enable_standards="no"])
83 if test "x$enable_standards" = "xyes"; then
84         AC_DEFINE([_ISOC99_SOURCE], 1,
85                         [Define to enforce ISO/IEC 9899:1999 (C99) compliance.])
86         AC_DEFINE([_POSIX_C_SOURCE], 200112L,
87                         [Define to enforce IEEE 1003.1-2001 (POSIX:2001) compliance.])
88         AC_DEFINE([_XOPEN_SOURCE], 600,
89                         [Define to enforce X/Open 6 (XSI) compliance.])
90         AC_DEFINE([_REENTRANT], 1,
91                         [Define to enable reentrant interfaces.])
92         AC_DEFINE([_THREAD_SAFE], 1,
93                         [Define to enable reentrant interfaces.])
95         for flag in -std=c99 -pedantic; do
96                 AC_MSG_CHECKING([whether $CC accepts $flag])
98                 if test_cc_flags $flag; then
99                         CFLAGS="$CFLAGS $flag"
100                         AC_MSG_RESULT([yes])
101                 else
102                         AC_MSG_RESULT([no])
103                 fi
104         done
105 fi
107 dnl Hardening (see e.g. http://wiki.debian.org/Hardening for a motivation).
108 AC_DEFINE([_FORTIFY_SOURCE], 2,
109                 [Define to enable protection against static sized buffer overflows.])
110 AC_ARG_ENABLE([hardening],
111                 AS_HELP_STRING([--disable-hardening],
112                                 [hardening options @<:@default=yes@:>@]),
113                 [enable_hardening="$enableval"],
114                 [enable_hardening="yes"])
116 if test "x$enable_hardening" = "xyes"; then
117         hardening=0
118         hardening_tests=0
119         for flag in -Wformat -Wformat-security; do
120                 hardening_tests=$(($hardening_tests + 1))
121                 AC_MSG_CHECKING([whether $CC accepts $flag])
123                 if test_cc_flags $flag; then
124                         CFLAGS="$CFLAGS $flag"
125                         hardening=$(($hardening + 1))
126                         AC_MSG_RESULT([yes])
127                 else
128                         AC_MSG_RESULT([no])
129                 fi
130         done
131         if test $hardening -ne $hardening_tests; then
132                 AC_MSG_WARN(
133                                 [Some hardening options are not supported by your compiler!])
134         fi
135 fi
137 dnl Strict checking for potential problems.
138 AC_ARG_ENABLE([strict-checks],
139                 AS_HELP_STRING([--disable-strict-checks],
140                                 [strict compiler checks @<:@default=yes@:>@]),
141                 [enable_strict_checks="$enableval"],
142                 [enable_strict_checks="yes"])
144 STRICT_CFLAGS=""
145 for flag in -Wall -Werror; do
146         AC_MSG_CHECKING([whether $CC accepts $flag])
148         if test_cc_flags $flag; then
149                 STRICT_CFLAGS="$STRICT_CFLAGS $flag"
150                 AC_MSG_RESULT([yes])
151         else
152                 AC_MSG_RESULT([no])
153         fi
154 done
156 if test "x$enable_strict_checks" = "xyes"; then
157         for flag in -Wextra \
158                         -Wbad-function-cast \
159                         -Wcast-align \
160                         -Wcast-qual \
161                         -Wconversion \
162                         -Wdeclaration-after-statement \
163                         -Wmissing-prototypes \
164                         -Wpointer-arith \
165                         -Wshadow \
166                         -Wstrict-prototypes \
167                         -Wunreachable-code; do
168                 AC_MSG_CHECKING([whether $CC accepts $flag])
170                 if test_cc_flags $flag; then
171                         STRICT_CFLAGS="$STRICT_CFLAGS $flag"
172                         AC_MSG_RESULT([yes])
173                 else
174                         AC_MSG_RESULT([no])
175                 fi
176         done
177 fi
178 AC_SUBST([STRICT_CFLAGS])
180 build_date="`date --utc '+%F %T'` (UTC)"
181 AC_DEFINE_UNQUOTED([BUILD_DATE], ["$build_date"],
182                 [Define to the date the package has been built on.])
184 dnl Version information provided by fb_features.h.
185 FB_VERSION_MAJOR=`echo $PACKAGE_VERSION | cut -d'.' -f1`
186 FB_VERSION_MINOR=`echo $PACKAGE_VERSION | cut -d'.' -f2`
187 FB_VERSION_PATCH=`echo $PACKAGE_VERSION | cut -d'.' -f3`
188 FB_VERSION_EXTRA=`echo $PACKAGE_VERSION | cut -d'.' -f4-`
189 FB_VERSION_STRING="$FB_VERSION_MAJOR.$FB_VERSION_MINOR.$FB_VERSION_PATCH"
191 AC_SUBST(FB_VERSION_MAJOR)
192 AC_SUBST(FB_VERSION_MINOR)
193 AC_SUBST(FB_VERSION_PATCH)
194 AC_SUBST(FB_VERSION_EXTRA)
195 AC_SUBST(FB_VERSION_STRING)
197 AC_CHECK_HEADERS(libgen.h)
199 AC_CONFIG_FILES([Makefile src/Makefile src/fb_features.h])
200 AC_OUTPUT
202 cat <<EOF;
204 $PACKAGE_NAME has been configured successfully.
206 Run 'make' to compile the software and use 'make install' to
207 install the package into $prefix.
209 Configuration summary:
211   package version: $PACKAGE_VERSION
212   build date: $build_date
214 Please report bugs to $PACKAGE_BUGREPORT.
216 EOF