SHELL = /bin/sh

VPATH = @srcdir@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = .

PACKAGE = @PACKAGE@
VERSION = @VERSION@

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include

MKDIR = $(top_srcdir)/mkinstalldirs
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

@SET_MAKE@

INSTALLED_INCLUDES = $(addprefix $(top_srcdir)/include/sane/,sane.h \
	saneopts.h)

SUBDIRS	= lib sanei backend frontend doc tools

all: all-recursive

$(PACKAGE)-$(VERSION).lsm: $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE).lsm
	( cat $(PACKAGE).lsm | \
	 sed -e "s|_DATE_|`date +%d%b%y`|g" \
	  -e "s|_VERSION_|$(VERSION)|g" \
	  -e "s|_T_S_|`find $(PACKAGE)-$(VERSION).tar.gz -printf \"%3k\"`|g"\
	  -e "s|_L_S_|`find $(PACKAGE).lsm -printf "%3k"`|g" > \
	     $(PACKAGE)-$(VERSION).lsm \
	)
lsm: $(PACKAGE)-$(VERSION).lsm

install: install-recursive
	$(MKDIR) $(includedir)/sane
	@list="$(INSTALLED_INCLUDES)"; for file in $$list; do \
	  echo installing $${file} in $(includedir)/sane...; \
	  $(INSTALL_DATA) $${file} $(includedir)/sane || exit 1; \
	done

clean: clean-recursive

distclean: clean distclean-recursive
	rm -f *~ include/*~ include/sane/*~ *.log *.bak libtool
	rm -f include/sane/config.h Makefile config.cache config.status
	rm -f japi/Makefile

depend: depend-recursive

all-recursive install-recursive clean-recursive distclean-recursive \
depend-recursive:
	for subdir in $(SUBDIRS); do		\
	  target=`echo $@ | sed s/-recursive//`; \
	  echo making $$target in $$subdir;	\
	  (cd $$subdir && $(MAKE) $$target)	\
	   || case "$(MFLAGS)" in *k*) fail=yes;; *) exit 1;; esac; \
	done && test -z "$$fail"

.PHONY: all clean depend \
	all-recursive install-recursive clean-recursive depend-recursive
