# Copyright (C) 2008, The Perl Foundation.
# $Id: /mirror/trunk/languages/markdown/config/makefiles/root.in 35586 2009-01-14T21:41:42.331703Z fperrad  $

## arguments we want to run parrot with
PARROT_ARGS =

## configuration settings
BUILD_DIR     = @build_dir@

## 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
#IF(darwin):
#IF(darwin):# MACOSX_DEPLOYMENT_TARGET must be defined for OS X compilation/linking
#IF(darwin):export MACOSX_DEPLOYMENT_TARGET := @osx_version@

## places to look for things
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

all: markdown.pbc

SOURCES = \
  markdown.pir \
  src/Compiler.pir \
  src/Node.pir \
  src/gen_grammar.pir \
  src/gen_actions.pir \
  src/gen_builtins.pir

BUILTINS_PIR = \
  src/builtins/length.pir \

# the default target
markdown.pbc: $(PARROT) $(SOURCES)
	$(PARROT) $(PARROT_ARGS) -o markdown.pbc markdown.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

src/gen_builtins.pir: $(BUILTINS_PIR)
	$(CAT) $(BUILTINS_PIR) >src/gen_builtins.pir

# regenerate the Makefile
Makefile: config/makefiles/root.in
	$(PERL) Configure.pl

# 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:               markdown.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
	cd .. && $(PERL) t/harness --languages=markdown

spectest: all t/MarkdownTest_1.0
	cd .. && $(PERL) t/harness --languages=markdown

t/MarkdownTest_1.0.zip:
	cd t && perl -MLWP::Simple -e "getstore(q{http:////daringfireball.net//projects//downloads//MarkdownTest_1.0.zip}, q{MarkdownTest_1.0.zip});"

t/MarkdownTest_1.0: t/MarkdownTest_1.0.zip
	cd t && perl -MArchive::Zip -e "Archive::Zip->new(q{MarkdownTest_1.0.zip})->extractTree();"

TEST_CLEANUPS = \
  "t/*.html" \
  "t/*.text"

testclean:
	$(RM_RF) t/MarkdownTest_1.0
	$(RM_F) $(TEST_CLEANUPS)

GEN_CLEANUPS = \
  markdown.pbc \
  src/gen_grammar.pir \
  src/gen_actions.pir

clean: testclean
	$(RM_F) $(GEN_CLEANUPS)

realclean: clean
	$(RM_F) Makefile t/MarkdownTest_1.0.zip

distclean: realclean

