UNAME := $(shell uname)
MACH := $(shell uname -m | sed 's/i.86/x86_32/')
ifeq ($(UNAME),SunOS)
    EUID := $(shell /usr/xpg4/bin/id -u)
    SHELL=bash
    CC=gcc
else
    EUID := $(shell id -u)
endif
SYSNAME := $(shell uname -n)

# No version number yet...
VERSION=0.0

# Installation prefix...
PREFIX=/usr/local
PREFIX=/usr

# Pathnames for this package...
BIN=$(PREFIX)/bin
SHAREZJS=$(PREFIX)/share/foo2zjs
SHAREOAK=$(PREFIX)/share/foo2oak
SHAREHP=$(PREFIX)/share/foo2hp
SHAREXQX=$(PREFIX)/share/foo2xqx
SHARELAVA=$(PREFIX)/share/foo2lava
SHAREQPDL=$(PREFIX)/share/foo2qpdl
SHARESLX=$(PREFIX)/share/foo2slx
MANDIR=$(PREFIX)/share/man
DOCDIR=$(PREFIX)/share/doc/foo2zjs/
INSTALL=install

# Pathnames for referenced packages...
FOODB=/usr/share/foomatic/db/source

# User ID's
LPuid=-olp
LPgid=-glp
ifeq ($(UNAME),Darwin)
    LPuid=-oroot
    LPgid=-gwheel
endif
ifeq ($(UNAME),FreeBSD)
    LPuid=-oroot
    LPgid=-gwheel
endif
ifeq ($(UNAME),OpenBSD)
    LPuid=-oroot
    LPgid=-gwheel
endif
ifeq ($(UNAME),SunOS)
    LPuid=-oroot
    LPgid=-glp
    INSTALL=/usr/ucb/install
endif
# If we aren't root, don't try to set ownership
ifneq ($(EUID),0)
    LPuid=
    LPgid=
endif

# Definition of modtime()
MODTIME= date -d "1/1/1970 utc + `stat -t $$1 | cut -f14 -d' '` seconds" "+%a %b %d %T %Y"
ifeq ($(UNAME),FreeBSD)
    MODTIME= stat -f "%Sm" -t "%a %b %d %T %Y" $$1
endif
ifeq ($(UNAME),OpenBSD)
    MODTIME= stat -f "%Sm" -t "%a %b %d %T %Y" $$1
endif
ifeq ($(UNAME),Darwin)
    MODTIME= stat -f "%Sm" -t "%a %b %d %T %Y" $$1
endif
ifeq ($(UNAME),SunOS)
    MODTIME= `ls -e $$1 | cut -c42-61`
endif

#
# Files for tarball
#
NULL=
WEBFILES=	\
		foo2zjs.html.in \
		style.css \
		archzjs.fig \
		2300.png \
		2430.png \
		1020.png \
		foo2oak.html.in \
		archoak.fig \
		1500.gif \
		foo2hp.html.in \
		archhp.fig \
		2600.gif \
		foo2xqx.html.in \
		archxqx.fig \
		m1005.gif \
		foo2lava.html.in \
		archlava.fig \
		2530.gif \
		foo2qpdl.html.in \
		archqplp.fig \
		foo2slx.html.in \
		archslx.fig \
		c500n.png \
		$(NULL)
	
