# $Id: pge.in 16877 2007-02-03 05:03:52Z tewk $

# Setup some commands
LN_S     = @lns@
PERL     = @perl@
RM_RF    = @rm_rf@
PARROT   = ../../parrot@exe@
TOOL_DIR = ../..
CP       = @cp@
BUILD    = $(PERL) @build_dir@/tools/build/dynpmc.pl
O        = @o@
LOAD_EXT = @load_ext@
PARROT_DYNEXT = @build_dir@/runtime/parrot/dynext
PMCDIR   = PGE/pmc

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

# the default target
all: $(PMCDIR)/pge_group$(LOAD_EXT) $(PARROT_LIBRARY)/PGE.pbc 

PMCS = \
	codestring

PMC_SOURCES = \
	$(PMCDIR)/codestring.pmc

SOURCES = PGE.pir \
  PGE/CodeString.pir \
  PGE/Exp.pir \
  PGE/Match.pir \
  PGE/Regex.pir \
  PGE/P6Regex.pir \
  PGE/OPTable.pir \
  PGE/P5Regex.pir \
  PGE/builtins.pg \
  pgc.pir \

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

PGE.pbc: $(PARROT) $(SOURCES)
	$(RM_RF) PGE.pbc $(PARROT_LIBRARY)/PGE.pbc
	$(PERL) -e "" >PGE/builtins_gen.pir
	$(PARROT) -o PGE.pbc --output-pbc PGE.pir
	$(PARROT) pgc.pir  --output=PGE/builtins_gen.pir PGE/builtins.pg
	$(PARROT) -o PGE.pbc --output-pbc PGE.pir

$(PMCDIR)/pge_group$(LOAD_EXT): $(PARROT) $(PMC_SOURCES)
	cd $(PMCDIR) && $(BUILD) generate $(PMCS)
	cd $(PMCDIR) && $(BUILD) compile $(PMCS)
	cd $(PMCDIR) && $(BUILD) linklibs $(PMCS)
	cd $(PMCDIR) && $(BUILD) copy --destination=$(PARROT_DYNEXT) $(PMCS)

# 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
	cd $(TOOL_DIR); prove -r t/compilers/pge

testclean:
	$(RM_RF) "../../t/compilers/pge/*.pir" \
	    "../../t/compilers/pge/p5regex/*.pir" \
	    "../../t/compilers/pge/p6regex/*.pir"
	$(RM_RF) "../../t/compilers/pge/*.pbc" \
	    "../../t/compilers/pge/p5regex/*.pbc" \
	    "../../t/compilers/pge/p6regex/*.pbc"

clean: testclean
	$(RM_RF) \
    PGE.pbc \
    $(PARROT_LIBRARY)/PGE.pbc \
    PGE/builtins_gen.pir \
    $(PMCDIR)/*.h \
    $(PMCDIR)/*.c \
    $(PMCDIR)/*.dump \
    $(PMCDIR)/*.pdb \
    $(PMCDIR)/*.lib \
    $(PMCDIR)/*.exp \
    $(PMCDIR)/*.ilk \
    $(PMCDIR)/*$(O) \
    $(PMCDIR)/*$(LOAD_EXT)

realclean: clean
	$(RM_RF) Makefile

distclean: realclean
