# Makefile for the UniversityOS Fonts for UC Berkeley
# Created by Jonathan Sprinkle, Ph.D.
# The old-fashioned way: vi


### f=free
### gy=goudy
### weight:	l light
### 			r regular
### 			k book
### 			m medium
### 			d demi
### 			s semibold
### 			b bold
### 			c black
### 	some width codes:
### 			c condensed
### 			p compressed
### 			n narrow
### 			- normal
### 			e expanded
### 			x extended
### some variant codes:
### 			a alternate
### 			d display, titling
### 			f fraktur, handtooled
### 			j oldstyle digits
### 			n informal, casual
### 			p ornaments
### 			s sans serif
### 			t typewriter
### 			w script, handwriting
### 			x expert
### some shape codes:
### 			c small caps
### 			i italic
### 			o oblique, slanted
### 			u unslanted italic
### how does it break down?
### fgy[weight][variant(s)]8a[width]


MAKEFILE = Makefile

ECHO	= echo

SHELL	= /bin/sh


OUT		= universityos.tar.gz
INTERNAL= universityos-install.tar.gz

VPATH = .:$(TYPE1DIR)

### 
### All of the directories we either populate,
###  or extract from, to do building or installation
### 

AFMDIR = fonts/afm/free/UniversityOS
TFMDIR = fonts/tfm/free/UniversityOS
VFDIR = fonts/vf/free/UniversityOS
TTFDIR = fonts/truetype/free/UniversityOS
TYPE1DIR = fonts/type1/free/UniversityOS
TTF2TFMDIR = ttf2tfm/base
FGYSTYDIR = tex/latex/free/UniversityOS
DVIPSDIR = dvips/config
PDFTEXDIR = pdftex/config
MIKTEXDIR = miktex/config

DIVIDER = "_____________________________"

FAMILY = fgy

WEIGHTS = r b d

SHAPES = o i c

FAMILYWEIGHTS = $(foreach fam, $(FAMILY), $(foreach weight, $(WEIGHTS), $(fam)$(weight) ) )

### INFERIORS = $(foreach fam, $(FAMILY), $(foreach weight, $(WEIGHTS), $(fam)0$(weight) ) )

### SUPERIORS = $(foreach fam, $(FAMILY), $(foreach weight, $(WEIGHTS), $(fam)1$(weight) ) )

BASEFONTS = $(FAMILYWEIGHTS) $(foreach shape, $(SHAPES), $(foreach famweight, $(FAMILYWEIGHTS), $(famweight)$(shape) ) )

INFERIORFONTS =
SUPERIORFONTS =

### INFERIORFONTS = $(INFERIORS) $(foreach shape, i c, $(foreach famweight, $(INFERIORS), $(famweight)$(shape) ) )
### SUPERIORFONTS = $(SUPERIORS) $(foreach shape, i c, $(foreach famweight, $(SUPERIORS), $(famweight)$(shape) ) )
REGULARFONTS = $(BASEFONTS)

FULLFONTS = $(REGULARFONTS) $(SUPERIORFONTS) $(INFERIORFONTS)

FONTS = $(FULLFONTS)

### FONTS = \
### 	fgyb fgybc fgybi \
### 	fgyd fgydi fgydc \
### 	fgyr fgyrc fgyri \
### 	fgyc fgycc fgyci

USELATER = \
	fgyrd fgybd fgybij fgycij fgydij fgyrij

RAWENC = 8a
AFMENC = $(RAWENC)
FNTENC = 8r 8x
VFNTENC= 8t 9e 8c 9c
TFMENC = $(VFNTENC)

INFENC = 8t 9e
SUPENC = $(INFENC)

ALTENC = 8t 9e 

# reset the suffixes
.SUFFIXES: 

# these are the ones we are using
.SUFFIXES: .afm .pl .vpl .tfm .pfb ### .ttf 

FILEPREF  = $(foreach file, $(BASEFONTS), $(file)$(AFMENC) )

TMPEXT = vpl pl log mtx tfm vf fd

AFMBASE	= $(foreach file, $(BASEFONTS), $(file)$(AFMENC) ) 
AFMS	= $(foreach file, $(AFMBASE), $(file).afm ) 
TFMBASE = $(foreach file, $(BASEFONTS), $(foreach enc, $(TFMENC), $(file)$(enc)) ) \
			$(foreach file, $(INFERIORFONTS), $(foreach enc, $(INFENC), $(file)$(enc)) ) \
			$(foreach file, $(SUPERIORFONTS), $(foreach enc, $(SUPENC), $(file)$(enc)) ) 
