ACLOCAL_AMFLAGS = -I scripts/.autostuff/m4
MAKEFLAGS = $(SILENT_MAKEFLAGS_$(V))
SILENT_MAKEFLAGS_ = $(SILENT_MAKEFLAGS_$(AM_DEFAULT_VERBOSITY))
SILENT_MAKEFLAGS_0 = --no-print-directory -s
SILENT_MAKEFLAGS_1 =

EXTRA_DIST = .version

bin_PROGRAMS =
bin_SCRIPTS =
dist_bin_SCRIPTS =

lib_LTLIBRARIES =
noinst_LIBRARIES =

CLEANFILES =
DISTCLEANFILES =
MAINTAINERCLEANFILES =
BUILT_SOURCES =

#===============================================================================
# Docs
dist_doc_DATA = \
	docs/kconfig-language.txt \
	docs/kconfig.txt

#===============================================================================
# Libraries

SUFFIXES = .gperf

lib_LTLIBRARIES += libs/parser/libkconfig-parser.la
libs_parser_libkconfig_parser_la_SOURCES = libs/parser/yconf.y
dist_EXTRA_libs_parser_libkconfig_parser_la_SOURCES = \
	libs/parser/hconf.gperf \
	libs/parser/lconf.l \
	libs/parser/confdata.c \
	libs/parser/menu.c \
	libs/parser/symbol.c \
	libs/parser/util.c \
	libs/parser/expr.c \
	libs/parser/expr.h \
	libs/parser/lkc.h \
	libs/parser/lkc_proto.h
libs_parser_libkconfig_parser_la_CPPFLAGS = \
	-DROOTMENU="\"$(root_menu)\"" \
	-DCONFIG_=\"$(config_prefix)\" \
	-DGPERF_LEN_TYPE="$(GPERF_LEN_TYPE)" \
	$(intl_CPPFLAGS) \
	-I$(top_srcdir)/libs/parser \
	-I$(top_builddir)/libs/parser
libs_parser_libkconfig_parser_la_CFLAGS = \
	$(AM_CFLAGS) \
	$(kf_CFLAGS)
libs_parser_libkconfig_parser_la_LDFLAGS = \
	-release $(KCONFIGPARSER_LIB_VERSION) \
	-no-undefined
libs_parser_libkconfig_parser_la_LIBADD = $(intl_LIBS)

libs_parser_kconfig_includedir = $(includedir)/kconfig
libs_parser_kconfig_include_HEADERS = \
	libs/parser/list.h \
	libs/parser/lkc.h \
	libs/parser/expr.h \
	libs/parser/lkc_proto.h

AM_V_GPERF = $(AM_V_GPERF_$(V))
AM_V_GPERF_ = $(AM_V_GPERF_$(AM_DEFAULT_VERBOSITY))
AM_V_GPERF_0 = @echo "  GPERF   " $@;
AM_V_GPERF_1 =

.gperf.c:
	$(AM_V_GPERF)$(GPERF) -t --output-file $@ -a -C -E -g -k 1,3,$$ -p -t $<

# The following rule may produce a warning with some versions of automake:
#   Makefile.am:85: user target `.l.c' defined here...
#   /usr/share/automake-1.11/am/lex.am: ... overrides Automake target
#   `.l.c' defined here
#
# This is expected, and can't be avoided (for now).
# That's because, when working with lex+yacc sources, the default is to
# build each files searately, and then link them together into the final
# output. But the Linux kernel's parser simply #include-s the lexer,
# so we can't put lconf.l into the _SOURCES (it's in EXTRA_SOURCES),
# and thus automake does not catch the need to call lex.
# Secondly, when flex is told to change the symbols' prefix (kconfig
# uses zconf in lieue of the original yy), then the output file is
# also renamed, but automake does not now that, and make would fail
# because it would think no file was generated.
.l.c:
	$(AM_V_LEX)$(LEXCOMPILE) -o$@ $<

# yconf.c not listed, because it is the real _SOURCES, but others are
# in _EXTRA_SOURCES (above), so must be listed:
BUILT_SOURCES += \
	libs/parser/hconf.c \
	libs/parser/lconf.c
# Still, .c files generated from .y files are not cleaned by default,
# so yconf.c must be explicitly listed:
MAINTAINERCLEANFILES += \
	libs/parser/hconf.c \
	libs/parser/lconf.c \
	libs/parser/yconf.c
EXTRA_DIST += \
	libs/parser/hconf.c \
	libs/parser/hconf.gperf.patch \
	libs/parser/yconf.y.patch

# libs/parser/kconfig-parser.pc generated by AC_CONFIG_FILES in configure.ac
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libs/parser/kconfig-parser.pc
DISTCLEANFILES += libs/parser/kconfig-parser.pc
EXTRA_DIST += libs/parser/kconfig-parser.pc.in

