autotools: Make petitboot autoreconfable
[petitboot] / configure.ac
1 ## configure.ac -- Process this file with autoconf to produce configure
2 #
3 #  This program is free software; you can redistribute it and/or modify
4 #  it under the terms of the GNU General Public License as published by
5 #  the Free Software Foundation; version 2 of the License.
6 #
7 #  This program is distributed in the hope that it will be useful,
8 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
9 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 #  GNU General Public License for more details.
11 #
12 #  You should have received a copy of the GNU General Public License
13 #  along with this program; if not, write to the Free Software
14 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15 #
16
17 AC_INIT([petitboot],
18     [m4_esyscmd_s([./version.sh])],
19     [Geoff Levand <geoff@infradead.org>])
20
21 AC_CONFIG_MACRO_DIR([m4])
22
23 AC_PREFIX_DEFAULT([/usr/local])
24
25 AS_IF([test "x$CFLAGS" = "x"], [AC_SUBST([CFLAGS], [""])])
26
27 AC_PROG_CC
28 AC_PROG_LEX
29 AC_PROG_YACC
30 AC_PROG_INSTALL
31
32 AM_INIT_AUTOMAKE
33 AC_GNU_SOURCE
34 LT_INIT
35
36 AX_WITH_CURSES
37 AX_WITH_CURSES_MENU
38 AX_WITH_CURSES_FORM
39
40 AM_CONDITIONAL([WITH_NCURSES], [test "x$ax_cv_curses" = "xyes"])
41
42 if test "x$ax_cv_curses" = xyes; then
43         if test "x$ax_cv_menu" != xyes; then
44                 AC_MSG_ERROR([--with-ncurses requires the ncurses menu library])
45         fi
46         if test "x$ax_cv_form" != xyes; then
47                 AC_MSG_ERROR([--with-ncurses requires the ncurses form library])
48         fi
49 fi
50
51 AC_CHECK_LIB([udev], [udev_new],
52         [],
53         [AC_MSG_FAILURE([The libudev development library is required by petitboot.  Try installing the package libudev-dev or libudev-devel.])]
54 )
55
56 AC_CHECK_HEADERS([stdarg.h])
57 AC_CHECK_HEADERS([varargs.h])
58
59 dnl Checking for va_copy availability
60 AC_MSG_CHECKING([for va_copy])
61 AC_TRY_LINK([#include <stdarg.h>
62 va_list ap1,ap2;], [va_copy(ap1,ap2);],
63 have_va_copy=yes,
64 have_va_copy=no)
65 AC_MSG_RESULT($have_va_copy)
66 if test x"$have_va_copy" = x"yes"; then
67     AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
68 else
69     AC_MSG_CHECKING([for __va_copy])
70     AC_TRY_LINK([#include <stdarg.h>
71     va_list ap1,ap2;], [__va_copy(ap1,ap2);],
72     have___va_copy=yes,
73     have___va_copy=no)
74     AC_MSG_RESULT($have___va_copy)
75     if test x"$have___va_copy" = x"yes"; then
76         AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
77     fi
78 fi
79
80 AC_ARG_WITH(
81         [twin-x11],
82         [AS_HELP_STRING([--with-twin-x11],
83                 [build x11 GUI programs using the twin window system [default=yes]]
84         )],
85         [],
86         [with_twin_x11=yes]
87 )
88 AM_CONDITIONAL([WITH_TWIN_X11], [test "x$with_twin_x11" = "xyes"])
89
90 AC_ARG_WITH(
91         [twin-fbdev],
92         [AS_HELP_STRING(
93                 [--with-twin-fbdev],
94                 [build frame buffer GUI programs using the twin window system [default=no]]
95         )],
96         [],
97         [with_twin_fbdev=yes]
98 )
99 AM_CONDITIONAL([WITH_TWIN_FBDEV], [test "x$with_twin_fbdev" = "xyes"])
100
101 AM_CONDITIONAL(
102         [WITH_TWIN],
103         [test "x$with_twin_x11" = "xyes" || test "x$with_twin_fbdev" = "xyes"])
104
105 AS_IF(
106         [test "x$with_twin_x11" = "xyes" || test "x$with_twin_fbdev" = "xyes"],
107         [PKG_CHECK_MODULES(
108                 [twin],
109                 [libtwin],
110                 [SAVE_LIBS="$LIBS" LIBS="$LIBS $twin_LIBS"
111                         AC_CHECK_LIB(
112                                 [twin],
113                                 [twin_feature_init],
114                                 [],
115                                 [AC_MSG_FAILURE([--with-twin was given but the test for libtwin failed.])]
116                         )
117                         LIBS="$SAVE_LIBS"
118                 ],
119                 [AC_MSG_RESULT([$twin_PKG_ERRORS])
120                         AC_MSG_FAILURE([ Consider adjusting PKG_CONFIG_PATH environment variable])
121                 ]
122         )]
123 )
124
125 AS_IF(
126         [test "x$with_twin_x11" = "xyes"],
127         [SAVE_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $twin_CFLAGS"
128                 AC_CHECK_HEADERS(
129                         [libtwin/twin_x11.h],
130                         [],
131                         [AC_MSG_FAILURE([ --with-twin-x11 given but libtwin/twin_x11.h not found])]
132                 )
133                 CPPFLAGS="$SAVE_CPPFLAGS"
134         ]
135 )
136
137 AS_IF(
138         [test "x$with_twin_fbdev" = "xyes"],
139         [SAVE_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $twin_CFLAGS"
140                 AC_CHECK_HEADERS(
141                         [libtwin/twin_fbdev.h],
142                         [],
143                         [AC_MSG_FAILURE([ --with-twin-fbdev given but libtwin/twin_fbdev.h not found])]
144                 )
145                 CPPFLAGS="$SAVE_CPPFLAGS"
146         ]
147 )
148
149 AC_ARG_ENABLE(
150         [busybox],
151         [AS_HELP_STRING(
152                 [--enable-busybox],
153                 [build programs with extra support for busybox [default=no]])
154         ],
155         [],
156         [enable_busybox=no]
157 )
158 #AM_CONDITIONAL([ENABLE_BUSYBOX], [test "x$enable_busybox" = "xyes"])
159
160 AC_ARG_ENABLE(
161         [ps3],
162         [AS_HELP_STRING(
163                 [--enable-ps3],
164                 [build additional programs for the PS3 game console [default=no]]
165         )],
166         [],
167         [enable_ps3=no]
168 )
169 AM_CONDITIONAL([ENABLE_PS3], [test "x$enable_ps3" = "xyes"])
170
171 AC_ARG_ENABLE(
172         [debug],
173         [AS_HELP_STRING([--enable-debug],
174                 [build programs with extra debug info [default=no]]
175         )],
176         [],
177         [enable_debug=check]
178 )
179 #AM_CONDITIONAL([ENABLE_DEBUG], [test "x$enable_debug" = "xyes"])
180
181 AC_ARG_ENABLE(
182         [test-valgrind],
183         [AS_HELP_STRING([--enable-test-valgrind],
184                 [run all tests with valgrind]
185         )],
186 )
187 AM_CONDITIONAL([ENABLE_TEST_VALGRIND], [test "x$enable_test_valgrind" = "xyes"])
188
189 # host program paths
190 AC_DEFUN([DEFINE_HOST_PROG],
191         [
192                 AC_ARG_VAR([HOST_PROG_$1], [Path to "$2" on the host [default $3]])
193                 if test "x$HOST_PROG_$1" = "x"; then
194                         HOST_PROG_$1="$3"
195                 fi
196                 AC_DEFINE_UNQUOTED(HOST_PROG_$1, ["$HOST_PROG_$1"],
197                                 [Path to "$2" on the host])
198         ])
199
200 DEFINE_HOST_PROG(CP, cp, [/bin/cp])
201 DEFINE_HOST_PROG(KEXEC, kexec, [/sbin/kexec])
202 DEFINE_HOST_PROG(MOUNT, mount, [/bin/mount])
203 DEFINE_HOST_PROG(SHUTDOWN, shutdown, [/sbin/shutdown])
204 DEFINE_HOST_PROG(SFTP, sftp, [/usr/bin/sftp])
205 DEFINE_HOST_PROG(TFTP, tftp, [/usr/bin/tftp])
206 DEFINE_HOST_PROG(UMOUNT, umount, [/bin/umount])
207 DEFINE_HOST_PROG(WGET, wget, [/usr/bin/wget])
208 DEFINE_HOST_PROG(IP, ip, [/sbin/ip])
209 DEFINE_HOST_PROG(UDHCPC, udhcpc, [/sbin/udhcpc])
210
211 AC_ARG_WITH(
212     [tftp],
213     [AS_HELP_STRING([--with-tftp=TYPE],
214         [Use TYPE-type ftp client (either hpa or busybox) [default=runtime-check]]
215     )],
216     [],
217     [with_tftp=detect]
218 )
219
220 case x$with_tftp in
221 'xhpa')
222     tftp_type='TFTP_TYPE_HPA'
223     ;;
224 'xbusybox')
225     tftp_type='TFTP_TYPE_BUSYBOX'
226     ;;
227 *)
228     tftp_type='TFTP_TYPE_UNKNOWN'
229     ;;
230 esac
231
232 AC_DEFINE_UNQUOTED(TFTP_TYPE, $tftp_type, [tftp client type])
233
234 default_cflags="--std=gnu99 -g \
235         -Wall -W -Wunused -Wstrict-prototypes -Wmissing-prototypes \
236         -Wmissing-declarations -Wredundant-decls"
237
238 AC_ARG_ENABLE(
239         [werror],
240         [AS_HELP_STRING([--enable-werror],
241                 [build programs with -Werror]
242         )],
243         [default_cflags="$default_cflags -Werror"]
244 )
245
246 AS_IF(
247         [test "x$enable_debug" = "xyes"],
248         [AC_SUBST([DEFAULT_CFLAGS], ["$default_cflags -O0 -DDEBUG"])],
249         [AC_SUBST([DEFAULT_CFLAGS], ["$default_cflags -O2 -DNDEBUG"])]
250 )
251  
252
253 AC_SUBST([LIBTOOL_DEPS])
254 AC_SUBST([DESTDIR])
255 AC_SUBST([pkgsysconfdir], ["${sysconfdir}/${package}"])
256
257 AC_CONFIG_HEADERS([config.h])
258 AC_CONFIG_FILES([
259         Makefile
260         discover/Makefile
261         discover/grub2/Makefile
262         lib/Makefile
263         man/Makefile
264         test/Makefile
265         test/lib/Makefile
266         test/parser/Makefile
267         test/urls/Makefile
268         ui/Makefile
269         ui/common/Makefile
270         ui/ncurses/Makefile
271         ui/test/Makefile
272         ui/twin/Makefile
273         utils/Makefile
274 ])
275
276 AC_OUTPUT