# $Id: /mirror/trunk/languages/PIR/config/makefiles/root.in 28688 2008-06-23T00:33:41.905243Z coke  $

## arguments we want to run parrot with
PARROT_ARGS =

## configuration settings
BUILD_DIR     = @build_dir@
LOAD_EXT      = @load_ext@
O             = @o@

## Setup some commands
LN_S          = @lns@
PERL          = @perl@
RM_RF         = @rm_rf@
CP            = @cp@
PARROT        = ../../parrot@exe@
CAT           = $(PERL) -MExtUtils::Command -e cat
BUILD_DYNPMC  = $(PERL) $(BUILD_DIR)/tools/build/dynpmc.pl
RECONFIGURE   = $(PERL) $(BUILD_DIR)/tools/dev/reconfigure.pl
#CONDITIONED_LINE(darwin):
#CONDITIONED_LINE(darwin):# MACOSX_DEPLOYMENT_TARGET must be defined for OS X compilation/linking
#CONDITIONED_LINE(darwin):export MACOSX_DEPLOYMENT_TARGET := @osx_version@

## places to look for things
PARROT_DYNEXT = $(BUILD_DIR)/runtime/parrot/dynext
PGE_LIBRARY   = $(BUILD_DIR)/runtime/parrot/library/PGE
PERL6GRAMMAR  = $(PGE_LIBRARY)/Perl6Grammar.pbc
NQP           = $(BUILD_DIR)/compilers/nqp/nqp.pbc
PCT           = $(BUILD_DIR)/runtime/parrot/library/PCT.pbc

PMC_DIR       = src/pmc

all: pirc.pbc 

#PERL6_GROUP = $(PMC_DIR)/perl6_group$(LOAD_EXT)

SOURCES = pirc.pir \
  src/gen_grammar.pir \
  src/gen_actions.pir \
  src/pasm/gen_pasm.pir \
  src/pasm/gen_pasm_args.pir \
  src/pasm/gen_pasm_instr.pir \
  src/pasm/gen_pasm_core.pir \
  src/pasm/gen_pasm_io.pir \
  src/pasm/gen_pasm_pmc.pir  

PASMGRAMMAR = src/pasm/gen_pasm.pbc \
  src/pasm/gen_pasm_instr.pbc \
  src/pasm/gen_pasm_io.pbc \
  src/pasm/gen_pasm_pmc.pbc \
  src/pasm/gen_pasm_args.pbc \
  src/pasm/gen_pasm_core.pbc

# the default target
pirc.pbc: $(PARROT) $(SOURCES) $(PASMGRAMMAR)
	$(PARROT) $(PARROT_ARGS) -o pirc.pbc pirc.pir

src/gen_grammar.pir: $(PERL6GRAMMAR) src/pir.pg
	$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
	    --output=src/gen_grammar.pir \
	    src/pir.pg

src/gen_actions.pir: $(NQP) $(PCT) src/actions.pm
	$(PARROT) $(PARROT_ARGS) $(NQP) --output=src/gen_actions.pir \
	    --target=pir src/actions.pm

src/pasm/gen_pasm.pir: $(PERL6GRAMMAR) src/pasm/pasm.pg
	$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
	    --output=src/pasm/gen_pasm.pir \
	    src/pasm/pasm.pg

src/pasm/gen_pasm_args.pir: $(PERL6GRAMMAR) src/pasm/pasm_args.pg
	$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
	    --output=src/pasm/gen_pasm_args.pir \
	    src/pasm/pasm_args.pg

src/pasm/gen_pasm_instr.pir: $(PERL6GRAMMAR) src/pasm/pasm_instr.pg
	$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
	    --output=src/pasm/gen_pasm_instr.pir \
	    src/pasm/pasm_instr.pg

src/pasm/gen_pasm_core.pir: $(PERL6GRAMMAR) src/pasm/pasm_core.pg
	$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
	    --output=src/pasm/gen_pasm_core.pir \
	    src/pasm/pasm_core.pg

src/pasm/gen_pasm_io.pir: $(PERL6GRAMMAR) src/pasm/pasm_io.pg
	$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
	    --output=src/pasm/gen_pasm_io.pir \
	    src/pasm/pasm_io.pg

src/pasm/gen_pasm_pmc.pir: $(PERL6GRAMMAR) src/pasm/pasm_pmc.pg
	$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
	    --output=src/pasm/gen_pasm_pmc.pir \
	    src/pasm/pasm_pmc.pg

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

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

src/pasm/gen_pasm_args.pbc: src/pasm/gen_pasm_args.pir
	$(PARROT) --output-pbc -o src/pasm/gen_pasm_args.pbc src/pasm/gen_pasm_args.pir
	
src/pasm/gen_pasm_io.pbc: src/pasm/gen_pasm_io.pir
	$(PARROT) --output-pbc -o src/pasm/gen_pasm_io.pbc src/pasm/gen_pasm_io.pir

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

src/pasm/gen_pasm_core.pbc: src/pasm/gen_pasm_core.pir
	$(PARROT) --output-pbc -o src/pasm/gen_pasm_core.pbc src/pasm/gen_pasm_core.pir
	
# regenerate the Makefile
Makefile: config/makefiles/root.in
	cd $(BUILD_DIR) && $(RECONFIGURE) --step=gen::languages --languages=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 "  spectest:          Run the official Perl 6 tests"
	@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:

spectest: all t/spec
# XXX when tests pass, run more here.
	@echo "only running sanity tests..."
	$(PERL) t/harness t/spec/01-sanity t/spec/operators t/spec/builtins \
                          t/spec/builtins/math

t/spec:
	$(PERL) t/fetchspec

CLEANUPS = \
  pirc.pbc \
  src/gen_grammar.pir \
  src/gen_actions.pir \
  src/gen_builtins.pir \
  src/pasm/gen_pasm_pmc.pir \
  src/pasm/gen_pasm.pir \
  src/pasm/gen_pasm_io.pbc \
  src/pasm/gen_pasm_core.pir \
  src/pasm/gen_pasm_pmc.pbc \
  src/pasm/gen_pasm.pbc \
  src/pasm/gen_pasm_args.pir \
  src/pasm/gen_pasm_instr.pir \
  src/pasm/gen_pasm_core.pbc \
  src/pasm/gen_pasm_args.pbc \
  src/pasm/gen_pasm_io.pir \
  src/pasm/gen_pasm_instr.pbc

clean:
	$(RM_RF) $(CLEANUPS)

realclean: clean
	$(RM_RF) Makefile

distclean: realclean