FILES	=	\
		README \
		README.in \
		INSTALL \
		INSTALL.in \
		INSTALL.osx \
		INSTALL.usb \
		COPYING \
		ChangeLog \
		Makefile \
		foo2zjs.c \
		foo2zjs.1in \
		jbig.c \
		jbig.h \
		jbig_tab.c \
		zjsdecode.c \
		zjsdecode.1in \
		zjs.h \
		foo2hp.c \
		foo2hp.1in \
		foo2xqx.c \
		foo2xqx.1in \
		foo2lava.c \
		foo2lava.1in \
		foo2qpdl.c \
		foo2qpdl.1in \
		foo2slx.c \
		foo2slx.1in \
		cups.h \
		xqx.h \
		xqxdecode.c \
		xqxdecode.1in \
		lavadecode.c \
		lavadecode.1in \
		qpdl.h \
		qpdldecode.c \
		qpdldecode.1in \
		opldecode.c \
		opldecode.1in \
		slx.h \
		slxdecode.c \
		slxdecode.1in \
		foo2zjs-wrapper.in \
		foo2zjs-wrapper.1in \
		foo2hp2600-wrapper.in \
		foo2hp2600-wrapper.1in \
		foo2xqx-wrapper.in \
		foo2xqx-wrapper.1in \
		foo2lava-wrapper.in \
		foo2lava-wrapper.1in \
		foo2qpdl-wrapper.in \
		foo2qpdl-wrapper.1in \
		foo2slx-wrapper.in \
		foo2slx-wrapper.1in \
		gamma.ps \
		gamma-lookup.ps \
		align.ps \
		testpage.ps \
		foomatic-db/*/*.xml \
		foomatic-test \
		getweb.in \
		icc2ps/*.[ch] \
		icc2ps/Makefile \
		icc2ps/AUTHORS \
		icc2ps/COPYING \
		icc2ps/README \
		icc2ps/README.foo2zjs \
		PPD/*.ppd \
		crd/zjs/*.crd \
		crd/zjs/*.ps \
		crd/qpdl/*cms* \
		crd/qpdl/*.ps \
		arm2hpdl.c \
		usb_printerid.c \
		hplj1000 \
		hplj10xx.rules \
		msexpand \
		oak.h \
		foo2oak.c \
		oakdecode.c \
		foo2oak.1in \
		foo2oak-wrapper.in \
		foo2oak-wrapper.1in \
		oakdecode.1in \
		okidecode.c \
		oki.h \
		c5200mono.prn \
		foo2zjs-pstops.sh \
		foo2zjs-pstops.1in \
		hplj1020.desktop \
		hplj1020_icon.png \
		hplj1020_icon.gif \
		hplj10xx_gui.tcl \
		$(NULL)

# hpclj2600n-0.icm km2430_0.icm km2430_1.icm km2430_2.icm samclp300-0.icm
# sihp1000.img sihp1005.img sihp1020.img sihp1018.img
# sihpP1005.img sihpP1006.img sihpP1505.img

# Programs and libraries
PROGS=		foo2zjs zjsdecode arm2hpdl foo2hp foo2xqx xqxdecode
PROGS+=		foo2lava lavadecode foo2qpdl qpdldecode opldecode
PROGS+=		foo2oak oakdecode
PROGS+=		foo2slx slxdecode
ifeq ($(SYSNAME),amd.rkkda.org)
    PROGS+=	okidecode
endif
SHELLS=		foo2zjs-wrapper foo2oak-wrapper foo2hp2600-wrapper \
		foo2xqx-wrapper foo2lava-wrapper foo2qpdl-wrapper \
		foo2slx-wrapper
SHELLS+=	foo2zjs-pstops
MANPAGES=	foo2zjs-wrapper.1 foo2zjs.1 zjsdecode.1
MANPAGES+=	foo2oak-wrapper.1 foo2oak.1 oakdecode.1
MANPAGES+=	foo2hp2600-wrapper.1 foo2hp.1
MANPAGES+=	foo2xqx-wrapper.1 foo2xqx.1 xqxdecode.1
MANPAGES+=	foo2lava-wrapper.1 foo2lava.1 lavadecode.1 opldecode.1
MANPAGES+=	foo2qpdl-wrapper.1 foo2qpdl.1 qpdldecode.1
MANPAGES+=	foo2slx-wrapper.1 foo2slx.1 slxdecode.1
LIBJBG	=	jbig.o jbig_tab.o
BINPROGS=

ifeq ($(UNAME),Linux)
	BINPROGS += usb_printerid
endif

# Compiler flags
CFLAGS +=	-O2 -Wall
#CFLAGS +=	-g

#
# Rules to create test documents
#
GX=10200
GY=6600
GXR=1200
GYR=600
GSOPTS=	-q -dBATCH -dSAFER -dQUIET -dNOPAUSE -sPAPERSIZE=letter -r$(GXR)x$(GYR)
JBGOPTS=-m 16 -d 0 -p 92	# Equivalent options for pbmtojbg

.SUFFIXES: .ps .pbm .pgm .pgm2 .ppm .ppm2 .zjs .cmyk .pksm .zc .zm .jbg \
	   .cups .cupm .1 .1in .fig .gif .xqx .lava .qpdl .slx

.fig.gif:
	fig2dev -L gif $*.fig | giftrans -t "#ffffff" -o $*.gif
	# fig2dev -L ppm  $*.fig | pnmquant -fs 256 \
	    | ppmtogif -transparent rgb:ff/ff/ff >$*.gif

.ps.cups:
	gs $(GSOPTS) -r600x600 \
	    -dcupsColorSpace=6 -dcupsBitsPerColor=2 -dcupsColorOrder=2 \
	    -sDEVICE=cups -sOutputFile=$*.cups $*.ps

.ps.cupm:
	gs $(GSOPTS) -r600x600 \
	    -dcupsColorSpace=3 -dcupsBitsPerColor=2 -dcupsColorOrder=2 \
	    -sDEVICE=cups -sOutputFile=$*.cupm $*.ps

.ps.pbm:
	gs $(GSOPTS) -sDEVICE=pbmraw -sOutputFile=$*.pbm $*.ps

.ps.ppm:
	gs $(GSOPTS) -sDEVICE=ppmraw -sOutputFile=$*.ppm $*.ps

.ps.pgm:
	gs $(GSOPTS) -sDEVICE=pgmraw -sOutputFile=- $*.ps \
	| pnmdepth 3 > $*.pgm

.ps.pgm2:
	gs.rick $(GSOPTS) -sDEVICE=pgmraw2 -sOutputFile=$*.pgm2 $*.ps

.ps.cmyk:
	gs $(GSOPTS) -sDEVICE=bitcmyk -sOutputFile=$*.cmyk $*.ps

.ps.pksm:
	gs $(GSOPTS) -sDEVICE=pksmraw -sOutputFile=$*.pksm $*.ps

.ps.zc:
	gs $(GSOPTS) -sDEVICE=bitcmyk -sOutputFile=- - < $*.ps \
	| ./foo2zjs -r1200x600 -g10200x6600 -p1 >$*.zc

.ps.zm:
	gs $(GSOPTS) -sDEVICE=pbmraw -sOutputFile=- - < $*.ps \
	| ./foo2zjs -r1200x600 -g10200x6600 -p1 >$*.zm

.pbm.zjs:
	./foo2zjs < $*.pbm > $*.zjs

.cmyk.zjs:
	./foo2zjs < $*.cmyk > $*.zjs

.pksm.zjs:
	./foo2zjs < $*.pksm > $*.zjs

.pbm.xqx:
	./foo2xqx < $*.pbm > $*.xqx

.pbm.qpdl:
	./foo2qpdl < $*.pbm > $*.qpdl

.pbm.slx:
	./foo2slx < $*.pbm > $*.slx

#
# The usual build rules
#
all:	all-test $(PROGS) $(BINPROGS) $(SHELLS) getweb all-icc2ps man doc \
	all-done

all-test:
	#
	# Dependencies...
	#
	@if ! type $(CC) >/dev/null 2>&1; then \
	    echo "      ***"; \
	    echo "      *** Error: $(CC) is not installed!"; \
	    echo "      ***"; \
	    echo "      *** Install Software Development (gcc) package"; \
	    echo "      ***"; \
	    exit 1; \
	fi
	@if ! test -f /usr/include/stdio.h; then \
	    echo "      ***"; \
	    echo "      *** Error: /usr/include/stdio.h is not installed!"; \
	    echo "      ***"; \
	    echo "      *** Install Software Development (gcc) package"; \
	    echo "      *** for Ubuntu: sudo apt-get install build-essential"; \
	    echo "      ***"; \
	    exit 1; \
	fi
	@if ! type gs >/dev/null 2>&1; then \
	    echo "      ***"; \
	    echo "      *** Error: gs is not installed!"; \
	    echo "      ***"; \
	    echo "      *** Install ghostscript (gs) package"; \
	    echo "      ***"; \
	    exit 1; \
	fi
	# ... OK!
	#

all-done:
	@echo
	@echo "It is possible that certain products which can be built using this"
	@echo "software module might form inventions protected by patent rights in"
	@echo "some countries (e.g., by patents about arithmetic coding algorithms"
	@echo "owned by IBM and AT&T in the USA). Provision of this software by the"
	@echo "author does NOT include any licences for any patents. In those"
	@echo "countries where a patent licence is required for certain applications"
	@echo "of this software module, you will have to obtain such a licence"
	@echo "yourself."


foo2zjs: foo2zjs.o $(LIBJBG)
	$(CC) $(CFLAGS) -o $@ foo2zjs.o $(LIBJBG)

foo2hp: foo2hp.o $(LIBJBG)
	# $(CC) $(CFLAGS) -o $@ foo2hp.o $(LIBJBG) /usr/local/lib/libdmalloc.a
	$(CC) $(CFLAGS) -o $@ foo2hp.o $(LIBJBG)

foo2xqx: foo2xqx.o $(LIBJBG)
	$(CC) $(CFLAGS) -o $@ foo2xqx.o $(LIBJBG)

foo2lava: foo2lava.o $(LIBJBG)
	$(CC) $(CFLAGS) -o $@ foo2lava.o $(LIBJBG)

foo2qpdl: foo2qpdl.o $(LIBJBG)
	$(CC) $(CFLAGS) -o $@ foo2qpdl.o $(LIBJBG)

foo2oak: foo2oak.o $(LIBJBG)
	$(CC) $(CFLAGS) -o $@ foo2oak.o $(LIBJBG)

foo2slx: foo2slx.o $(LIBJBG)
	$(CC) $(CFLAGS) -o $@ foo2slx.o $(LIBJBG)


foo2zjs-wrapper: foo2zjs-wrapper.in Makefile
	[ ! -f $@ ] || chmod +w $@
	sed < $@.in > $@ \
	    -e 's@^PREFIX=.*@PREFIX=$(PREFIX)@' || (rm -f $@ && exit 1)
	chmod 555 $@

foo2hp2600-wrapper: foo2hp2600-wrapper.in Makefile
	[ ! -f $@ ] || chmod +w $@
	sed < $@.in > $@ \
	    -e 's@^PREFIX=.*@PREFIX=$(PREFIX)@' || (rm -f $@ && exit 1)
	chmod 555 $@

foo2xqx-wrapper: foo2xqx-wrapper.in Makefile
	[ ! -f $@ ] || chmod +w $@
	sed < $@.in > $@ \
	    -e 's@^PREFIX=.*@PREFIX=$(PREFIX)@' || (rm -f $@ && exit 1)
	chmod 555 $@

foo2lava-wrapper: foo2lava-wrapper.in Makefile
	[ ! -f $@ ] || chmod +w $@
	sed < $@.in > $@ \
	    -e 's@^PREFIX=.*@PREFIX=$(PREFIX)@' || (rm -f $@ && exit 1)
	chmod 555 $@

foo2qpdl-wrapper: foo2qpdl-wrapper.in Makefile
	[ ! -f $@ ] || chmod +w $@
	sed < $@.in > $@ \
	    -e 's@^PREFIX=.*@PREFIX=$(PREFIX)@' || (rm -f $@ && exit 1)
	chmod 555 $@

foo2oak-wrapper: foo2oak-wrapper.in Makefile
	[ ! -f $@ ] || chmod +w $@
	sed < $@.in > $@ \
	    -e 's@^PREFIX=.*@PREFIX=$(PREFIX)@' || (rm -f $@ && exit 1)
	chmod 555 $@

foo2slx-wrapper: foo2slx-wrapper.in Makefile
	[ ! -f $@ ] || chmod +w $@
	sed < $@.in > $@ \
	    -e 's@^PREFIX=.*@PREFIX=$(PREFIX)@' || (rm -f $@ && exit 1)
	chmod 555 $@


getweb: getweb.in Makefile
	[ ! -f $@ ] || chmod +w $@
	sed < $@.in > $@ \
	    -e "s@\$${URLZJS}@$(URLZJS)@" \
	    -e 's@^PREFIX=.*@PREFIX=$(PREFIX)@' || (rm -f $@ && exit 1)
	chmod 555 $@

all-icc2ps:
	cd icc2ps; $(MAKE) all

ok: ok.o $(LIBJBG)
	$(CC) $(CFLAGS) ok.o $(LIBJBG) -o $@

zjsdecode: zjsdecode.o $(LIBJBG)
	$(CC) $(CFLAGS) zjsdecode.o $(LIBJBG) -o $@

okidecode: okidecode.o $(LIBJBG)
	$(CC) $(CFLAGS) okidecode.o $(LIBJBG) -o $@

splcdecode: splcdecode.o $(LIBJBG)
	$(CC) $(CFLAGS) splcdecode.o $(LIBJBG) -lz -o $@

xqxdecode: xqxdecode.o $(LIBJBG)
	$(CC) $(CFLAGS) xqxdecode.o $(LIBJBG) -o $@

lavadecode: lavadecode.o $(LIBJBG)
	$(CC) $(CFLAGS) lavadecode.o $(LIBJBG) -o $@

qpdldecode: qpdldecode.o $(LIBJBG)
	$(CC) $(CFLAGS) qpdldecode.o $(LIBJBG) -o $@

opldecode: opldecode.o $(LIBJBG)
	$(CC) $(CFLAGS) -g opldecode.o $(LIBJBG) -o $@

oakdecode: oakdecode.o $(LIBJBG)
	$(CC) $(CFLAGS) -g oakdecode.o $(LIBJBG) -o $@

slxdecode: slxdecode.o $(LIBJBG)
	$(CC) $(CFLAGS) slxdecode.o $(LIBJBG) -o $@

#
# Installation rules
#
install: all install-test install-prog install-icc2ps install-extra \
	    install-crd install-foo install-ppd \
	    install-gui install-desktop \
	    install-man install-doc
	#
	# If you use CUPS, then restart the spooler:
	#	make cups
	#
	# Now use your printer configuration GUI to create a new printer.
	#
	# On Redhat 7.2/7.3/8.0/9.0 and Fedora Core 1-5, run "printconf-gui".
	# On Fedora Core 6 and Fedora 7/8, run "system-config-printer".
	# On Mandrake, run "printerdrake"
	# On Suse 9.x/10.x, run "yast"
	# On Ubuntu 5.10/6.06/6.10/7.04, run "gnome-cups-manager"
	# On Ubuntu 7.10, run "system-config-printer".

install-test:
	#
	# Installation Dependencies...
	#
	@if [ -f /usr/local/libexec/cups/filter/foomatic-rip ]; then \
	    : ; \
	elif [ -f /usr/lib/lp/bin/foomatic-rip ]; then \
	    : ; \
	elif ! type foomatic-rip >/dev/null 2>&1; then \
	    echo "      ***"; \
	    echo "      *** Error: foomatic-rip is not installed!"; \
	    echo "      ***"; \
	    echo "      *** Install foomatic package(s) for your OS"; \
	    echo "      ***"; \
	    exit 1; \
	fi
	# ... OK!
	#
    

UDEVBIN=/bin/

install-prog:
	#
	# Install driver, wrapper, and development tools
	#
	$(INSTALL) -c $(PROGS) $(SHELLS) $(BIN)/
	if [ "$(BINPROGS)" != "" ]; then \
	    $(INSTALL) -c $(BINPROGS) $(UDEVBIN); \
	fi
	#
	# Install gamma correction files.  These are just templates,
	# and don't actually do anything right now.  If anybody wants
	# to tune them or point me at a process for doing that, please...
	#
	$(INSTALL) -d $(SHAREZJS)/
	$(INSTALL) -c -m 644 gamma.ps $(SHAREZJS)/
	$(INSTALL) -c -m 644 gamma-lookup.ps $(SHAREZJS)/
	$(INSTALL) -d $(SHAREOAK)/
	$(INSTALL) -d $(SHAREHP)/
	$(INSTALL) -d $(SHAREXQX)/
	$(INSTALL) -d $(SHARELAVA)/

install-foo:
	#
	# Remove obsolete foomatic database files from previous versions
	#
	rm -f $(FOODB)/opt/foo2zjs-Media.xml
	rm -f $(FOODB)/opt/foo2zjs-PaperSize.xml
	rm -f $(FOODB)/opt/foo2zjs-Source.xml
	rm -f $(FOODB)/opt/foo2zjs-DitherPPI.xml
	#
	# Install current database files
	#
	@if [ -d $(FOODB) ]; then \
	    for dir in driver printer opt; do \
		echo install -m 644 foomatic-db/$$dir/*.xml $(FOODB)/$$dir/; \
		$(INSTALL) -c -m 644 foomatic-db/$$dir/*.xml $(FOODB)/$$dir/; \
	    done \
	else \
	    echo "***"; \
	    echo "*** WARNING! You don't have directory $(FOODB)/"; \
	    echo "*** If you want support for foomatic printer configuration,";\
	    echo "*** then you will have to manually install these files..."; \
	    echo "***"; \
	    ls foomatic-db/*/*.xml | sed 's/^/	/'; \
	    echo "***"; \
	    echo "*** ... wherever foomatic is stashed on your machine."; \
	    echo "***"; \
	fi
	#
	# Clear foomatic cache and rebuild database if needed
	#
	rm -rf /var/cache/foomatic/*/*
	rm -f /var/cache/foomatic/printconf.pickle
	if [ -d /var/cache/foomatic/compiled ]; then \
	    cd /var/cache/foomatic/compiled; \
	    foomatic-combo-xml -O >overview.xml; \
	fi

install-icc2ps:
	#
	# Install ICM to Postscript file conversion utility
	#
	cd icc2ps; $(MAKE) PREFIX=$(PREFIX) install

install-crd:
	#
	# Install prebuilt CRD files (from m2300w project)
	#
	$(INSTALL) -d $(SHAREZJS)/
	$(INSTALL) $(LPuid) $(LPgid) -m 775 -d $(SHAREZJS)/crd/
	for i in crd/zjs/*.*; do \
	    $(INSTALL) -c -m 644 $$i $(SHAREZJS)/crd/; \
	done
	#
	# Install prebuilt CRD files for CLP-300/CLP-600
	#
	$(INSTALL) -d $(SHAREQPDL)/
	$(INSTALL) $(LPuid) $(LPgid) -m 775 -d $(SHAREQPDL)/crd/
	for i in crd/qpdl/*cms* crd/qpdl/*.ps; do \
	    $(INSTALL) -c -m 644 $$i $(SHAREQPDL)/crd/; \
	done

install-psfiles:
	#
	# Install prebuilt psfiles files (from m2300w project)
	#
	$(INSTALL) -d $(SHAREHP)/
	$(INSTALL) $(LPuid) $(LPgid) -m 775 -d $(SHAREHP)/psfiles/
	for i in psfiles/*.*; do \
	    $(INSTALL) -c -m 644 $$i $(SHAREHP)/psfiles/; \
	done

install-extra:
	#
	# Install extra files (ICM and firmware), if any exist here.
	#
	# Get files from the printer manufacturer, i.e. www.minolta-qms.com,
	# or use the "./getweb" convenience script.
	#
	$(INSTALL) -d $(SHAREZJS)/
	# foo2zjs ICM files (if any)
	$(INSTALL) $(LPuid) $(LPgid) -m 775 -d $(SHAREZJS)/icm/
	for i in DL*.icm CP*.icm km2430*.icm; do \
	    if [ -f $$i ]; then \
		$(INSTALL) -c -m 644 $$i $(SHAREZJS)/icm/; \
	    fi; \
	done
	# foo2zjs Firmware files (if any)
	$(INSTALL) $(LPuid) $(LPgid) -m 775 -d $(SHAREZJS)/firmware/
	for i in sihp1*.img; do \
	    if [ -f $$i ]; then \
		base=`basename $$i .img`; \
		./arm2hpdl $$i >$$base.dl; \
		$(INSTALL) -c -m 644 $$base.dl $(SHAREZJS)/firmware/; \
	    fi; \
	done
	# foo2xqx Firmware files (if any)
	$(INSTALL) $(LPuid) $(LPgid) -m 775 -d $(SHAREXQX)/firmware/
	for i in sihpP*.img; do \
	    if [ -f $$i ]; then \
		base=`basename $$i .img`; \
		./arm2hpdl $$i >$$base.dl; \
		$(INSTALL) -c -m 644 $$base.dl $(SHAREXQX)/firmware/; \
	    fi; \
	done
	# foo2oak ICM files (if any)
	$(INSTALL) $(LPuid) $(LPgid) -m 775 -d $(SHAREOAK)/icm/
	for i in hpclj26*.icm; do \
	    if [ -f $$i ]; then \
		$(INSTALL) -c -m 644 $$i $(SHAREOAK)/icm/; \
	    fi; \
	done
	# foo2hp ICM files (if any)
	$(INSTALL) $(LPuid) $(LPgid) -m 775 -d $(SHAREHP)/icm/
	for i in hpclj26*.icm km2430*.icm; do \
	    if [ -f $$i ]; then \
		$(INSTALL) -c -m 644 $$i $(SHAREHP)/icm/; \
	    fi; \
	done
	# foo2lava ICM files (if any)
	$(INSTALL) $(LPuid) $(LPgid) -m 775 -d $(SHARELAVA)/icm/
	for i in km2530*.icm; do \
	    if [ -f $$i ]; then \
		$(INSTALL) -c -m 644 $$i $(SHARELAVA)/icm/; \
	    fi; \
	done
	# foo2qpdl ICM files (if any)
	$(INSTALL) $(LPuid) $(LPgid) -m 775 -d $(SHAREQPDL)/icm/
	for i in samclp300*.icm; do \
	    if [ -f $$i ]; then \
		$(INSTALL) -c -m 644 $$i $(SHAREQPDL)/icm/; \
	    fi; \
	done
	# foo2slx ICM files (if any)
	$(INSTALL) $(LPuid) $(LPgid) -m 775 -d $(SHARESLX)/icm/
	for i in lex*.icm; do \
	    if [ -f $$i ]; then \
		$(INSTALL) -c -m 644 $$i $(SHARESLX)/icm/; \
	    fi; \
	done

MODEL=/usr/share/cups/model
LOCALMODEL=/usr/local/share/cups/model
PPD=/usr/share/ppd
VARPPD=/var/lp/ppd
install-ppd:
	#
	# Install PPD files for CUPS
	#
	if [ -x /usr/sbin/ppdmgr -a -s $(VARPPD)/ppdcache ]; then \
	    $(INSTALL) $(LPgid) -d $(VARPPD)/user; \
	    cd PPD; \
	    for ppd in *.ppd; do \
		manuf=`echo "$$ppd" | sed 's/-.*//'`; \
		$(INSTALL) $(LPgid) -d $(VARPPD)/user/$$manuf; \
		gzip < $$ppd > $(VARPPD)/user/$$manuf/$$ppd.gz; \
	    done; \
	    ppdmgr -u; \
	elif [ -d $(PPD) ]; then \
	    find $(PPD) -name '*foo2zjs*' | xargs rm -rf; \
	    find $(PPD) -name '*foo2hp*' | xargs rm -rf; \
	    find $(PPD) -name '*foo2xqx*' | xargs rm -rf; \
	    find $(PPD) -name '*foo2lava*' | xargs rm -rf; \
	    find $(PPD) -name '*foo2qpdl*' | xargs rm -rf; \
	    find $(PPD) -name '*foo2slx*' | xargs rm -rf; \
            [ -d $(PPD)/foo2zjs ] || mkdir $(PPD)/foo2zjs; \
	    cd PPD; \
	    for ppd in *.ppd; do \
		gzip < $$ppd > $(PPD)/foo2zjs/$$ppd.gz; \
	    done; \
	fi
	if [ -d $(MODEL) ]; then \
	    cd PPD; \
	    for ppd in *.ppd; do \
		gzip < $$ppd > $(MODEL)/$$ppd.gz; \
	    done; \
	elif [ -d $(LOCALMODEL) ]; then \
	    cd PPD; \
	    for ppd in *.ppd; do \
		gzip < $$ppd > $(LOCALMODEL)/$$ppd.gz; \
	    done; \
	fi

