# $Id: /mirror/trunk/languages/pipp/config/makefiles/root.in 35445 2009-01-11T14:17:06.155209Z bernhard  $

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

# Set up directories
BUILD_DIR     = @build_dir@
LIBRARY_DIR   = $(BUILD_DIR)/runtime/parrot/library
INCLUDE_DIR   = $(BUILD_DIR)/include
PMC_DIR       = src/pmc
PARROT_DYNEXT = $(BUILD_DIR)/runtime/parrot/dynext

# Set up commands
PARROT        = $(BUILD_DIR)/parrot@exe@
PERL          = @perl@
RM_F          = @rm_f@
PMCBUILD      = $(PERL) @build_dir@/tools/build/dynpmc.pl
NQP           = $(BUILD_DIR)/compilers/nqp/nqp.pbc
PCT           = $(BUILD_DIR)/runtime/parrot/library/PCT.pbc
PBC_TO_EXE    = $(BUILD_DIR)/pbc_to_exe$(EXE)
CC            = @cc@
#copy/pasta from CFLAGS in config/gen/makefiles/dynpmc_pl.in
CFLAGS        = @ccflags@ @cc_shared@ @cc_debug@ @ccwarn@ @cc_hasjit@ @cg_flag@ @gc_flag@
TOUCH         = @touch@

PMCS = \
  php \
  phparray \
  phpboolean \
  phpfloat \
  phpinteger \
  phpresource \
  phpstring \
  phpnull

PMC_SOURCES = \
  $(PMC_DIR)/php.pmc \
  $(PMC_DIR)/phparray.pmc \
  $(PMC_DIR)/phpboolean.pmc \
  $(PMC_DIR)/phpfloat.pmc \
  $(PMC_DIR)/phpinteger.pmc \
  $(PMC_DIR)/phpresource.pmc \
  $(PMC_DIR)/phpstring.pmc \
  $(PMC_DIR)/phpnull.pmc

HASH_SOURCES = $(PMC_DIR)/pipp_hash.c
HASH_H       = $(PMC_DIR)/pipp_hash.h
HASH_OBJS    = $(PMC_DIR)/pipp_hash$(O)

PHP_GROUP = $(PMC_DIR)/php_group$(LOAD_EXT)

INTERNALS_PIR = \
  src/classes/Object.pir

PHP_SRC_STD_EXT = \
  src/common/php_API.pir \
  src/common/php_array.pir \
  src/common/php_assert.pir \
  src/common/php_base64.pir \
  src/common/php_basic.pir \
  src/common/php_builtin.pir \
  src/common/php_browscap.pir \
  src/common/php_crc32.pir \
  src/common/php_crypt.pir \
  src/common/php_cyr_convert.pir \
  src/common/php_datetime.pir \
  src/common/php_dir.pir \
  src/common/php_dl.pir \
  src/common/php_dns.pir \
  src/common/php_exec.pir \
  src/common/php_file.pir \
  src/common/php_filestat.pir \
  src/common/php_formatted_print.pir \
  src/common/php_fsock.pir \
  src/common/php_ftok.pir \
  src/common/php_head.pir \
  src/common/php_html.pir \
  src/common/php_http.pir \
  src/common/php_image.pir \
  src/common/php_info.pir \
  src/common/php_iptc.pir \
  src/common/php_lcg.pir \
  src/common/php_levenshtein.pir \
  src/common/php_link.pir \
  src/common/php_mail.pir \
  src/common/php_math.pir \
  src/common/php_md5.pir \
  src/common/php_metaphone.pir \
  src/common/php_microtime.pir \
  src/common/php_pack.pir \
  src/common/php_pageinfo.pir \
  src/common/php_proc_open.pir \
  src/common/php_quot_print.pir \
  src/common/php_rand.pir \
  src/common/php_reg.pir \
  src/common/php_sha1.pir \
  src/common/php_soundex.pir \
  src/common/php_streamsfuncs.pir \
  src/common/php_string.pir \
  src/common/php_syslog.pir \
  src/common/php_type.pir \
  src/common/php_uniqid.pir \
  src/common/php_url.pir \
  src/common/php_user_filters.pir \
  src/common/php_uuencode.pir \
  src/common/php_var.pir \
  src/common/php_versioning.pir

