# Emacs: -*- makefile -*-
#
# Toplevel Makefile.am for a YaST2 subproject
#
# -- This file is generated by y2automake - DO NOT EDIT! --
#    (Edit ./SUBDIRS instead)
#

#where devtools are
PREFIX := $(shell pkg-config --print-errors --variable=prefix yast2-devtools)
Y2TOOL = $(PREFIX)/bin/y2tool

VERSION			= $(shell cat $(srcdir)/VERSION)
RPMNAME 		= $(shell cat $(srcdir)/RPMNAME)
SUBDIRS_FILE		= $(shell test -e $(srcdir)/SUBDIRS      && echo SUBDIRS)
ACINCLUDE_FILE		= $(shell test -e $(srcdir)/acinclude.m4 && echo acinclude.m4)

HAS_YAST_LICENSE	= $(shell test -e $(srcdir)/YAST_LICENSE && echo YAST_LICENSE)

# do we do Makefile.am for devtools? It is a little special...
IS_DEVTOOLS		= $(findstring yast2-devtools,$(RPMNAME))

DEVTOOLS_DIR 		= $(if $(IS_DEVTOOLS),$(srcdir)/devtools,$(PREFIX)/share/YaST2/data/devtools)
ALL_PACKAGES		= $(DEVTOOLS_DIR)/admin/all-packages
LEGALESE_DIR		= $(if $(HAS_YAST_LICENSE),$(DEVTOOLS_DIR)/admin/copyright/yast,$(DEVTOOLS_DIR)/admin/copyright/gpl)

COPYRIGHT_files_gpl	= README COPYING COPYRIGHT.english

COPYRIGHT_files_yast	= YAST_LICENSE README COPYING COPYRIGHT.english \
			  COPYRIGHT.french COPYRIGHT.german COPYRIGHT.spanish

extra_COPYRIGHT_files =  $(if $(HAS_YAST_LICENSE), $(COPYRIGHT_files_yast), $(COPYRIGHT_files_gpl))

AUTOMAKE_OPTIONS = foreign dist-bzip2
# where devtools instal m4 snippets
# argh, executed literally
#ACLOCAL_AMFLAGS = -I $(PREFIX)/share/aclocal
ACLOCAL_AMFLAGS = -I `if test -d ./devtools/admin; then echo ./devtools/admin; else pkg-config --print-errors --variable=datadir yast2-devtools; fi`/aclocal

Makefile.am.common: $(DEVTOOLS_DIR)/admin/Makefile.am.common
	cmp -s $< $@ || cp -f $< $@

# create bzip2ed tar and make some sanity checks
$(RPMNAME)-$(VERSION).tar.bz2: checkpo dist-bzip2
	@if [ `bunzip2 -c $(RPMNAME)-$(VERSION).tar.bz2 | wc --bytes` = 0 ] ; then \
	    echo "Error: created tar is empty" ; \
	    exit 1 ; \
	fi

CLEANFILES =
MAINTAINERCLEANFILES = package/$(RPMNAME)-$(VERSION).tar.bz2 package/$(RPMNAME).spec

POT_DST = $(shell find -type d -name testsuite -prune , \
	-type f -name "*.pot") 

EXTRA_DIST = \
	VERSION RPMNAME MAINTAINER configure.in.in		\
	$(SUBDIRS_FILE) $(ACINCLUDE_FILE)			\
	$(if $(IS_DEVTOOLS),Makefile.am.common,$(POT_DST))

show-extra-dist:
	@echo $(EXTRA_DIST)

# info '(automake)Conditionals'
if CREATE_PKGCONFIG
# create the file here instead of by configure
# because the prerequisite is made here (not anymore!)
# and we don't want any paths in y2autoconf
# info '(autoconf)config.status Invocation'
$(RPMNAME).pc: $(RPMNAME).pc.in
	./config.status --file=$@:$<

if CREATE_PKGCONFIG_NOARCH
pkgconfigdata_DATA = $(RPMNAME).pc
else
pkgconfig_DATA = $(RPMNAME).pc
endif

EXTRA_DIST += $(RPMNAME).pc.in
endif

dist-hook:
	@for I in $(extra_COPYRIGHT_files) ;					\
	do									\
	    EX="" ;								\
	    if test -f $(srcdir)/$$I ; then					\
		EX=$(srcdir)/$$I ;						\
	    elif test -f $(LEGALESE_DIR)/$$I ; then				\
		EX=$(LEGALESE_DIR)/$$I ;					\
	    else								\
	        echo "Error: No file $$I in $(srcdir)/ or in $$LEGALESE_DIR/";	\
		exit 1 ;							\
	    fi ;								\
	    echo "cp $$EX $(distdir)" ;						\
	    cp $$EX "$(distdir)" ;						\
	done

pot:
	$(Y2TOOL) y2makepot -s $(srcdir)

