# The Makefile for pfd2tfm.
# For copyright information see the individual sources.
# GFLAG = -g
DEFS = -DSYS_V=$(SYS_V)
INCS =  -I../h -I../../h
CFLAGS = $(GFLAG) $(INCS) $(DEFS)
LINT_FLAGS =      $(INCS) $(DEFS)

OTHER_SRC = main.c ly.c texdefs.c kernlig.c afm.c\
	pl.c writepdr.c emul.c fixw.c remap.c util.c \
	mapfn.c execps.c defccv.c exc.c
OTHER_OBJ = main.o ly.o texdefs.o kernlig.o afm.o\
	pl.o writepdr.o emul.o fixw.o remap.o util.o \
	mapfn.o execps.o defccv.o exc.o

# Lex and related stuff: .afm files.
LEX_AFM_SRC = afm-lex.c afm-ptok.c
LEX_AFM_OBJ = afm-lex.o afm-ptok.o

# Lex and related stuff: .pfd files.
LEX_PFD_SRC = pfd-lex.c pfd-ptok.c
LEX_PFD_OBJ = pfd-lex.o pfd-ptok.o

# Lex stuff for reading in default encoding vector and default ligatures.
LEX_DEFENC = defenc-lex.c

# yacc options (.afm and .pfd).
YACCOPT = -v

# All the sources.
SRC = 	$(LEX_AFM_SRC) afm-yacc.c\
	$(LEX_PFD_SRC) pfd-yacc.c\
	$(OTHER_SRC) defenc-lex.c

HFILES_X = afm-tokenlex.h pfd-tokenlex.h

# All the objects.
OBJ = 	$(LEX_AFM_OBJ) afm-yacc.o\
	$(LEX_PFD_OBJ) pfd-yacc.o\
	defenc-lex.o $(OTHER_OBJ)

LIB_DIR = ../../lib
SUP = ../../sup

# The install command to be used.
INSTALL = install -c -s

all:
	@make prep-all
	@make pfd2tfm

relink:
	@$(RM) pfd2tfm
	@make prep-all
	@make pfd2tfm

install:	all
	$(RM) $(PFD_BINDIR)/pfd2tfm
	$(INSTALL) pfd2tfm $(PFD_BINDIR)/pfd2tfm

prep-all:
	@cd $(LIB_DIR); make
	@cd ../../otherc; make
	@cd $(SUP); make

pfd2tfm:	 $(OBJ)
	@$(RM) $@ lint
	$(CC) -o $@ $(GFLAG) $(OBJ) ../../otherc/sig.o ../../otherc/defaults.o $(LIB_DIR)/libics.a -lm

# First all stuff having to do with reading in .pfd files, lex and yacc.
# **********************************************************************
# All the yy... identifiers are now YY in lex and yacc.
pfd-tokenlex.h:	pfd-tokens.tdef
	$(SUP)/tokprep -H $@ pfd-tokens.tdef

pfd-tokens.y:	pfd-tokens.tdef
	$(SUP)/tokprep -Y $@ pfd-tokens.tdef

pfd-ptok.c:	pfd-tokens.tdef
	$(SUP)/tokprep -N PrintTokenPfd -C $@ pfd-tokens.tdef

pfd-tokens.lex:	pfd-tokens.tdef
	$(SUP)/tokprep -c -L $@ pfd-tokens.tdef

pfd-lex.c:	pfd-1.lex pfd-tokens.lex pfd-2.lex
	cat     pfd-1.lex pfd-tokens.lex pfd-2.lex  > lexin.tmp
	$(LEX) lexin.tmp
	@$(RM) lexin.tmp
	sed -e 's/yylex()/YYlex_pfd()/g'\
	    -e 's/yy/YY/g'\
	    -e 's/YYerror/yyerror/'\
	    -e 's/YYwrap/yywrap/' lex.yy.c > $@
	$(RM) lex.yy.c

pfd-yacc.c pfd-output pfd-all.y:	pfd-1.y	pfd-tokens.y pfd-2.y
	$(RM) pfd-all.y pfd-yacc.c pfd-output
	echo 	'/* TMP file generated in "make", can be removed. */ > pfd-all.y
	cat 	pfd-1.y pfd-tokens.y			        >> pfd-all.y
	echo	'%start program'				>> pfd-all.y
	cat 	pfd-2.y			        		>> pfd-all.y
	$(YACC) $(YACCOPT) pfd-all.y
	sed -e 's/yylex()/Mylex()/g' \
	    -e 's/yyparse()/yyparse_pfd()/g'\
	    -e 's/yy/YY/g'\
	    -e 's/YYerror/yyerror/g'    y.tab.c > pfd-yacc.c
	$(RM) y.tab.c
	$(MV) y.output	pfd-output

# Second all stuff having to do with reading in .afm files, lex and yacc
# **********************************************************************
# All the yy identifiers stay lower case
afm-tokenlex.h: afm-tokens.tdef
	$(SUP)/tokprep -H $@ afm-tokens.tdef

afm-tokens.y:	afm-tokens.tdef
	$(SUP)/tokprep -Y $@ afm-tokens.tdef

afm-ptok.c:	afm-tokens.tdef
	$(SUP)/tokprep -N PrintTokenAfm -C $@ afm-tokens.tdef

