############################################################
#		Makefile  (Gnu make) 
# Description:  src2fm filters - from source code to FrameMaker/html/etc.
# RCS: $Header: /homes/young/systems/hypercode/RCS/Makefile,v 1.78 1997/05/11 22:42:52 young Exp $ 
# 
############################################################
# 
#      Parameters
#
SHELL = /bin/csh#  for filename expansion 
GCCOPTS = -g 
# FLEX = /usr/local/gnu/flex-2.4.7 ## Minimum version required
FLEX = /usr/local/gnu/flex         ## I'm using 2.5.2 currently
AWK = /bin/nawk			   
# AWK = /usr/local/gnu/gawk
GCC = gcc 			  
#
############################################################
#       %%%%  Generic recipes  %%%%
# 
#  get rid of all suffix rules - they're often wrong
 .SUFFIXES:
#
#  Although pattern rules are useful,they may not be standard.
#  It would be nice to use, for example, Gnu make targets, but
#  it's a pain to have an installation fail because you don't
#  have the developer's favorite version of Make. 
#  I'll keep the RCS rule for my local work, the others are
#  removed to minimize configuration hassles for users.
## %.o: %.c ; $(GCC) -c -o $*.o $*.c
## %.l.c: %.l ; $(FLEX)  -t $*.l >$*.l.c
%:: RCS/%,v ; co $*

############################################################
## Composite and management targets 

## Recent change: Don't set SCRIPTDIR and BINDIR here, make the 
## change in file "Configuration".  Then, "make wwwbin" or "make fmbin"
## will configure all the scripts, including the installation script.
##

##  If you want only some of the front ends, eliminate the other
##  filters/scripts from these lists
##

default: 
	@ echo "Likely target: wwwbin (src2www only),"\
	" all (src2www and src2fm), or fmbin (src2fm only)."
	@ echo "Since this Makefile serves all, I don't know which " \
	"to create by default." 
	@ echo "Also be sure to edit Configuration.src and "\
	"save as Configuration"

##  We divide the scripts into two categories:  csh scripts which
##  must be configured using the "doconfigure" script, and everything
##  else.  Note that "doconfigure" is the only csh script which is 
##  not itself listed as a script to be configured! 
##
WWWCSH = src2www html_wrap pstogif
WWWSRC = src2www.src html_wrap.src pstogif.src
WWWTEMPLATES = model-colored.html model-plain.html 
$(WWWCSH): $(WWWSRC) Configuration doconfigure
	./doconfigure $(WWWCSH) 

WWWAWK = html_markers.awk html_index.awk html_global_index.awk \
	html_guide_index.awk  html_clean.awk 

WWWSCRIPTS = $(WWWCSH) $(WWWAWK)

FMCSH = src2fm
FMSRC = src2fm.src
$(FMCSH): $(FMSRC) Configuration doconfigure
	./doconfigure $(FMCSH)

FMSCRIPTS  = $(FMSCSH)

SHAREBIN = crfilt
WWWBIN = ada2html c2html awk2html csh2html 
FMBIN  = ada2mif c2mif  awk2mif csh2mif 
TEXBIN = ada2tex c2tex awk2tex csh2tex
BINARIES = $(WWWBIN) $(FMBIN) $(TEXBIN) $(SHAREBIN)

INSTALLERS = Configuration doconfigure doinstall

SCRIPTS = $(WWWSCRIPTS) $(FMSCRIPTS) $(WWWAWK) $(INSTALLERS)

INSTALLABLE = $(WWWSCRIPTS) $(FMSCRIPTS) $(BINARIES) $(WWWTEMPLATES)

scripts:  $(SCRIPTS)

binaries: $(BINARIES)
templates: CodeTemplate.fm $(WWWTEMPLATES)
docs:	README.SRC2FM  README.SRC2WWW
all:  scripts binaries templates docs

wwwbin: $(WWWBIN) $(SHAREBIN) $(WWWSCRIPTS) $(WWWTEMPLATES) README.SRC2WWW 

fmbin:  $(FMBIN) $(SHAREBIN) $(FMSCRIPTS)  $(INSTALLERS) \
	templates README.SRC2FM  

##  Installation is a bit messed up --- What I really need is 
##  conditional sensing of either products to be installed for a 
##  src2www installation or a src2fm installation, but since I 
##  am aiming for a "least common denominator" Makefile I can't 
##  use the conditional constructs that come in some particular 
##  flavors of make.  The current hack is to have two targets, 
##  fminstall and wwwinstall, but currently they both install 
##  everything they find (so, if you make both sets of executables,
##  either installation will install both). 

install: 
	-echo "Please try 'make wwwinstall' or 'make fminstall'"

fminstall: fmbin
	./doinstall $(INSTALLABLE)

wwwinstall: wwwbin
	./doinstall $(INSTALLABLE)

## Presently not installing templates ... need to think about this

configure: 
	-echo "There is no longer a 'configure' target."
	-echo "Edit Configuration.src, save as Configuration, then "
	-echo " 'make scripts' "

unconfigure: Configuration
	mv Configuration Configuration.src

## Make distributions from the PARENT of the DIST directory
VERSION = 0.9j
FMDIST = src2fm-$(VERSION)
WWWDIST = src2www-$(VERSION)

fmdist: ; 
	mkdir $(FMDIST)
	cd $(FMDIST); ln -s ../RCS .
	cp Makefile $(FMDIST)/Makefile
	cd $(FMDIST); make fmbin;  make clean; make unconfigure
	tar cf - $(FMDIST) | compress >$(FMDIST).$(OSTYPE).tar.Z
	cd $(FMDIST); make cleaner;
	tar cf - $(FMDIST) | compress >$(FMDIST).src.tar.Z

wwwdist: ; 
	mkdir $(WWWDIST)
	cd $(WWWDIST); ln -s ../RCS .
	cp Makefile $(WWWDIST)/Makefile
	cd $(WWWDIST); make wwwbin; make clean; 
	cd $(WWWDIST); make unconfigure
	tar cf - $(WWWDIST) | gzip >$(WWWDIST).$(OSTYPE).tar.gz
	cd $(WWWDIST); make cleaner
	tar cf - $(WWWDIST) | gzip >$(WWWDIST).src.tar.gz


# "clean" removes intermediate products 
# that don't belong in a binary distribution.
# Csh scripts are removed because they should be regenerated as part
# of the configuration process (e.g., src2www from src2www.src)
# Note:  I leave c2gr.c, which is not ultimate source, for the
#        convenience of users who don't have flex
#
clean: ; 
	- rm -f *.o *.tab.h *.tab.c *.l.c *.y.output *.y.h *.y.c 
	- rm -f $(WWWCSH) $(FMCSH) glyphcodes.h

# "cleaner" removes the executables as well, leaving
# a source distribution

cleaner: clean 
	 - rm -f  $(BINARIES)
	 
############################################################
## Real targets

## Front end, language independent objects
FrontParts = flexdriver.o groptions.o 

## MIF (FrameMaker) back end objects
MIFParts = grmif.o mifdrvr.o 

## HTML (world-wide-web) back end objects
HTMLParts = grhtml.o htmldrvr.o html_styles.o

## LaTeX back end objects
TeXParts = grtex.o texdrvr.o 

## Debugging back-end (prints each call to gr.h)


## In general, combine foo2gr.o with a FrontParts and either
## MIFParts or HTMLParts to form a complete processor for language foo

## ####
## FrontPart modules
## ####


## Glyph mapping tables; one shared list of possible glyphs, and one
##    mapping table for each back end.

glyphcodes.h:	glyphcodes.src glyphcodes.awk
	$(AWK) -f glyphcodes.awk glyphcodes.src >glyphcodes.h


glyphs_tex.h:	glyphcodes.src glyphs_tex.src glyphmaps.awk 
	$(AWK) -f glyphmaps.awk glyphcodes.src glyphs_tex.src >glyphs_tex.h

glyphs_html.h:	glyphcodes.src glyphs_html.src glyphmaps.awk 
	$(AWK) -f glyphmaps.awk glyphcodes.src glyphs_html.src >glyphs_html.h

glyphs_mif.h:	glyphcodes.src glyphs_mif.src glyphmaps.awk 
	$(AWK) -f glyphmaps.awk glyphcodes.src glyphs_mif.src >glyphs_mif.h

## Fixed driver parts

flexdriver.o: flexdriver.c gr.h groptions.h 
	$(GCC) -c flexdriver.c 

groptions.o: groptions.c groptions.h
	$(GCC) -g -c groptions.c

## ###
## Language-specific front ends 
## Note that some use flex with the -i option, some without,
##  depending on whether the language is case-sensitive.
##
## For each langgr.c there can be also a langbug.c, where
##  the bug version uses flex debugging
## ### 

ada95gr.c: ada95gr.l gr.h glyphcodes.h
	$(FLEX) -i -t ada95gr.l >ada95gr.c

ada95bug.c: ada95gr.l gr.h glyphcodes.h
	$(FLEX) -i -d -t ada95gr.l >ada95bug.c

ada95gr.o: ada95gr.c gr.h glyphcodes.h
	$(GCC) -c ada95gr.c 

ada2bug.o: ada95bug.c gr.h glyphcodes.h
	$(GCC) -c ada95bug.c 

c2gr.c: c2gr.l gr.h  glyphcodes.h
	$(FLEX) -t c2gr.l > c2gr.c

c2bug.c: c2gr.l gr.h  glyphcodes.h
	$(FLEX) -d -t c2gr.l > c2bug.c

c2gr.o: c2gr.c gr.h glyphcodes.h
	$(GCC) -c c2gr.c 

c2bug.o: c2bug.c gr.h glyphcodes.h
	$(GCC) -c c2bug.c 

awk2gr.c: awk2gr.l gr.h glyphcodes.h
	$(FLEX) -t awk2gr.l > awk2gr.c

awk2bug.c: awk2gr.l gr.h glyphcodes.h
	$(FLEX) -d -t awk2gr.l > awk2bug.c

awk2gr.o: awk2gr.c gr.h glyphcodes.h
	$(GCC) -c awk2gr.c 

awk2bug.o: awk2bug.c gr.h glyphcodes.h
	$(GCC) -c awk2bug.c 


csh2gr.c: csh2gr.l gr.h glyphcodes.h
	$(FLEX) -t csh2gr.l >csh2gr.c

csh2gr.o: csh2gr.c gr.h glyphcodes.h
	$(GCC) -c csh2gr.c 


jill2gr.c: jill2gr.l gr.h glyphcodes.h
	$(FLEX) -i -t jill2gr.l >jill2gr.c

jill2gr.o: jill2gr.c gr.h glyphcodes.h
	$(GCC) -c jill2gr.c 


##  Matching rule language for the analyzer generator
##       (Pezze & Young, ICSE 97)
##
match2gr.c: match2gr.l gr.h
	$(FLEX) -i -t match2gr.l >match2gr.c

match2gr.o: match2gr.c gr.h glyphcodes.h
	$(GCC) -c match2gr.c

match2bug.c: match2gr.l gr.h
	$(FLEX) -i -d -t match2gr.l > match2bug.c

match2bug.o: match2bug.c gr.h
	$(GCC) -c match2bug.c 

## The eiffel matcher was never finished ... so far the 
##    only request was from the company that sells eiffel,
##    so I'm not sure if there is real demand. 
eiffel2gr.c: eiffel2gr.l
	$(FLEX) -t eiffel2gr.l >eiffel2gr.c

eiffel2gr.o: eiffel2gr.c gr.h
	$(GCC) -c eiffel2gr.c


## Pleiades is an Ada extension with persistent data structures.
## See http://zoo.cs.umass.edu/tools/Pleiades.html for more info
pleiades2gr.c: pleiades2gr.l gr.h glyphcodes.h
	$(FLEX) -t pleiades2gr.l > pleiades2gr.c

pleiades2gr.o: pleiades2gr.c gr.h glyphcodes.h
	$(GCC) -c pleiades2gr.c 

##
##  ada with extractor --- a stop-gap until we pull out 
##	good cross reference information out of gnat
##	xref and (unimaginably hideous) Verdix xref.
##

get_with.c: get_with.l
	$(FLEX) -t get_with.l > get_with.c

get_with: get_with.c
	$(GCC) get_with.c -o get_with

##
##  Gnat xref --- experimental and in development, not ready 
##    for prime time yet. 
##

gnatx2triple.y.c gnatx2triple.y.h: gnatx2triple.y 
	bison  -o gnatx2triple.y.c  --defines --debug --verbose gnatx2triple.y;

gnatx2triple.l.c: gnatx2triple.l gnatx2triple.y.h 
	$(FLEX) -t gnatx2triple.l > gnatx2triple.l.c

gnatx2triple: gnatx2triple.l.c gnatx2triple.y.c gnatx2triple.y.h
	$(GCC) ${GCCOPTS} -o gnatx2triple gnatx2triple.l.c gnatx2triple.y.c -ll

ada95procs.c: ada95procs.l 
	$(FLEX) -i -t ada95procs.l >ada95procs.c

ada95procs:	ada95procs.c
	$(GCC) $(GCCOPTS) -o ada95procs ada95procs.c

## ###
## MIF Back end 
## ###

mifdrvr.o: mifdrvr.c mifdrvr.h  glyphs_mif.h
	$(GCC) -g -c mifdrvr.c

grmif.o: grmif.c gr.h mifdrvr.h
	$(GCC) -g -c grmif.c 
## ###
## HTML Back end
## ###

htmldrvr.o: htmldrvr.c htmldrvr.h glyphs_html.h
	$(GCC) -g -c htmldrvr.c

html_styles.o: html_styles.h html_styles.c
	$(GCC) -g -c html_styles.c

grhtml.o: grhtml.c gr.h groptions.h htmldrvr.h html_styles.h
	$(GCC) -g -c grhtml.c 

## ###
## LaTeX Back end
## ###

texdrvr.o: texdrvr.c texdrvr.h  glyphs_tex.h
	$(GCC) -g -c texdrvr.c

grtex.o: grtex.c gr.h groptions.h texdrvr.h 
	$(GCC) -g -c grtex.c 


## ###
## Debugging back end
## ###

grdebug.o:	grdebug.c gr.h
	$(GCC) -c grdebug.c

## ###
## Filters constructed from back and front ends 
## ###

ada2mif: ada95gr.o  $(FrontParts) $(MIFParts) 
	$(GCC) -g -o ada2mif ada95gr.o $(FrontParts) $(MIFParts)

ada2html: ada95gr.o $(FrontParts) $(HTMLParts) 
	$(GCC) -g -o ada2html ada95gr.o $(FrontParts) $(HTMLParts) 

ada2tex: ada95gr.o $(FrontParts) $(TeXParts) 
	$(GCC) -g -o ada2tex ada95gr.o $(FrontParts) $(TeXParts) 

ada2bug: ada95bug.o grdebug.o $(FrontParts)
	$(GCC) -g -o ada2bug ada95bug.c grdebug.o $(FrontParts)


c2mif: c2gr.o $(FrontParts) $(MIFParts) 
	$(GCC) -g -o c2mif c2gr.o $(FrontParts) $(MIFParts)

c2html: c2gr.o   $(FrontParts) $(HTMLParts) 
	$(GCC) -g -o c2html c2gr.o $(FrontParts) $(HTMLParts) 

c2tex: c2gr.o   $(FrontParts) $(TeXParts) 
	$(GCC) -g -o c2tex c2gr.o $(FrontParts) $(TeXParts) 

c2bug: c2bug.o grdebug.o $(FrontParts)
	$(GCC) -g -o c2bug c2bug.c grdebug.o $(FrontParts)


awk2mif: awk2gr.o $(FrontParts) $(MIFParts) 
	$(GCC) -g -o awk2mif awk2gr.o $(FrontParts) $(MIFParts)

awk2html: awk2gr.o   $(FrontParts) $(HTMLParts) 
	$(GCC) -g -o awk2html awk2gr.o $(FrontParts) $(HTMLParts) 

awk2tex: awk2gr.o   $(FrontParts) $(TeXParts) 
	$(GCC) -g -o awk2tex awk2gr.o $(FrontParts) $(TeXParts) 

awk2bug: awk2bug.o grdebug.o $(FrontParts)
	$(GCC) -g -o awk2bug awk2bug.c grdebug.o $(FrontParts)

## csh 
csh2mif: csh2gr.o $(FrontParts) $(MIFParts)
	$(GCC) -g -o csh2mif csh2gr.o $(FrontParts) $(MIFParts)

csh2html: csh2gr.o   $(FrontParts) $(HTMLParts) 
	$(GCC) -g -o csh2html csh2gr.o $(FrontParts) $(HTMLParts) 

csh2tex: csh2gr.o   $(FrontParts) $(TeXParts) 
	$(GCC) -g -o csh2tex csh2gr.o $(FrontParts) $(TeXParts) 

csh2bug: csh2bug.o grdebug.o $(FrontParts)
	$(GCC) -g -o csh2bug csh2bug.c grdebug.o $(FrontParts)

## jill (a process programming language)

jill2mif: jill2gr.o $(FrontParts) $(MIFParts)
	$(GCC) -g -o jill2mif jill2gr.o $(FrontParts) $(MIFParts)

jill2html: jill2gr.o   $(FrontParts) $(HTMLParts) 
	$(GCC) -g -o jill2html jill2gr.o $(FrontParts) $(HTMLParts) 

jill2tex: jill2gr.o   $(FrontParts) $(TeXParts) 
	$(GCC) -g -o jill2tex jill2gr.o $(FrontParts) $(TeXParts) 

jill2bug: jill2bug.o grdebug.o $(FrontParts)
	$(GCC) -g -o jill2bug jill2bug.c grdebug.o $(FrontParts)



#
# Matching rule language, Pezze & Young 97
#
match2tex:  match2gr.o $(FrontParts) $(TeXParts) 
	$(GCC) -g -o match2tex match2gr.o $(FrontParts) $(TeXParts)

match2html:  match2gr.o $(FrontParts) $(HTMLParts) 
	$(GCC) -g -o match2html match2gr.o $(FrontParts) $(HTMLParts)

match2bug:  match2bug.o $(FrontParts) grdebug.o 
	$(GCC) -g -o match2bug match2bug.o grdebug.o $(FrontParts)


## ###
##  Auxillary tools (you may not need all of these)
##  
## ###

## crfilt is a filter for converting DOS or Mac text file
##  line ending conventions into the Unix line end convention. 
##  It should have no effect on text files that are already in
##  Unix convention.  This sometimes avoids some frustration 
##  when postscript figures are prepared on a personal computer.
##  
crfilt:	crfilt.c
	$(GCC) -g -o crfilt crfilt.c	

crfilt.c: crfilt.l
	$(FLEX)  -t crfilt.l >crfilt.c

################################################################








