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

uninstall: uninstall-recursive
	rm -rf $(includedir)/sane

#
# Keep the .cvsignore files sorted, and use this target to do it.
#
PERL=perl
sort-cvsignore:
	for f in `find . -name .cvsignore`; do \
		$(PERL) -e 'print sort <>;' < $$f > $$f.tmptmp; \
		mv $$f.tmptmp $$f; \
	done
#
# Check to make sure only sane_ and sanei_ symbols are exported from
# the libraries
#
libcheck:
	echo "Libraries exporting 'illegal' symbols:"
	@for lib in backend/.libs/*.a; do \
	  if nm -g $$lib|grep ' T '|egrep -v ' sane_| sanei_' > /dev/null; \
	  then \
	    echo "  $$lib"; \
	  fi \
	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 uninstall-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 \
	uninstall-recursive