APPL=/usr/share/applications
OLDAPPL=/usr/share/gnome/apps/System
PIXMAPS=/usr/share/pixmaps
install-desktop:
	#
	# Install GNOME desktop
	#
	if [ -d $(APPL) ]; then \
	    $(INSTALL) -c -m 644 hplj1020.desktop $(APPL); \
	fi
	if [ -d $(OLDAPPL) ]; then \
	    $(INSTALL) -c -m 644 hplj1020.desktop $(OLDAPPL); \
	fi
	if [ -d $(PIXMAPS) ]; then \
	    $(INSTALL) -c -m 644 hplj1020_icon.png $(PIXMAPS); \
	fi

install-gui:
	#
	# Install GUI
	#
	$(INSTALL) -c -m 644 hplj1020_icon.gif $(SHAREZJS)
	$(INSTALL) -c -m 755 hplj10xx_gui.tcl $(SHAREZJS)
	

USBDIR=/etc/hotplug/usb
UDEVDIR=/etc/udev/rules.d
RULES=hplj10xx.rules
install-hotplug: install-hotplug-test install-hotplug-prog

install-hotplug-test:
	#
	# Hotplug Installation Dependencies...
	#
	@if ! type ex >/dev/null 2>&1; then \
	    echo "      ***"; \
	    echo "      *** Error: "ex" is not installed!"; \
	    echo "      ***"; \
	    echo "      *** Install "vim" package(s) for your OS"; \
	    echo "      ***"; \
	    exit 1; \
	fi
	# ... OK!
	#

