## Process this file with automake to produce Makefile.in

# AM_GNU_GETTEXT requires po in SUBDIRS
SUBDIRS = po docs/help/bt-edit
# see fake subdir rules
FAKE_SUBDIRS = \
  docs/reference/bt-core docs/reference/bt-ic \
  docs/reference/bt-cmd docs/reference/bt-edit \
  docs/reference/bt-gst
DIST_SUBDIRS = $(SUBDIRS) $(FAKE_SUBDIRS)

ACLOCAL_AMFLAGS = -I m4
DISTCHECK_CONFIGURE_FLAGS = \
  --enable-gtk-doc \
  --enable-debug \
	--disable-update-desktop \
	--disable-update-mime \
	--disable-update-icon-cache \
  --disable-scrollkeeper

AM_CPPFLAGS = \
	-I$(top_srcdir)/src/lib \
	-I$(top_builddir)/src/lib \
	-DPREFIX=\"$(prefix)\" \
	-DSYSCONFDIR=\"$(sysconfdir)\" \
	-DLOCALEDIR=\"$(localedir)\" \
	-DLIBDIR=\"$(libdir)\" \
	-DDATADIR=\"$(datadir)\" \
	-DTESTSONGDIR=\"$(abs_top_srcdir)/tests/songs\" \
	-DG_LOG_DOMAIN=\"buzztrax\" \
	-DG_SETTINGS_ENABLE_BACKEND \
	$(BASE_DEPS_CFLAGS) \
	$(BT_CFLAGS)

AM_LDFLAGS = $(BT_LDFLAGS)

EXTRA_DIST = \
	org.buzztrax.gschema.xml \
	$(appdata_in_files) \
	buzztrax.convert \
	intltool-extract.in \
	intltool-merge.in \
	intltool-update.in \
	COPYING-DOCS \
	omf.make \
	xmldocs.make \
	README.md TODO \
	docs/version.entities.in \
	docs/buzztrax.xsd \
	po/$(GETTEXT_PACKAGE).pot

# BUILT_SOURCES is for generated source
BUILT_SOURCES = builddirs
	
# CLEANFILES is for files generated by make
CLEANFILES = $(appdata_DATA)

# DISTCLEANFILES is for files generated by configure
DISTCLEANFILES = \
	intltool-extract \
	intltool-merge \
	intltool-update \
	docs/version.entities

# define list variables once so that we can unconditionally append
noinst_HEADERS =
noinst_LTLIBRARIES =

include $(top_srcdir)/Makefile.icons.am
include $(top_srcdir)/Makefile.src.am
include $(top_srcdir)/Makefile.tests.am

#-- settings

# gsettings_SCHEMAS is a list of all the schemas you want to install
gsettings_SCHEMAS = org.buzztrax.gschema.xml

# include the appropriate makefile rules for schema handling
@GSETTINGS_RULES@

# convert the gconf data to gsettings
gconfconvertdir = $(datadir)/GConf/gsettings
gconfconvert_DATA = buzztrax.convert

#-- app-data for package manager
appdatadir = $(datadir)/appdata
appdata_DATA = $(appdata_in_files:.xml.in=.xml)
appdata_in_files = buzztrax.appdata.xml.in

#-- fake subdir rules

docs: docs-bt-core docs-bt-ic docs-bt-cmd docs-bt-edit docs-bt-gst

docs/reference/version.entities:
	@cp docs/version.entities docs/reference/

docs-bt-core: libbuzztrax-core.la libbtbsl.la libbuzztrax-ic.la docs/reference/version.entities
	@$(MAKE) -C docs/reference/bt-core

docs-bt-ic: libbuzztrax-ic.la docs/reference/version.entities
	@$(MAKE) -C docs/reference/bt-ic

docs-bt-cmd: libbtcmd.la libbuzztrax-ic.la libbuzztrax-core.la docs/reference/version.entities
	@$(MAKE) -C docs/reference/bt-cmd

docs-bt-edit: libbtedit.la libbuzztrax-ic.la libbuzztrax-core.la docs/reference/version.entities
	@$(MAKE) -C docs/reference/bt-edit

docs-bt-gst: libbuzztrax-gst.la
	@$(MAKE) -C docs/reference/bt-gst

all-local: docs

check-local:
	@for dir in $(FAKE_SUBDIRS); do $(MAKE) -C $$dir check; done

