# $Id: past.in 17095 2007-02-20 20:11:27Z paultcochrane $

# Setup some commands
LN_S     = @lns@
PERL     = @perl@
RM_RF    = @rm_rf@
PARROT   = ../../parrot@exe@
TOOL_DIR = ../..
CP       = @cp@
MKPATH   = @mkpath@

# Where to put things
PARROT_LIBRARY    = ../../runtime/parrot/library

# the default target
all: $(PARROT_LIBRARY)/PAST $(PARROT_LIBRARY)/PAST.pbc $(PARROT_LIBRARY)/Node.pbc

SOURCES = PAST.pir \
  Node.pir \
  PAST/Code.pir \
  PAST/Exp.pir \
  PAST/Op.pir \
  PAST/Stmt.pir \
  PAST/Stmts.pir \
  PAST/Sub.pir \
  PAST/Val.pir \
  PAST/Var.pir

$(PARROT_LIBRARY)/PAST:
	$(MKPATH) $(PARROT_LIBRARY)/PAST

$(PARROT_LIBRARY)/Node.pbc: Node.pbc
	$(CP) Node.pbc $(PARROT_LIBRARY)

$(PARROT_LIBRARY)/PAST.pbc: PAST.pbc
	$(CP) PAST.pbc $(PARROT_LIBRARY)
	$(CP) PAST/Code.pbc $(PARROT_LIBRARY)/PAST
	$(CP) PAST/Exp.pbc $(PARROT_LIBRARY)/PAST
	$(CP) PAST/Op.pbc $(PARROT_LIBRARY)/PAST
	$(CP) PAST/Stmt.pbc $(PARROT_LIBRARY)/PAST
	$(CP) PAST/Stmts.pbc $(PARROT_LIBRARY)/PAST
	$(CP) PAST/Sub.pbc $(PARROT_LIBRARY)/PAST
	$(CP) PAST/Val.pbc $(PARROT_LIBRARY)/PAST
	$(CP) PAST/Var.pbc $(PARROT_LIBRARY)/PAST

Node.pbc: $(PARROT) $(SOURCES)
	$(RM_RF) Node.pbc $(PARROT_LIBRARY)/Node.pbc
	$(PARROT) -o Node.pbc --output-pbc Node.pir

PAST.pbc: $(PARROT) $(SOURCES)
	$(RM_RF) PAST.pbc $(PARROT_LIBRARY)/PAST.pbc
	$(PARROT) -o PAST.pbc --output-pbc PAST.pir
	$(PARROT) -o PAST/Code.pbc --output-pbc PAST/Code.pir
	$(PARROT) -o PAST/Exp.pbc --output-pbc PAST/Exp.pir
	$(PARROT) -o PAST/Op.pbc --output-pbc PAST/Op.pir
	$(PARROT) -o PAST/Stmt.pbc --output-pbc PAST/Stmt.pir
	$(PARROT) -o PAST/Stmts.pbc --output-pbc PAST/Stmts.pir
	$(PARROT) -o PAST/Sub.pbc --output-pbc PAST/Sub.pir
	$(PARROT) -o PAST/Val.pbc --output-pbc PAST/Val.pir
	$(PARROT) -o PAST/Var.pbc --output-pbc PAST/Var.pir

# This is a listing of all targets that users can call
help:
	@echo ""
	@echo "The following targets are available for the user:"
	@echo ""
	@echo "  all:               PAST.pbc"
	@echo "                     This is the default."
	@echo ""
	@echo "Testing:"
	@echo "  test:              Run the test suite cleaning up."
	@echo "  testclean:         Clean up test results."
	@echo ""
	@echo "Cleaning:"
	@echo "  clean:             Basic cleaning up."
	@echo "  realclean:         Removes also files generated by 'Configure.pl'"
	@echo "  distclean:         Removes also anything built, in theory"
	@echo ""
	@echo "Misc:"
	@echo "  help:              Print this help message."
	@echo ""

test: all
	cd $(TOOL_DIR); prove -r t/compilers/past

testclean:
	$(RM_RF) "../../t/compilers/*.pir"

clean: testclean
	$(RM_RF) Node.pbc   $(PARROT_LIBRARY)/Node.pbc
	$(RM_RF) PAST.pbc   $(PARROT_LIBRARY)/PAST.pbc
	$(RM_RF) PAST/*.pbc $(PARROT_LIBRARY)/PAST/*.pbc

realclean: clean
	$(RM_RF) Makefile

distclean: realclean