install-hotplug-prog:
	if [ -d $(UDEVDIR) ]; then \
	    $(INSTALL) -c -m 644 $(RULES) $(UDEVDIR)/11-$(RULES); \
	fi
	[ -d $(USBDIR) ] || $(INSTALL) -d -m 755 $(USBDIR)/
	$(INSTALL) -c -m 755 hplj1000 $(USBDIR)/
	ln -sf $(USBDIR)/hplj1000 $(USBDIR)/hplj1005
	ln -sf $(USBDIR)/hplj1000 $(USBDIR)/hplj1018
	ln -sf $(USBDIR)/hplj1000 $(USBDIR)/hplj1020
	ln -sf $(USBDIR)/hplj1000 $(USBDIR)/hpljP1005
	ln -sf $(USBDIR)/hplj1000 $(USBDIR)/hpljP1006
	ln -sf $(USBDIR)/hplj1000 $(USBDIR)/hpljP1505
	$(USBDIR)/hplj1000 install-usermap
	$(USBDIR)/hplj1005 install-usermap
	$(USBDIR)/hplj1018 install-usermap
	$(USBDIR)/hplj1020 install-usermap
	$(USBDIR)/hpljP1005 install-usermap
	$(USBDIR)/hpljP1006 install-usermap
	$(USBDIR)/hpljP1505 install-usermap

