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

# Setup some commands
LN_S     = @lns@
PERL     = @perl@
RM_F     = @rm_f@
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

# the default target
all: c99.pbc #$(PMCDIR)/c99_group$(LOAD_EXT)

#PMCS = \
#  c99object \
#  c99integer \
#  c99hash \
#  c99bignum \
#  c99complex \
#  c99fixnum \
#  c99float \
#  c99string

#PMC_SOURCES = \
#  $(PMCDIR)/c99object.pmc \
#  $(PMCDIR)/c99integer.pmc \
#  $(PMCDIR)/c99hash.pmc \
#  $(PMCDIR)/c99bignum.pmc \
#  $(PMCDIR)/c99complex.pmc \
#  $(PMCDIR)/c99fixnum.pmc \
#  $(PMCDIR)/c99float.pmc \
#  $(PMCDIR)/c99string.pmc

#BUILTINS_PIR = \
#  src/builtins/assign.pir \
#  src/builtins/cmp.pir \
#  src/builtins/io.pir

GEN_PIR = \
	src/c99_grammar_gen.pir \
  src/CPP_ASTGrammar.pir \
  src/CPP_AST2Constants.pir \
#  src/OSTGrammar.pir \
#  src/builtins_gen.pir

GEN_PBC = \
	src/c99_grammar_gen.pbc \
	src/c99_PGE.pbc \
  src/CPP_PGE2AST.pbc \
  src/CPP_PASTNodes.pbc \
  src/CPP_AST2Constants.pbc
#  src/AST2OST.pbc \
#  src/POST.pbc

c99.pbc: c99.pir $(GEN_PIR) $(GEN_PBC)
	$(PARROT) -o c99.pbc --output-pbc c99.pir 

.SUFFIXES : .pir .pg .tg .pbc

.pir.pbc: 
	$(PARROT) -o $@ --output-pbc $< 

.tg.pir:
	$(PARROT) $(TGE_DIR)/tgc.pir --output=$@ $<

src/c99_grammar_gen.pir: src/c99.pg
	$(PARROT) $(PGE_DIR)/pgc.pir --output=src/c99_grammar_gen.pir src/c99.pg

src/c99_grammar_gen.pbc: src/c99_grammar_gen.pir
	$(PARROT) -o src/c99_grammar_gen.pbc --output-pbc src/c99_grammar_gen.pir 

src/c99_PGE.pbc: src/c99_PGE.pir src/c99_grammar_gen.pir
	$(PARROT) -o src/c99_PGE.pbc --output-pbc src/c99_PGE.pir 

src/CPP_PGE2AST.pbc: src/CPP_PGE2AST.pir src/CPP_ASTGrammar.pir src/preamble
	$(PARROT) -o src/CPP_PGE2AST.pbc --output-pbc src/CPP_PGE2AST.pir 

#src/OSTGrammar.pir: src/OSTGrammar.tg
#	$(PARROT) $(TGE_DIR)/tgc.pir --output=src/OSTGrammar.pir src/OSTGrammar.tg

#src/AST2OST.pbc: src/AST2OST.pir src/OSTGrammar.pir src/preamble
#	$(PARROT) -o src/AST2OST.pbc --output-pbc src/AST2OST.pir 

#$(PMCDIR)/c99_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:               c99.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) -Isrc -I../../src t/harness

testclean:
	$(RM_F) "t/*.c99" "t/*.out"

CLEANUPS = \
  c99.pbc \
  $(GEN_PIR) \
  $(GEN_PBC) \
  $(PMCDIR)/*.h \
  $(PMCDIR)/*.c \
  $(PMCDIR)/*.dump \
  $(PMCDIR)/*$(O) \
  $(PMCDIR)/*$(LOAD_EXT) \
  t/*.out \
  t/*.rb

clean: 
	$(RM_RF) $(CLEANUPS)

realclean: clean
	$(RM_RF) Makefile

distclean: realclean
