# $Id: root.in 17096 2007-02-20 20:20:48Z paultcochrane $

# Setup some commands
LN_S     = @lns@
PERL     = @perl@
RM_RF    = @rm_rf@
PARROT   = ../../parrot@exe@
BUILD    = $(PERL) @build_dir@/tools/build/dynpmc.pl
TOOL_DIR = ../..
PGE_DIR  = ../../compilers/pge
TGE_DIR  = ../../compilers/tge
CAT      = $(PERL) -MExtUtils::Command -e cat
CP       = @cp@
O        = @o@
LOAD_EXT = @load_ext@
PARROT_DYNEXT = @build_dir@/runtime/parrot/dynext

PMCDIR   = src/pmc

all: perl6.pbc 

SOURCES = perl6.pir \
  src/parser/grammar_rules.pg \
  src/parser/grammar_optok.pg \
  src/parser/expression.pir \
  src/parser/quote.pir \
  src/parser/regex.pir \
  src/PAST/Grammar.tg \
  src/PAST/Perl6.pir \
  src/builtins_gen.pir \
  $(PMCDIR)/perl6_group$(LOAD_EXT)

BUILTINS_PIR = \
  src/builtins/assign.pir \
  src/builtins/cmp.pir \
  src/builtins/control.pir \
  src/builtins/hash.pir \
  src/builtins/io.pir \
  src/builtins/list.pir \
  src/builtins/match.pir \
  src/builtins/math.pir \
  src/builtins/named-unary.pir \
  src/builtins/op.pir \
  src/builtins/range.pir \
  src/builtins/string.pir \
  src/classes/Code.pir \
  src/classes/List.pir \
  src/classes/Num.pir \
  src/classes/Str.pir

PMCS = perl6str
PMC_SOURCES = $(PMCDIR)/perl6str.pmc

# the default target
perl6.pbc: $(PARROT) $(PGE_DIR)/pgc.pir $(SOURCES)
	$(PARROT) $(PGE_DIR)/pgc.pir --output=src/parser/grammar_gen.pir \
	    src/parser/grammar_rules.pg src/parser/grammar_optok.pg
	$(PARROT) $(TGE_DIR)/tgc.pir --output=src/PAST/Grammar_gen.pir src/PAST/Grammar.tg
	$(PARROT) -o perl6.pbc perl6.pir

$(PMCDIR)/perl6_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)

src/builtins_gen.pir: $(BUILTINS_PIR)
	$(CAT) $(BUILTINS_PIR) >src/builtins_gen.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:               perl6.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
	$(PERL) t/harness

# this target has nothing to do
testclean:

CLEANUPS = \
  perl6.pbc \
  perl6-orig.pbc \
  src/parser/grammar_gen.pir \
  src/parse2past_gen.pir \
  src/pge2past_gen.pir \
  src/past2post_gen.pir \
  src/builtins_gen.pir \
  src/PAST/Grammar_gen.pir \
  $(PMCDIR)/*.h \
  $(PMCDIR)/*.c \
  $(PMCDIR)/*.dump \
  $(PMCDIR)/*$(O) \
  $(PMCDIR)/*$(LOAD_EXT)

clean: 
	$(RM_RF) $(CLEANUPS)

realclean: clean
	$(RM_RF) Makefile

distclean: realclean