cups:	FRC
	if [ -x /etc/init.d/cups ]; then \
	    /etc/init.d/cups restart; \
	elif [ -x /etc/rc.d/rc.cups ]; then \
	    /etc/rc.d/rc.cups restart; \
	elif [ -x /etc/init.d/cupsys ]; then \
	    /etc/init.d/cupsys restart; \
	elif [ -x /etc/init.d/cupsd ]; then \
	    /etc/init.d/cupsd restart; \
	elif [ -x /usr/local/etc/rc.d/cups.sh ]; then \
	    /usr/local/etc/rc.d/cups.sh restart; \
	elif [ -x /usr/local/etc/rc.d/cups.sh.sample ]; then \
	    cp /usr/local/etc/rc.d/cups.sh.sample /usr/local/etc/rc.d/cups.sh; \
	    /usr/local/etc/rc.d/cups.sh restart; \
	fi

#
# Uninstall
#
uninstall:
	-rm -f /etc/hotplug/usb/hplj1000
	-rm -f /etc/hotplug/usb/hplj1005
	-rm -f /etc/hotplug/usb/hplj1018
	-rm -f /etc/hotplug/usb/hplj1020
	-rm -f /etc/hotplug/usb/foo2zjs.usermap
	-(echo "g/^hplj10[02][05]/d"; echo "w") | ex /etc/hotplug/usb.usermap
	-rm -f /etc/udev/rules.d/11-hplj10xx.rules
	-rm -f /usr/bin/usb_printerid /bin/usb_printerid /sbin/usb_printerid
	-rm -f /etc/hotplug/usb/hplj.usermap #
	-rm -f /etc/udev/rules.d/58-foo2zjs.rules #
	-rm -f /sbin/foo2zjs-loadfw #
	-rm -rf /usr/share/doc/foo2zjs/
	-rm -f $(MANDIR)/man1/foo2zjs*.1 $(MANDIR)/man1/zjsdecode.1
	-rm -f $(MANDIR)/man1/foo2hp*.1
	-rm -f $(MANDIR)/man1/foo2oak*.1 $(MANDIR)/man1/oakdecode.1
	-rm -f $(MANDIR)/man1/foo2lava*.1 $(MANDIR)/man1/lavadecode.1
	-rm -f $(MANDIR)/man1/foo2qpdl*.1 $(MANDIR)/man1/qpdldecode.1
	-rm -f $(MANDIR)/man1/foo2slx*.1 $(MANDIR)/man1/slxdecode.1
	-rm -f $(MANDIR)/man1/foo2xqx*.1 $(MANDIR)/man1/xqxdecode.1
	-rm -f $(MANDIR)/man1/opldecode.1 $(MANDIR)/man1/rodecode.1
	-rm -rf /usr/share/foo2zjs/
	-rm -rf /usr/share/foo2hp/
	-rm -rf /usr/share/foo2oak/
	-rm -rf /usr/share/foo2xqx/
	-rm -rf /usr/share/foo2lava/
	-rm -rf /usr/share/foo2qpdl/
	-rm -rf /usr/share/foo2slx/
	-rm -f /usr/bin/arm2hpdl
	-rm -f /usr/bin/foo2zjs-wrapper /usr/bin/foo2zjs /usr/bin/zjsdecode
	-rm -f /usr/bin/foo2oak-wrapper /usr/bin/foo2oak /usr/bin/oakdecode
	-rm -f /usr/bin/foo2hp2600-wrapper /usr/bin/foo2hp
	-rm -f /usr/bin/foo2xqx-wrapper /usr/bin/foo2xqx /usr/bin/xqxdecode
	-rm -f /usr/bin/foo2lava-wrapper /usr/bin/foo2lava /usr/bin/lavadecode
	-rm -f /usr/bin/foo2qpdl-wrapper /usr/bin/foo2qpdl /usr/bin/qpdldecode
	-rm -f /usr/bin/foo2slx-wrapper /usr/bin/foo2slx /usr/bin/slxdecode
	-rm -f /usr/bin/opldecode
	-rm -f /usr/bin/okidecode /usr/bin/rodecode
	-rm -f /usr/bin/foo2zjs-icc2ps
	-rm -f /usr/bin/foo2zjs-pstops
	-rm -f /usr/share/applications/hplj1020.desktop
	-rm -f /usr/share/pixmaps/hplj1020_icon.png
	-cd foomatic-db; for i in `find driver opt printer -name "*.xml"`; do \
		rm -f $(FOODB)/$$i; \
	done
	cd PPD; for ppd in *.ppd; do \
	    rm -f $(MODEL)/$$ppd.gz; \
	done;
	-rm -f /var/cache/foomatic/printconf.pickle

#
# Clean
#
clean:
	-rm -f $(PROGS) $(BINPROGS) $(SHELLS)
	-rm -f *.zc *.zm
	-rm -f xxx.* xxxomatic
	-rm -f foo2zjs.o jbig.o jbig_tab.o zjsdecode.o foo2hp.o
	-rm -f foo2xqx.o xqxdecode.o
	-rm -f foo2lava.o lavadecode.o
	-rm -f foo2qpdl.o qpdldecode.o
	-rm -f foo2slx.o slxdecode.o
	-rm -f opldecode.o
	-rm -f foo2oak.html foo2zjs.html foo2hp.html foo2xqx.html foo2lava.html
	-rm -f foo2slx.html
	-rm -f foo2qpdl.html
	-rm -f index.html
	-rm -f arch*.gif
	-rm -f sihp*.dl
	-rm -f *.tar.gz
	-rm -f getweb
	-rm -f patch.db
	-rm -f $(MANPAGES) manual.pdf
	-rm -f *.zjs *.zm *.zc *.zc? *.zc?? *.oak *.pbm *.pksm *.cmyk
	-rm -f pksm2bitcmyk
	-rm -f *.icm.*.ps
	-rm -f okidecode.o
	cd icc2ps; $(MAKE) $@

