SHELL = /bin/sh


srcdir = .
top_srcdir = ..
top_builddir = ..

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_DATA = ${INSTALL} -m 644

CC = gcc
INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include \
	 -I/usr/local/include
DEFS = -DHAVE_CONFIG_H
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

LIBTOOL = ../libtool
MINST	= --mode=install
MLINK	= --mode=link
SANED	= saned

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

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



BINPROGS = scanimage # tstbackend
SBINPROGS = $(SANED)
PROGRAMS = $(BINPROGS) $(SBINPROGS)
TESTPROGRAMS = test
LIBLIB = ../lib/liblib.a
LIBSANE = ../backend/libsane.la
LIBSANEI = ../sanei/libsanei.a

SCAN_OBJS = scanimage.o stiff.o

DISTFILES = Makefile.in saned.c scanimage.c stiff.c stiff.h test.c tstbackend.c

.PHONY: all clean depend dist distclean install uninstall

.c.o:
	$(COMPILE) $<

all: $(PROGRAMS)

install: $(PROGRAMS)
	$(MKDIR) $(DESTDIR)$(bindir) $(DESTDIR)$(sbindir) $(DESTDIR)$(datadir)
	@for program in $(BINPROGS); do \
	  $(LIBTOOL) $(MINST) $(INSTALL_PROGRAM) $${program} \
	    $(DESTDIR)$(bindir)/$${program}; \
	done
	@for program in $(SBINPROGS); do \
	  $(LIBTOOL) $(MINST) $(INSTALL_PROGRAM) $${program} \
	    $(DESTDIR)$(sbindir)/$${program}; \
	done

uninstall:
	@for program in $(BINPROGS); do \
	  rm -f $(bindir)/$${program}; \
	done
	@for program in $(SBINPROGS); do \
	  rm -f $(sbindir)/$${program}; \
	done

test: test.o $(LIBSANE) $(LIBLIB)
	@$(LIBTOOL) $(MLINK) $(LINK) test.o $(LIBLIB) $(LIBSANE) $(LIBS)

saned: saned.o $(LIBSANEI) $(LIBSANE) $(LIBLIB)
	@$(LIBTOOL) $(MLINK) $(LINK) saned.o $(LIBSANEI) $(LIBLIB) $(LIBSANE)  \
		$(LIBS)

scanimage: $(SCAN_OBJS) $(LIBSANE) $(LIBLIB)
	@$(LIBTOOL) $(MLINK) $(LINK) $(SCAN_OBJS) $(LIBLIB) $(LIBSANE)  $(LIBS)

# tstbackend is not compiled by default. 
# To compile it, add tstbackend to BINPROGS.
tstbackend: tstbackend.o $(LIBSANE) $(LIBLIB)
	@$(LIBTOOL) $(MLINK) $(LINK) tstbackend.o $(LIBLIB) $(LIBSANE) $(LIBS)

clean:
	rm -f *.o tstbackend
	rm -rf .libs

distclean: clean
	rm -f $(DISTCLEAN_FILES)
	rm -f Makefile $(PROGRAMS) $(TESTPROGRAMS)

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

dist: $(DISTFILES)
	for file in $(DISTFILES); do \
	  ln $$file $(distdir)/frontend 2> /dev/null \
	    || cp -p $$file $(distdir)/frontend ; \
	done

