SHELL = /bin/sh

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

PACKAGE = @PACKAGE@
VERSION = @VERSION@
distdir = $(PACKAGE)-$(VERSION)

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datarootdir = @datarootdir@
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@

DISTCLEAN_FILES = @DISTCLEAN_FILES@
DEPEND_RECURSIVE = @DEPEND_RECURSIVE@

@SET_MAKE@

SUBDIRS	= include lib sanei backend frontend tools doc po

DISTFILES = AUTHORS COPYING ChangeLog ChangeLog-1.0.0 ChangeLog-1.0.1 \
  ChangeLog-1.0.2 ChangeLog-1.0.3 ChangeLog-1.0.4 ChangeLog-1.0.5 \
  ChangeLog-1.0.6 ChangeLog-1.0.7 ChangeLog-1.0.8 ChangeLog-1.0.9 \
  ChangeLog-1.0.10 ChangeLog-1.0.12 ChangeLog-1.0.13 ChangeLog-1.0.14 \
  ChangeLog-1.0.15 ChangeLog-1.0.16 ChangeLog-1.0.17 ChangeLog-1.0.18 \
  LICENSE Makefile.in NEWS \
  PROBLEMS PROJECTS README README.aix README.beos README.darwin README.djpeg \
  README.freebsd \
  README.hp-ux README.linux README.netbsd \
  README.openbsd README.os2 README.solaris README.unixware2 README.unixware7 \
  README.windows README.zeta \
  acinclude.m4 aclocal.m4 \
  config.guess config.sub configure \
  configure.in install-sh ltmain.sh mkinstalldirs \
  sane-backends.lsm

.PHONY: all all-recursive clean clean-recursive depend \
  depend-recursive dist install install-recursive libcheck lsm \
  sane-backends sort-cvsignore uninstall uninstall-recursive

all: $(DEPEND_RECURSIVE) 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 \"%4k\"`|g"\
	  -e "s|_L_S_|`find $(PACKAGE).lsm -printf "%4k"`|g" > \
	     $(PACKAGE)-$(VERSION).lsm \
	)

lsm: $(PACKAGE)-$(VERSION).lsm

install: install-recursive

uninstall: uninstall-recursive

#
# 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 \
	  lines=`nm -g $$lib|grep '\( T \)\|\( D \)'|egrep -v ' sane_| sanei_'` ; \
	  if test -n "$$lines" ; \
	  then \
	    echo -e "*** $$lib:\n$$lines"; \
	  fi \
	done
	@echo "Libraries exporting 'non-standard sane_*' symbols:"
	@for lib in backend/.libs/*.a; do \
	  lines=`nm -g $$lib|grep '\( T \)\|\( D \)'|egrep ' sane_' | egrep -v 'sane_.*init|sane_.*exit|sane_.*get_devices|sane_.*open|sane_.*close|sane_.*get_option_descriptor|sane_.*control_option|sane_.*get_parameters|sane_.*start|sane_.*read|sane_.*cancel|sane_.*set_io_mode|sane_.*get_select_fd|sane_strstatus'` ; \
	  if test -n "$$lines" ; \
	  then \
	    echo -e "*** $$lib:\n$$lines"; \
	  fi \
	done

clean: clean-recursive

distclean: clean distclean-recursive
	rm -f $(DISTCLEAN_FILES)
	rm -f Makefile config.cache config.status libtool *.tar.gz 
	rm -f sane-backends-*.lsm
	rm -f $(distdir).tar.gz.md5
	rm -f japi/Makefile testsuite/Makefile
	rm -f japi/*.class japi/*.h
	rm -rf japi/.libs 
	rm -f $(addprefix japi/,$(DISTCLEAN_FILES))
	rm -f $(addprefix testsuite/,$(DISTCLEAN_FILES))
	rm -rf $(distdir)
	rm -f TAGS
	rm -rf autom4te.cache

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"

dist: $(DISTFILES)
	rm -fr $(distdir)
	$(MKDIR) $(distdir)
	for file in $(DISTFILES); do \
	  ln $$file $(distdir) 2>/dev/null || cp -p $$file $(distdir); \
	done
	for subdir in $(SUBDIRS) japi testsuite ; do \
	  mkdir $(distdir)/$$subdir || exit 1; \
	  chmod 777 $(distdir)/$$subdir; \
	  (cd $$subdir && $(MAKE) $@) || exit 1; \
	done
	tar chzf $(distdir).tar.gz $(distdir)
	rm -fr $(distdir)

$(PACKAGE)-$(VERSION).tar.gz: dist

md5: dist
	md5sum $(distdir).tar.gz > $(distdir).tar.gz.md5

sane-backends: dist lsm md5

etags:
	etags */*.[ch] */*/*.h
