Code

Initial commit.
[libjunos.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2 dnl
3 dnl This is the libJUNOS configure script.
4 dnl
5 dnl Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
6 dnl All rights reserved.
7 dnl
8 dnl Redistribution and use in source and binary forms, with or without
9 dnl modification, are permitted provided that the following conditions
10 dnl are met:
11 dnl 1. Redistributions of source code must retain the above copyright
12 dnl    notice, this list of conditions and the following disclaimer.
13 dnl 2. Redistributions in binary form must reproduce the above copyright
14 dnl    notice, this list of conditions and the following disclaimer in the
15 dnl    documentation and/or other materials provided with the distribution.
16 dnl
17 dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 dnl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 dnl TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 dnl PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
21 dnl CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 dnl OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 dnl ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 AC_INIT([JUNOScript client library],[m4_esyscmd(./version-gen.sh)],
30                 [sh@tokkee.org],
31                 [libJUNOS],
32                 [http://git.tokkee.org/?p=libjunos.git])
33 PACKAGE_MAINTAINER="Sebastian 'tokkee' Harl <sh@tokkee.org>"
34 AC_DEFINE_UNQUOTED([PACKAGE_MAINTAINER], ["$PACKAGE_MAINTAINER"],
35                 [Define to the name of the maintainer of this package.])
36 AC_CONFIG_SRCDIR([src/junosc.c])
37 AC_CONFIG_HEADERS([src/config.h])
38 AC_PREFIX_DEFAULT([/opt/libjunos])
40 AM_INIT_AUTOMAKE([foreign -Wall])
42 AC_LANG(C)
44 AC_SYS_LARGEFILE
46 AC_PROG_CC
47 AC_PROG_CPP
48 AC_PROG_INSTALL
49 AC_PROG_LN_S
50 AC_PROG_MAKE_SET
52 AM_PROG_CC_C_O
54 AC_FUNC_STRERROR_R
56 m4_ifdef([LT_INIT],
57         [
58          LT_INIT
59         ],
60         # else
61         # (older libtools)
62         [
63          AC_PROG_LIBTOOL
64         ]
65 )
67 PKG_PROG_PKG_CONFIG
69 test_cc_flags() {
70         AC_LANG_CONFTEST([AC_LANG_PROGRAM([[ ]], [[ ]])])
71         $CC -c conftest.c $CFLAGS $@ > /dev/null 2> /dev/null
72         ret=$?
73         rm -f conftest.o
74         return $ret
75 }
77 m4_divert_once([HELP_ENABLE], [
78 Build options:])
80 dnl Optionally stick to standard C99 and POSIX:2001 as close as possible.
81 AC_ARG_ENABLE([standards],
82                 AS_HELP_STRING([--enable-standards],
83                                 [C99 / POSIX standards compliance mode @<:@default=no@:>@]),
84                 [enable_standards="$enableval"],
85                 [enable_standards="no"])
87 if test "x$enable_standards" = "xyes"; then
88         AC_DEFINE([_ISOC99_SOURCE], 1,
89                         [Define to enforce ISO/IEC 9899:1999 (C99) compliance.])
90         AC_DEFINE([_POSIX_C_SOURCE], 200112L,
91                         [Define to enforce IEEE 1003.1-2001 (POSIX:2001) compliance.])
92         AC_DEFINE([_XOPEN_SOURCE], 600,
93                         [Define to enforce X/Open 6 (XSI) compliance.])
94         AC_DEFINE([_REENTRANT], 1,
95                         [Define to enable reentrant interfaces.])
96         AC_DEFINE([_THREAD_SAFE], 1,
97                         [Define to enable reentrant interfaces.])
99         for flag in -std=c99 -pedantic; do
100                 AC_MSG_CHECKING([whether $CC accepts $flag])
102                 if test_cc_flags $flag; then
103                         CFLAGS="$CFLAGS $flag"
104                         AC_MSG_RESULT([yes])
105                 else
106                         AC_MSG_RESULT([no])
107                 fi
108         done
109 fi
111 dnl Hardening (see e.g. http://wiki.debian.org/Hardening for a motivation).
112 AC_DEFINE([_FORTIFY_SOURCE], 2,
113                 [Define to enable protection against static sized buffer overflows.])
114 AC_ARG_ENABLE([hardening],
115                 AS_HELP_STRING([--disable-hardening],
116                                 [hardening options @<:@default=yes@:>@]),
117                 [enable_hardening="$enableval"],
118                 [enable_hardening="yes"])
120 if test "x$enable_hardening" = "xyes"; then
121         hardening=0
122         hardening_tests=0
123         for flag in -Wformat -Wformat-security; do
124                 hardening_tests=$(($hardening_tests + 1))
125                 AC_MSG_CHECKING([whether $CC accepts $flag])
127                 if test_cc_flags $flag; then
128                         CFLAGS="$CFLAGS $flag"
129                         hardening=$(($hardening + 1))
130                         AC_MSG_RESULT([yes])
131                 else
132                         AC_MSG_RESULT([no])
133                 fi
134         done
135         if test $hardening -ne $hardening_tests; then
136                 AC_MSG_WARN(
137                                 [Some hardening options are not supported by your compiler!])
138         fi
139 fi
141 dnl Strict checking for potential problems.
142 AC_ARG_ENABLE([strict-checks],
143                 AS_HELP_STRING([--disable-strict-checks],
144                                 [strict compiler checks @<:@default=yes@:>@]),
145                 [enable_strict_checks="$enableval"],
146                 [enable_strict_checks="yes"])
148 STRICT_CFLAGS=""
149 for flag in -Wall -Werror; do
150         AC_MSG_CHECKING([whether $CC accepts $flag])
152         if test_cc_flags $flag; then
153                 STRICT_CFLAGS="$STRICT_CFLAGS $flag"
154                 AC_MSG_RESULT([yes])
155         else
156                 AC_MSG_RESULT([no])
157         fi
158 done
160 if test "x$enable_strict_checks" = "xyes"; then
161         for flag in -Wextra \
162                         -Wbad-function-cast \
163                         -Wcast-align \
164                         -Wcast-qual \
165                         -Wconversion \
166                         -Wdeclaration-after-statement \
167                         -Wmissing-prototypes \
168                         -Wpointer-arith \
169                         -Wshadow \
170                         -Wstrict-prototypes \
171                         -Wunreachable-code; do
172                 AC_MSG_CHECKING([whether $CC accepts $flag])
174                 if test_cc_flags $flag; then
175                         STRICT_CFLAGS="$STRICT_CFLAGS $flag"
176                         AC_MSG_RESULT([yes])
177                 else
178                         AC_MSG_RESULT([no])
179                 fi
180         done
181 fi
182 AC_SUBST([STRICT_CFLAGS])
184 AC_CHECK_HEADERS(libgen.h)
186 dnl Check for dependencies.
187 build_documentation="yes"
189 have_xsltproc="yes"
190 AC_PATH_PROG([XSLTPROC], [xsltproc])
191 if test "x$XSLTPROC" = "x"; then
192        have_xsltproc="no"
193        build_documentation="no (missing xsltproc)"
194 fi
196 have_a2x="yes"
197 AC_PATH_PROG([A2X], [a2x])
198 if test "x$A2X" = "x"; then
199        have_a2x="no"
200        build_documentation="no (missing a2x)"
201 fi
202 AC_SUBST([A2X])
204 AM_CONDITIONAL([BUILD_DOCUMENTATION], test "x$build_documentation" = "xyes")
206 PKG_CHECK_MODULES([LIBSSH2], [libssh2])
207 LIBSSH2_VERSION=`$PKG_CONFIG --modversion libssh2`
208 LIBSSH2_IDIRS=`$PKG_CONFIG --cflags-only-I libssh2`
210 PKG_CHECK_MODULES([LIBXML2], [libxml-2.0])
211 LIBXML2_VERSION=`$PKG_CONFIG --modversion libxml-2.0`
212 LIBXML2_IDIRS=`$PKG_CONFIG --cflags-only-I libxml-2.0`
214 dnl Try to ignore compiler warnings caused by third-party headers
215 for flag in $LIBSSH2_IDIRS $LIBXML2_IDIRS; do
216         I_dir=${flag#-I}
218         flag="-isystem $I_dir"
219         AC_MSG_CHECKING([whether $CC accepts $flag])
220         if test_cc_flags "$flag"; then
221                 STRICT_CFLAGS="$STRICT_CFLAGS $flag"
222                 AC_MSG_RESULT([yes])
223         else
224                 AC_MSG_RESULT([no])
225         fi
226 done
228 AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile])
229 AC_OUTPUT
231 BUILD_DATE="`date --utc '+%F %T'` (UTC)"
233 AC_MSG_RESULT()
234 AC_MSG_RESULT([$PACKAGE_NAME has been configured successfully.])
235 AC_MSG_RESULT()
236 AC_MSG_RESULT([Run 'make' to compile the software and use 'make install' to])
237 AC_MSG_RESULT([install the package into $prefix.])
238 AC_MSG_RESULT()
239 AC_MSG_RESULT([Configuration summary:])
240 AC_MSG_RESULT()
241 AC_MSG_RESULT([  package version: $PACKAGE_VERSION])
242 AC_MSG_RESULT([  build date: $BUILD_DATE])
243 AC_MSG_RESULT()
244 AC_MSG_RESULT([  Tools:])
245 AC_MSG_RESULT([    AsciiDoc (a2x): . . . . . . $have_a2x])
246 AC_MSG_RESULT([    xsltproc: . . . . . . . . . $have_xsltproc])
247 AC_MSG_RESULT()
248 AC_MSG_RESULT([  Libraries:])
249 AC_MSG_RESULT([    libssh2:  . . . . . . . . . $LIBSSH2_VERSION])
250 AC_MSG_RESULT([    libxml2:  . . . . . . . . . $LIBXML2_VERSION])
251 AC_MSG_RESULT()
252 AC_MSG_RESULT([  Features:])
253 AC_MSG_RESULT([    documentation:  . . . . . . $build_documentation])
254 AC_MSG_RESULT([    SSH access: . . . . . . . . yes])
255 AC_MSG_RESULT()
256 AC_MSG_RESULT([This package is maintained by $PACKAGE_MAINTAINER.])
257 AC_MSG_RESULT([Please report bugs to $PACKAGE_BUGREPORT.])
258 AC_MSG_RESULT()