summaryrefslogtreecommitdiff
path: root/configure.ac
blob: 032758466363e4b9b7225abebb977fa9e11f2731 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)

AC_INIT([murphy], m4_esyscmd([build-aux/git-version-gen .tarball-version]))

AC_CONFIG_SRCDIR([src])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADER([src/config.h])
AM_INIT_AUTOMAKE([-Wno-portability])

AC_SUBST(ACLOCAL_AMFLAGS, "-I m4")

m4_define(version_major, `echo $VERSION | cut -d. -f1 | cut -d- -f1`)
m4_define(version_minor, `echo $VERSION | cut -d. -f2 | cut -d- -f1`)
m4_define(version_patch, `echo $VERSION | cut -d. -f3 | cut -d- -f1`)

AC_SUBST(VERSION)
AC_SUBST(VERSION_MAJOR, version_major)
AC_SUBST(VERSION_MINOR, version_minor)
AC_SUBST(VERSION_PATCH, version_patch)
AC_SUBST(VERSION_FULL, version_major.version_minor.version_patch)

MURPHY_VERSION_INFO="0:0:0"
AC_SUBST(MURPHY_VERSION_INFO)

# Disable static libraries.
AC_DISABLE_STATIC

# Checks for programs.
AC_PROG_CC
AC_PROG_CC_C99
# We need AC_PROG_CXX if Qt support is enabled but (at least some
# versions of autotools) cannot handle conditional use of this.
AC_PROG_CXX
AC_PROG_AWK
AC_PROG_INSTALL
AM_PROG_CC_C_O
AM_PROG_LIBTOOL
AC_PROG_LEX
AC_PROG_YACC
AM_PROG_LEX
AC_SUBST(LEXLIB)

# Check that we have flex/bison and not lex/yacc.
AC_MSG_CHECKING([for flex vs. lex])
case $LEX in
    *missing\ flex*)
        AC_MSG_ERROR([looks like you're missing flex])
        ;;
    *flex*)
        AC_MSG_RESULT([ok, looks like we have flex])
        ;;
    *)
        AC_MSG_ERROR([flex is required])
        ;;
esac

AC_MSG_CHECKING([for bison vs. yacc])
case $YACC in
    *missing\ *)
        AC_MSG_ERROR([looks like you're missing bison])
        ;;
    *bison*)
        AC_MSG_RESULT([ok, looks like we have bison])
        ;;
    *)
        AC_MSG_ERROR([bison is required])
        ;;
esac