#
# Header dependencies
#
zjsdecode.o: zjs.h jbig.h
foo2zjs.o: zjs.h jbig.h
jbig.o: jbig.h
foo2hp.o: zjs.h jbig.h cups.h
xqxdecode.o: xqx.h jbig.h
foo2xqx.o: xqx.h jbig.h
lavadecode.o: jbig.h
foo2lava.o: jbig.h
qpdldecode.o: jbig.h
foo2qpdl.o: jbig.h qpdl.h
opldecode.o: jbig.h
slxdecode.o: slx.h jbig.h
foo2slx.o: slx.h jbig.h

#
# foo2* Regression tests
#
test:		testzjs testhp
	#
	# All regression tests passed.
	#
	# Send the appropriate test page .zm/.zc ZjStream file(s) to
	# your printer using a *RAW* printer queue.

#
# foo2zjs Regression tests
#
testzjs:	testpage.zm \
		testpage.zc10 testpage.zc1 testpage.zc2 testpage.zc3 \
		lj1000.zm lj1020.zm

testpage.zm: testpage.ps foo2zjs-wrapper foo2zjs Makefile FRC
	#
	# Tests will pass only if you are using ghostscript-7.05-24.7
	# or ghostscript-8.60 (gs.foo)
	#
	# Monochrome test page for Minolta 2200/2300 DL
	PATH=.:$$PATH time -p foo2zjs-wrapper testpage.ps > $@
	@want1="ff6a74bc76aed25224d22a30f4debcee  $@"; \
	want2="6d4bb7ea61c181d93f464bce2b4e2fe2  $@"; \
	got=`md5sum $@`; [ "$$want1" = "$$got" -o "$$want2" = "$$got" ] || \
	    { echo "*** Test failure, got $$got"; exit 1; }

testpage.zc10: testpage.ps foo2zjs-wrapper foo2zjs Makefile FRC
	#
	# Color test page for Minolta 2200/2300 DL
	PATH=.:$$PATH time -p foo2zjs-wrapper -c -C10 testpage.ps > $@
	@want1="94b77586bab210ad54eaf7b652817a4c  $@"; \
	want2="1c35cb5f615ab68acea9c271c8aeaf63  $@"; \
	got=`md5sum $@`; [ "$$want1" = "$$got" -o "$$want2" = "$$got" ] || \
	    { echo "*** Test failure, got $$got"; exit 1; }

testpage.zc1: testpage.ps foo2zjs-wrapper foo2zjs Makefile FRC
	PATH=.:$$PATH time -p foo2zjs-wrapper -c -C1 testpage.ps > $@
	@want="3d3b6fc08d9a1c9f80a99fec867596df  $@"; got=`md5sum $@`; \
	#[ "$$want" = "$$got" ] || \
	#    { echo "*** Test failure, got $$got"; exit 1; }

testpage.zc2: testpage.ps foo2zjs-wrapper foo2zjs Makefile FRC
	PATH=.:$$PATH time -p foo2zjs-wrapper -c -C2 testpage.ps > $@
	@want="3d3b6fc08d9a1c9f80a99fec867596df  $@"; got=`md5sum $@`; \
	#[ "$$want" = "$$got" ] || \
	#    { echo "*** Test failure, got $$got"; exit 1; }

testpage.zc3: testpage.ps foo2zjs-wrapper foo2zjs Makefile FRC
	PATH=.:$$PATH time -p foo2zjs-wrapper -c -C3 testpage.ps > $@
	@want="3d3b6fc08d9a1c9f80a99fec867596df  $@"; got=`md5sum $@`; \
	#[ "$$want" = "$$got" ] || \

lj1000.zm: testpage.ps foo2zjs-wrapper foo2zjs Makefile FRC
	#
	# Monochrome test page for HP LJ1000
	PATH=.:$$PATH time -p foo2zjs-wrapper -r600x600 -P testpage.ps >$@
	@want1="5b1ff464419fe6b00f3338efbba33423  $@"; \
	want2="2d99292c01ebf2d2376a1726a5aac4c5  $@"; \
	got=`md5sum $@`; [ "$$want1" = "$$got" -o "$$want2" = "$$got" ] || \
	    { echo "*** Test failure, got $$got"; exit 1; }

lj1020.zm: testpage.ps foo2zjs-wrapper foo2zjs Makefile FRC
	#
	# Monochrome test page for HP LJ1020
	PATH=.:$$PATH time -p foo2zjs-wrapper -r600x600 -P -z1 \
	    testpage.ps >$@
	@want1="c145d399f24f4e3e31b26a9d5e62acc5  $@"; \
	want2="4a2f252855cc48cefef92b05386e9c0f  $@"; \
	got=`md5sum $@`; [ "$$want1" = "$$got" -o "$$want2" = "$$got" ] || \
	    { echo "*** Test failure, got $$got"; exit 1; }

#
# foo2hp Regression tests
#
testhp: lj2600.zm1 lj2600.zc1

lj2600.zm1: testpage.ps foo2hp2600-wrapper foo2hp Makefile FRC
	#
	# Monochrome test page for HP 2600n (1-bit)
	PATH=.:$$PATH time -p foo2hp2600-wrapper testpage.ps > $@
	@want1="d99c262e77db7221a1773927732ef17a  $@"; \
	want2="c92932247335abcf506f40569f4e20d7  $@"; \
	got=`md5sum $@`; [ "$$want1" = "$$got" -o "$$want2" = "$$got" ] || \
	    { echo "*** Test failure, got $$got"; exit 1; }

lj2600.zc1: testpage.ps foo2hp2600-wrapper foo2hp Makefile FRC
	#
	# Color test page for HP 2600n (1-bit)
	PATH=.:$$PATH time -p foo2hp2600-wrapper -c testpage.ps > $@
	@want1="96afa96d774bd9fc9ede66c9ccd90460  $@"; \
	want2="2e414ac1af09f183435ae105e7bb61cd  $@"; \
	got=`md5sum $@`; [ "$$want1" = "$$got" -o "$$want2" = "$$got" ] || \
	    { echo "*** Test failure, got $$got"; exit 1; }

#
# foo2oak Regression tests
#
testoak: pprtest-0.oak pprtest-1.oak pprtest-2.oak pprtest-3.oak

pprtest-0.oak: FRC
	#
	# 1-bit Monochrome test page for OAKT
	PATH=.:$$PATH foo2oak-wrapper -b1 -D12345678 pprtest.ps > $@
	@want="fbd4c1a560985a6ad47ff23b018c7ce8  $@"; got=`md5sum $@`; \
	[ "$$want" = "$$got" ] || \
	    { echo "*** Test failure, got $$got"; exit 1; }

