# makefile
# A GNU make(1) makefile for VARKON postscript/PLT conversions for 
# the lemur.com VARKON Hershey study.
#
# It only implements the conversions I needed.

GLYPH_BASENAMES=$(basename $(wildcard glyph-*.PLT))
GLYPHBOXED_BASENAMES=$(basename $(wildcard glyphboxed-*.PLT))
GLYPHS=$(patsubst %,%.ps,$(GLYPH_BASENAMES))
GLYPHSBOXED=$(patsubst %,%.ps,$(GLYPHSBOXED_BASENAMES))
RANGE_BASENAMES=$(basename $(wildcard range-*.PLT))
RANGEBOXED_BASENAMES=$(basename $(wildcard rangeboxed-*.PLT))
RANGES=$(patsubst %,%.ps,$(RANGE_BASENAMES))
RANGESBOXED=$(patsubst %,%.ps,$(RANGEBOXED_BASENAMES))
TABLE_BASENAMES=$(basename $(wildcard table-*.PLT))
TABLEBOXED_BASENAMES=$(basename $(wildcard tableboxed-*.PLT))
TABLES=$(patsubst %,%.ps,$(TABLE_BASENAMES))
TABLESBOXED=$(patsubst %,%.ps,$(TABLEBOXED_BASENAMES))

#all: $(GLYPHS) $(GLYPHSBOXED) $(RANGES) $(RANGESBOXED) $(TABLES) $(TABLESBOXED)
all: $(RANGES) $(RANGESBOXED) $(TABLES)

$(GLYPHS): %.ps : %.PLT

$(GLYPHSBOXED): %.ps : %.PLT

$(RANGES): %.ps : %.PLT
	(if [ $*.PLT = "range-80.PLT" -o $*.PLT = "range-185.PLT" ]; \
            then postscript -s0.35 -v90 -x-40 -y-60 < $*.PLT > $*.ps; \
                 convert $*.ps -rotate 90 -crop 0x0 -resize 750 $*.png; \
            else postscript -s0.45 -v90 -x-40 -y-60 < $*.PLT > $*.ps; \
                 convert $*.ps -rotate 90 -crop 0x0 -resize 930 $*.png; \
         fi)
# Note:
# width of ordinary range (in VARKON mm): 480
# width of large    range (in VARKON mm): 595
# arbitrarily resized width of normal image (in pixels): 750 (x381)
# relatively  resized width of large  image (in pixels) 595/480*750 = 930 (x583)
# Note: -crop 0x0 does autocropping

$(RANGESBOXED): %.ps : %.PLT
	(if [ $*.PLT = "range-80.PLT" -o $*.PLT = "range-185.PLT" ]; \
            then postscript -s0.15 -v90 -x-40 -y-60 < $*.PLT > $*.ps; \
            else postscript -s0.3 -v90 -x-60 -y-60 < $*.PLT > $*.ps; \
         fi)
	# I'm not good enough in invoking ImageMagick's convert
	# to get crisp Postscript to PNG conversions, so I just use
	# the originals in VARKON (which will always be the best anyway).

$(TABLES): %.ps : %.PLT
	postscript -s0.07 -v90 -x-150 -y-40 < $*.PLT > $*.ps
	# use screen capture for PNG; it's crisper than conversion through ps

$(TABLESBOXED): %.ps : %.PLT

clean:
	rm -f *.ps
	rm -f *.png

mrproper: clean
	rm -f *.PLT

# references: info make, Static Pattern Rules
#             info make, Automatic Variables

# Copyright 2003-2005 by David M. MacMillan

# This work is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# NOTICE OF DISCLAIMER OF WARRANTY AND LIABILITY:

# This work is distributed WITHOUT ANY WARRANTY;
# without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.

# In no event will the author(s), editor(s), or publisher(s) of this work
# be liable to you or to any other party for damages,
# including but not limited to any general, special, incidental
# or consequential damages arising out of your use of or inability to use this
# work or the information contained in it, even if you have been advised
# of the possibility of such damages.

# In no event will the author(s), editor(s), or publisher(s) of this work
# be liable to you or to any other party for any injury, death,
# disfigurement, or other personal damage arising out of your use of
# or inability to use this work or the information
# contained in it, even if you have been advised of the
# possibility of such injury, death, disfigurement, or other
# personal damage.

# You should have received a copy of the GNU General Public License
# along with this work; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA  02111-1307, USA.