clean-local: test-clean-local
	-@rm docs/reference/version.entities
	-@rm -f po/.intltool-merge-cache
	@for dir in $(FAKE_SUBDIRS); do \
	  if test -f $$dir/Makefile; then \
	    $(MAKE) -C $$dir clean; \
	  fi; \
	done	

install-data-local:
	@for dir in $(FAKE_SUBDIRS); do $(MAKE) -C $$dir install-data; done

uninstall-local:
	@for dir in $(FAKE_SUBDIRS); do $(MAKE) -C $$dir uninstall; done

# silly hack to fix make distcheck on a clean package
po/$(GETTEXT_PACKAGE).pot:
	$(MAKE) -C po update-po

## this seems to fail during make distcheck
##uninstall-local:
##	rm -r $(datadir)/$(PACKAGE)

install-data-hook: update-icon-cache update-desktop-db update-mime-db
uninstall-hook: update-icon-cache update-desktop-db update-mime-db

## We get warnings for left-over files when doing 'make distuninstallcheck'
distuninstallcheck_listfiles = find . -type f -print

## Workaround for scrollkeeper bug
distuninstallcheck_listfiles += | grep -v '/var/scrollkeeper'
## Workaround for installing files in own prefix
distuninstallcheck_listfiles += | grep -v '/share/mime'
## Workaround for installing icon theme in own prefix
distuninstallcheck_listfiles += | grep -v 'icon-theme.cache'
## Workaround for installing icon theme in own prefix
distuninstallcheck_listfiles += | grep -v 'mimeinfo.cache'

# the mkdir is needed because of an INTLTOOL bug
# https://bugs.launchpad.net/intltool/+bug/605826
builddirs:
	$(AM_V_at)$(MKDIR_P) src/lib/core/songio/bsl/ src/ui/edit

# meh, if we build from a tarball, there won't be a .git/index
AUTHORS: $(wildcard $(top_srcdir)/.git/index)
	$(AM_V_GEN)if test -d "$(top_srcdir)/.git"; \
	then \
		( cd "$(top_srcdir)" && \
		  git log --no-merges --pretty=format:"%an <%ae>" . | \
		  sed -e 's/sourceforge.net/sf.net/' \
		      -e 's/Stefan Sauer <ensonic@hora-obscura.de>/Stefan Sauer <ensonic@users.sf.net>/' \
		      -e 's/\(Joseph Orbegoso Pea <joseph.pea@climate.com>\|trusktr <trusktr@gmail.com>\)/Joe Pea <trusktr@gmail.com>/' \
		      -e 's/\(Tom Mast <thomasomast@gmail.com>\|tom__m <thomasomast@gmail.com>\)/Tom Mast <amishmansteve@users.sf.net>/' \
		      -e 's/\(Thomas Wabner <waffel@hora-obscura.de>\|Waffel <waffel@hora-obscura.de>\|waffel <waffel@users.sf.net>\)/Thomas Wabner <waffel@users.sf.net>/' | \
		  sort | uniq -c | sed -e 's/^\ *//' | sort -rn | cut -d' ' -f2-; echo; \
		  echo 'src/lib/dllwrapper is based on the work of various authors of the winelib and xine projects' \
		  ) > $@.tmp && \
		cmp -s $@ $@.tmp; \
		if test "$(?)" = "0"; then rm -f $@.tmp; touch $@; else mv -f $@.tmp $@; fi \
		|| ( rm -f $@.tmp ; \
		     echo Failed to generate $@ >&2 ); \
	fi


.PHONY: \
  builddirs \
  docs docs-bt-core docs-bt-ic docs-bt-cmd docs-bt-edit \
  install-gconf uninstall-gconf \
  update-icon-cache update-desktop-db update-mime-db \
  dict cc10 cc20

# make dict            -- create an aspell dictionary from tags
dict:: tags
	echo "personal_ws" >$(PACKAGE).aspell_dict
	@find . -name tags -exec grep -v "$\!" {} \; | cut -f1 | sort | uniq >>$(PACKAGE).aspell_dict

# -k2 in sort for Tranditional McCabe Cyclomatic Complexity
# make cc10            -- report McCabe Cyclomatic Complexity
# make cc20            -- report McCabe Cyclomatic Complexity
cc10::
	@pmccabe `find src -name '*.c'` | sort -nr | awk '($$1 > 10)'
cc20::
	@pmccabe `find src -name '*.c'` | sort -nr | awk '($$1 > 20)'

include $(top_srcdir)/common.mak