PHP_EXT = \
  src/common/php_ctype.pbc \
  src/common/php_gmp.pbc \
  src/common/php_pcre.pbc

# default
all: build

# 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 "Building:"
	@echo "  all:               Build pipp.pbc"
	@echo "                     This is the default."
	@echo "  pipp$(EXE):        A fancy executable."
	@echo "  build              Same as 'all'."
	@echo "  build-pmc          Build all PMCs."
	@echo ""
	@echo "Testing:"
	@echo "  test:              Run the test suite for Pipp."
	@echo "  test-all:          Run the test suite for reference implementation and for Pipp."
	@echo "  test-php:          Run the test suite for the reference implementation."
	@echo "  test-pmc:          Run the test suite for Pipp's PMCs."
	@echo "  smoke:             Run the test suite and send report to the smolder server"
	@echo ""
	@echo "Cleaning:"
	@echo "  clean:             Clean up."
	@echo "  clean-test:        Clean up temporary files from testing."
	@echo "  clean-pmc:         Clean up temporary files from the PMC build process."
	@echo "  realclean:         Clean and remove Makefile."
	@echo ""
	@echo "Misc:"
	@echo "  help:              Print this help message."
	@echo ""

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

build:           build-common

#build-common:    build-pmc src/common/pipplib.pbc pipp.pbc $(PHP_EXT) Test.pir
build-common:    build-pmc src/common/pipplib.pbc pipp.pbc $(PHP_EXT)

# Target for building a standalone Pipp.
pipp$(EXE): build-common
	$(PBC_TO_EXE) pipp.pbc

src/common/pipplib.pbc: \
  src/common/builtins.pir \
  src/common/guts.pir \
  src/common/eval.pir \
  src/common/php_standard.pir \
  $(INTERNALS_PIR) \
  $(PHP_SRC_STD_EXT) \
  src/common/php_API.pir \
  src/common/php_MACRO.pir
	$(PARROT) -o src/common/pipplib.pbc src/common/builtins.pir

src/common/php_ctype.pbc: src/common/php_ctype.pir src/common/php_MACRO.pir
	$(PARROT) -o src/common/php_ctype.pbc src/common/php_ctype.pir

src/common/php_gmp.pbc: src/common/php_gmp.pir src/common/php_MACRO.pir
	$(PARROT) -o src/common/php_gmp.pbc src/common/php_gmp.pir

src/common/php_pcre.pbc: src/common/php_pcre.pir src/common/php_MACRO.pir
	$(PARROT) -o src/common/php_pcre.pbc src/common/php_pcre.pir

src/pct/gen_grammar.pir: $(LIBRARY_DIR)/PGE/Perl6Grammar.pir src/pct/grammar.pg
	$(PARROT) $(LIBRARY_DIR)/PGE/Perl6Grammar.pir \
            --output=src/pct/gen_grammar.pir src/pct/grammar.pg

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

pipp.pbc: \
  pipp.pir \
  src/pct/gen_grammar.pir \
  src/pct/gen_actions.pir \
  src/pct/quote_expression.pir
	$(PARROT) -o pipp.pbc pipp.pir

Test.pir: Test.php pipp.pbc
	$(PARROT) pipp.pbc --target=pir --output=Test.pir Test.php


build-pmc: $(HASH_OBJS) $(PHP_GROUP)

#Any change to the hash code means phparray needs to be relinked too.
#Recompiling is close enough for now.
$(HASH_OBJS): $(HASH_SOURCES) $(HASH_H)
	$(TOUCH) $(PMC_DIR)/phparray.pmc
	$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $(HASH_SOURCES) -c -g -o $(HASH_OBJS)

