# This Makefile is here, because I am to lazy to type
# all parameters again and again.....

# Author: Jens Apel
# Purpose: Creates a printer driver packages for Lexmark Printers,
# that can be load to Samba.
# Prerequsites:
# - Samba 2.2.0 or higher
# - imprints 0.0.9b or higher from
#   imprints.sorceforge.net

# Settings section start
# Where did you install imprints
IMPRINTS_BASE = /opt/imprints

# The perl skript doing all work for creating the package
MK_PRINT_PKG  = $(IMPRINTS_BASE)/bin/mkprintpkg.pl

# The perl script that installs a printer package
INSTALL_PRINTER_DRIVER = $(IMPRINTS_BASE)/scripts/install_printer_drivers.pl

# Where are we
CURRENT_DIR = `pwd`

# Where are all the drivers, win dlls and other stuff ?
ARCHIVE_DIR = $(CURRENT_DIR)/win_driver/ALL_IN1/

# This works not, since unzip (Linux) can not unzip it
# because it is not a self extracting .exe
# ARCHIVE_DIR = $(CURRENT_DIR)/win_driver/optra1855s.exe
# So you have to unzip it on Windows starting it...;-)

# on which Samba Server do you want to install the package ?
SAMBA_HOST = intra1

# Whats the user/password combination ?
# currently the user has to be root
SAMBA_USER = "root%secret"


# Settings section end
help:
       @echo "Possible targets are:"
       @echo "prepare - copys all files in _ONE_ directory"
       @echo "package - creates the packages"
       @echo "install - installs the package on the Samba Server"

# First put all windows driver files into one directory
# only that way imprints can work
prepare:
       rm -rf $(ARCHIVE_DIR)
       mkdir $(ARCHIVE_DIR)
       find $(CURRENT_DIR)/win_driver/win32drv -name "*.*" \
       -exec cp {} $(ARCHIVE_DIR) \;

# build the package
# Because of the deflating all files, this can last up to 10 minutes
package: package_1855

package_1650:
       @echo "###########################################################"
       @echo "# Building the package for Lexmark 1650 S for Win NT/2000 #"
       @echo "###########################################################"
       $(MK_PRINT_PKG) --name="optra1650S_NT" --version="1.0" \
       --display "Lexmark Optra S 1650 PS2" $(ARCHIVE_DIR) \
       --inf-fname "lexpsnt.inf" --model "Lexmark Optra S 1625 PS2" --debug

package_1855:
       @echo "###########################################################"
       @echo "# Building the package for Lexmark 1855 S for Win NT/2000 #"
       @echo "###########################################################"
       $(MK_PRINT_PKG) --name="optra1855S_NT" --version="1.0" \
       --display "Lexmark Optra S 1855 PS2" $(ARCHIVE_DIR) \
       --inf-fname "lexpsnt.inf" --model "Lexmark Optra S 1855 PS2" --debug

install: install_1855

install_1855:
       @echo "Installing the package for optra 1855 S (NT only)"
       $(INSTALL_PRINTER_DRIVER) --verbose \
       --cache-dir=$(CURRENT_DIR) --local-pkg=optra1855S_NT-1.0.tar.gz \
       'Lexmark Optra S 1855 PS2'

install_1650:
       @echo "Installing the package for optra 1650 S (NT)"
       $(INSTALL_PRINTER_DRIVER) --verbose \
       --cache-dir=$(CURRENT_DIR) --local-pkg=optra1650S_NT-1.0.tar.gz \
       'Lexmark Optra S 1650 PS2'

install_check:
       @echo "Call rpcclient and look what printers are installed"
       rpcclient $(SAMBA_HOST)  -U $(SAMBA_USER) -c "enumports 2"
       rpcclient $(SAMBA_HOST)  -U $(SAMBA_USER) -c "enumprinters 2"

       rpcclient $(SAMBA_HOST)  -U $(SAMBA_USER) -c "getprinter pr01"
       rpcclient $(SAMBA_HOST)  -U $(SAMBA_USER) -c "getprinter pr02"
       rpcclient $(SAMBA_HOST)  -U $(SAMBA_USER) -c "getprinter pr03"

       rpcclient $(SAMBA_HOST) -U $(SAMBA_USER) -c "getdriver pr01"
       rpcclient $(SAMBA_HOST) -U $(SAMBA_USER) -c "getdriver pr02"
       rpcclient $(SAMBA_HOST) -U $(SAMBA_USER) -c "getdriver pr03"

clean:
       @echo "Cleaning up"
       rm optra*.tar.gz