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
20 AC_INIT([foobar],[m4_esyscmd(./version-gen.sh)],
21 [Sebastian Harl <sh@tokkee.org>])
22 AC_CONFIG_SRCDIR([src/foobar.c])
23 AC_CONFIG_HEADERS([src/config.h])
24 AC_PREFIX_DEFAULT([/opt/foobar])
26 AM_INIT_AUTOMAKE([foreign -Wall])
28 AC_LANG(C)
30 AC_SYS_LARGEFILE
32 AC_PROG_CC
33 AC_PROG_CPP
34 AC_PROG_INSTALL
35 AC_PROG_LN_S
36 AC_PROG_MAKE_SET
38 AM_PROG_CC_C_O
40 AC_PROG_LIBTOOL
42 test_cc_flags() {
43 AC_LANG_CONFTEST([int main() {}])
44 $CC -c conftest.c $CFLAGS $@ > /dev/null 2> /dev/null
45 ret=$?
46 rm -f conftest.o
47 return $ret
48 }
50 m4_divert_once([HELP_ENABLE], [
51 Build options:])
53 dnl Optionally stick to standard C99 and POSIX:2001 as close as possible.
54 AC_ARG_ENABLE([standards],
55 AS_HELP_STRING([--enable-standards],
56 [C99 / POSIX standards compliance mode @<:@default=no@:>@]),
57 [enable_standards="$enableval"],
58 [enable_standards="no"])
60 if test "x$enable_standards" = "xyes"; then
61 AC_DEFINE([_ISOC99_SOURCE], 1,
62 [Define to enforce ISO/IEC 9899:1999 (C99) compliance.])
63 AC_DEFINE([_POSIX_C_SOURCE], 200112L,
64 [Define to enforce IEEE 1003.1-2001 (POSIX:2001) compliance.])
65 AC_DEFINE([_XOPEN_SOURCE], 600,
66 [Define to enforce X/Open 6 (XSI) compliance.])
67 AC_DEFINE([_REENTRANT], 1,
68 [Define to enable reentrant interfaces.])
69 AC_DEFINE([_THREAD_SAFE], 1,
70 [Define to enable reentrant interfaces.])
72 for flag in -std=c99 -pedantic; do
73 AC_MSG_CHECKING([whether $CC accepts $flag])
75 if test_cc_flags $flag; then
76 CFLAGS="$CFLAGS $flag"
77 AC_MSG_RESULT([yes])
78 else
79 AC_MSG_RESULT([no])
80 fi
81 done
82 fi
84 dnl Hardening (see e.g. http://wiki.debian.org/Hardening for a motivation).
85 AC_DEFINE([_FORTIFY_SOURCE], 2,
86 [Define to enable protection against static sized buffer overflows.])
87 AC_ARG_ENABLE([hardening],
88 AS_HELP_STRING([--disable-hardening],
89 [hardening options @<:@default=yes@:>@]),
90 [enable_hardening="$enableval"],
91 [enable_hardening="yes"])
93 if test "x$enable_hardening" = "xyes"; then
94 hardening=0
95 hardening_tests=0
96 for flag in -Wformat -Wformat-security; do
97 hardening_tests=$(($hardening_tests + 1))
98 AC_MSG_CHECKING([whether $CC accepts $flag])
100 if test_cc_flags $flag; then
101 CFLAGS="$CFLAGS $flag"
102 hardening=$(($hardening + 1))
103 AC_MSG_RESULT([yes])
104 else
105 AC_MSG_RESULT([no])
106 fi
107 done
108 if test $hardening -ne $hardening_tests; then
109 AC_MSG_WARN(
110 [Some hardening options are not supported by your compiler!])
111 fi
112 fi
114 dnl Strict checking for potential problems.
115 AC_ARG_ENABLE([strict-checks],
116 AS_HELP_STRING([--disable-strict-checks],
117 [strict compiler checks @<:@default=yes@:>@]),
118 [enable_strict_checks="$enableval"],
119 [enable_strict_checks="yes"])
121 STRICT_CFLAGS=""
122 for flag in -Wall -Werror; do
123 AC_MSG_CHECKING([whether $CC accepts $flag])
125 if test_cc_flags $flag; then
126 STRICT_CFLAGS="$STRICT_CFLAGS $flag"
127 AC_MSG_RESULT([yes])
128 else
129 AC_MSG_RESULT([no])
130 fi
131 done
133 if test "x$enable_strict_checks" = "xyes"; then
134 for flag in -Wextra \
135 -Wbad-function-cast \
136 -Wcast-align \
137 -Wcast-qual \
138 -Wconversion \
139 -Wdeclaration-after-statement \
140 -Wmissing-prototypes \
141 -Wpointer-arith \
142 -Wshadow \
143 -Wstrict-prototypes \
144 -Wunreachable-code \
145 -Wvla; 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
155 fi
156 AC_SUBST([STRICT_CFLAGS])
158 build_date="`date --utc '+%F %T'` (UTC)"
159 AC_DEFINE_UNQUOTED([BUILD_DATE], ["$build_date"],
160 [Define to the date the package has been built on.])
162 dnl Version information provided by fb_features.h.
163 FB_VERSION_MAJOR=`echo $PACKAGE_VERSION | cut -d'.' -f1`
164 FB_VERSION_MINOR=`echo $PACKAGE_VERSION | cut -d'.' -f2`
165 FB_VERSION_PATCH=`echo $PACKAGE_VERSION | cut -d'.' -f3`
166 FB_VERSION_EXTRA=`echo $PACKAGE_VERSION | cut -d'.' -f4-`
167 FB_VERSION_STRING="$FB_VERSION_MAJOR.$FB_VERSION_MINOR.$FB_VERSION_PATCH"
169 AC_SUBST(FB_VERSION_MAJOR)
170 AC_SUBST(FB_VERSION_MINOR)
171 AC_SUBST(FB_VERSION_PATCH)
172 AC_SUBST(FB_VERSION_EXTRA)
173 AC_SUBST(FB_VERSION_STRING)
175 AC_CHECK_HEADERS(libgen.h)
177 AC_CONFIG_FILES([Makefile src/Makefile src/fb_features.h])
178 AC_OUTPUT
180 cat <<EOF;
182 $PACKAGE_NAME has been configured successfully.
184 Run 'make' to compile the software and use 'make install' to
185 install the package into $prefix.
187 Configuration summary:
189 package version: $PACKAGE_VERSION
190 build date: $build_date
192 Please report bugs to $PACKAGE_BUGREPORT.
194 EOF