#--------------------------
# lxdialog lib (for mconf)
if COND_lxdialog

noinst_LIBRARIES += libs/lxdialog/libkconfig-lxdialog.a

libs_lxdialog_libkconfig_lxdialog_a_SOURCES = \
	libs/lxdialog/checklist.c \
	libs/lxdialog/dialog.h \
	libs/lxdialog/inputbox.c \
	libs/lxdialog/menubox.c \
	libs/lxdialog/textbox.c \
	libs/lxdialog/util.c \
	libs/lxdialog/yesno.c
libs_lxdialog_libkconfig_lxdialog_a_CPPFLAGS = \
	$(AM_CPPFLAGS) \
	$(ncurses_mconf_CPPFLAGS) \
	$(intl_CPPFLAGS)
libs_lxdialog_liblxdialog_a_CFLAGS = \
	$(AM_CFLAGS) \
	$(kf_CFLAGS)

endif # COND_lxdialog

#--------------------------
# kconfig meta frontend
if COND_images

noinst_LIBRARIES += libs/images/libkconfig-images.a

libs_images_libkconfig_images_a_SOURCES = libs/images/images.c_orig
nodist_libs_images_libkconfig_images_a_SOURCES = libs/images/images.c

libs/images/images.c: libs/images/images.c_orig
	$(AM_V_GEN)$(SED) -e 's/^static //' $< >$@

libs/images/images.h: libs/images/images.c_orig
	$(AM_V_GEN)$(SED) -e '/^static \(const char \*xpm_\(.\{1,\}\)\[\]\) = {/!d; s//extern \1;/' \
		$< >$@

BUILT_SOURCES += \
	libs/images/images.c \
	libs/images/images.h
CLEANFILES += \
	libs/images/images.c \
	libs/images/images.h

endif # COND_images

#===============================================================================
# Frontends

#--------------------------
# kconfig meta frontend
if COND_kconfig

bin_SCRIPTS += frontends/kconfig

frontends/kconfig: frontends/kconfig.in
	$(AM_V_GEN)$(SED) -e 's/@KCFG_LIST@/$(kcfg_list)/g' \
		$< >$@
	@chmod +x $@

EXTRA_DIST += frontends/kconfig.in

endif # COND_kconfig

#--------------------------
# conf frontend
if COND_conf

bin_PROGRAMS += frontends/conf/kconfig-conf

frontends_conf_kconfig_conf_SOURCES = frontends/conf/conf.c
frontends_conf_kconfig_conf_CPPFLAGS = \
	$(AM_CPPFLAGS) \
	$(intl_CPPFLAGS) \
	-I$(top_srcdir)/libs/parser
frontends_conf_kconfig_conf_CFLAGS = \
	$(AM_CFLAGS) \
	$(kf_CFLAGS)
frontends_conf_kconfig_conf_LDADD = \
	$(top_builddir)/libs/parser/libkconfig-parser.la \
	$(intl_LIBS) \
	$(conf_EXTRA_LIBS)

endif # COND_conf

#--------------------------
# mconf frontend
if COND_mconf

bin_PROGRAMS += frontends/mconf/kconfig-mconf

frontends_mconf_kconfig_mconf_SOURCES = frontends/mconf/mconf.c
frontends_mconf_kconfig_mconf_CPPFLAGS = \
	$(AM_CPPFLAGS) \
	$(ncurses_mconf_CPPFLAGS) \
	$(intl_CPPFLAGS) \
	-I$(top_srcdir)/libs \
	-I$(top_srcdir)/libs/parser
frontends_mconf_kconfig_mconf_CFLAGS = \
	$(AM_CFLAGS) \
	$(kf_CFLAGS)
frontends_mconf_kconfig_mconf_LDADD = \
	$(top_builddir)/libs/parser/libkconfig-parser.la \
	$(top_builddir)/libs/lxdialog/libkconfig-lxdialog.a \
	$(intl_LIBS) $(ncurses_LIBS) $(mconf_EXTRA_LIBS)

endif # COND_mconf

#--------------------------
# nconf frontend
if COND_nconf

bin_PROGRAMS += frontends/nconf/kconfig-nconf

frontends_nconf_kconfig_nconf_SOURCES = \
	frontends/nconf/nconf.c \
	frontends/nconf/nconf.gui.c \
	frontends/nconf/nconf.h
frontends_nconf_kconfig_nconf_CPPFLAGS = \
	$(AM_CPPFLAGS) \
	$(intl_CPPFLAGS) \
	$(ncurses_nconf_CPPFLAGS) \
	-I$(top_srcdir)/libs/parser
frontends_nconf_kconfig_nconf_CFLAGS = \
	$(AM_CFLAGS) \
	$(kf_CFLAGS)
