SHELL = /bin/sh


srcdir = .
top_srcdir = ..
top_builddir = ..
subdir = tools

PACKAGE = sane-backends
VERSION = 1.0.19
distdir = $(top_srcdir)/$(PACKAGE)-$(VERSION)

prefix = /usr/local
exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
sbindir = ${exec_prefix}/sbin
libexecdir = ${exec_prefix}/libexec
datarootdir = ${prefix}/share
datadir = ${datarootdir}
sysconfdir = ${prefix}/etc
sharedstatedir = ${prefix}/com
localstatedir = ${prefix}/var
libdir = ${exec_prefix}/lib
infodir = ${datarootdir}/info
mandir = ${datarootdir}/man
includedir = ${prefix}/include
oldincludedir = /usr/include
configdir = ${sysconfdir}/sane.d

MKDIR = $(top_srcdir)/mkinstalldirs
INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644
RANLIB = ranlib

CC = gcc
INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include
CPPFLAGS =  -D_REENTRANT -DPATH_SANE_CONFIG_DIR=$(configdir) 	  -DPATH_SANE_DATA_DIR=$(datadir) 	  -DPATH_SANE_LOCK_DIR=$(locksanedir) 	  -DV_MAJOR=1 -DV_MINOR=0
CFLAGS = -march=i486 -mtune=i686 -O2 -pipe -W -Wall
LDFLAGS = 
LIBS = -lusb -lpthread -lm  -ljpeg -ltiff
DEFS = -DHAVE_CONFIG_H

LIBTOOL = ../libtool
MCOMP	= --mode=compile
MLINK	= --mode=link
MINST	= --mode=install

COMPILE = $(CC) -c $(CFLAGS) $(DEFS) $(INCLUDES) $(CPPFLAGS)
LINK = $(CC) $(LDFLAGS) -o $@

DISTCLEAN_FILES = *~ .*~ *.log *.bak *.old *.orig *.out *.rej "\#"* ".\#"*



ifeq (no,no)
HOTPLUG_SCRIPTS = hotplug/libsane.usermap hotplug-ng/libsane.db \
		  udev/libsane.rules hal/libsane.fdi
else
HOTPLUG_SCRIPTS =
endif

DESTINATIONS = sane-find-scanner sane-config umax_pp gamma4scanimage \
	       sane-desc $(HOTPLUG_SCRIPTS)

EXTRA = sane_strstatus.lo ../sanei/sanei_init_debug.lo \
	../sanei/sanei_config.lo ../sanei/sanei_config2.lo \
	../lib/usleep.lo ../lib/strndup.lo

LIBSANEI = ../sanei/libsanei.a
# Library routines that should be part of libc, but aren't on some systems:
LIBLIB = ../lib/liblib.a

DISTFILES = Makefile.in RenSaneDlls.cmd README libtool-get-dll-ext     \
	mustek600iin-off.c sane-config.in sane-desc.c check-usb-chip.c \
	sane-find-scanner.c umax_pp.c xerox gamma4scanimage.c check-po.awk

SUBDIRS = hotplug hotplug-ng udev hal

.PHONY: all clean depend dist distclean install uninstall

.c.o:
	$(COMPILE) $<

%.lo:	%.c
	@$(LIBTOOL) $(MCOMP) $(COMPILE) -DLIBDIR=$(libdir) $<

all:	$(DESTINATIONS)

install: sane-config sane-find-scanner gamma4scanimage
	$(INSTALL_SCRIPT) sane-config $(DESTDIR)$(bindir)/sane-config
	$(INSTALL_PROGRAM) sane-find-scanner $(DESTDIR)$(bindir)/sane-find-scanner
	$(INSTALL_PROGRAM) gamma4scanimage $(DESTDIR)$(bindir)/gamma4scanimage

uninstall: 
	rm -f $(bindir)/sane-config $(bindir)/sane-find-scanner $(bindir)/gamma4scanimage

sane-config: sane-config.in $(top_builddir)/config.status 
	cd $(top_builddir) \
          && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status