TFMS	= $(foreach file, $(TFMBASE), $(file).tfm )
PLBASE	= $(foreach file, $(REGULARFONTS), $(foreach enc, $(FNTENC), $(file)$(enc)) ) 
PLS		= $(foreach file, $(PLBASE), $(file).pl ) 
VPLBASE	= $(foreach file, $(FONTS), $(foreach enc, $(VFNTENC), $(file)$(enc)) )
VPLS	= $(foreach file, $(VPLBASE), $(file).vpl)
VFBASE	= $(foreach file, $(FONTS), $(foreach enc, $(ALTENC), $(file)$(enc)) )
VFS		= $(foreach file, $(VFBASE), $(file).vf)

STYLES	= universityos.sty T1.enc 8rfgy.fd t1fgy.fd
DVIPSS	= fgy.map fgy_config.ps
PDFTEXS	= fgy.map fgy_pdftex.cfg
MIKTEXS = fgy_updmap.cfg

DISTRIBUTIONFILES = \
	$(foreach afm, $(AFMS), $(AFMDIR)/$(afm)) \
	$(foreach tfm, $(TFMS), $(TFMDIR)/$(tfm)) \
	$(foreach sty, $(STYLES), $(FGYSTYDIR)/$(sty)) \
	$(foreach dvi, $(DVIPSS), $(DVIPSDIR)/$(dvi)) \
	$(foreach pdf, $(PDFTEXS),$(PDFTEXDIR)/$(pdf)) \
	$(foreach mik, $(MIKTEXS),$(MIKTEXDIR)/$(mik)) \
	$(foreach vf, $(VFS), $(VFDIR)/$(vf))

### 
### All of the files that we would want to remove later
###  when we do an uninstall
### 

UNINSTALLFILES = \
	$(OUT) \
	$(INTERNAL) \
	$(DISTRIBUTIONFILES) \
	Makefile


default:
	@$(ECHO) $(DIVIDER)
	@$(ECHO) "You must use an actual title, to avoid blasting files away:"
	@$(ECHO) "  extract:   unzip the installation, followed by user file-integration"
	@$(ECHO) "  install:   initialize, update maps/databases, and run tests"
	@$(ECHO) "  uninstall: blast away all installed files "
	@$(ECHO) "             WARNING!! Could require you to reinstall other applications for TeX!!!"
	@$(ECHO) "  dist:      rebuild the distribution from sources"
	@$(ECHO) "             (not required if the *-install.tar.gz file exists)"
	@$(ECHO) ""
	@$(ECHO) ""

extract:
	if [ -e $(MIKTEXDIR)/updmap.cfg.fgy.bak ]; then rm $(MIKTEXDIR)/updmap.cfg.fgy.bak; fi
	if [ -e $(MIKTEXDIR)/updmap.cfg ]; then mv $(MIKTEXDIR)/updmap.cfg $(MIKTEXDIR)/updmap.cfg.fgy.bak; fi
	tar xzf $(INTERNAL)
	mv $(MIKTEXDIR)/fgy_updmap.cfg $(MIKTEXDIR)/updmap.cfg
	@$(ECHO) ""
	@$(ECHO) "Please update the following files, by copying them without the 'fgy_'"
	@$(ECHO) " prefix, or by incorporating them into the existing file without the prefix."
	@$(ECHO) ""
	@$(ECHO) $(DVIPSDIR)/fgy_config.ps
	@$(ECHO) $(PDFTEXDIR)/fgy_pdftex.cfg
	@$(ECHO) $(MIKTEXDIR)/fgy_updmap.cfg
	@$(ECHO) ""
	@$(ECHO) "Make sure that 'make install' runs after this..."
	@$(ECHO) ""
	@$(ECHO) ""

install: extract
	initexmf --mkmaps
	texhash
	$(MAKE) test
	@$(ECHO) "Check files "
	@$(ECHO) " testUCBFonts/testUCBFonts.pdf "
	@$(ECHO) " testUCBFonts/testUCBFonts.dvi "
	@$(ECHO) " testUCBFonts/latestUCBFonts.pdf "
	@$(ECHO) " testUCBFonts/latestUCBFonts.dvi "
	@$(ECHO) "To determine the proper functionality of your installation."
	@$(ECHO) ""
	@$(ECHO) ""

