# Make(1) rules for FleXML XML processor generator system.
# Copyright  1999 Kristoffer Rose.  All rights reserved.
#
# This file is part of the FleXML XML processor generator system.
# Copyright  1999 Kristoffer Rose.  All rights reserved.
#
# This program 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.
#
# This program is distributed in the hope that it will be useful, but 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.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place, Suite 330, Boston, MA 02111-1307 USA.

# $Id: Makefile,v 1.1 2001/08/31 03:51:23 shack Exp $

# FILES.

SAMPS =	my.dtd my-show.act my-joke.xml my-joke2.xml my-joke3.xml \
	tricky.dtd tricky.act tricky.xml \
	test.html

SRC =	$(SAMPS)
ALL =	$(SAMPS)

# SETUP.

# Installation paths
USR = /usr
BINDIR = $(USR)/bin
LIBDIR = $(USR)/lib
SHARE = /usr/share
MAN1DIR = $(SHARE)/man/man1
DOCDIR = $(SHARE)/doc
DATADIR = $(SHARE)/flexml
TMPDIR = /var/tmp

# Permanent program locations
PERL = /usr/bin/perl
FLEX = /usr/bin/flex
FLEXML = $(BINDIR)/flexml
ACT = $(LIBDIR)/flexml-act
SKEL = $(DATADIR)/skel

# Build compilation setup.
CC = gcc -Wall -ansi -pedantic
CFLAGS = -O2 -g
#FLEXDEBUG = -d

# PRIMARY TARGETS.

.PHONY:		all install dist test clean

start: test

all:		$(ALL)

install:	$(ALL)
	mkdir -p $(DESTDIR)$(DOCDIR)/flexml/examples
	install -m444 $(SAMPS) $(DESTDIR)$(DOCDIR)/flexml/examples/

dist:		clean
	#rsync -v FleXML.html $(WEBHOME)/FleXML.html
	#rsync -va --cvs-exclude --delete-excluded ./ $(FTPHOME)/

clean::; @echo "Cleaning examples..."
	$(RM) *.[olh1] *-dummy.? lex.* *~ ./#*

test::		all
	@echo "Testing..."

# DEFAULT RULES.

# Generate C source from flex scanner.
%.c: 		%.l
	$(FLEX) -Bsv $(FLEXDEBUG) -o$@ $<

# Direct generation of stand-alone XML processor+application.
# Note: The dependency must be of the form "appl.l: appl.act proc.dtd".
%.l:		%.act
	../flexml.pl $(FLEXDEBUG) -vA -a $^

# Generate XML processor to link with application.
%.l %.h:	%.dtd ../skel
	../flexml.pl $(FLEXDEBUG) -v -s ../skel $<

# Generate XML application C source to compile and link with processor.
# Note: The dependency must be of the form "appl.c: appl.act proc.dtd".
%.c:		%.act
	../flexml.pl $(FLEXDEBUG) -vD -a $^


# MAIN PROGRAM.

clean::; $(RM) flexml flexml-act flexml-act.c

flexml:		flexml.pl
	sed -e "s;^[#][!].*perl;#!$(PERL);" \
	    -e "s;[.][/]flexml-act;$(ACT);g" \
	    -e "s;[.][/]skel;$(SKEL);g" \
	    -e "s;/var/tmp;$(TMPDIR);g" \
	    -e "s;/usr/share/doc/;$(DOCDIR)/;g" flexml.pl >flexml
	chmod +x flexml

# Action language...
flexml-act.l:		flexml-act.dtd ../skel
	../flexml.pl $(FLEXDEBUG) -Lv -ractions -s ../skel $<

flexml-act.c:		flexml-act.l
	$(FLEX) -Bsv -oflexml-act.c flexml-act.l

flexml-act.o:		flexml-act.c flexml-act.h
flexml-act-bootstrap.o:	flexml-act-bootstrap.c flexml-act.h
flexml-act:		flexml-act.o flexml-act-bootstrap.o

# DOCUMENTS.

# TESTS.

# Example: LINK processor with application:

my.l my.h:	my.dtd
my.c:		my.l
my.o:		my.c my.h

my-show.c:	my-show.act my.dtd
my-show.o:	my-show.c my.h
my-show:	my-show.o my.o

test::		my-show
	./my-show <my-joke.xml && echo OK
	./my-show <my-joke2.xml && echo OK
	./my-show <my-joke3.xml || echo OK

clean::; $(RM) my.c my-show my-show.c my-dummy my-dummy.c

# Example: COMPILE processor into application

tricky.l:	tricky.act tricky.dtd
tricky.c:	tricky.l
tricky.o:	tricky.c
tricky:		tricky.o

test::		tricky
	./tricky <tricky.xml

clean::; $(RM) tricky.[lco] tricky

# Complex example: application to print XHTML <a href=...> values.
# XHTML is big, so...we must use a patched flex (included in Debian).


xhtml1-transitional.dtd:
	wget 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'

xhtml1-transitional.l xhtml1-transitional.h: xhtml1-transitional.dtd ../skel
	./flexml.pl $(FLEXDEBUG) -s../skel -rhtml \
		-p "-//W3C//DTD XHTML 1.0 Transitional//EN" \
		-u "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" \
		xhtml1-transitional.dtd

xhtml1-transitional.c:	xhtml1-transitional.l
	$(FLEX) -Bsv -Ca -oxhtml1-transitional.c xhtml1-transitional.l

xhtml1-transitional.o:	xhtml1-transitional.c xhtml1-transitional.h

xhtml-href.c:	xhtml-href.act xhtml1-transitional.dtd
xhtml-href.o:	xhtml-href.c xhtml1-transitional.h
xhtml-href:	xhtml-href.o xhtml1-transitional.o

test::		xhtml-href
	./xhtml-href <test.html
	./xhtml-href <FleXML.html

clean::; $(RM) xhtml1-*.dtd xhtml1-*.[lhco] xhtml-href.[co] xhtml-href

# END.

clean::; @echo "Done cleaning."
test::;	@echo "Done testing."