pprtest-1.oak: FRC
	#
	# 2-bit Monochrome test page for OAKT
	PATH=.:$$PATH foo2oak-wrapper -b2 -D12345678 pprtest.ps > $@
	@want="bec9a24ee1ce0d388b773f83609a4d01  $@"; got=`md5sum $@`; \
	[ "$$want" = "$$got" ] || \
	    { echo "*** Test failure, got $$got"; exit 1; }

pprtest-2.oak: FRC
	#
	# 1-bit color test page for OAKT
	PATH=.:$$PATH foo2oak-wrapper -c -b1 -D12345678 pprtest.ps > $@
	@want="c714bcd69fe5f3b2b257d7435eb938d1  $@"; got=`md5sum $@`; \
	[ "$$want" = "$$got" ] || \
	    { echo "*** Test failure, got $$got"; exit 1; }

pprtest-3.oak: FRC
	#
	# 2-bit color test page for OAKT
	PATH=.:$$PATH foo2oak-wrapper -c -b2 -D12345678 pprtest.ps > $@
	@want="ed89abcd873979bc9337e02263511964  $@"; got=`md5sum $@`; \
	[ "$$want" = "$$got" ] || \
	    { echo "*** Test failure, got $$got"; exit 1; }

#
#	icc2ps regression tests
#
ICC2PS=./icc2ps/foo2zjs-icc2ps
icctest:
	for g in *.icm; do \
	    for i in 0 1 2 3; do \
		$(ICC2PS) -o $$g -t$$i \
		| sed '/Created:/d' > $$g.$$i.ps; \
	    done; \
	done


#
# Make phony print devices for testing full spooler interface without printing
#
tmpdev:
	DEV=/tmp/OAK; > $$DEV; chmod 666 $$DEV
	DEV=/tmp/OAKCM; > $$DEV; chmod 666 $$DEV
	DEV=/tmp/testfile; > $$DEV; chmod 666 $$DEV

#
# Test files for debugging
#
testpage.pbm: testpage.ps Makefile
xxx.zc: FRC
xxx.zm: FRC

#
#	PPD files
#
ppd:
	# Did you do a "make install"????
	./getweb ppd

#
# Manpage generation.  No, I am not interested in "info" files or
# HTML documentation.
#
man: $(MANPAGES)

.1in.1:
	-rm -f $*.1
	modtime() { $(MODTIME); }; \
	MODpage=`modtime $*.1in`; \
	MODver=$(VERSION); \
	sed < $*.1in > $*.1 \
	    -e "s@\$${URLOAK}@$(URLOAK)@" \
	    -e "s@\$${URLZJS}@$(URLZJS)@" \
	    -e "s@\$${URLHP}@$(URLHP)@" \
	    -e "s@\$${URLXQX}@$(URLXQX)@" \
	    -e "s@\$${URLLAVA}@$(URLLAVA)@" \
	    -e "s@\$${URLQPDL}@$(URLQPDL)@" \
	    -e "s@\$${URLSLX}@$(URLSLX)@" \
	    -e "s/\$${MODpage}/$$MODpage/" \
	    -e "s/\$${MODver}/$$MODver/"
	chmod -w $*.1

install-man: man
	#
	# Install manual pages
	#
	$(INSTALL) -d -m 755 $(MANDIR)
	$(INSTALL) -d -m 755 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2zjs.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2zjs-wrapper.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 zjsdecode.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2oak.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2oak-wrapper.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 oakdecode.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2hp.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2hp2600-wrapper.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 xqxdecode.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2xqx.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2xqx-wrapper.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 lavadecode.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2lava.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2lava-wrapper.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 qpdldecode.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2qpdl.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2qpdl-wrapper.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 opldecode.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 slxdecode.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2slx.1 $(MANDIR)/man1/
	$(INSTALL) -c -m 644 foo2slx-wrapper.1 $(MANDIR)/man1/

doc: README INSTALL manual.pdf

install-doc: doc
	#
	# Install documentation
	#
	$(INSTALL) -d -m 755 $(DOCDIR)
	$(INSTALL) -c -m 644 manual.pdf $(DOCDIR)
	$(INSTALL) -c -m 644 COPYING $(DOCDIR)
	$(INSTALL) -c -m 644 INSTALL $(DOCDIR)
	$(INSTALL) -c -m 644 INSTALL.osx $(DOCDIR)
	$(INSTALL) -c -m 644 README $(DOCDIR)
	$(INSTALL) -c -m 644 ChangeLog $(DOCDIR)

GROFF=/usr/local/test/bin/groff
GROFF=groff
manual.pdf: $(MANPAGES)
	-$(GROFF) -t -man $(MANPAGES) | ps2pdf - $@

README: README.in
	rm -f $@
	sed < $@.in > $@ \
	    -e "s@\$${URLOAK}@$(URLOAK)@" \
	    -e "s@\$${URLZJS}@$(URLZJS)@"
	chmod -w $@

INSTALL: INSTALL.in
	rm -f $@
	sed < $@.in > $@ \
	    -e "s@\$${URLOAK}@$(URLOAK)@" \
	    -e "s@\$${URLZJS}@$(URLZJS)@"
	chmod -w $@

