# $Id: past-pm.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 = ../..
TGE_DIR  = ../../compilers/tge
PGE_DIR  = ../../compilers/pge
TEST_DIR = ../../t/compilers/past-pm
CP       = @cp@
BUILD    = $(PERL) @build_dir@/tools/build/dynpmc.pl
O        = @o@
LOAD_EXT = @load_ext@
PARROT_DYNEXT = @build_dir@/runtime/parrot/dynext

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

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

SOURCES = PAST-pm.pir \
  PAST/Node.pir \
  PAST/Compiler.pir \
  POST/Node.pir \
  POST/Grammar.tg \
  POST/Compiler.pir

$(PARROT_LIBRARY)/PAST-pm.pbc: PAST-pm.pbc
	$(CP) PAST-pm.pbc $(PARROT_LIBRARY)/PAST-pm.pbc

PAST-pm.pbc: $(PARROT) $(SOURCES)
	$(RM_RF) PAST-pm.pbc $(PARROT_LIBRARY)/PAST-pm.pbc
	$(PARROT) $(TGE_DIR)/tgc.pir --output=POST/Grammar_gen.pir POST/Grammar.tg
	$(PARROT) -o PAST-pm.pbc --output-pbc PAST-pm.pir

# This is a listing of all targets, that are meant to be called by users
help:
	@echo ""
	@echo "Following targets are available for the user:"
	@echo ""
	@echo "  all:               PGE.pbc"
	@echo "                     This is the default."
	@echo "Testing:"
	@echo "  test:              Run the test suite."
	@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 NoneParser.pir NoneGrammar.pir
	cd $(TOOL_DIR); prove -r t/compilers/past-pm

# NoneParser and NoneGrammar are external modules for some of
# the tests. They will be moved into the test file later.
NoneParser.pir: $(TEST_DIR)/NoneParser.pg
	$(PARROT) $(PGE_DIR)/pgc.pir \
	    --output=$(TEST_DIR)/NoneParser.pir \
	    $(TEST_DIR)/NoneParser.pg

NoneGrammar.pir: $(TEST_DIR)/NoneGrammar.tg
	$(PARROT) $(TGE_DIR)/tgc.pir \
	    --output=$(TEST_DIR)/NoneGrammar.pir \
	    $(TEST_DIR)/NoneGrammar.tg

testclean:
	$(RM_RF) $(TEST_DIR)/*.pir \
	    $(TEST_DIR)/*.pbc

clean: testclean
	$(RM_RF) \
    PAST-pm.pbc \
    $(PARROT_LIBRARY)/PAST-pm.pbc \
    POST/Grammar_gen.pir

realclean: clean
	$(RM_RF) Makefile

distclean: realclean
