# $Id: /mirror/trunk/languages/perl6/config/makefiles/root.in 35669 2009-01-16T17:58:08.111320Z jonathan  $

# arguments we want to run parrot with
PARROT_ARGS =

# places to look for things
BUILD_DIR     = @build_dir@
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
OPSDIR        = src/ops
OPSLIB        = perl6
OPS_FILE      = src/ops/perl6.ops

# Set up extensions
LOAD_EXT      = @load_ext@
O             = @o@
EXE           = @exe@

# Setup some commands
MAKE          = @make_c@
PERL          = @perl@
RM_F          = @rm_f@
PARROT        = ../../parrot$(EXE)
CAT           = $(PERL) -MExtUtils::Command -e cat
BUILD_DYNPMC  = $(PERL) $(BUILD_DIR)/tools/build/dynpmc.pl
BUILD_DYNOPS  = $(PERL) $(BUILD_DIR)/tools/build/dynoplibs.pl
RECONFIGURE   = $(PERL) $(BUILD_DIR)/tools/dev/reconfigure.pl
PBC_TO_EXE    = $(BUILD_DIR)/pbc_to_exe$(EXE)
#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@

SOURCES = perl6.pir \
  src/gen_grammar.pir \
  src/gen_actions.pir \
  src/gen_builtins.pir \
  src/gen_metaop.pir \
  src/gen_junction.pir \
  src/parser/expression.pir \
  src/parser/methods.pir \
  src/parser/quote_expression.pir \
  $(PERL6_GROUP) \
  src/ops/perl6_ops$(LOAD_EXT)

BUILTINS_PIR = \
  src/classes/ClassHOW.pir \
  src/classes/Object.pir \
  src/classes/Any.pir \
  src/classes/Signature.pir \
  src/classes/Role.pir \
  src/classes/Abstraction.pir \
  src/classes/Protoobject.pir \
  src/classes/Positional.pir \
  src/classes/Associative.pir \
  src/classes/Callable.pir \
  src/classes/Bool.pir \
  src/classes/Str.pir \
  src/classes/Num.pir \
  src/classes/Int.pir \
  src/classes/Order.pir \
  src/classes/Complex.pir \
  src/classes/IO.pir \
  src/classes/List.pir \
  src/classes/Array.pir \
  src/classes/Mapping.pir \
  src/classes/Hash.pir \
  src/classes/Range.pir \
  src/classes/Code.pir \
  src/classes/Block.pir \
  src/classes/Routine.pir \
  src/classes/Sub.pir \
  src/classes/Regex.pir \
  src/classes/Method.pir \
  src/classes/Submethod.pir \
  src/classes/Junction.pir \
  src/classes/Failure.pir \
  src/classes/Exception.pir \
  src/classes/Nil.pir \
  src/classes/Pair.pir \
  src/classes/Whatever.pir \
  src/classes/Capture.pir \
  src/classes/Match.pir \
  src/classes/Grammar.pir \
  src/classes/Module.pir \
  src/builtins/globals.pir \
  src/builtins/any-list.pir \
  src/builtins/any-num.pir \
  src/builtins/any-str.pir \
  src/builtins/assign.pir \
  src/builtins/cmp.pir \
  src/builtins/control.pir \
  src/builtins/eval.pir \
  src/builtins/enums.pir \
  src/builtins/guts.pir \
  src/builtins/io.pir \
  src/builtins/match.pir \
  src/builtins/math.pir \
  src/builtins/misc.pir \
  src/builtins/named-unary.pir \
  src/builtins/op.pir \
  src/builtins/parrot.pir \
  src/builtins/system.pir \
  src/builtins/traits.pir \

PMCS        = perl6str objectref perl6scalar mutablevar perl6multisub

PMC_SOURCES = $(PMC_DIR)/perl6str.pmc $(PMC_DIR)/objectref.pmc $(PMC_DIR)/perl6scalar.pmc \
              $(PMC_DIR)/mutablevar.pmc $(PMC_DIR)/perl6multisub.pmc

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