sane-find-scanner: sane-find-scanner.o check-usb-chip.o ../backend/sane_strstatus.lo \
	../sanei/sanei_scsi.lo ../sanei/sanei_usb.lo ../sanei/sanei_init_debug.lo \
	../sanei/sanei_config.lo
	@$(LIBTOOL) $(MLINK) $(LINK) sane-find-scanner.o check-usb-chip.o \
	  ../backend/sane_strstatus.lo $(LIBSANEI) $(LIBLIB) $(LIBS)

gamma4scanimage: gamma4scanimage.o
	@$(LIBTOOL) $(MLINK) $(LINK) gamma4scanimage.o -lm

../backend/umax_pp_low.o: ../backend/umax_pp_low.c 
	$(COMPILE) ../backend/umax_pp_low.c -o ../backend/umax_pp_low.o \
	  -DBACKEND_NAME=umax_pp_low

umax_pp: umax_pp.o ../backend/umax_pp_low.o
	@$(LIBTOOL) $(MLINK) $(LINK) umax_pp.o ../backend/umax_pp_low.o \
	   $(LIBSANEI) $(LIBLIB) $(LIBS)
sane-desc: sane-desc.o
	@$(LIBTOOL) $(MLINK) $(LINK) sane-desc.o $(LIBSANEI) $(LIBLIB)

hotplug/libsane.usermap: $(wildcard ${top_srcdir}/doc/descriptions/*.desc) $(wildcard ${top_srcdir}/doc/descriptions-external/*.desc) sane-desc
	@./sane-desc -m usermap -s ${top_srcdir}/doc/descriptions:${top_srcdir}/doc/descriptions-external \
	   -d 1 > $@

hotplug-ng/libsane.db: $(wildcard ${top_srcdir}/doc/descriptions/*.desc) $(wildcard ${top_srcdir}/doc/descriptions-external/*.desc) sane-desc
	@./sane-desc -m db -s ${top_srcdir}/doc/descriptions:${top_srcdir}/doc/descriptions-external \
	   -d 0 > $@

udev/libsane.rules: $(wildcard ${top_srcdir}/doc/descriptions/*.desc) $(wildcard ${top_srcdir}/doc/descriptions-external/*.desc) sane-desc
	@./sane-desc -m udev -s ${top_srcdir}/doc/descriptions:${top_srcdir}/doc/descriptions-external \
	   -d 0 > $@

hal/libsane.fdi: $(wildcard ${top_srcdir}/doc/descriptions/*.desc) $(wildcard ${top_srcdir}/doc/descriptions-external/*.desc) sane-desc
	@./sane-desc -m hal -s ${top_srcdir}/doc/descriptions:${top_srcdir}/doc/descriptions-external \
	   -d 0 > $@


depend:
	makedepend $(INCLUDES) *.c 2>/dev/null

clean:
	rm -f *.lo *.o *.la
	find . -type l -name \*-s.c | xargs rm -f
	rm -rf .libs
	rm -f hotplug/libsane.usermap hotplug-ng/libsane.db hotplug/libsane.rules

distclean: clean
	rm -f Makefile $(DESTINATIONS) mustek600iin-off sane-desc
	rm -f $(DISTCLEAN_FILES)
	for subdir in $(SUBDIRS) ; do \
	  ( cd $$subdir ; rm -f $(DISTCLEAN_FILES) ); \
	done

dist: $(DISTFILES)
	for subdir in $(SUBDIRS) ; do \
	  $(MKDIR) $(distdir)/tools/$${subdir} ; \
	  for file in $${subdir}/* ; do \
	    ln $$file $(distdir)/tools/$${subdir} 2> /dev/null \
	      || cp -p $$file $(distdir)/tools/$${subdir} \
	      || echo "ignoring: $$file" ; \
	  done ; \
	done
	for file in $(DISTFILES); do \
	  ln $$file $(distdir)/tools 2> /dev/null \
	    || cp -p $$file $(distdir)/tools ; \
	done

