# $Id: /mirror/trunk/languages/ecmascript/config/makefiles/root.in 35360 2009-01-10T04:08:55.034776Z tewk  $

## 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_F          = @rm_f@
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
PBC_TO_EXE    = $(BUILD_DIR)/pbc_to_exe@exe@

PMCDIR   = src/pmc


# the default target
all: js.pbc #$(PMCDIR)/js_group$(LOAD_EXT)

SOURCES = \
  js.pir \
  src/gen_grammar.pir \
  src/gen_actions.pir \
  src/builtin/builtins.pir \
  src/classes/Object.pir \
  src/classes/Array.pir \
  src/classes/Null.pir \
  src/classes/Boolean.pir \
  src/classes/Number.pir \
  src/classes/String.pir \
  src/classes/Undefined.pir \

#PMCS = \
#  jsobject \
#  jsinteger \
#  jshash \
#  jsbignum \
#  jscomplex \
#  jsfixnum \
#  jsfloat \
#  jsstring

#PMC_SOURCES = \
#  $(PMCDIR)/jsobject.pmc \
#  $(PMCDIR)/jsinteger.pmc \
#  $(PMCDIR)/jshash.pmc \
#  $(PMCDIR)/jsbignum.pmc \
#  $(PMCDIR)/jscomplex.pmc \
#  $(PMCDIR)/jsfixnum.pmc \
#  $(PMCDIR)/jsfloat.pmc \
#  $(PMCDIR)/jsstring.pmc

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

#GEN_PIR = \
#  src/js_grammar_gen.pir \
#  src/ASTGrammar.pir \
#  src/OSTGrammar.pir \
#  src/builtins_gen.pir

#GEN_PBC = \
#  src/CardinalGrammar.pbc \
#  src/PGE2AST.pbc \
#  src/AST2OST.pbc \
#  src/PAST.pbc \
#  src/POST.pbc

# target for building a standalone javascript compiler
js@exe@: js.pbc
	$(PBC_TO_EXE) js.pbc

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

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

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

# no builtins yet
#src/gen_builtins.pir: $(BUILTINS_PIR)
#	$(CAT) $(BUILTINS_PIR) >src/gen_builtins.pir


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

# 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:               js.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

testclean:
	$(RM_F) "t/*.js" "t/*.out"
	$(RM_F) "t/sanity_pt/*.js" "t/sanity_pt/*.out"
	$(RM_F) "t/js_pt/*.js" "t/js_pt/*.out"


CLEANUPS = \
  js.pbc \
  js@exe@ \
  js.c \
  src/gen_grammar.pir \
  src/gen_actions.pir \
  src/gen_builtins.pir \
  $(PMCDIR)/*.h \
  $(PMCDIR)/*.c \
  $(PMCDIR)/*.dump \
  $(PMCDIR)/*$(O) \
  $(PMCDIR)/*$(LOAD_EXT) \
  $(PMC_DIR)/*.exp \
  $(PMC_DIR)/*.ilk \
  $(PMC_DIR)/*.manifest \
  $(PMC_DIR)/*.pdb \
  $(PMC_DIR)/*.lib \
  t/*.out \
  t/*.rb

clean: 
	$(RM_RF) $(CLEANUPS)

realclean: clean
	$(RM_RF) Makefile

distclean: realclean