install-pot: pot
	@POT_DST=`find -type d -name testsuite -prune , \
		-type f -name "*.pot"` ; \
	if [ -n "$$POT_DST" ] ; then \
	    echo "mkdir -p $(DESTDIR)$(potdir)" ; \
	    mkdir -p $(DESTDIR)$(potdir) ; \
	    list="$$POT_DST"; \
	    for I in $$list ; \
	    do \
		echo $$I ; \
		if [ "$$I" == "pot" ] ; then \
			continue ; \
		fi ; \
		echo "$(INSTALL_DATA) $$I $(DESTDIR)$(potdir)" ; \
		$(INSTALL_DATA) $$I $(DESTDIR)$(potdir) ; \
	    done ; \
	fi

spellcheck: pot
	$(Y2TOOL) pot-spellcheck

# all-local: $(if $(IS_DEVTOOLS),,$(POT_DST))

install-data-local: # $(if $(IS_DEVTOOLS),,install-pot)
	mkdir -p $(DESTDIR)$(docdir)
	@for I in $(extra_COPYRIGHT_files) ;					\
	do									\
	    EX="" ;								\
	    if test -f $(srcdir)/$$I ; then					\
		EX=$(srcdir)/$$I ;						\
	    elif test -f $(LEGALESE_DIR)/$$I ; then				\
		EX=$(LEGALESE_DIR)/$$I ;					\
	    else								\
		echo "Error: No file $$I in $(srcdir)/ or in $(LEGALESE_DIR)/";	\
		exit 1 ;							\
	    fi ;								\
	    echo "$(INSTALL_DATA) $$EX $(DESTDIR)$(docdir)" ;			\
	    $(INSTALL_DATA) $$EX $(DESTDIR)$(docdir) ;				\
	done

package-local: check-parse $(if $(IS_DEVTOOLS),,$(POT_DST)) $(RPMNAME)-$(VERSION).tar.bz2
	rm -f package/$(RPMNAME)-*.tar.bz2
	rm -f package/*~
	rm -f package/*.bak
	rm -f package/*.auto
	mv $(RPMNAME)-$(VERSION).tar.bz2 package/
	if ! test -x $(Y2TOOL); then \
	    echo "$(Y2TOOL): not found."; \
	    echo "You have to install yast2-devtools to making a package"; \
	    false; \
	fi
	here=`pwd`; \
	cd $(srcdir) && for i in $(RPMNAME)*.spec.in; do \
	    newname="`echo "$$i" | sed "s/\.in$$//g"`"; \
	    $(Y2TOOL) create-spec < $$i > $$here/package/$${newname} ; \
	done

package: check-up-to-date check-tagversion check-all-packages check-textdomain package-local

TAGVERSION	 = $(Y2TOOL) tagversion

check-up-to-date check-cvs-up-to-date check-svn-up-to-date:
	if [ -d $(srcdir)/CVS ]; then \
	  cd $(srcdir) && ! cvs -q -n up 2>/dev/null | grep '^[MCAR] ';\
	else \
	  cd $(srcdir) && ! LC_ALL=C svn status --show-updates --quiet | grep -v '^Status against revision' ;\
	fi

check-tagversion:
	@if [ -d $(srcdir)/CVS ]; then \
	  cd $(srcdir) && cvs status -v VERSION | grep -w `$(TAGVERSION) -n` ;\
	else \
	  cd $(srcdir) && svn cat `$(TAGVERSION) --echourl`/VERSION; \
	fi >/dev/null; \
	[ $$? = 0 ] || ( echo "ERROR: Please run 'tagversion' first"; false )

check-parse-old:
	@if [ `find -type f -name "*.ycp" | wc -l` -gt 0 -a "$(RPMNAME)" != "yast2-core" ] ; then \
		echo "Running parseycp..." ; \
		parseycp -q -R ; \
	else \
		echo "Not running parseycp." ; \
	fi

check-parse:
	@echo "Not running parseycp."

check-all-packages:
	@if [ ! -e "$(ALL_PACKAGES)" ]; then				\
		echo ERROR: "Can't find $(ALL_PACKAGES)"; false;	\
	fi
	@if ! grep -q "^$(RPMNAME)[[:space:]]" $(ALL_PACKAGES); then		\
		echo ERROR: "$(RPMNAME) not in $(ALL_PACKAGES)"; false;	\
	fi
	@if grep -q "^$(RPMNAME)[[:space:]]\+.*?" $(ALL_PACKAGES); then	\
		echo ERROR: "$(RPMNAME) info in $(ALL_PACKAGES) contains some unknown (?) fields:";	\
		echo;							\
		grep "^$(RPMNAME)[[:space:]]\+.*?" $(ALL_PACKAGES);	\
		echo;							\
		false;							\
	fi

check-textdomain:
	$(Y2TOOL) check-textdomain $(srcdir)

stable: checkin-stable

checkin-stable: package
	$(Y2TOOL) checkin-stable


# For po/ modules
checkpo:
	test ! -d $(srcdir)/po || $(MAKE) -C po checkpo
#	test ! -d $(srcdir)/po \
#	  || { $(MAKE) -C po checkpo && $(MAKE) -C po make-pox; }
# Contents of ./SUBDIRS
SUBDIRS = agents src pofiles