UNAME := $(shell uname)
MACH := $(shell uname -m | sed 's/i.86/ia32/')
EUID := $(shell id -u)

# No version number yet...
VERSION=0.0

# Installation prefix...
PREFIX=/usr/local
PREFIX=$(DESTDIR)/usr

# Pathnames for this package...
BIN=$(PREFIX)/bin
SHAREZJS=$(PREFIX)/share/foo2zjs
SHAREOAK=$(PREFIX)/share/foo2oak
SHAREHP=$(PREFIX)/share/foo2hp
MANDIR=$(PREFIX)/share/man
DOCDIR=$(PREFIX)/share/doc/foo2zjs/

# 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
# If we aren't root, don't try to set ownership
ifneq ($(EUID),0)
    LPuid=
    LPgid=
endif

#
# Files for tarball
#
NULL=
FILES	=	\
		README \
		README.in \
		INSTALL \
		INSTALL.in \
		INSTALL.osx \
		COPYING \
		foo2zjs.html.in \
		style.css \
		arch.fig \
		2300.png \
		arch.gif \
		ChangeLog \
		Makefile \
		foo2zjs.c \
		foo2zjs.1in \
		jbig.c \
		jbig.h \
		jbig_tab.c \
		zjsdecode.c \
		zjsdecode.1in \
		zjs.h \
		foo2hp.c \
		foo2zjs-wrapper.in \
		foo2zjs-wrapper.1in \
		foo2hp2600-wrapper.in \
		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/2300w-1200@150-l250-kx,ucr100,0-per.crd \
		crd/2300w-1200@150-l250-kx,ucr100,50-per.crd \
		crd/2300w-1200@150-l250-kx,ucr100,75-per.crd \
		crd/2300w-1200@150-l250-kx,ucr125,75-per.crd \
		crd/kh.crd \
		crd/kx.crd \
		crd/prolog.ps \
		crd/screen1200.ps \
		crd/screen2400.ps \
		arm2hpdl.c \
		usb_printerid.c \
		hplj1000 \
		hplj10xx.rules \
		msexpand \
		foo2oak.1in \
		foo2oak-wrapper.in \
		foo2oak-wrapper.1in \
		oakdecode.1in \
		foo2oak.html.in \
		1500.gif \
		archoak.fig \
		archoak.gif \
		foo2hp.html.in \
		$(NULL)

# Programs and libraries
PROGS=		foo2zjs zjsdecode arm2hpdl foo2hp
SHELLS=		foo2zjs-wrapper foo2oak-wrapper foo2hp2600-wrapper
MANPAGES=	foo2zjs-wrapper.1 foo2zjs.1 zjsdecode.1
MANPAGES+=	foo2oak-wrapper.1 foo2oak.1 oakdecode.1
LIBJBG	=	jbig.o jbig_tab.o
BINPROGS=

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

# Compiler flags
CFLAGS +=	-O2 -Wall

#
# 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 \
	   .1 .1in

.ps.cups:
	gs $(GSOPTS) -r600x600 \
	    -dcupsColorSpace=6 -dcupsBitsPerColor=2 -dcupsColorOrder=2 \
	    -sDEVICE=cups -sOutputFile=$*.cups $*.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

.zc.jbg:
	./zjsdecode -r $* <$*.zc

.zm.jbg:
	./zjsdecode -r $* <$*.zm

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

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)

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

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 $@

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

#
# Installation rules
#
install: all install-prog install-icc2ps install-extra install-crd \
	    install-foo install-ppd install-man install-doc
	#
	# 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/2/3, run "printconf-gui".
	# On Mandrake, run "printerdrake"
	# On Suse 9.0, run "yast"
	# On Ubunto 5.10, run "gnome-cups-manager"