afm-tokens.lex:	afm-tokens.tdef
	$(SUP)/tokprep -b -c -L $@ afm-tokens.tdef

afm-lex.c:	afm-1.lex afm-tokens.lex afm-2.lex
	@$(RM) $@ lexin.tmp
	cat afm-1.lex afm-tokens.lex afm-2.lex  > lexin.tmp
	$(LEX) lexin.tmp
	@$(RM) lexin.tmp
	sed -e 's/yylex()/yylex_afm()/g' lex.yy.c > $@
	$(RM) lex.yy.c

afm-yacc.c afm-output afm-all.y:	afm-1.y	afm-tokens.y afm-2.y
	@$(RM) afm-all.y afm-yacc.c afm-output
	echo 	'/* TMP file generated in "make", can be removed */'> afm-all.y
	cat 	afm-1.y afm-tokens.y			           >> afm-all.y
	echo	'%start program'				   >> afm-all.y
	cat 	afm-2.y					           >> afm-all.y
	$(YACC) $(YACCOPT) afm-all.y
	sed -e 's/yylex()/Mylex()/g' \
	    -e 's/yyparse()/yyparse_afm()/g'         y.tab.c > afm-yacc.c
	@$(RM) y.tab.c
	$(MV) y.output	afm-output

defenc-lex.c:	defenc.lex
	@$(RM) $@
	$(LEX) defenc.lex
	sed -e 's/yylex()/Yylex_defenc()/g'\
	    -e 's/yy/Yy/g'\
	    -e 's/Yyerror/yyerror/'\
	    -e 's/Yywrap/yywrap/' lex.yy.c > $@
	$(RM) lex.yy.c

print:
	$(PRINT_COMMAND) Makefile $(OTHER_SRC)\
		pfd-1.lex pfd-2.lex pfd-tokens.in pfd-1.y pfd-2.y\
		afm-1.lex afm-2.lex afm-tokens.in afm-1.y afm-2.y\
		defenc.lex

lint:	$(LEX_AFM_SRC) $(LEX_PFD_SRC) pfd-yacc.c afm-yacc.c $(SRC)
	lint $(CFLAGS) $(OTHER_SRC)\
		$(LEX_AFM_SRC)	$(LEX_PFD_SRC)\
		pfd-yacc.c afm-yacc.c > $@

clean::
	$(RM) pfd2tfm *.tfm *.pdr\
		*tokenlex.h *ptok.* lex.yy.c yacc.tokens\
		afm-tokens.lex pfd-tokens.lex\
	 	afm-tokens.y pfd-tokens.y\
		afm-output   pfd-output\
		afm-all.y    pfd-all.y\
		afm-lex.c    pfd-lex.c\
		afm-yacc.c   pfd-yacc.c\
		compiler.c y.output y.tab.c\
		defenc-lex.c

depend:	$(SRC) $(HFILES_X)
	maketd -mIMakefile $(INC_DEFS) $(SRC)

# DO NOT DELETE THIS LINE - make depend DEPENDS ON IT
A=../../h
B=../h

afm-lex.o: $A/defs.h $B/yaccreturn.h afm-lex.c afm-tokenlex.h

afm-ptok.o: afm-ptok.c

afm-yacc.o: $A/char.h $A/defs.h $B/yaccreturn.h afm-yacc.c

pfd-lex.o: $A/defs.h $B/yaccreturn.h pfd-lex.c pfd-tokenlex.h

pfd-ptok.o: pfd-ptok.c

pfd-yacc.o: $A/char.h $A/defs.h $B/defenc.h $B/pfd2tfm.h $B/yaccreturn.h \
	pfd-yacc.c

main.o: $A/char.h $A/defs.h $A/extfil.h $A/tfm.h $B/pfd2tfm.h main.c

ly.o: $A/defs.h $A/extfil.h $B/pfd2tfm.h ly.c

texdefs.o: $A/char.h $A/defs.h $A/extfil.h $A/pdr.h texdefs.c

kernlig.o: $A/char.h $A/defs.h $A/extfil.h $B/defenc.h $B/pfd2tfm.h kernlig.c

afm.o: $A/char.h $A/defs.h $A/pdr.h $B/pfd2tfm.h afm.c

pl.o: $A/char.h $A/defs.h $A/extfil.h $B/pfd2tfm.h pl.c

writepdr.o: $A/char.h $A/defs.h $A/extfil.h $A/pdr.h $A/tfm.h $A/units.h \
	writepdr.c

emul.o: $A/char.h $A/defs.h $A/pdr.h $A/tfm.h emul.c

fixw.o: $A/char.h $A/defs.h $B/pfd2tfm.h fixw.c

remap.o: $A/char.h $A/defs.h remap.c

util.o: $A/defs.h $B/pfd2tfm.h util.c

mapfn.o: $A/defs.h $A/extfil.h mapfn.c

execps.o: $A/char.h $A/defs.h $A/pdr.h execps.c

defccv.o: $A/char.h $A/defs.h $A/extfil.h $B/defenc.h $B/pfd2tfm.h defccv.c

exc.o: $A/char.h $A/defs.h $B/pfd2tfm.h exc.c

defenc-lex.o: $A/defs.h $B/defenc.h defenc-lex.c

# *** Do not add anything here - It will go away. ***