export DYNPMC_INCLUDE=$(BUILD_DIR)/languages/pipp
export DYNPMC_LINK=$(BUILD_DIR)/languages/pipp/$(HASH_OBJS)

$(PHP_GROUP): $(PMC_SOURCES)
	@cd $(PMC_DIR) && $(PMCBUILD) generate $(PMCS)
	@cd $(PMC_DIR) && $(PMCBUILD) compile $(PMCS)
	@cd $(PMC_DIR) && $(PMCBUILD) linklibs $(PMCS)
	@cd $(PMC_DIR) && $(PMCBUILD) copy "--destination=$(PARROT_DYNEXT)" $(PMCS)

test:     all
	- $(PERL) t/harness

test-all: all test-php test test-pmc

test-php:
	- $(PERL) t/harness --with-php

# run the test suite, create a TAP archive and send it off to smolder
smolder_test : smoke
smoke : build
	- $(PERL) t/harness --archive --send-to-smolder


# make sure debugging output is disabled while running the tests
export PMCDEBUG=

test-pmc: build-pmc
	@ prove -I../../lib t/pmc

# this does not work yet
test-pcc-testsuite: all t/pcc-testsuite
	cd t/pcc-testsuite && svn up
	cd t/pcc-testsuite && php dotest.php -d .

t/pcc-testsuite:
	svn co http:////code.roadsend.com//svn//pcc//trunk//pcc-testsuite t/pcc-testsuite

# this does not work yet
# Make sue that php 5.3 is in $PATH,
# e.g export PATH=~/devel/PHP/php5/sapi/cli:$PATH
test-php-qa-testsuite: pipp \
  t/php_qa_testsuite/php5/run-tests.php \
  t/php_qa_testsuite/php5/tests
 #t/php_qa_testsuite/php5/Zend/tests
	cd t/php_qa_testsuite/php5 && cvs update tests run-tests.php
	cd t/php_qa_testsuite/php5 && \
 TEST_PHP_EXECUTABLE=pipp \
 TEST_PHP_CGI_EXECUTABLE=pipp \
 php run-tests.php -v --keep-all | tee run_tests.log

t/php_qa_testsuite/php5/run-tests.php:
	cd t/php_qa_testsuite && cvs -d :pserver:cvsread@cvs.php.net:/repository checkout -r PHP_5_3 php5/run-tests.php

t/php_qa_testsuite/php5/tests:
	cd t/php_qa_testsuite && cvs -d :pserver:cvsread@cvs.php.net:/repository checkout -r PHP_5_3 php5/tests

#t/php_qa_testsuite/php5/Zend/tests:
	#cd php_qa_testsuite && cvs -d :pserver:cvsread@cvs.php.net:/repository/ZendEngine2 checkout -r PHP_5_3 php5/Zend/tests


# cleaning up
clean: clean-pmc clean-test clean-hash
	$(RM_F) \
  src/common/pipplib.pbc \
  src/common/*.pbc \
  src/pct/gen_grammar.pir \
  src/pct/gen_actions.pir \
  pipp.pbc \
  pipp.c \
  pipp.o \
  pipp$(EXE)

clean-pmc:
	$(RM_F) \
  "$(PMC_DIR)/*dump" \
  "$(PMC_DIR)/php*.c" \
  "$(PMC_DIR)/pmc_*h" \
  "$(PMC_DIR)/php_group.h" \
  "$(PMC_DIR)/*$(O)" \
  "$(PMC_DIR)/*$(LOAD_EXT)"


clean-test:
	$(RM_F) \
  t/php/*.php \
  t/php/*.pir \
  t/php/*.out \
  t/pmc/*.pir \
  pipp_test_run.tar.gz
  
clean-hash:
	$(RM_F) "$(HASH_OBJS)"

realclean: clean
	$(RM_F) Makefile

# Local variables:
# mode: makefile
# ex: ft=make
# End:
