############################################################
#		Makefile  (Gnu make) 
# Description:  src2fm filters - from source code to FrameMaker/html/etc.
# RCS: $Header: /homes/young/systems/hypercode/RCS/Makefile,v 1.55 1996/06/23 22:23:36 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
#
############################################################
#       %%%%  Generic recipes  %%%%
# 
#  get rid of all suffix rules - they're often wrong
 .SUFFIXES:
#
#  Although pattern rules are useful,they may not be standard.
#  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 


##  The scripts must use the same  same BINDIR as set here. 
##  Edit "Configuration" and then run the doconfigure script
##  ("make configure") to point all the scripts to the right
##  directories and tools.
##  

SCRIPTDIR = ./
BINDIR = ./ 

##  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

WWWSCRIPTS = html_markers.awk html_index.awk html_global_index.awk \
	html_guide_index.awk  html_clean.awk \
	Configuration doconfigure $(WWWCSH)

FMCSH = src2fm

FMSCRIPTS  = doconfigure Configuration $(FMSCSH)

WWWBIN = ada2html c2html crfilt
FMBIN  = ada2mif c2mif csh2mif crfilt

SCRIPTS = $(WWWSCRIPTS) $(FMSCRIPTS)
BINARIES = ada2mif c2mif ada2html c2html csh2mif csh2html

scripts:  $(SCRIPTS)
	-echo '==Note: use script "doconfigure" to configure the scripts'
binaries: $(BINARIES)
templates: CodeTemplate.fm
docs:	README.SRC2FM  README.SRC2WWW
all:  scripts binaries templates docs

wwwbin: $(WWWBIN) $(WWWSCRIPTS) README.SRC2WWW configure

fmbin:  $(FMBIN) $(FMSCRIPTS)  templates README.SRC2FM configure

install: all
	mv -f $(BINARIES) $(BINDIR)
	mv -f $(SCRIPTS)  $(SCRIPTDIR) 
## Presently not installing templates ... need to think about this

configure: doconfigure Configuration $(SCRIPTS)
	doconfigure $(WWWCSH) $(FMCSH)

unconfigure: Configuration
	doconfigure -deconfigure $(WWWCSH) $(FMCSH)
	mv Configuration Configuration.src

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

fmdist: ; 
	mkdir $(FMDIST)
	cd $(FMDIST); ln -s ../RCS .
	cp Makefile $(FMDIST)/Makefile
	cd $(FMDIST); make fmbin; make clean
	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
# 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 

# "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 

## 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
## ####

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
	$(FLEX) -i -t ada95gr.l >ada95gr.c

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

ada95gr.o: ada95gr.c gr.h 
	gcc -c ada95gr.c 

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

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

c2gr.o: c2gr.c gr.h 
	gcc -c c2gr.c 

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

csh2gr.o: csh2gr.c gr.h 
	gcc -c csh2gr.c 

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
	$(FLEX) -t pleiades2gr.l > pleiades2gr.c

pleiades2gr.o: pleiades2gr.c gr.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 
##    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



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

mifdrvr.o: mifdrvr.c mifdrvr.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
	gcc -g -c htmldrvr.c

grhtml.o: grhtml.c gr.h groptions.h htmldrvr.h 
	gcc -g -c grhtml.c 

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

texdrvr.o: texdrvr.c texdrvr.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)

## ###
##  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

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








