configure.ac: Add checks for libflash and libdevmapper
[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 AM_GNU_GETTEXT([external])
35 AM_GNU_GETTEXT_VERSION(0.18.1)
36 LT_INIT
37
38 AM_SILENT_RULES([yes])
39
40 AX_WITH_CURSES
41 AX_WITH_CURSES_MENU
42 AX_WITH_CURSES_FORM
43
44 AM_CONDITIONAL([WITH_NCURSES], [test "x$ax_cv_curses" = "xyes"])
45
46 if test "x$ax_cv_curses" = xyes; then
47         if test "x$ax_cv_menu" != xyes; then
48                 AC_MSG_ERROR([--with-ncurses requires the ncurses menu library])
49         fi
50         if test "x$ax_cv_form" != xyes; then
51                 AC_MSG_ERROR([--with-ncurses requires the ncurses form library])
52         fi
53 fi
54
55 AC_CHECK_LIB([udev], [udev_new],
56         [UDEV_LIBS=-ludev],
57         [AC_MSG_FAILURE([The libudev development library is required by petitboot.  Try installing the package libudev-dev or libudev-devel.])]
58 )
59
60 AC_CHECK_LIB([devmapper], [dm_task_create],
61         [DEVMAPPER_LIBS=-ldevmapper],
62         [AC_MSG_FAILURE([The libdevmapper development library is required by petitboot.  Try installing the package libdevmapper-dev or libdevmapper-devel.])]
63 )
64
65 AC_ARG_WITH([fdt],
66         AS_HELP_STRING([--without-fdt],
67                 [Build without libfdt (default: no)]))
68
69 AS_IF([test "x$with_fdt" != "xno"],
70         AC_CHECK_LIB([fdt], [fdt_check_header],
71                 [FDT_LIBS=-lfdt; have_libfdt=yes]))
72
73 AM_CONDITIONAL([HAVE_LIBFDT], [test x"$have_libfdt" = xyes])
74
75 AC_CHECK_HEADERS([stdarg.h])
76 AC_CHECK_HEADERS([varargs.h])
77
78 dnl Checking for va_copy availability
79 AC_MSG_CHECKING([for va_copy])
80 AC_TRY_LINK([#include <stdarg.h>
81 va_list ap1,ap2;], [va_copy(ap1,ap2);],
82 have_va_copy=yes,
83 have_va_copy=no)
84 AC_MSG_RESULT($have_va_copy)
85 if test x"$have_va_copy" = x"yes"; then
86     AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
87 else
88     AC_MSG_CHECKING([for __va_copy])
89     AC_TRY_LINK([#include <stdarg.h>
90     va_list ap1,ap2;], [__va_copy(ap1,ap2);],
91     have___va_copy=yes,
92     have___va_copy=no)
93     AC_MSG_RESULT($have___va_copy)
94     if test x"$have___va_copy" = x"yes"; then
95         AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
96     fi
97 fi
98
99 AC_ARG_WITH(
100         [twin-x11],
101         [AS_HELP_STRING([--with-twin-x11],
102                 [build x11 GUI programs using the twin window system [default=yes]]
103         )],
104         [],
105         [with_twin_x11=yes]
106 )
107 AM_CONDITIONAL([WITH_TWIN_X11], [test "x$with_twin_x11" = "xyes"])
108
109 AC_ARG_WITH(
110         [twin-fbdev],
111         [AS_HELP_STRING(
112                 [--with-twin-fbdev],
113                 [build frame buffer GUI programs using the twin window system [default=no]]
114         )],
115         [],
116         [with_twin_fbdev=yes]
117 )
118 AM_CONDITIONAL([WITH_TWIN_FBDEV], [test "x$with_twin_fbdev" = "xyes"])
119
120 AM_CONDITIONAL(
121         [WITH_TWIN],
122         [test "x$with_twin_x11" = "xyes" || test "x$with_twin_fbdev" = "xyes"])
123
124 AS_IF(
125         [test "x$with_twin_x11" = "xyes" || test "x$with_twin_fbdev" = "xyes"],
126         [PKG_CHECK_MODULES(
127                 [twin],
128                 [libtwin],
129                 [SAVE_LIBS="$LIBS" LIBS="$LIBS $twin_LIBS"
130                         AC_CHECK_LIB(
131                                 [twin],
132                                 [twin_feature_init],
133                                 [],
134                                 [AC_MSG_FAILURE([--with-twin was given but the test for libtwin failed.])]
135                         )
136                         LIBS="$SAVE_LIBS"
137                 ],
138                 [AC_MSG_RESULT([$twin_PKG_ERRORS])
139                         AC_MSG_FAILURE([ Consider adjusting PKG_CONFIG_PATH environment variable])
140                 ]
141         )]
142 )
143
144 AS_IF(
145         [test "x$with_twin_x11" = "xyes"],
146         [SAVE_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $twin_CFLAGS"
147                 AC_CHECK_HEADERS(
148                         [libtwin/twin_x11.h],
149                         [],
150                         [AC_MSG_FAILURE([ --with-twin-x11 given but libtwin/twin_x11.h not found])]
151                 )
152                 CPPFLAGS="$SAVE_CPPFLAGS"
153         ]
154 )
155
156 AS_IF(
157         [test "x$with_twin_fbdev" = "xyes"],
158         [SAVE_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $twin_CFLAGS"
159                 AC_CHECK_HEADERS(
160                         [libtwin/twin_fbdev.h],
161                         [],
162                         [AC_MSG_FAILURE([ --with-twin-fbdev given but libtwin/twin_fbdev.h not found])]
163                 )
164                 CPPFLAGS="$SAVE_CPPFLAGS"
165         ]
166 )
167
168 AC_ARG_ENABLE(
169         [busybox],
170         [AS_HELP_STRING(
171                 [--enable-busybox],
172                 [build programs with extra support for busybox [default=no]])
173         ],
174         [],
175         [enable_busybox=no]
176 )
177 #AM_CONDITIONAL([ENABLE_BUSYBOX], [test "x$enable_busybox" = "xyes"])
178
179 AC_ARG_ENABLE(
180         [mtd],
181         [AS_HELP_STRING(
182                 [--enable-mtd],
183                 [Add support for MTD devices on certain platforms [default=no]]
184         )],
185         [],
186         [enable_mtd=no]
187 )
188 AM_CONDITIONAL([ENABLE_MTD], [test "x$enable_mtd" = "xyes"])
189 AS_IF([test "x$enable_mtd" = "xyes"],
190       [AC_DEFINE(MTD_SUPPORT, 1, [Enable MTD support])],
191       []
192 )
193
194 AS_IF(
195         [test "x$enable_mtd" = "xyes"],
196                 AC_CHECK_LIB([flash], [arch_flash_init],
197                         [LIBFLASH_LIBS=-lflash],
198                         [AC_MSG_FAILURE([--enable-mtd requires the libflash library])]
199                 )
200 )
201 AS_IF(
202         [test "x$enable_mtd" = "xyes"],
203         [SAVE_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $libflash_CFLAGS"
204                 AC_CHECK_HEADERS(
205                         [libflash/libflash.h],
206                         [],
207                         [AC_MSG_FAILURE([--enable-mtd given but libflash/libflash.h not found])]
208                 )
209                 CPPFLAGS="$SAVE_CPPFLAGS"
210         ]
211 )
212
213 AC_ARG_ENABLE(
214         [ps3],
215         [AS_HELP_STRING(
216                 [--enable-ps3],
217                 [build additional programs for the PS3 game console [default=no]]
218         )],
219         [],
220         [enable_ps3=no]
221 )
222 AM_CONDITIONAL([ENABLE_PS3], [test "x$enable_ps3" = "xyes"])
223
224 AC_ARG_ENABLE(
225         [debug],
226         [AS_HELP_STRING([--enable-debug],
227                 [build programs with extra debug info [default=no]]
228         )],
229         [],
230         [enable_debug=check]
231 )
232 #AM_CONDITIONAL([ENABLE_DEBUG], [test "x$enable_debug" = "xyes"])
233
234 AC_ARG_ENABLE(
235         [test-valgrind],
236         [AS_HELP_STRING([--enable-test-valgrind],
237                 [run all tests with valgrind]
238         )],
239 )
240 AM_CONDITIONAL([ENABLE_TEST_VALGRIND], [test "x$enable_test_valgrind" = "xyes"])
241
242 # host program paths
243 AC_DEFUN([DEFINE_HOST_PROG],
244         [
245                 AC_ARG_VAR([HOST_PROG_$1], [Path to "$2" on the host [default $3]])
246                 if test "x$HOST_PROG_$1" = "x"; then
247                         HOST_PROG_$1="$3"
248                 fi
249                 AC_DEFINE_UNQUOTED(HOST_PROG_$1, ["$HOST_PROG_$1"],
250                                 [Path to "$2" on the host])
251         ])
252
253 DEFINE_HOST_PROG(CP, cp, [/bin/cp])
254 DEFINE_HOST_PROG(KEXEC, kexec, [/sbin/kexec])
255 DEFINE_HOST_PROG(MOUNT, mount, [/bin/mount])
256 DEFINE_HOST_PROG(SHUTDOWN, shutdown, [/sbin/shutdown])
257 DEFINE_HOST_PROG(SFTP, sftp, [/usr/bin/sftp])
258 DEFINE_HOST_PROG(TFTP, tftp, [/usr/bin/tftp])
259 DEFINE_HOST_PROG(UMOUNT, umount, [/bin/umount])
260 DEFINE_HOST_PROG(WGET, wget, [/usr/bin/wget])
261 DEFINE_HOST_PROG(IP, ip, [/sbin/ip])
262 DEFINE_HOST_PROG(UDHCPC, udhcpc, [/sbin/udhcpc])
263
264 AC_ARG_WITH(
265     [tftp],
266     [AS_HELP_STRING([--with-tftp=TYPE],
267         [Use TYPE-type ftp client (either hpa or busybox) [default=runtime-check]]
268     )],
269     [],
270     [with_tftp=detect]
271 )
272
273 case x$with_tftp in
274 'xhpa')
275     tftp_type='TFTP_TYPE_HPA'
276     ;;
277 'xbusybox')
278     tftp_type='TFTP_TYPE_BUSYBOX'
279     ;;
280 *)
281     tftp_type='TFTP_TYPE_UNKNOWN'
282     ;;
283 esac
284
285 AC_DEFINE_UNQUOTED(TFTP_TYPE, $tftp_type, [tftp client type])
286
287 default_cflags="--std=gnu99 -g \
288         -Wall -W -Wunused -Wstrict-prototypes -Wmissing-prototypes \
289         -Wmissing-declarations -Wredundant-decls"
290
291 AC_ARG_ENABLE(
292         [werror],
293         [AS_HELP_STRING([--enable-werror],
294                 [build programs with -Werror]
295         )],
296         [default_cflags="$default_cflags -Werror"]
297 )
298
299 AS_IF(
300         [test "x$enable_debug" = "xyes"],
301         [
302                 AC_SUBST([DEFAULT_CFLAGS], ["$default_cflags -O0"])
303                 AC_SUBST([DEFAULT_CPPFLAGS], ["-DDEBUG"])
304         ],
305         [
306                 AC_SUBST([DEFAULT_CFLAGS], ["$default_cflags -O2"])
307                 AC_SUBST([DEFAULT_CPPFLAGS], ["-DNDEBUG"])
308         ]
309 )
310  
311 AC_SUBST([UDEV_LIBS])
312 AC_SUBST([DEVMAPPER_LIBS])
313 AC_SUBST([FDT_LIBS])
314 AC_SUBST([LIBFLASH_LIBS])
315 AC_SUBST([LIBTOOL_DEPS])
316 AC_SUBST([DESTDIR])
317 AC_SUBST([pkgsysconfdir], ["${sysconfdir}/${package}"])
318
319 AC_CONFIG_HEADERS([config.h])
320 AC_CONFIG_FILES([
321         Makefile
322         po/Makefile.in
323 ])
324
325 AC_OUTPUT