# -----------------------------------------------------------------------------
# Ulm's Oberon Library
# Copyright (C) 1989-1994 by University of Ulm, SAI, D-89069 Ulm, Germany
# -----------------------------------------------------------------------------
# This makefile 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 makefile 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., 675 Mass Ave, Cambridge, MA 02139, USA.
# -----------------------------------------------------------------------------
# {stamp: updated by mmo Wed Jul 20 13:19:54 MET DST 1994}
# {options: +a +A +L -P}
# -----------------------------------------------------------------------------
# default settings which are overrided by the parent makefile
# the Oberon library is self-containing, so OBPATH should be "."
OBPATH :=	.
# directory of the compiler and the associated files
OBLIB :=	/usr/local/lib/oberon
# compilation flags (usually -OC -OT to suppress range and conversion checks)
ocflags :=	-OC -OT
# where to install the libraries (usually equivalent to OBLIB)
LIBDIR :=	$(OBLIB)
# -----------------------------------------------------------------------------
.SUFFIXES:
# {macros}
src :=		Conclusions.od Conclusions.om Print.od Print.om Read.od \
		Read.om Scan.od Scan.om Write.od Write.om
libs :=
liboptions :=	$(patsubst %,-l%,$(libs))
defs :=		$(filter %.od,$(src))
mods :=		$(filter %.om,$(src))
syms :=
refs :=		$(patsubst %.om,%.r,$(mods))
objects :=
lib :=		libo.a
libobjects =	$(patsubst %.om,$(lib)(%.o),$(mods))
defsyms :=
modobjs :=
cyclesyms :=
# {targets}
libdeps :=	SYM(Print.sy) $(lib)(Print.o) SYM(Scan.sy) $(lib)(Scan.o) \
		SYM(Read.sy) $(lib)(Read.o) SYM(Write.sy) $(lib)(Write.o) \
		SYM(Conclusions.sy) $(lib)(Conclusions.o)
$(lib):		$(libdeps)
T :=
.PHONY:		all
all:		$T $(defsyms) $(lib)
#
OC_CMD :=	OBPATH=$(OBPATH) OBLIB=$(OBLIB) oc
# {rules}
%.o:		%.r
OC :=		$(OC_CMD)
OCFLAGS :=	$(ocflags)
NEWER :=	newer
RM :=		rm -f
TOUCH :=	touch
$(lib)(%.o):	%.om SYM(%.sy)
		@$(TOUCH) $*.ts
		$(OC) $(OCFLAGS) $(liboptions) -c -u -o $(lib) $<
		@[ -z "$(D_$*)" ] || $(NEWER) $*.ts SYM || $(MAKE) $(D_$*)
		@$(RM) $*.ts
SYM(%.sy) $(lib)(%.o): %.od
		$(OC) $(OCFLAGS) $(liboptions) -c -u -o $(lib) $< $*.om
# -----------------------------------------------------------------------------
# {dependencies}
SYM(Conclusions.sy): ./SYM(Events.sy) ./SYM(RelatedEven.sy) ./SYM(Streams.sy) \
		./SYM(Errors.sy)
$(lib)(Conclusions.o): ./SYM(Events.sy) ./SYM(Process.sy) \
		./SYM(RelatedEven.sy) ./SYM(Streams.sy) ./SYM(Errors.sy) \
		SYM(Conclusions.sy) ./SYM(StreamDisci.sy) ./SYM(Strings.sy) \
		SYM(Write.sy)
SYM(Print.sy):	./SYM(Events.sy) ./SYM(RelatedEven.sy) ./SYM(Streams.sy)
$(lib)(Print.o): ./SYM(Events.sy) ./SYM(Priorities.sy) ./SYM(Reals.sy) \
		./SYM(RelatedEven.sy) ./SYM(Streams.sy) SYM(Print.sy) \
		./SYM(StreamDisci.sy)
SYM(Read.sy):	./SYM(Streams.sy)
$(lib)(Read.o):	./SYM(ASCII.sy) ./SYM(Sets.sy) ./SYM(Streams.sy) SYM(Read.sy) \
		SYM(Scan.sy) ./SYM(StreamDisci.sy)
SYM(Scan.sy):	./SYM(Streams.sy)
$(lib)(Scan.o):	./SYM(ASCII.sy) ./SYM(Reals.sy) ./SYM(Sets.sy) \
		./SYM(Streams.sy) SYM(Scan.sy) ./SYM(StreamDisci.sy)
SYM(Write.sy):	./SYM(Streams.sy)
$(lib)(Write.o): ./SYM(ASCII.sy) ./SYM(Streams.sy) SYM(Print.sy) \
		./SYM(StreamDisci.sy) SYM(Write.sy)
# {reversed-dependencies}
D_Conclusions :=
D_Print :=	'$(lib)(Write.o)'
D_Read :=
D_Scan :=	'$(lib)(Read.o)'
D_Write :=	'$(lib)(Conclusions.o)'
# -----------------------------------------------------------------------------
.PHONY:		install
install:	$(LIBDIR)/$(lib) $(LIBDIR)/REF $(LIBDIR)/SYM

$(LIBDIR)/$(lib): $(lib)
		cp $^ $@
		ranlib -t $@
$(LIBDIR)/REF:	REF
		cp $^ $@
$(LIBDIR)/SYM:	SYM
		cp $^ $@
# -----------------------------------------------------------------------------
.PHONY:		clean
clean:
		$(RM) core PROT PROT.line *.ts
# -----------------------------------------------------------------------------
PR :=		pr
SPOOL :=	lpr
.PHONY:		prdefs prmods pr
pr:		prdefs prmods
prdefs:		prdefs.stamp
prmods:		prmods.stamp
prdefs.stamp:	$(defs)
		$(PR) $? | $(SPOOL)
		@-touch $@
prmods.stamp:	$(mods)
		$(PR) $? | $(SPOOL)
		@-touch $@
# -----------------------------------------------------------------------------
OBTAGS :=	obtags
tags:		$(mods)
		$(OBTAGS) $^
# -----------------------------------------------------------------------------