CLEANUPS = \
  perl6.pbc \
  perl6.c \
  *.manifest \
  *.pdb \
  perl6$(O) \
  perl6$(EXE) \
  installable_perl6$(EXE) \
  Test.pir \
  src/gen_*.pir \
  $(PMC_DIR)/*.h \
  $(PMC_DIR)/*.c \
  $(PMC_DIR)/*.dump \
  $(PMC_DIR)/*$(O) \
  $(PMC_DIR)/*$(LOAD_EXT) \
  $(PMC_DIR)/*.exp \
  $(PMC_DIR)/*.ilk \
  $(PMC_DIR)/*.manifest \
  $(PMC_DIR)/*.pdb \
  $(PMC_DIR)/*.lib \
  $(PMC_DIR)/objectref.pmc \
  $(OPSDIR)/*.h \
  $(OPSDIR)/*.c \
  $(OPSDIR)/*$(O) \
  $(OPSDIR)/*$(LOAD_EXT) \

# NOTE: eventually, we should remove --keep-exit-code and --fudge
#       as the goal is that all tests must pass without fudge
HARNESS_WITH_FUDGE = $(PERL) t/harness --fudge --keep-exit-code
HARNESS_WITH_FUDGE_JOBS = $(HARNESS_WITH_FUDGE) --jobs


# the default target
all: perl6.pbc

##  targets for building a standalone perl6.
# (We're not quite ready to make this a default target.)
perl6$(EXE): perl6.pbc
	$(PBC_TO_EXE) perl6.pbc

spectest_checkout : t/spec

t/spec : 
	svn co http:////svn.pugscode.org//pugs//t//spec t/spec

spectest_update :
	-cd t/spec && svn up

testable : all Test.pir spectest_checkout spectest_update

xmas: perl6$(EXE)


##  supporting targets for perl6
# the Perl 6 compiler
perl6.pbc: $(PARROT) $(SOURCES) $(BUILTINS_PIR)
	$(PARROT) $(PARROT_ARGS) -o perl6.pbc perl6.pir

installable_perl6$(EXE): perl6.pbc
	$(PBC_TO_EXE) perl6.pbc --install

Test.pir: Test.pm perl6.pbc
	$(PARROT) $(PARROT_ARGS) perl6.pbc --target=pir --output=Test.pir Test.pm

$(PMC_DIR)/objectref.pmc : $(PMC_DIR)/objectref_pmc.template build/gen_objectref_pmc.pl
	$(PERL) build/gen_objectref_pmc.pl $(PMC_DIR)/objectref_pmc.template \
		$(PMC_DIR)/objectref.pmc

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

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

src/gen_builtins.pir: build/gen_builtins_pir.pl Makefile
	$(PERL) build/gen_builtins_pir.pl $(BUILTINS_PIR) > src/gen_builtins.pir

src/gen_metaop.pir: build/gen_metaop_pir.pl
	$(PERL) build/gen_metaop_pir.pl > src/gen_metaop.pir

src/gen_junction.pir: build/gen_junction_pir.pl
	$(PERL) build/gen_junction_pir.pl src/gen_junction.pir

$(PERL6_GROUP): $(PARROT) $(PMC_SOURCES)
	cd $(PMC_DIR) && $(BUILD_DYNPMC) generate $(PMCS)
	cd $(PMC_DIR) && $(BUILD_DYNPMC) compile $(PMCS)
	cd $(PMC_DIR) && $(BUILD_DYNPMC) linklibs $(PMCS)
	cd $(PMC_DIR) && $(BUILD_DYNPMC) copy --destination=$(PARROT_DYNEXT) $(PMCS)

src/ops/perl6_ops$(LOAD_EXT) : $(OPS_FILE)
	@cd $(OPSDIR) && $(BUILD_DYNOPS) generate $(OPSLIB)
	@cd $(OPSDIR) && $(BUILD_DYNOPS) compile $(OPSLIB)
	@cd $(OPSDIR) && $(BUILD_DYNOPS) linklibs $(OPSLIB)
	@cd $(OPSDIR) && $(BUILD_DYNOPS) copy "--destination=$(PARROT_DYNEXT)" $(OPSLIB)

t/localtest.data:
	$(PERL) -MExtUtils::Command -e test_f $@


##  testing targets
test    : coretest

codetest:
	$(MAKE) $(BUILD_DIR) codetest

coretest: all
	prove t/pmc
	$(PERL) t/harness t/00-parrot t/01-sanity

fulltest: coretest spectest codetest

# Run the tests in t/localtest.data
localtest: all Test.pir spectest_checkout t/localtest.data
	@$(HARNESS_WITH_FUDGE_JOBS) --tests-from-file=t/localtest.data

# Run the tests in t/localtest.data with a higher verbosity
localtest_loud: all Test.pir spectest_checkout t/localtest.data
	@$(HARNESS_WITH_FUDGE) --tests-from-file=t/localtest.data --verbosity=1

# Run the spectests that we know work.
spectest_regression: spectest
spectest: testable t/spectest.data
	$(HARNESS_WITH_FUDGE_JOBS) --tests-from-file=t/spectest.data

spectest_full: testable
	$(HARNESS_WITH_FUDGE_JOBS) t/spec

# Run many tests of your choise.
# make sometests TESTFILES=t/foo/bar
sometests: all
	@$(HARNESS_WITH_FUDGE_JOBS) $(TESTFILES)

# Run a single test
t/*.t t/*/*.t t/*/*/*.t: all Test.pir
	@$(HARNESS_WITH_FUDGE) --verbosity=1 $@


##  cleaning
clean:
	$(RM_F) $(CLEANUPS)

distclean: realclean

realclean: clean
	$(RM_F) src/utils/Makefile Makefile

testclean:


##  miscellaneous targets
# a listing of all targets 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 "  perl6$(EXE):       Some want a pony, others are satisfied with an executable."
	@echo "  spectest_checkout  Performs svn checkout of official test suite."
	@echo "  spectest_update    Performs svn update of official test suite."
	@echo "  testable:          Create the perl6 executable, compile the Test library,"
	@echo "                     and update official test suite."
	@echo "  xmas:              Christmas is when Perl 6 is released. Alias of perl6$(EXE)."
	@echo ""
	@echo "Testing:"
	@echo "  test:              Run coretest and codetest."
	@echo "  codetest:          Run Parrot's code tests."
	@echo "  coretest:          Run rakudo's core tests."
	@echo "  fulltest:          Run coretest, spectest, and codetest."
	@echo "  localtest:         Run the official tests given in t/localtest.data."
	@echo "  spectest:          Run the tests of the official test suite that are known to pass."
	@echo "  spectest_full:     Run all tests of the official test suite"
	@echo ""
	@echo "Cleaning:"
	@echo "  clean:             Basic cleaning up."
	@echo "  distclean:         Removes also anything built, in theory."
	@echo "  realclean:         Removes also files generated by 'Configure.pl'."
	@echo "  testclean:         Clean up test results."
	@echo ""
	@echo "Misc:"
	@echo "  help:              Print this help message."
	@echo "  Makefile:          Regenerate the Makefile."
	@echo ""

# regenerate the Makefile
Makefile: config/makefiles/root.in config/makefiles/utils.in
	cd $(BUILD_DIR) && $(RECONFIGURE) --step=gen::languages --languages=perl6