#
#	Check db files against current foomatic to see if any changes
#	need to be made or reported.
#
MYFOODB=../foomatic/foomatic-db/db/source
checkdb:
	@for dir in driver printer opt; do \
	    for file in foomatic-db/$$dir/*.xml ; do \
		ofile=$(MYFOODB)/$$dir/`basename $$file`; \
		: echo diff -N -u $$ofile $$file; \
		if [ ! -f  $$ofile ]; then \
		    ofile=/dev/null; \
		fi; \
		diff -N -u $$ofile $$file; \
	    done \
	done

#
#	Mail my latest foomatic-db entries to Till.
#
WHO=rick.richardson@comcast.net
WHO=till.kamppeter@gmx.net
maildb:
	$(MAKE) -s checkdb > patch.db
	echo "Here is a patch for the foomatic-db foo2zjs/foo2oak entries." | \
	mutt -a patch.db \
	    -s "foo2zjs/foo2oak - patch for foomatic database" $(WHO)

#
# Create tarball
#
tar:	
	HERE=`basename $$PWD`; \
	/bin/ls $(FILES) | \
	sed -e "s?^?$$HERE/?" | \
	(cd ..; tar -c -z -f $$HERE/$$HERE.tar.gz -T-)

#
# Populate the web site
#	make web
#	make webworld
#	make webextra
#
URLOAK=http://foo2oak.rkkda.com
URLZJS=http://foo2zjs.rkkda.com
URLHP=http://foo2hp.rkkda.com
URLXQX=http://foo2xqx.rkkda.com
URLLAVA=http://foo2lava.rkkda.com
URLQPDL=http://foo2qpdl.rkkda.com
URLSLX=http://foo2slx.rkkda.com
FTPSITE=~/.ncftp-website

foo2zjs.html foo2oak.html foo2hp.html \
    foo2xqx.html foo2lava.html foo2qpdl.html foo2slx.html: thermometer.gif FRC
	rm -f $@
	HERE=`basename $$PWD`; \
	TZ=`date | cut -c 21-24`; \
	modtime() { $(MODTIME); }; \
	MODindex=`modtime $@.in`; \
	MODtarball=`modtime $$HERE.tar.gz`; \
	PRODUCT=`basename $@ .html`; \
	./includer-html $@.in | sed > $@ \
	    -e "s@\$${URLOAK}@$(URLOAK)@g" \
	    -e "s@\$${URLZJS}@$(URLZJS)@g" \
	    -e "s@\$${URLHP}@$(URLHP)@g" \
	    -e "s@\$${URLXQX}@$(URLXQX)@g" \
	    -e "s@\$${URLLAVA}@$(URLLAVA)@g" \
	    -e "s@\$${URLQPDL}@$(URLQPDL)@g" \
	    -e "s@\$${URLSLX}@$(URLSLX)@g" \
	    -e "s@\$${PRODUCT}@$$PRODUCT@g" \
	    -e "s/\$${MODindex}/$$MODindex $$TZ/" \
	    -e "s/\$${MODtarball}/$$MODtarball $$TZ/"
	chmod -w $@

web: test tar manual.pdf webindex
	ncftpput -m -f $(FTPSITE) foo2zjs \
	    ChangeLog INSTALL manual.pdf *.tar.gz;

webt: tar manual.pdf webindex
	ncftpput -m -f $(FTPSITE) foo2zjs \
	    ChangeLog INSTALL manual.pdf *.tar.gz;

webworld: web webpics

webindex: INSTALL zjsindex oakindex hpindex xqxindex lavaindex \
	qpdlindex oakindex slxindex

webpics: redhat suse ubuntu mandriva fedora

zjsindex: foo2zjs.html archzjs.gif thermometer.gif
	ln -sf foo2zjs.html index.html
	ncftpput -m -f $(FTPSITE) foo2zjs \
	    index.html style.css archzjs.gif thermometer.gif \
	    INSTALL INSTALL.osx zjsfavicon.png;

oakindex: foo2oak.html archoak.gif thermometer.gif
	ln -sf foo2oak.html index.html
	ncftpput -m -f $(FTPSITE) foo2oak \
	    index.html style.css archoak.gif thermometer.gif \
	    INSTALL;

hpindex: foo2hp.html archhp.gif thermometer.gif
	ln -sf foo2hp.html index.html
	ncftpput -m -f $(FTPSITE) foo2hp \
	    index.html style.css archhp.gif thermometer.gif \
	    INSTALL hpfavicon.png;

xqxindex: foo2xqx.html archxqx.gif thermometer.gif
	ln -sf foo2xqx.html index.html
	ncftpput -m -f $(FTPSITE) foo2xqx \
	    index.html style.css archxqx.gif thermometer.gif \
	    INSTALL xqxfavicon.png;

lavaindex: foo2lava.html archlava.gif thermometer.gif
	ln -sf foo2lava.html index.html
	ncftpput -m -f $(FTPSITE) foo2lava \
	    index.html style.css archlava.gif thermometer.gif \
	    INSTALL lavafavicon.png;

qpdlindex: foo2qpdl.html archqpdl.gif thermometer.gif
	ln -sf foo2qpdl.html index.html
	ncftpput -m -f $(FTPSITE) foo2qpdl \
	    index.html style.css archqpdl.gif thermometer.gif \
	    INSTALL qpdlfavicon.png;

slxindex: foo2slx.html archslx.gif thermometer.gif
	ln -sf foo2slx.html index.html
	ncftpput -m -f $(FTPSITE) foo2slx \
	    index.html style.css archslx.gif thermometer.gif \
	    INSTALL slxfavicon.png;

foo2zjs.html: warning.html contribute.html resources.html unsupported.html
foo2hp.html: warning.html contribute.html resources.html unsupported.html
foo2xqx.html: warning.html contribute.html resources.html unsupported.html
foo2lava.html: warning.html contribute.html resources.html unsupported.html
foo2qpdl.html: warning.html contribute.html resources.html unsupported.html
foo2slx.html: warning.html contribute.html resources.html unsupported.html
foo2oak.html: warning.html contribute.html resources.html unsupported.html

# RedHat
redhat: FRC
	cd redhat; $(MAKE) web FTPSITE=$(FTPSITE)

# Fedora Core 6+
fedora: FRC
	cd fedora; $(MAKE) web FTPSITE=$(FTPSITE)

suse: FRC
	cd suse; $(MAKE) web FTPSITE=$(FTPSITE)

ubuntu: FRC
	cd ubuntu; $(MAKE) web FTPSITE=$(FTPSITE)

mandriva: FRC
	cd mandriva; $(MAKE) web FTPSITE=$(FTPSITE)

#
#	Extra files from web
#
webextra: webicm webfw

webicm: icm/km2430.tar.gz icm/hpclj2600n.tar.gz icm/km2530.tar.gz \
	icm/samclp300.tar.gz icm/lexc500.tar.gz
	ncftpput -m -f $(FTPSITE) foo2zjs/icm icm/km2430.tar.gz;
	ncftpput -m -f $(FTPSITE) foo2hp/icm icm/hpclj2600n.tar.gz;
	ncftpput -m -f $(FTPSITE) foo2lava/icm icm/km2530.tar.gz;
	ncftpput -m -f $(FTPSITE) foo2qpdl/icm icm/samclp300.tar.gz;
	ncftpput -m -f $(FTPSITE) foo2slx/icm icm/lexc500.tar.gz;

icm/km2430.tar.gz: FRC
	cd icm; tar -c -z -f ../$@ km2430*.icm
icm/hpclj2600n.tar.gz: FRC
	cd icm; tar -c -z -f ../$@ hpclj2600*.icm
icm/km2530.tar.gz: FRC
	cd icm; tar -c -z -f ../$@ km2530*.icm
icm/samclp300.tar.gz: FRC
	cd icm; tar -c -z -f ../$@ samclp300*.icm
icm/lexc500.tar.gz: FRC
	cd icm; tar -c -z -f ../$@ lexR*.icm

webfw:	firmware/sihp1000.tar.gz \
	firmware/sihp1005.tar.gz \
	firmware/sihp1018.tar.gz \
	firmware/sihp1020.tar.gz \
	firmware/sihpP1005.tar.gz \
	firmware/sihpP1006.tar.gz \
	firmware/sihpP1505.tar.gz \
	$(NULL)
	ncftpput -m -f $(FTPSITE) foo2zjs/firmware firmware/*.tar.gz;

firmware/sihp1000.tar.gz: FRC
	cd firmware; tar -c -z -f ../$@ sihp1000.img
firmware/sihp1005.tar.gz: FRC
	cd firmware; tar -c -z -f ../$@ sihp1005.img
firmware/sihp1018.tar.gz: FRC
	cd firmware; tar -c -z -f ../$@ sihp1018.img
firmware/sihp1020.tar.gz: FRC
	cd firmware; tar -c -z -f ../$@ sihp1020.img
firmware/sihpP1005.tar.gz: FRC
	cd firmware; tar -c -z -f ../$@ sihpP1005.img
firmware/sihpP1006.tar.gz: FRC
	cd firmware; tar -c -z -f ../$@ sihpP1006.img
firmware/sihpP1505.tar.gz: FRC
	cd firmware; tar -c -z -f ../$@ sihpP1505.img

FRC:

#
# Misc
#
misc: pksm2bitcmyk phorum-logo.gif

pksm2bitcmyk: pksm2bitcmyk.c
	$(CC) $(CFLAGS) pksm2bitcmyk.c -lnetpbm -o $@

phorum-logo.gif: archhp.fig
	fig2dev -L gif -m.25 archhp.fig | giftrans -t "#ffffff" -o $@