install-prog:
	#
	# Install driver, wrapper, and development tools
	#
	install -c $(PROGS) $(SHELLS) $(BIN)/
	install -c $(BINPROGS) $(PREFIX)/bin/
	#
	# 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-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/*/*
	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/*.*; do \
	    install -c -m 644 $$i $(SHAREZJS)/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; 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 sihp*.img; do \
#	    if [ -f $$i ]; then \
#		base=`basename $$i .img`; \
#		./arm2hpdl $$i >$$base.dl; \
#		install -c -m 644 $$base.dl $(SHAREZJS)/firmware/; \
#	    fi; \
#	done
	# foo2oak ICM files (if any)
	install $(LPuid) $(LPgid) -m 775 -d $(SHAREOAK)/icm/
	# foo2hp ICM files (if any)
	install $(LPuid) $(LPgid) -m 775 -d $(SHAREHP)/icm/
	for i in hpclj26*.icm; do \
	    if [ -f $$i ]; then \
		install -c -m 644 $$i $(SHAREHP)/icm/; \
	    fi; \
	done

MODEL=/usr/share/cups/model
install-ppd:
	#
	# Install PPD files for CUPS
	#
	if [ -d $(MODEL) ]; then \
	    cd PPD; \
	    for ppd in *.ppd; do \
		gzip < $$ppd > $(MODEL)/$$ppd.gz; \
	    done; \
	fi

USBDIR=/etc/hotplug/usb
UDEVDIR=/etc/udev/rules.d
RULES=hplj10xx.rules
install-hotplug:
	[ -d $(USBDIR) ] || install -d -m 755 $(USBDIR)/
	install -c -m 755 hplj1000 $(USBDIR)/
	ln -sf $(USBDIR)/hplj1000 $(USBDIR)/hplj1005
	ln -sf $(USBDIR)/hplj1000 $(USBDIR)/hplj1020
	$(USBDIR)/hplj1000 install-usermap
	$(USBDIR)/hplj1005 install-usermap
	$(USBDIR)/hplj1020 install-usermap
	if [ -d $(UDEVDIR) ]; then \
	    install -c -m 644 $(RULES) $(UDEVDIR)/11-$(RULES); \
	fi

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 *.o
	-rm -f foo2oak.html foo2zjs.html foo2hp.html index.html
	-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
	cd icc2ps; $(MAKE) $@

#
# Header dependencies
#
zjsdecode.o: zjs.h jbig.h
foo2zjs.o: zjs.h jbig.h
jbig.o: jbig.h

#
# foo2zjs Regression tests
#
test:		testpage.zm \
		testpage.zc10 testpage.zc1 testpage.zc2 testpage.zc3 \
		lj1000.zm
	#
	# All regression tests passed.
	#
	# Send the appropriate test page .zm/.zc ZjStream file(s) to
	# your printer using a *RAW* printer queue.

testpage.zm: testpage.ps foo2zjs-wrapper foo2zjs Makefile FRC
	#
	# Tests will pass only if you are using ghostscript-7.05-24.7
	#
	# Monochrome test page for Minolta 2200/2300 DL
	PATH=.:$$PATH time -p foo2zjs-wrapper -b gs testpage.ps > $@
	@want="c4cf1940d6fb854cc3efdd6283388ea4  $@"; got=`md5sum $@`; \
	[ "$$want" = "$$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 -b gs -c -C10 testpage.ps > $@
	@want="3d3b6fc08d9a1c9f80a99fec867596df  $@"; got=`md5sum $@`; \
	[ "$$want" = "$$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 -b gs -r600x600 -P testpage.ps > $@
	@want="e458bacac57331ec5206cacd0181fe8a  $@"; got=`md5sum $@`; \
	[ "$$want" = "$$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:
	./getweb ppd

MODEL=$(PREFIX)/share/cups/model
install-ppd:
	install -d -m 755 $(MODEL)
	#
	# Install PPD files for CUPS
	#
	if [ -d $(MODEL) ]; then \
           cd PPD; \
           for ppd in *.ppd; do \
               gzip < $$ppd > $(MODEL)/$$ppd.gz; \
           done; \
       fi


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

.1in.1:
	-rm -f $*.1
	modtime() { ls --full-time $$1 | cut -c 44-67; }; \
	MODpage=`modtime $*.1in`; \
	MODver=$(VERSION); \
	sed < $*.1in > $*.1 \
	    -e "s@\$${URLOAK}@$(URLOAK)@" \
	    -e "s@\$${URLZJS}@$(URLZJS)@" \
	    -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/

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=rickr@mn.rr.com
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
#
URLOAK=http://foo2oak.rkkda.com
URLZJS=http://foo2zjs.rkkda.com
URLHP=http://foo2hp.rkkda.com
FTPSITE=~/.ncftp-website

foo2zjs.html foo2oak.html foo2hp.html: FRC
	rm -f $@
	HERE=`basename $$PWD`; \
	TZ=`date | cut -c 21-24`; \
	modtime() { ls --full-time $$1 | cut -c 44-67; }; \
	MODindex=`modtime $@.in`; \
	MODtarball=`modtime $$HERE.tar.gz`; \
	sed < $@.in > $@ \
	    -e "s@\$${URLOAK}@$(URLOAK)@g" \
	    -e "s@\$${URLZJS}@$(URLZJS)@g" \
	    -e "s@\$${URLHP}@$(URLHP)@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;

webindex: INSTALL zjsindex oakindex hpindex redhat ubuntu

zjsindex: foo2zjs.html
	ln -sf foo2zjs.html index.html
	ncftpput -m -f $(FTPSITE) foo2zjs \
	    index.html style.css arch.gif INSTALL;

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

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

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

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

cups: FRC
	ncftpput -m -f $(FTPSITE) foo2hp/cups cups/*.*;
	ncftpput -m -f $(FTPSITE) foo2zjs/cups cups/*.*;

FRC:

#
#	Target for building Oak Technologies encoder/decoder (for HP1500)
#
#	This source code will not be made available unless someone sponsors
#	me to finish the work on it.
#
LIBJBGOAK	=	jbig.o jbig_tab.o
o: oakdecode foo2oak foo2oak-wrapper
	root install oakdecode foo2oak foo2oak-wrapper $(BIN)/
oakdecode: oakdecode.o $(LIBJBGOAK)
	$(CC) $(CFLAGS) oakdecode.o $(LIBJBGOAK) -o $@
foo2oak: foo2oak.o $(LIBJBGOAK)
	$(CC) $(CFLAGS) -o $@ foo2oak.o $(LIBJBGOAK)
foo2oak-wrapper: foo2oak-wrapper.in Makefile
	[ ! -f $@ ] || chmod +w $@
	sed < $@.in > $@ \
	    -e 's@^PREFIX=.*@PREFIX=$(PREFIX)@' || (rm -f $@ && exit 1)
	chmod 555 $@

SYSNAME := $(shell uname -n)
ifeq ($(SYSNAME),ipcroe.rkkda.com)
foo2oak.o: oak.h jbig.h
endif

#
# Misc
#
misc: pksm2bitcmyk

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