frontends_nconf_kconfig_nconf_LDADD = \
	$(top_builddir)/libs/parser/libkconfig-parser.la \
	$(intl_LIBS) $(ncurses_panel_menu_LIBS) $(ncurses_LIBS) \
	$(nconf_EXTRA_LIBS)

endif # COND_nconf

#--------------------------
# gconf frontend
if COND_gconf

bin_PROGRAMS += frontends/gconf/kconfig-gconf

frontends_gconf_kconfig_gconf_SOURCES = \
	frontends/gconf/gconf.c \
	frontends/gconf/gconf.glade
frontends_gconf_kconfig_gconf_CPPFLAGS = \
	$(AM_CPPFLAGS) \
	$(intl_CPPFLAGS) \
	-I$(top_srcdir)/libs/parser \
	-I$(top_builddir)/libs/images \
	-DGUI_PATH='"$(pkgdatadir)/gconf.glade"'
frontends_gconf_kconfig_gconf_CFLAGS = \
	$(AM_CFLAGS) \
	$(kf_CFLAGS) \
	$(gtk_CFLAGS)
frontends_gconf_kconfig_gconf_LDADD = \
	$(top_builddir)/libs/parser/libkconfig-parser.la \
	$(top_builddir)/libs/images/libkconfig-images.a \
	$(intl_LIBS) \
	$(gtk_LIBS) \
	$(gconf_EXTRA_LIBS)
frontends_gconf_kconfig_gconfdir = $(pkgdatadir)
frontends_gconf_kconfig_gconf_DATA = frontends/gconf/gconf.glade

EXTRA_DIST += frontends/gconf/gconf.c.patch

endif # COND_gconf

#--------------------------
# gconf frontend
if COND_qconf

bin_PROGRAMS += frontends/qconf/kconfig-qconf

frontends_qconf_kconfig_qconf_SOURCES = \
	frontends/qconf/qconf.cc \
	frontends/qconf/qconf.h
BUILT_SOURCES += frontends/qconf/qconf.moc
frontends_qconf_kconfig_qconf_CPPFLAGS = \
	$(AM_CPPFLAGS) \
	$(intl_CPPFLAGS) \
	-I$(top_srcdir)/libs/parser \
	-I$(top_builddir)/libs/images \
	-I$(top_builddir)/frontends/qconf
frontends_qconf_kconfig_qconf_CXXFLAGS = \
	$(AM_CXXFLAGS) \
	$(kf_CFLAGS) \
	$(Qt5_CFLAGS) \
	-fPIC -std=c++11
frontends_qconf_kconfig_qconf_LDADD = \
	$(top_builddir)/libs/parser/libkconfig-parser.la \
	$(top_builddir)/libs/images/libkconfig-images.a \
	$(intl_LIBS) $(Qt5_LIBS) $(qconf_EXTRA_LIBS)

AM_V_MOC = $(AM_V_MOC_$(V))
AM_V_MOC_ = $(AM_V_MOC_$(AM_DEFAULT_VERBOSITY))
AM_V_MOC_0 = @echo "  MOC     " $@;
AM_V_MOC_1 =

.h.moc:
	$(AM_V_MOC)$(MOC) -i $< -o $@

CLEANFILES += frontends/qconf/qconf.moc
EXTRA_DIST += frontends/qconf/qconf.cc.patch

endif # COND_qconf

#===============================================================================
# Utilities
if COND_utils

bin_SCRIPTS += utils/kconfig-tweak
dist_bin_SCRIPTS += utils/kconfig-diff utils/kconfig-merge

if COND_utils_gettext
MAYBE_utils_gettext = utils/kconfig-gettext
endif
bin_PROGRAMS += $(MAYBE_utils_gettext)

utils_kconfig_gettext_SOURCES = utils/gettext.c
utils_kconfig_gettext_CPPFLAGS = \
	$(AM_CPPFLAGS) \
	-I$(top_srcdir)/libs/parser
utils_kconfig_gettext_CFLAGS = \
	$(AM_CFLAGS) \
	$(kf_CFLAGS)
utils_kconfig_gettext_LDADD = \
	$(top_builddir)/libs/parser/libkconfig-parser.la \
	$(intl_LIBS)

CLEANFILES += utils/kconfig-tweak
EXTRA_DIST += \
	utils/kconfig-tweak.in \
	utils/kconfig-tweak.in.patch

utils/kconfig-tweak: utils/kconfig-tweak.in
	$(MKDIR_P) $(@D)
	$(AM_V_GEN)$(SED) -e "s/@CONFIG_@/$(config_prefix)/g" \
		$< >$@
	@chmod +x $@

endif # COND_utils

#===============================================================================
# Misc. scripts
EXTRA_DIST += \
	scripts/ksync.sh \
	scripts/ksync.list \
	scripts/version.sh