# Guesstimate native compiler if we're cross-compiling.
if test "$cross_compiling" != "no"; then
    AC_MSG_NOTICE([Looks like we're being cross-compiled...])
    if test -z "$CC_FOR_BUILD"; then
        CC_FOR_BUILD=cc
    fi
else
    AC_MSG_NOTICE([Looks like we're doing a native compilation...])
    CC_FOR_BUILD='$(CC)'
fi
AC_SUBST(CC_FOR_BUILD)
UNSHAVED_CC_FOR_BUILD="$CC_FOR_BUILD"

# Make first invocation of PKG_CHECK_MODULES 'if-then-else-fi'-safe.
PKG_PROG_PKG_CONFIG

# Checks for libraries.
AC_CHECK_LIB([dl], [dlopen dlclose dlsym dlerror])

# Checks for header files.
AC_PATH_X
AC_CHECK_HEADERS([fcntl.h stddef.h stdint.h stdlib.h string.h sys/statvfs.h sys/vfs.h syslog.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_CHECK_MEMBERS([struct stat.st_rdev])
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
AC_CHECK_TYPES([ptrdiff_t])

# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
AC_HEADER_MAJOR
if test "$cross_compiling" = "no"; then
    AC_FUNC_MALLOC
fi
AC_FUNC_STRTOD
AC_CHECK_FUNCS([clock_gettime memmove memset regcomp strcasecmp strchr strdup strrchr strtol strtoul])

# Check and enable extra compiler warnings if they are supported.
AC_ARG_ENABLE(extra-warnings,
              [  --enable-extra-warnings enable extra compiler warnings],
	      [extra_warnings=$enableval], [extra_warnings=auto])

WARNING_CFLAGS=""
warncflags="-Wall -Wextra"
if test "$extra_warnings" != "no"; then
    save_CPPFLAGS="$CPPFLAGS"
    for opt in $warncflags; do
        AC_PREPROC_IFELSE([AC_LANG_PROGRAM([])],
	                  [WARNING_CFLAGS="$WARNING_CFLAGS $opt"])
    done
    CPPFLAGS="$save_CPPFLAGS"
fi

AC_SUBST(WARNING_CFLAGS)

# By default try to find the system default Lua (assumed to be
# called lua(.pc). If that is not found, try to look for
# packages lua5.2 and lua5.1, which can be found in Debian-based
# distributions.
#
# You can override this using the --with-lua option. For instance
# to use Lua 5.1 on Ubuntu while having 5.2 installed, you'd use
# --with-lua=lua5.1.
AC_ARG_WITH(lua,
            [  --with-lua                build with specified Lua (pkgconfig filename without .pc suffix)],
            [with_lua=$withval], [with_lua=default])

if test "x$with_lua" = "xdefault"; then
    # Check for "lua" first, then "lua5.2" and finally for "lua5.1"
    AC_MSG_NOTICE([Checking for an installed Lua...])
    PKG_CHECK_MODULES([LUA], [lua >= 5.1.1],
        [with_lua=lua],
        [PKG_CHECK_MODULES([LUA52], [lua5.2],
            [with_lua=lua5.2
             LUA_CFLAGS=$LUA52_CFLAGS
             LUA_LIBS=$LUA52_LIBS],
            [PKG_CHECK_MODULES([LUA51], [lua5.1 >= 5.1.1],
                [with_lua=lua5.1
                 LUA_CFLAGS=$LUA51_CFLAGS
                 LUA_LIBS=$LUA51_LIBS],
                [AC_MSG_ERROR(Package requirement (lua >= 5.1.1) was not met!)])
         ])
    ])
else
    # Check for pre-defined Lua.
    AC_MSG_NOTICE([Compiling with Lua package $with_lua.])
    PKG_CHECK_MODULES(LUA, $with_lua >= 5.1.1)
fi

AC_SUBST(LUA_CFLAGS)
AC_SUBST(LUA_LIBS)

# Check if potentially GPL bits are allowed to be enabled.
AC_ARG_ENABLE(gpl,
              [  --enable-gpl            enable linking against GPL code],
	      [enable_gpl=$enableval], [enable_gpl=no])

# Check if original libdbus-based DBUS support was enabled.
AC_ARG_ENABLE(libdbus,
              [  --enable-libdbus        enable libdbus-based D-BUS support],
	      [enable_libdbus=$enableval], [enable_libdbus=no])

if test "$enable_libdbus" = "yes"; then
    if test "$enable_gpl" = "no"; then
        AC_MSG_ERROR([libdbus D-Bus support requires the --enable-gpl option.])
    fi
    PKG_CHECK_MODULES(LIBDBUS, dbus-1 >= 0.70)

    DBUS_SESSION_DIR="`pkg-config --variable session_bus_services_dir dbus-1`"
    AC_SUBST(DBUS_SESSION_DIR)

    AC_DEFINE([LIBDBUS_ENABLED], 1, [Enable libdbus D-Bus support ?])
else
    AC_MSG_NOTICE([libdbus-based D-Bus support is disabled.])
fi

AM_CONDITIONAL(LIBDBUS_ENABLED, [test "$enable_libdbus" = "yes"])
AC_SUBST(LIBDBUS_ENABLED)
AC_SUBST(LIBDBUS_CFLAGS)
AC_SUBST(LIBDBUS_LIBS)

# Check if systemd-bus-based D-Bus support was enabled.
AC_ARG_ENABLE(sdbus,
              [  --enable-sdbus         enable systemd-based D-BUS support],
	      [enable_sdbus=$enableval], [enable_sdbus=no])

if test "$enable_sdbus" = "yes"; then
    PKG_CHECK_MODULES(SDBUS, libsystemd-bus)
    AC_DEFINE([SDBUS_ENABLED], 1, [Enable systemd-bus support ?])

    if test -z "$DBUS_SESSION_DIR"; then
        # Try to determine the session bus service directory.
        DBUS_SESSION_DIR="`pkg-config --variable \
                               session_bus_services_dir dbus-1`"
        if test "$?" != "0" -o -z "$DBUS_SESSION_DIR"; then
            DBUS_SESSION_DIR="/usr/share/dbus-1/services"
        fi
        AC_SUBST(DBUS_SESSION_DIR)
    fi
else
    AC_MSG_NOTICE([libsystemd-bus based D-Bus support is disabled.])
fi

AM_CONDITIONAL(SDBUS_ENABLED, [test "$enable_sdbus" = "yes"])
AC_SUBST(SDBUS_ENABLED)
AC_SUBST(SDBUS_CFLAGS)
AC_SUBST(SDBUS_LIBS)

# Check if PulseAudio mainloop support was enabled.
AC_ARG_ENABLE(pulse,
              [  --enable-pulse          enable PulseAudio mainloop support],
	      [enable_pulse=$enableval], [enable_pulse=auto])

if test "$enable_pulse" != "no"; then
    PKG_CHECK_MODULES(PULSE, libpulse >= 0.9.22,
    			     [have_pulse=yes], [have_pulse=no])
    if test "$have_pulse" = "no" -a "$enable_pulse" = "yes"; then
        AC_MSG_ERROR([PulseAudio development libraries not found.])
    fi

    if test "$enable_gpl" = "no"; then
        if test "$enable_pulse" = "yes"; then
           AC_MSG_ERROR([PulseAudio support requires the --enable-gpl option.])
        else
           enable_pulse="no"
        fi
    else
        enable_pulse="$have_pulse"
    fi
else
    AC_MSG_NOTICE([PulseAudio mainloop support is disabled.])
fi

if test "$enable_pulse" = "yes"; then
    AC_DEFINE([PULSE_ENABLED], 1, [Enable PulseAudio mainloop support ?])
fi
AM_CONDITIONAL(PULSE_ENABLED, [test "$enable_pulse" = "yes"])
AC_SUBST(PULSE_ENABLED)
AC_SUBST(PULSE_CFLAGS)
AC_SUBST(PULSE_LIBS)

# Check if EFL/ecore mainloop support was enabled.
AC_ARG_ENABLE(ecore,
              [  --enable-ecore          enable EFL/ecore mainloop support],
	      [enable_ecore=$enableval], [enable_ecore=auto])


if test "$enable_ecore" != "no"; then
    # We are using features which are present only at ecore 1.2 onwards.
    PKG_CHECK_MODULES(ECORE, ecore >= 1.2,
                      [have_ecore=yes], [have_ecore=no])
    if test "$have_ecore" = "no" -a "$enable_ecore" = "yes"; then
        AC_MSG_ERROR([EFL/ecore development libraries not found.])
    fi

    enable_ecore="$have_ecore"
else
    AC_MSG_NOTICE([EFL/ecore mainloop support is disabled.])
fi

if test "$enable_ecore" = "yes"; then
    AC_DEFINE([ECORE_ENABLED], 1, [Enable EFL/ecore mainloop support ?])
fi
AM_CONDITIONAL(ECORE_ENABLED, [test "$enable_ecore" = "yes"])
AC_SUBST(ECORE_ENABLED)
AC_SUBST(ECORE_CFLAGS)
AC_SUBST(ECORE_LIBS)

# Check if glib mainloop support was enabled.
AC_ARG_ENABLE(glib,
              [  --enable-glib           enable glib mainloop support],
	      [enable_glib=$enableval], [enable_glib=auto])

if test "$enable_glib" != "no"; then
    PKG_CHECK_MODULES(GLIB, glib-2.0,
                      [have_glib=yes], [have_glib=no])
    if test "$have_glib" = "no" -a "$enable_glib" = "yes"; then
        AC_MSG_ERROR([glib development libraries not found.])
    fi

    enable_glib="$have_glib"
else
    AC_MSG_NOTICE([glib mainloop support is disabled.])
fi

if test "$enable_glib" = "yes"; then
    AC_DEFINE([GLIB_ENABLED], 1, [Enable glib mainloop support ?])
fi
AM_CONDITIONAL(GLIB_ENABLED, [test "$enable_glib" = "yes"])
AC_SUBST(GLIB_ENABLED)
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)

# Check if qt mainloop support was enabled.
AC_ARG_ENABLE(qt,
              [  --enable-qt             enable qt mainloop support],
              [enable_qt=$enableval], [enable_qt=auto])

if test "$enable_qt" != "no"; then
    PKG_CHECK_MODULES(QTCORE, QtCore,
                      [have_qt=yes], [have_qt=no])
    if test "$have_qt" = "no" -a "$enable_qt" = "yes"; then
        AC_MSG_ERROR([Qt(Core) development libraries not found.])
    fi

    enable_qt="$have_qt"
else
    AC_MSG_NOTICE([Qt mainloop support is disabled.])
fi

if test "$enable_qt" = "yes"; then
    AC_DEFINE([QT_ENABLED], 1, [Enable qt mainloop support ?])
    QT_MOC="`pkg-config --variable moc_location QtCore`"
    AC_SUBST(QT_MOC)
fi
AM_CONDITIONAL(QT_ENABLED, [test "$enable_qt" = "yes"])
AC_SUBST(QT_ENABLED)
AC_SUBST(QTCORE_CFLAGS)
AC_SUBST(QTCORE_LIBS)

# Check if building murphy-console was enabled.
AC_ARG_ENABLE(console,
              [  --enable-console        build Murphy console],
	      [enable_console=$enableval], [enable_console=yes])

if test "$enable_console" = "no"; then
    AC_MSG_NOTICE([Murphy console binary is disabled.])
else
    AC_MSG_NOTICE([Murphy console binary is enabled.])
fi

if test "$enable_console" = "yes"; then
    AC_DEFINE([CONSOLE_ENABLED], 1, [Build Murphy console ?])
fi
AM_CONDITIONAL(CONSOLE_ENABLED, [test "$enable_console" = "yes"])
AC_SUBST(CONSOLE_ENABLED)
AC_SUBST(READLINE_CFLAGS)
AC_SUBST(READLINE_LIBS)

# Check for json(-c).
PKG_CHECK_MODULES(JSON, [json], [have_json=yes], [have_json=no])

if test "$have_json" = "no"; then
    PKG_CHECK_MODULES(JSON, [json-c >= 0.11])
fi

AC_MSG_CHECKING([if json-c has headers under json-c include path])
saved_CFLAGS="$CFLAGS"
saved_LIBS="$LIBS"
CFLAGS="${JSON_CFLAGS}"
LIBS="${JSON_LIBS}"
AC_LINK_IFELSE(
   [AC_LANG_PROGRAM(
         [[#include <../json-c/json.h>]],
         [[return 0;]])],
    [json_include_jsonc=yes],
    [json_include_jsonc=no])
AC_MSG_RESULT([$json_include_jsonc])
CFLAGS="$saved_CFLAGS"
LIBS="$saved_LIBS"

if test "$json_include_jsonc" = "yes"; then
    AC_DEFINE([JSON_INCLUDE_PATH_JSONC], 1, [json headers under json-c ?])
fi

AC_MSG_CHECKING([for json_tokener_get_error()])
saved_CFLAGS="$CFLAGS"
saved_LIBS="$LIBS"
CFLAGS="${JSON_CFLAGS}"
LIBS="${JSON_LIBS}"
AC_LINK_IFELSE(
   [AC_LANG_PROGRAM(
         [[#include <json.h>]],
         [[json_tokener *tok = NULL;
           if (json_tokener_get_error(tok) != json_tokener_success)
              return 0;
           else
               return 1;]])],
    [have_json_tokener_get_error=yes],
    [have_json_tokener_get_error=no])
AC_MSG_RESULT([$have_json_tokener_get_error])
CFLAGS="$saved_CFLAGS"
LIBS="$saved_LIBS"

if test "$have_json_tokener_get_error" = "yes"; then
    AC_DEFINE([HAVE_JSON_TOKENER_GET_ERROR], 1, [json_tokener_get_error ?])
fi

# Check if websocket support was/can be enabled.
CHECK_WEBSOCKETS()

# Check if SMACK support should be enabled.
AC_ARG_ENABLE(smack,
              [  --enable-smack          enable SMACK support],
	      [enable_smack=$enableval], [enable_smack=auto])

if test "$enable_smack" != "no"; then
    PKG_CHECK_MODULES(SMACK, libsmack, [have_smack=yes], [have_smack=no])
    if test "$have_smack" = "no" -a "$enable_smack" = "yes"; then
        AC_MSG_ERROR([SMACK development libraries not found.])
    fi

    enable_smack="$have_smack"
else
    AC_MSG_NOTICE([SMACK support is disabled.])
fi

if test "$enable_smack" = "yes"; then
    AC_DEFINE([SMACK_ENABLED], 1, [Enable SMACK support ?])
fi
AM_CONDITIONAL(SMACK_ENABLED, [test "$enable_smack" = "yes"])
AC_SUBST(SMACK_ENABLED)
AC_SUBST(SMACK_CFLAGS)
AC_SUBST(SMACK_LIBS)

# Check if systemd support should be enabled.
AC_ARG_ENABLE(systemd,
              [  --enable-systemd          enable systemd support],
	      [enable_systemd=$enableval], [enable_systemd=auto])

if test "$enable_systemd" != "no"; then
    PKG_CHECK_MODULES(SYSTEMD, libsystemd-journal libsystemd-daemon,
                      [have_systemd=yes], [have_systemd=no])
    if test "$have_systemd" = "no" -a "$enable_systemd" = "yes"; then
        AC_MSG_ERROR([systemd development libraries not found.])
    fi

    enable_systemd="$have_systemd"
else
    AC_MSG_NOTICE([systemd support is disabled.])
fi

if test "$enable_systemd" = "yes"; then
    AC_DEFINE([SYSTEMD_ENABLED], 1, [Enable systemd support ?])
fi
AM_CONDITIONAL(SYSTEMD_ENABLED, [test "$enable_systemd" = "yes"])
AC_SUBST(SYSTEMD_ENABLED)
AC_SUBST(SYSTEMD_CFLAGS)
AC_SUBST(SYSTEMD_LIBS)

# Set up murphy CFLAGS and LIBS.
MURPHY_CFLAGS=""
MURPHY_LIBS=""
AC_SUBST(MURPHY_CFLAGS)
AC_SUBST(MURPHY_LIBS)

# Allow substitution for LIBDIR and SYSCONFDIR.
AC_MSG_CHECKING([libdir])
AC_MSG_RESULT([$libdir])
AC_SUBST(LIBDIR, [$libdir])
AC_MSG_CHECKING([sysconfdir])
AC_MSG_RESULT([$sysconfdir])
AC_SUBST(SYSCONFDIR, [$sysconfdir])

#Check whether we build resources or not
AC_ARG_WITH(resources,
            [  --with-resources wheter to build resource management support],
	    [with_resources=$withval],[with_resources=yes])

AM_CONDITIONAL(BUILD_RESOURCES,  [ test x$with_resources = "xyes" ])


# Check which plugins should be disabled.
AC_ARG_WITH(disabled-plugins,
            [  --with-disabled-plugins=<plugin-list> specify which plugins to disable],
            [disabled_plugins=$withval],[disabled_plugins=none])

# Check which plugins should be compiled as standalone DSOs.
AC_ARG_WITH(dynamic-plugins,
            [  --with-dynamic-plugins=<plugin-list>  specify which plugins compile as DSOs],
            [dynamic_plugins=$withval],[dynamic_plugins=none])

all_plugins=$(find src/plugins/. -name plugin-*.c 2>/dev/null | \
              sed 's#^.*/plugin-##g;s#\.c$##g' | tr '\n' ' ')

#echo "all plugins: [$all_plugins]"

case $dynamic_plugins in
    all)  dynamic_plugins="$all_plugins";;
    none) dynamic_plugins="";;
esac

internal=""; it=""
external=""; et=""
disabled=""; dt=""
for plugin in $all_plugins; do 
    type=internal

    for p in ${dynamic_plugins//,/ }; do
        if test "$plugin" = "$p"; then
            type=external
        fi
    done

    for p in ${disabled_plugins//,/ }; do
        if test "$plugin" = "$p"; then
            type=disabled
        fi
    done

    case $type in
        internal) internal="$internal$it$plugin"; it=" ";;
        external) external="$external$et$plugin"; et=" ";;
        disabled) disabled="$disabled$dt$plugin"; dt=" ";;
    esac
done

DISABLED_PLUGINS="$disabled"
INTERNAL_PLUGINS="$internal"
EXTERNAL_PLUGINS="$external"


function check_if_disabled() {
    for p in $DISABLED_PLUGINS; do
        if test "$1" = "$p"; then
            return 0
        fi
    done

    return 1
}

function check_if_internal() {
    for p in $INTERNAL_PLUGINS; do
        if test "$1" = "$p"; then
            return 0
        fi
    done

    return 1
}

AM_CONDITIONAL(DISABLED_PLUGIN_TEST,     [check_if_disabled test])
AM_CONDITIONAL(DISABLED_PLUGIN_DBUS,     [check_if_disabled dbus])
AM_CONDITIONAL(DISABLED_PLUGIN_GLIB,     [check_if_disabled glib])
AM_CONDITIONAL(DISABLED_PLUGIN_CONSOLE,  [check_if_disabled console])
AM_CONDITIONAL(DISABLED_PLUGIN_RESOURCE_DBUS, [check_if_disabled resource-dbus])
AM_CONDITIONAL(DISABLED_PLUGIN_RESOURCE_WRT, [check_if_disabled resource-wrt])
AM_CONDITIONAL(DISABLED_PLUGIN_DOMAIN_CONTROL,
               [check_if_disabled domain-control])
AM_CONDITIONAL(DISABLED_PLUGIN_SYSTEMD,  [check_if_disabled systemd])

AM_CONDITIONAL(BUILTIN_PLUGIN_TEST,     [check_if_internal test])
AM_CONDITIONAL(BUILTIN_PLUGIN_DBUS,     [check_if_internal dbus])
AM_CONDITIONAL(BUILTIN_PLUGIN_GLIB,     [check_if_internal glib])
AM_CONDITIONAL(BUILTIN_PLUGIN_CONSOLE,  [check_if_internal console])
AM_CONDITIONAL(BUILTIN_PLUGIN_RESOURCE_DBUS, [check_if_internal resource-dbus])
AM_CONDITIONAL(BUILTIN_PLUGIN_RESOURCE_WRT, [check_if_internal resource-wrt])
AM_CONDITIONAL(BUILTIN_PLUGIN_DOMAIN_CONTROL,
               [check_if_internal domain-control])
AM_CONDITIONAL(BUILTIN_PLUGIN_LUA,      [check_if_internal lua])
AM_CONDITIONAL(BUILTIN_PLUGIN_SYSTEMD,  [check_if_internal systemd])

# Check for Check (unit test framework).
PKG_CHECK_MODULES(CHECK, 
                  check >= 0.9.4,
                  [has_check="yes"], [has_check="no"])
AM_CONDITIONAL(HAVE_CHECK, test "x$has_check" = "xyes")

AC_SUBST(CHECK_CFLAGS)
AC_SUBST(CHECK_LIBS)

if test "x$has_check" = "xno"; then
    AC_MSG_WARN([Check framework not found, unit tests are DISABLED.])
fi

# Check for documentation tools
AC_ARG_WITH([documentation],
            [AS_HELP_STRING([--with-documentation],
                            [generate pdf, html and other doc files])],
            [],
            [with_documentation=auto]
)

AS_IF( [ test x$with_documentation = xno ],
       [ has_doc_tools="no" ],
       [ AC_PATH_TOOL([MRP_DOXYGEN], doxygen)
         AC_PATH_TOOL([MRP_LYX], lyx)
         AC_PATH_TOOL([MRP_INKSCAPE], inkscape)
         AC_PATH_TOOL([MRP_PYTHON], python)
         AC_PATH_TOOL([MRP_TOUCH], touch)
         AC_PATH_TOOL([MRP_DBLATEX], dblatex)
         AC_PATH_TOOL([MRP_XMLTO], xmlto)

         AS_IF( [ test x$MRP_DOXYGEN = x -o x$MRP_LYX = x -o \
                       x$MRP_INKSCAPE = x -o x$MRP_PYTHON = x -o \
                       x$MRP_TOUCH = x],
                [ has_doc_tools="no";
                  AC_MSG_WARN([Some essential doc-tool is missing]) ],
                [ has_doc_tools="yes";
                  MRP_DOCINIT() ]
         ) ]
)

AS_IF( [ test x$has_doc_tools == "xno" -o x$MRP_DBLATEX = x ],
       [ can_make_pdfs="no";
         AC_WARN([No PDF documentation will be generated]) ],
       [ can_make_pdfs="yes"]
)

AS_IF([ test x$has_doc_tools == "xno" -o x$MRP_XMLTO = x ],
      [ can_make_html="no";
        AC_WARN([No HTML documentation will be generated]) ],
      [ can_make_html="yes" ]
)


AM_CONDITIONAL(BUILD_DOCUMENTATION,  [ test x$has_doc_tools = "xyes" ])
AM_CONDITIONAL(BUILD_PDF_DOCUMENTS,  [ test x$can_make_pdfs = "xyes" ])
AM_CONDITIONAL(BUILD_HTML_DOCUMENTS, [ test x$can_make_html = "xyes" ])

AC_SUBST(MRP_DOCDIR, [`pwd`/doc])
AC_SUBST(MRP_FIGDIR, [$MRP_DOCDIR/common/figures])
AC_SUBST(MRP_MAKE_DOCRULES, [$MRP_DOCDIR/Makefile.rules])
AC_SUBST(MRP_DOCSCRIPT_DIR, [$MRP_DOCDIR/scripts])
AC_SUBST(MRP_ABNF, [$MRP_DOCSCRIPT_DIR/abnf.py])
AC_SUBST(MRP_DBLYXFIX, [$MRP_DOCSCRIPT_DIR/dblyxfix.py])
AC_SUBST(MRP_DOXML2DB, [$MRP_DOCSCRIPT_DIR/doxml2db.py])
AC_SUBST(MRP_DOXYDEPS, [$MRP_DOCSCRIPT_DIR/doxydeps.py])


# Shave by default.
SHAVE_INIT([build-aux], [enable])

# Create murphy symlink to match domain controller's
# placing with how it is installed.
if test ! -L murphy/domain-control; then
    AC_MSG_NOTICE([Symlinking src/plugins/domain-control to src/domain-control...])
    cd src
    ln -s plugins/domain-control domain-control
    cd ..
fi

# Create murphy symlink to src.
if test ! -L murphy; then
    AC_MSG_NOTICE([Symlinking src to murphy...])
    ln -s src murphy
fi

# Generate output.
AC_CONFIG_FILES([build-aux/shave
		 build-aux/shave-libtool
		 Makefile
                 utils/Makefile
		 src/Makefile
		 src/common/tests/Makefile
		 src/core/tests/Makefile
		 src/core/lua-decision/tests/Makefile
		 src/daemon/tests/Makefile
		 src/plugins/tests/Makefile
		 src/common/murphy-common.pc
		 src/common/murphy-libdbus.pc
		 src/common/murphy-dbus-libdbus.pc
		 src/common/murphy-dbus-sdbus.pc
		 src/common/murphy-pulse.pc
		 src/common/murphy-ecore.pc
		 src/common/murphy-glib.pc
                 src/common/murphy-qt.pc
		 src/core/murphy-core.pc
                 src/core/lua-utils/murphy-lua-utils.pc
                 src/core/lua-decision/murphy-lua-decision.pc
		 src/breedline/breedline.pc
		 src/breedline/breedline-murphy.pc
		 src/breedline/breedline-glib.pc
		 src/breedline/tests/Makefile
		 src/murphy-db/Makefile
		 src/murphy-db/mdb/Makefile
		 src/murphy-db/mqi/Makefile
		 src/murphy-db/mql/Makefile
		 src/murphy-db/include/Makefile
		 src/murphy-db/tests/Makefile
		 src/resolver/murphy-resolver.pc
		 src/resolver/tests/Makefile
		 src/plugins/domain-control/murphy-domain-controller.pc
		 doc/Makefile
		 doc/plugin-developer-guide/Makefile
		 doc/plugin-developer-guide/db/Makefile
		 doc/plugin-developer-guide/doxml/Makefile
		 src/plugins/resource-native/libmurphy-resource/murphy-resource.pc
		 ])
AC_OUTPUT


# Display the configuration.
echo "----- configuration -----"
echo "Extra C warnings flags: $WARNING_CFLAGS"
echo "Cross-compiling: $cross_compiling"
if test "$cross_compiling" != "no"; then
    echo "     * native compiler: $UNSHAVED_CC_FOR_BUILD"
fi
echo "Lua (pkgconfig file) to use: $with_lua"
echo "    * cflags: $LUA_CFLAGS"
echo "    * libs: $LUA_LIBS"
echo "D-Bus (libdbus) support: $enable_libdbus"
echo "D-Bus (systemd-bus) support: $enable_sdbus"
echo "PulseAudio mainloop support: $enable_pulse"
echo "EFL/ecore mainloop support: $enable_ecore"
echo "glib mainloop support: $enable_glib"
echo "Qt mainloop support: $enable_qt"
echo "Murphy console plugin and client: $enable_console"
echo "Resource management support: $with_resources"
echo "Websockets support: $enable_websockets"
echo "systemd support: $enable_systemd"
echo "Plugins:"
echo "  - linked-in:"
for plugin in ${INTERNAL_PLUGINS:-none}; do
    echo "      $plugin"
done
echo "  - dynamic:"
for plugin in ${EXTERNAL_PLUGINS:-none}; do
    echo "      $plugin"
done
echo "  - disabled:"
for plugin in ${DISABLED_PLUGINS:-none}; do
    echo "      $plugin"
done