configure: Add conditional platform builds
[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     [https://lists.ozlabs.org/listinfo/petitboot])
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 if test -z "$($LEX --version)"; then
30         AC_MSG_ERROR([[Please install flex/lex]])
31 fi
32 AC_PROG_YACC
33 if test -z "$($YACC --version)"; then
34         AC_MSG_ERROR([[Please install bison/yacc]])
35 fi
36 AC_PROG_INSTALL
37
38 AM_INIT_AUTOMAKE
39 AC_GNU_SOURCE
40 AM_GNU_GETTEXT([external])
41 AM_GNU_GETTEXT_VERSION(0.18.1)
42 if test "$USE_NLS" = "yes" -a -z "$($MSGFMT --version)"; then
43         AC_MSG_ERROR([[Please install gettext]])
44 fi
45 LT_INIT
46
47 AM_SILENT_RULES([yes])
48
49 AX_WITH_CURSES
50 AX_WITH_CURSES_MENU
51 AX_WITH_CURSES_FORM
52
53 AM_CONDITIONAL([WITH_NCURSES], [test "x$ax_cv_curses" = "xyes"])
54
55 if test "x$ax_cv_curses" = xyes; then
56         if test "x$ax_cv_menu" != xyes; then
57                 AC_MSG_ERROR([--with-ncurses requires the ncurses menu library])
58         fi
59         if test "x$ax_cv_form" != xyes; then
60                 AC_MSG_ERROR([--with-ncurses requires the ncurses form library])
61         fi
62 fi
63
64 AC_CHECK_LIB([udev], [udev_new],
65         [UDEV_LIBS=-ludev],
66         [AC_MSG_FAILURE([The libudev development library is required by petitboot.  Try installing the package libudev-dev or libudev-devel.])]
67 )
68
69 PKG_CHECK_EXISTS(libudev >= 218, [old_udev=no], [old_udev=yes])
70 if test "$old_udev" = "yes" ; then
71       AC_DEFINE(UDEV_LOGGING, 1, [Support old udev logging interface])
72 fi
73
74 AC_CHECK_LIB([devmapper], [dm_task_create],
75         [DEVMAPPER_LIBS=-ldevmapper],
76         [AC_MSG_FAILURE([The libdevmapper development library is required by petitboot.  Try installing the package libdevmapper-dev or device-mapper-devel.])]
77 )
78
79 AC_ARG_WITH([fdt],
80         AS_HELP_STRING([--without-fdt],
81                 [Build without libfdt (default: no)]))
82
83 AS_IF([test "x$with_fdt" != "xno"],
84         AC_CHECK_LIB([fdt], [fdt_check_header],
85                 [FDT_LIBS=-lfdt; have_libfdt=yes]))
86
87 AM_CONDITIONAL([HAVE_LIBFDT], [test x"$have_libfdt" = xyes])
88
89 AC_CHECK_HEADERS([stdarg.h])
90 AC_CHECK_HEADERS([varargs.h])
91
92 dnl Checking for va_copy availability
93 AC_MSG_CHECKING([for va_copy])
94 AC_TRY_LINK([#include <stdarg.h>
95 va_list ap1,ap2;], [va_copy(ap1,ap2);],
96 have_va_copy=yes,
97 have_va_copy=no)
98 AC_MSG_RESULT($have_va_copy)
99 if test x"$have_va_copy" = x"yes"; then
100     AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
101 else
102     AC_MSG_CHECKING([for __va_copy])
103     AC_TRY_LINK([#include <stdarg.h>
104     va_list ap1,ap2;], [__va_copy(ap1,ap2);],
105     have___va_copy=yes,
106     have___va_copy=no)
107     AC_MSG_RESULT($have___va_copy)
108     if test x"$have___va_copy" = x"yes"; then
109         AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
110     fi
111 fi
112
113 AC_ARG_WITH(
114         [twin-x11],
115         [AS_HELP_STRING([--with-twin-x11],
116                 [build x11 GUI programs using the twin window system [default=yes]]
117         )],
118         [],
119         [with_twin_x11=no]
120 )
121 AM_CONDITIONAL([WITH_TWIN_X11], [test "x$with_twin_x11" = "xyes"])
122
123 AC_ARG_WITH(
124         [twin-fbdev],
125         [AS_HELP_STRING(
126                 [--with-twin-fbdev],
127                 [build frame buffer GUI programs using the twin window system [default=no]]
128         )],
129         [],
130         [with_twin_fbdev=no]
131 )
132 AM_CONDITIONAL([WITH_TWIN_FBDEV], [test "x$with_twin_fbdev" = "xyes"])
133
134 AM_CONDITIONAL(
135         [WITH_TWIN],
136         [test "x$with_twin_x11" = "xyes" || test "x$with_twin_fbdev" = "xyes"])
137
138 AS_IF(
139         [test "x$with_twin_x11" != "xyes" && \
140                 test "x$with_twin_fbdev" != "xyes" && \
141                 test "x$ax_cv_curses" != "xyes"],
142         [AC_MSG_WARN([ No user interface programs configured.  Consider using --with-ncurses, --with-twin-x11 or --with-twin-fbdev'])]
143 )
144
145 AS_IF(
146         [test "x$with_twin_x11" = "xyes" || test "x$with_twin_fbdev" = "xyes"],
147         [PKG_CHECK_MODULES(
148                 [twin],
149                 [libtwin],
150                 [SAVE_LIBS="$LIBS" LIBS="$LIBS $twin_LIBS"
151                         AC_CHECK_LIB(
152                                 [twin],
153                                 [twin_feature_init],
154                                 [],
155                                 [AC_MSG_FAILURE([--with-twin was given but the test for libtwin failed.])]
156                         )
157                         LIBS="$SAVE_LIBS"
158                 ],
159                 [AC_MSG_RESULT([$twin_PKG_ERRORS])
160                         AC_MSG_FAILURE([ Consider adjusting PKG_CONFIG_PATH environment variable])
161                 ]
162         )]
163 )
164
165 AS_IF(
166         [test "x$with_twin_x11" = "xyes"],
167         [SAVE_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $twin_CFLAGS"
168                 AC_CHECK_HEADERS(
169                         [libtwin/twin_x11.h],
170                         [],
171                         [AC_MSG_FAILURE([ --with-twin-x11 given but libtwin/twin_x11.h not found])]
172                 )
173                 CPPFLAGS="$SAVE_CPPFLAGS"
174         ]
175 )
176
177 AS_IF(
178         [test "x$with_twin_fbdev" = "xyes"],
179         [SAVE_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $twin_CFLAGS"
180                 AC_CHECK_HEADERS(
181                         [libtwin/twin_fbdev.h],
182                         [],
183                         [AC_MSG_FAILURE([ --with-twin-fbdev given but libtwin/twin_fbdev.h not found])]
184                 )
185                 CPPFLAGS="$SAVE_CPPFLAGS"
186         ]
187 )
188
189 AC_ARG_WITH(
190         [signed-boot],
191         [AS_HELP_STRING([--with-signed-boot=@<:@no|yes|gpgme|openssl@:>@],
192                         [Build kernel signature checking support with specified
193                          crypto pacakge. A @<:@yes@:>@ value will first check
194                          for gpgme then openssl and use the first found.
195                          @<:@default=no@:>@]
196         )],
197         [AS_IF([test "x$with_signed_boot" = xno],[],
198                [test "x$with_signed_boot" = xyes],
199                         [AM_PATH_GPGME([1.0.0],
200                                 [sboot=gpgme],
201                                 [AX_CHECK_OPENSSL(
202                                         [sboot=openssl],
203                                         [AC_MSG_FAILURE([--with-signed-boot=yes specified but gpgme or openssl not found])]
204                                 )]
205                         )],
206                [test "x$with_signed_boot" = xgpgme],
207                         [AM_PATH_GPGME([1.0.0],
208                                 [sboot=gpgme],
209                                 [AC_MSG_FAILURE([--with-signed-boot=gpgme specified but gpgme not found])]
210                         )],
211                [test "x$with_signed_boot" = xopenssl],
212                         [AX_CHECK_OPENSSL(
213                                 [sboot=openssl],
214                                 [AC_MSG_FAILURE([--with-signed-boot=openssl specified but openssl not found])]
215                         )],
216                [AC_MSG_FAILURE([--with-signed-boot given invalid option: $with_signed_boot])]
217         )],
218         [with_signed_boot=no]
219 )
220
221 AM_CONDITIONAL([WITH_GPGME], [test "x$sboot" = xgpgme])
222 AM_CONDITIONAL([WITH_OPENSSL], [test "x$sboot" = xopenssl])
223 AM_CONDITIONAL([WITH_SIGNED_BOOT], [test "x$with_signed_boot" != xno])
224 AM_COND_IF([WITH_SIGNED_BOOT],
225            [AC_DEFINE([SIGNED_BOOT], 1, [Define if you have signed boot enabled])],
226            [])
227
228 AC_ARG_VAR(
229         [lockdown_file],
230         [Location of authorized signature file [default = "/etc/pb-lockdown"]]
231 )
232 AS_IF([test "x$lockdown_file" = x], [lockdown_file="/etc/pb-lockdown"])
233 AC_DEFINE_UNQUOTED(LOCKDOWN_FILE, "$lockdown_file", [Lockdown file location])
234
235 AC_ARG_VAR(
236         [KEYRING_PATH],
237         [Path to keyring (gpgme home dir) @<:@default="/etc/gpg"@:>@]
238 )
239 AS_IF([test "x$KEYRING_PATH" = x], [KEYRING_PATH="/etc/gpg"])
240 AC_DEFINE_UNQUOTED(KEYRING_PATH, "$KEYRING_PATH", [gpgme home dir])
241
242 AC_ARG_VAR(
243         [VERIFY_DIGEST],
244         [Signed boot signature verification digest algorithm to use (only valid in openssl) @<:@default="sha256"@:>@]
245 )
246 AS_IF([test "x$VERIFY_DIGEST" = x], [VERIFY_DIGEST="sha256"])
247 AC_DEFINE_UNQUOTED(VERIFY_DIGEST, "$VERIFY_DIGEST", [openssl verify dgst])
248
249 AC_ARG_ENABLE([hard-lockdown],
250               [AS_HELP_STRING([--enable-hard-lockdown],
251                               [if signed boot configured, the absence of the
252                                LOCKDOWN_FILE does not disable signed boot at
253                                runtime @<:@default=no@:>@])],
254               [AC_DEFINE(HARD_LOCKDOWN, 1, [Enable hard lockdown])],
255               [])
256
257 AC_ARG_ENABLE(
258         [busybox],
259         [AS_HELP_STRING(
260                 [--enable-busybox],
261                 [build programs with extra support for busybox [default=no]])
262         ],
263         [],
264         [enable_busybox=no]
265 )
266 AM_CONDITIONAL([ENABLE_BUSYBOX], [test "x$enable_busybox" = "xyes"])
267 AS_IF([test "x$enable_busybox" = "xyes"],
268       [AC_DEFINE(WITH_BUSYBOX, 1, [Busybox environment enabled])],
269       []
270 )
271
272 AC_ARG_ENABLE(
273         [mtd],
274         [AS_HELP_STRING(
275                 [--enable-mtd],
276                 [Add support for MTD devices on certain platforms [default=no]]
277         )],
278         [],
279         [enable_mtd=no]
280 )
281 AM_CONDITIONAL([ENABLE_MTD], [test "x$enable_mtd" = "xyes"])
282 AS_IF([test "x$enable_mtd" = "xyes"],
283       [AC_DEFINE(MTD_SUPPORT, 1, [Enable MTD support])],
284       []
285 )
286
287 AS_IF(
288         [test "x$enable_mtd" = "xyes"],
289                 AC_CHECK_LIB([flash], [arch_flash_init],
290                         [LIBFLASH_LIBS=-lflash],
291                         [AC_MSG_FAILURE([--enable-mtd requires the libflash library])]
292                 )
293 )
294 AS_IF(
295         [test "x$enable_mtd" = "xyes"],
296         [SAVE_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $libflash_CFLAGS"
297                 AC_CHECK_HEADERS(
298                         [libflash/libflash.h],
299                         [],
300                         [AC_MSG_FAILURE([--enable-mtd given but libflash/libflash.h not found])]
301                 )
302                 CPPFLAGS="$SAVE_CPPFLAGS"
303         ]
304 )
305
306 # platform choice
307 AC_ARG_ENABLE(
308         [platform-all],
309         [AS_HELP_STRING(
310                 [--enable-platform-all],
311                 [build support for all platforms [default=no]]
312         )]
313 )
314 AS_IF(
315         [test "x$enable_platform_all" = "xyes"],
316         [enable_platform_powerpc="yes"; enable_platform_ps3="yes"]
317 )
318
319 AC_ARG_ENABLE(
320         [platform-auto],
321         [AS_HELP_STRING(
322                 [--enable-platform-auto],
323                 [auto detect platform support to build [default=yes]]
324         )],
325         [],
326         [enable_platform_auto="yes"]
327 )
328 AS_IF(
329         [test "x$enable_platform_auto" = "xyes"],
330         [AS_CASE([$host],
331                 [powerpc*-*-*],  [enable_platform_powerpc="yes"],
332         )]
333 )
334
335 AC_ARG_ENABLE(
336         [platform-powerpc],
337         [AS_HELP_STRING(
338                 [--enable-platform-powerpc],
339                 [build support for powerpc platforms [default=no]]
340         )]
341 )
342 AM_CONDITIONAL([PLATFORM_POWERPC], [test "x$enable_platform_powerpc" = "xyes"])
343
344 AC_ARG_ENABLE(
345         [platform-ps3],
346         [AS_HELP_STRING(
347                 [--enable-platform-ps3],
348                 [build support for the PS3 game console [default=no]]
349         )])
350 AM_CONDITIONAL([PLATFORM_PS3], [test "x$enable_platform_ps3" = "xyes"])
351
352 AC_ARG_ENABLE(
353         [debug],
354         [AS_HELP_STRING([--enable-debug],
355                 [build programs with extra debug info [default=no]]
356         )],
357         [],
358         [enable_debug=check]
359 )
360
361 AC_ARG_ENABLE(
362         [test-valgrind],
363         [AS_HELP_STRING([--enable-test-valgrind],
364                 [run all tests with valgrind]
365         )],
366 )
367 AM_CONDITIONAL([ENABLE_TEST_VALGRIND], [test "x$enable_test_valgrind" = "xyes"])
368
369 # host program paths
370 AC_DEFUN([DEFINE_HOST_PROG],
371         [
372                 AC_ARG_VAR([HOST_PROG_$1], [Path to "$2" on the host [default $3]])
373                 if test "x$HOST_PROG_$1" = "x"; then
374                         HOST_PROG_$1="$3"
375                 fi
376                 AC_DEFINE_UNQUOTED(HOST_PROG_$1, ["$HOST_PROG_$1"],
377                                 [Path to "$2" on the host])
378         ])
379
380 DEFINE_HOST_PROG(CP, cp, [/bin/cp])
381 DEFINE_HOST_PROG(KEXEC, kexec, [/sbin/kexec])
382 DEFINE_HOST_PROG(MOUNT, mount, [/bin/mount])
383 DEFINE_HOST_PROG(SHUTDOWN, shutdown, [/sbin/shutdown])
384 DEFINE_HOST_PROG(SFTP, sftp, [/usr/bin/sftp])
385 DEFINE_HOST_PROG(TFTP, tftp, [/usr/bin/tftp])
386 DEFINE_HOST_PROG(UMOUNT, umount, [/bin/umount])
387 DEFINE_HOST_PROG(WGET, wget, [/usr/bin/wget])
388 DEFINE_HOST_PROG(IP, ip, [/sbin/ip])
389 DEFINE_HOST_PROG(UDHCPC, udhcpc, [/sbin/udhcpc])
390 DEFINE_HOST_PROG(UDHCPC6, udhcpc6, [/usr/bin/udhcpc6])
391 DEFINE_HOST_PROG(VGSCAN, vgscan, [/usr/sbin/vgscan])
392 DEFINE_HOST_PROG(VGCHANGE, vgchange, [/usr/sbin/vgchange])
393 DEFINE_HOST_PROG(PB_PLUGIN, pb-plugin, [/usr/sbin/pb-plugin])
394 DEFINE_HOST_PROG(PB_EXEC, pb-exec, [/usr/sbin/pb-exec])
395 DEFINE_HOST_PROG(SH, sh, [/bin/sh])
396 DEFINE_HOST_PROG(SCSI_RESCAN, scsi-rescan, [/usr/sbin/scsi-rescan])
397
398 AC_ARG_WITH(
399     [tftp],
400     [AS_HELP_STRING([--with-tftp=TYPE],
401         [Use TYPE-type ftp client (either hpa or busybox) [default=runtime-check]]
402     )],
403     [],
404     [with_tftp=detect]
405 )
406
407 case x$with_tftp in
408 'xhpa')
409     tftp_type='TFTP_TYPE_HPA'
410     ;;
411 'xbusybox')
412     tftp_type='TFTP_TYPE_BUSYBOX'
413     ;;
414 *)
415     tftp_type='TFTP_TYPE_UNKNOWN'
416     ;;
417 esac
418
419 AC_DEFINE_UNQUOTED(TFTP_TYPE, $tftp_type, [tftp client type])
420
421 default_cflags="--std=gnu99 -g \
422         -Wall -W -Wunused -Wstrict-prototypes -Wmissing-prototypes \
423         -Wmissing-declarations -Wredundant-decls"
424
425 AC_ARG_ENABLE(
426         [werror],
427         [AS_HELP_STRING([--enable-werror],
428                 [build programs with -Werror]
429         )],
430         [default_cflags="$default_cflags -Werror"]
431 )
432
433 AS_IF(
434         [test "x$enable_debug" = "xyes"],
435         [
436                 AC_SUBST([DEFAULT_CFLAGS], ["$default_cflags -O0"])
437                 AC_SUBST([DEFAULT_CPPFLAGS], ["-DDEBUG"])
438         ],
439         [
440                 AC_SUBST([DEFAULT_CFLAGS], ["$default_cflags -O2"])
441                 AC_SUBST([DEFAULT_CPPFLAGS], ["-DNDEBUG"])
442         ]
443 )
444  
445 AC_SUBST([UDEV_LIBS])
446 AC_SUBST([DEVMAPPER_LIBS])
447 AC_SUBST([FDT_LIBS])
448 AC_SUBST([LIBFLASH_LIBS])
449 AC_SUBST([LIBTOOL_DEPS])
450 AC_SUBST([DESTDIR])
451 AC_SUBST([pkgsysconfdir], ["${sysconfdir}/${package}"])
452
453 AC_CONFIG_HEADERS([config.h])
454 AC_CONFIG_FILES([
455         Makefile
456         po/Makefile.in
457 ])
458
459 AC_OUTPUT