uninstall:
	@$(ECHO) "Currently not implemented, until tested. :)"

dist:	$(OUT)

all:	dist

### do not make the output file until we have the internal zipfile...
$(OUT)	: $(INTERNAL)
	tar cz \
		README-universityos \
		Makefile \
		$(INTERNAL) \
		-f $(OUT)

### do not make the internal zipfile until we have populated all of the copies...
$(INTERNAL): copies
	tar cz \
		dvips/config/* \
		pdftex/*  \
		miktex/*  \
		fonts/* \
		tex/* \
		testUCBFonts/testUCBFonts.tex \
		testUCBFonts/latestUCBFonts.tex \
		--exclude=CVS \
		--exclude=empty \
		--exclude=truetype \
		--exclude=originals \
		--exclude=*.fog \
		-f $(INTERNAL)


### do not distribute copies until we have manufactured the TFMS and their byproducts...
copies: $(TFMS)
	@$(ECHO) $(BASEFONTS)
	@$(ECHO) "Family weights:" 
	@$(ECHO) $(FAMILYWEIGHTS)
### 	cp *.afm $(AFMDIR)/
	cp *.tfm $(TFMDIR)/
	cp universityos.sty $(FGYSTYDIR)/
### 	cp T1.enc $(FGYSTYDIR)/
	cp *.fd $(FGYSTYDIR)/
	cp *.vf $(VFDIR)/
	cp fgy.map $(DVIPSDIR)/
	cp fgy.map $(PDFTEXDIR)/
	cp fgy_config.ps $(DVIPSDIR)/
	cp fgy_pdftex.cfg $(PDFTEXDIR)/
	cp fgy_updmap.cfg $(MIKTEXDIR)/

### ### produce AFM files from TTFs
### $(AFMS) : $(TTFS)
### 	@$(ECHO) $(DIVIDER) "Creating .afm files from .ttf files...TTF=@<"
### 	ttf2afm -a -e $(RAWENC).enc -o $(*F).afm $<

$(PLS) $(VPLS) : ucbLatin.tex
	@$(ECHO) BASEFONTS
	@$(ECHO) $(BASEFONTS)
	@$(ECHO) PLS VPLS
	@$(ECHO) $(PLS)
	@$(ECHO) $(VPLS)
	cp $(AFMDIR)/*.afm .
	@$(ECHO) $(DIVIDER) "Running fontinst..."
	tex ucbLatin.tex

### produce TFM files from AFMs...
$(TFMS): $(PLS) $(VPLS)
	(for vpl in $(VPLBASE); do vptovf $$vpl.vpl $$vpl.vf $$vpl.tfm; done )
	(for pl in $(PLBASE); do pltotf $$pl.pl $$pl.tfm; done )
	tex fgy-map.tex

### run tests to check font installation and stylefile placement...
test: tex-test latex-test

### produce a DVI and PDF file from the same TeX files. This does NOT test LaTeX, only TeX
tex-test:
	tex -interaction=nonstopmode -output-directory=testUCBFonts/ testUCBFonts/testUCBFonts.tex 
	pdftex -output-directory=testUCBFonts/ testUCBFonts/testUCBFonts.tex 

### produce a DVI and PDF file from the same LaTeX files. This does NOT test TeX, only LaTeX
latex-test:
	latex -interaction=nonstopmode -output-directory=testUCBFonts/ testUCBFonts/latestUCBFonts.tex 
	pdflatex -output-directory=testUCBFonts/ testUCBFonts/latestUCBFonts.tex 


distclean:
	-$(RM) $(foreach file, $(FONTS), $(foreach ext, $(TMPEXT), $(file)*.$(ext)))
	-$(RM) *.fd

clean: distclean
	@$(ECHO) $(DIVIDER) "Cleaning..."
	-$(RM) $(OUT)
	-$(RM) $(INTERNAL)

realclean:	clean
	@$(ECHO) $(DIVIDER) "Removing distributed files, and deep cleaning ./ ..."
	if [ -e goudy.mtx ]; then mv goudy.mtx goudy.save; fi
	-$(RM) $(foreach ext, $(TMPEXT), *.$(ext) )
	-$(RM)  \
		$(DISTRIBUTIONFILES) \
		testUCBFonts/latestUCBFonts.pdf \
		testUCBFonts/latestUCBFonts.dvi \
		testUCBFonts/testUCBFonts.pdf \
		testUCBFonts/testUCBFonts.dvi
	mv goudy.save goudy.mtx

