VERSION=${VERSION}${DEVEL}

BUILDPREFIX =
PREFIX = /usr/local/parrot/${VERSION}
EXEC_PREFIX = $(PREFIX)
BINDIR = $(EXEC_PREFIX)/bin
LIBDIR = $(EXEC_PREFIX)/lib
INCLUDEDIR = $(EXEC_PREFIX)/include

O = ${o}
SO = ${so}
A = ${a}
RM_F = ${rm_f}
RM_RF = ${rm_rf}
AR_CR = ${ar} ${ar_flags}
RANLIB = ${ranlib}
LINK = ${link}
LD = ${ld}
LD_SHARED = ${ld_shared}
LD_OUT = ${ld_out}
LD_SHARED_FLAGS=${ld_shared_flags}

INC=./${inc}

NONGEN_HEADERS = ${nongen_headers}

###############################################################################
#
# "STICKY" GENERATED FILES:
#
# These files are created when Configure.pl runs.
#
# We don't delete these on 'clean' only on 'realclean'.
# That way, we don't have to re-Configure.pl after making
# clean.
#
###############################################################################

GEN_MAKEFILES = Makefile classes/Makefile languages/Makefile docs/Makefile \
	languages/jako/Makefile languages/miniperl/Makefile \
	languages/scheme/Makefile languages/befunge/Makefile \
	languages/bf/Makefile languages/imcc/Makefile \
	languages/ook/Makefile languages/perl6/Makefile

GEN_CONFIGS  = include/parrot/config.h include/parrot/platform.h \
	include/parrot/platform_interface.h \
	include/parrot/has_header.h \
	include/parrot/feature.h \
	lib/Parrot/Config.pm lib/Parrot/PMC.pm platform.c \
	include/parrot/core_pmcs.h core_pmcs.c \
	CFLAGS languages/imcc/CFLAGS \
	libparrot.def \
	runtime/parrot/include/*.pasm

STICKY_FILES = $(GEN_CONFIGS) $(GEN_MAKEFILES) myconfig


###############################################################################
#
# "FLUID" GENERATED FILES:
#
# These files are created during the build process.
#
# We *do* delete these on 'clean'.
#
###############################################################################

GEN_OPSFILES =

GEN_HEADERS = $(INC)/vtable.h $(INC)/oplib/core_ops.h \
	$(INC)/oplib/core_ops_prederef.h \
	$(INC)/oplib/core_ops_switch.h $(INC)/jit_emit.h

GEN_SOURCES = core_ops.c core_ops_prederef.c fingerprint.c nci.c \
              core_ops_switch.c jit_cpu.c exec_cpu.c

GEN_MODULES = lib/Parrot/OpLib/core.pm

FLUID_FILES = $(GEN_OPSFILES) $(GEN_HEADERS) $(GEN_SOURCES) $(GEN_MODULES)


###############################################################################
#
# OTHER FILE GROUPS:
#
###############################################################################

GENERAL_H_FILES = $(NONGEN_HEADERS) $(GEN_HEADERS) ${cg_h}


ALL_H_FILES = $(GENERAL_H_FILES)

CLASS_PMC_FILES = ${pmc_classes_pmc}

CLASS_O_FILES = ${pmc_classes_o}

ENCODING_O_FILES = encodings/singlebyte$(O) encodings/utf8$(O) \
	encodings/utf16$(O) encodings/utf32$(O)

CHARTYPE_O_FILES = chartypes/unicode$(O) chartypes/usascii$(O)

IO_O_FILES = io/io$(O) io/io_buf$(O) io/io_unix$(O) io/io_win32$(O) \
	io/io_stdio$(O) io/io_passdown$(O)

INTERP_O_FILES = exceptions$(O) global_setup$(O) interpreter$(O) parrot$(O) \
	register$(O) core_ops$(O) core_ops_prederef$(O) core_ops_switch$(O) \
	memory$(O) objects$(O) ${exec_o} \
	packfile$(O) stacks$(O) string$(O) sub$(O) encoding$(O) \
	chartype$(O) runops_cores$(O) trace$(O) pmc$(O) key$(O) hash$(O) \
	core_pmcs$(O) platform$(O) ${jit_o} \
	${gc_o} rx$(O) rxstacks$(O) intlist$(O) list$(O) \
	embed$(O) warnings$(O)  ${cg_o} \
	packout$(O) byteorder$(O) debug$(O) smallobject$(O) \
	headers$(O) dod$(O) method_util$(O) exit$(O) \
	misc$(O) spf_render$(O) spf_vtable$(O) datatypes$(O) fingerprint$(O) \
	nci$(O) cpu_dep$(O) ${asmfun_o} tsq$(O) longopt$(O) events$(O) \
	dynext$(O) utils$(O)

O_FILES = $(INTERP_O_FILES) $(IO_O_FILES) $(CLASS_O_FILES) \
	$(ENCODING_O_FILES) $(CHARTYPE_O_FILES)

OPS_FILES = ${ops} $(GEN_OPSFILES)

###############################################################################
#
# BUILD TOOL CONFIGURATIONS:
#
# DO NOT ADD C COMPILER FLAGS HERE
# Add them in Configure.pl--look for the
# comment 'ADD C COMPILER FLAGS HERE'
#
###############################################################################

CFLAGS = ${ccflags} ${cc_debug} ${ccwarn} ${cc_inc} ${cc_hasjit} ${cg_flag} ${gc_flag}

LINKFLAGS = ${linkflags} ${link_debug} ${ld_debug}
LDFLAGS = ${ldflags} ${ld_debug}

C_LIBS = ${libs}

CC = ${cc}
PERL = ${perl}

# Make directory; do not die if dir exists.
MKDIR = $(PERL) -e ${PQ}-d or mkdir $$_,0777 or die foreach @ARGV${PQ}

###############################################################################
#
# BUILD TARGET CONFIGURATIONS:
#
###############################################################################

TEST_PROG = ${test_prog}${exe}
TEST_PROG_SO = ${test_prog}_so${exe}
LIBPARROT = ${blib_lib_libparrot_a}
# utils
DIS=disassemble${exe}
PDUMP = pdump${exe}
PINFO = pbc_info${exe}
PDB = pdb${exe}

IMCC_PROG = languages/imcc/imcc${exe}

# lclint has changed name to splint at v3.0
LINT = splint

# note: +distinctinternalnames with +externalnamelen at 8 characters
#       (the ANSI standard) is not going to fly for us.
LINTFLAGS = -weak +showscan +showsummary +posixstrictlib -abstract +aliasunique +ansireserved +ansireservedinternal +assignexpose +bitwisesigned +boolcompare +booltype BOOLVAL +casebreak -castfcnptr -charint +continuecomment +controlnestdepth 15 +cppnames +declundef +distinctinternalnames +evalorder +fielduse +forcehints -globs +imptype +includenest 8 +incondefs +incondefslib +linelen 9999 +longintegral +macroassign +macroempty +macroredef +matchanyintegral +nestedextern +noeffect +readonlystrings +realcompare +shadow -type

# slightly weaker, more realistic variant.
LINTFLAGS2 = $(LINTFLAGS) -ansireserved -retvalother -bitwisesigned

# added to lint target to simplify experimentation,
# ex: make LINTOPTS='-posixstrictlibs +posixlibs' lint
LINTOPTS =

###############################################################################
#
# MAKE CONFIGURATION:
#
###############################################################################

#
# This is set to  MAKE=$make if your $make command doesn't
# do it for you.
#
${make_set_make}

.c$(O) :
	@$(PERL) tools/dev/cc_flags.pl ./CFLAGS $(CC) $(CFLAGS) ${cc_o_out}$@ -c $<

all : flags_dummy $(TEST_PROG) $(IMCC_PROG) docs

world: all utils

utils: $(PDUMP) $(DIS) $(PINFO) $(PDB)

flags_dummy:
	echo Compiling with:
	@$(PERL) tools/dev/cc_flags.pl ./CFLAGS echo $(CFLAGS) xx$(O) -c xx.c


mops : examples/assembly/mops${exe} examples/mops/mops${exe}

$(TEST_PROG) : test_main$(O) $(GEN_HEADERS) $(LIBPARROT) lib/Parrot/OpLib/core.pm
	$(LINK) ${ld_out}$(TEST_PROG) $(LINKFLAGS) test_main$(O) $(LIBPARROT) $(C_LIBS)
	$(PERL) -MExtUtils::Command -e mv $(TEST_PROG) test_main$(EXE)

lib_deps_object : $(O_FILES)
	$(PERL) tools/dev/lib_deps.pl object $(O_FILES)

lib_deps_source : $(GENERAL_H_FILES)
	$(PERL) tools/dev/lib_deps.pl source all_source

lib_deps : lib_deps_object lib_deps_source

check_source : $(GENERAL_H_FILES)
	$(PERL) tools/dev/check_source_standards.pl all_source

###############################################################################
#
# Shared Library Targets:
#
###############################################################################

shared : $(GEN_HEADERS) blib/lib/libparrot$(SO) $(LIBPARROT)
static : $(GEN_HEADERS) $(LIBPARROT)

$(LIBPARROT) : $(O_FILES)
	$(MKDIR) blib blib/lib
	$(AR_CR) ${ar_out}$@ $(O_FILES)
	$(RANLIB) $@

blib/lib/libparrot$(SO) : $(O_FILES)
	$(MKDIR) blib blib/lib
	$(LD) $(LD_SHARED) $(LD_SHARED_FLAGS) $(LDFLAGS) $(LD_OUT)blib/lib/libparrot$(SO) $(O_FILES) $(C_LIBS)

$(TEST_PROG_SO) : test_main$(O) blib/lib/libparrot$(SO) lib/Parrot/OpLib/core.pm
	$(LINK) $(LINKFLAGS) $(LD_OUT)$(TEST_PROG) test_main$(O) $(LIBPARROT) $(C_LIBS)

# XXX The dependancies on SO.MAJOR.MINOR and SO.VERSION are removed
#     because those should be done at "make install" and not "make shared"
#     It also makes the task of getting this working on win32 much easier. :)
#
#blib/lib/libparrot$(SO).${VERSION} : $(O_FILES)
#	$(MKDIR) blib blib/lib
#	$(LD) $(LD_SHARED) -Wl,-soname,libparrot$(SO).${MAJOR} $(LDFLAGS) $(LD_OUT)blib/lib/libparrot$(SO).${VERSION} $(O_FILES)
#
#blib/lib/libparrot$(SO).${MAJOR}.${MINOR} : blib/lib/libparrot$(SO).${VERSION}
#	$(RM_F) $@
#	cd blib/lib; ln -s libparrot$(SO).${VERSION} libparrot$(SO).${MAJOR}.${MINOR}
#
#blib/lib/libparrot$(SO).${MAJOR} : blib/lib/libparrot$(SO).${MAJOR}.${MINOR}
#	$(RM_F) $@
#	cd blib/lib; ln -s libparrot$(SO).${MAJOR}.${MINOR} libparrot$(SO).${MAJOR}
#
#blib/lib/libparrot$(SO) : blib/lib/libparrot$(SO).${MAJOR}
#	$(RM_F) $@
#	cd blib/lib; ln -s libparrot$(SO).${MAJOR} libparrot$(SO)
#
#blib/lib/libcore_prederef$(SO).${VERSION} : core_ops_prederef$(O)
#	$(LD) $(LD_SHARED) -Wl,-soname,libparrot$(SO).${MAJOR} $(LDFLAGS) $(LD_OUT)blib/lib/libcore_prederef$(SO).${VERSION} core_ops_prederef$(O)
#
#blib/lib/libcore_prederef$(SO).${MAJOR}.${MINOR} : blib/lib/libcore_prederef$(SO).${VERSION}
#	$(RM_F) $@
#	cd blib/lib; ln -s libcore_prederef$(SO).${VERSION} libcore_prederef$(SO).${MAJOR}.${MINOR}
#
#blib/lib/libcore_prederef$(SO).${MAJOR} : blib/lib/libcore_prederef$(SO).${MAJOR}.${MINOR}
#	$(RM_F) $@
#	cd blib/lib; ln -s libcore_prederef$(SO).${MAJOR}.${MINOR} libcore_prederef$(SO).${MAJOR}
#
#blib/lib/libcore_prederef$(SO) : blib/lib/libcore_prederef$(SO).${MAJOR}
#	$(RM_F) $@
#	cd blib/lib; ln -s libcore_prederef$(SO).${MAJOR} libcore_prederef$(SO)


#
# Parrot Debugger
#

pdb$(O) : $(GENERAL_H_FILES)

$(PDB) : pdb$(O) $(LIBPARROT)
	$(LINK) ${ld_out}$(PDB) pdb$(O) $(LINKFLAGS) $(LIBPARROT) $(C_LIBS)

#
# Parrot Disassembler
#

disassemble$(O) : $(GENERAL_H_FILES)

$(DIS) : disassemble$(O) $(LIBPARROT)
	$(LINK) ${ld_out}$(DIS) disassemble$(O) $(LINKFLAGS) $(LIBPARROT) $(C_LIBS)

#
# Parrot Dump
#

$(PDUMP) : pdump$(O) packdump$(O) $(LIBPARROT)
	$(LINK) ${ld_out}$(PDUMP) pdump$(O) packdump$(O) $(LINKFLAGS) $(LIBPARROT) $(C_LIBS)


# pbc_info
$(PINFO) : pbc_info$(O) $(LIBPARROT)
	$(LINK) ${ld_out}$(PINFO) pbc_info$(O) $(LINKFLAGS) $(LIBPARROT) $(C_LIBS)

###############################################################################
#
# Other Dependencies and Build Rules:
#
###############################################################################

test_main$(O) : test_main.c $(GENERAL_H_FILES)

lib/Parrot/OpLib/core.pm : $(OPS_FILES) ops2pm.pl lib/Parrot/OpsFile.pm lib/Parrot/Op.pm
	$(PERL) ops2pm.pl $(OPS_FILES)

fingerprint.c : fingerprint_c.pl lib/Parrot/OpLib/core.pm
	$(PERL) fingerprint_c.pl > fingerprint.c

###############################################################################
#
# Examples (Assembly):
#
###############################################################################

examples/assembly/mops.pbc : examples/assembly/mops.pasm
	cd examples && cd assembly && $(MAKE) mops.pbc PERL=$(PERL) && cd .. && cd ..

examples/assembly/mops.c : examples/assembly/mops.pbc pbc2c.pl
	$(PERL) pbc2c.pl examples/assembly/mops.pbc > examples/assembly/mops.c

examples/assembly/mops${exe} : examples/assembly/mops$(O) $(LIBPARROT)
	$(LINK) $(LINKFLAGS) ${ld_out}examples/assembly/mops${exe} examples/assembly/mops$(O) $(LIBPARROT) $(C_LIBS)

examples/assembly/life.pbc : examples/assembly/life.pasm
	cd examples && cd assembly && $(MAKE) life.pbc PERL=$(PERL) && cd .. && cd ..

examples/assembly/life.c : examples/assembly/life.pbc pbc2c.pl
	$(PERL) pbc2c.pl examples/assembly/life.pbc > examples/assembly/life.c

examples/assembly/life${exe} : examples/assembly/life$(O) $(LIBPARROT)
	$(LINK) $(LINKFLAGS) ${ld_out}examples/assembly/life${exe} examples/assembly/life$(O) $(LIBPARROT) $(C_LIBS)

###############################################################################
#
# Examples (MOPS) - Comparative:
#
###############################################################################

examples/mops/mops$(O) : examples/mops/mops.c

examples/mops/mops${exe} : examples/mops/mops$(O)
	$(LINK) $(LINKFLAGS) ${ld_out}examples/mops/mops${exe} \
	examples/mops/mops$(O) $(LIBPARROT) $(C_LIBS)


###############################################################################
#
# Dependencies:
#
###############################################################################

global_setup$(O) : $(GENERAL_H_FILES)

pmc$(O) : $(GENERAL_H_FILES)

hash$(O) : $(GENERAL_H_FILES)

intlist$(O) : $(GENERAL_H_FILES)

list$(O) : $(GENERAL_H_FILES)

jit$(O) : $(GENERAL_H_FILES) ${jit_h} $(INC)/jit_emit.h

jit_debug$(O) : $(GENERAL_H_FILES) ${jit_h}

jit_cpu$(O): $(GENERAL_H_FILES) ${jit_h} $(INC)/jit_emit.h

exec$(O) : $(GENERAL_H_FILES) ${exec_h} ${jit_h} $(INC)/jit_emit.h

exec_cpu$(O): $(GENERAL_H_FILES) ${exec_h} ${jit_h} $(INC)/jit_emit.h

exec_start$(O) : $(GENERAL_H_FILES) ${exec_h}

exec_save$(O) : $(GENERAL_H_FILES) ${exec_h}

key$(O) : $(GENERAL_H_FILES)

smallobject$(O) : $(GENERAL_H_FILES)

headers$(O) : $(GENERAL_H_FILES)

dod$(O) : $(GENERAL_H_FILES)

resources$(O) : $(GENERAL_H_FILES)

platform$(O) : $(GENERAL_H_FILES)

core_pmcs$(O) : $(GENERAL_H_FILES)

trace$(O) : $(GENERAL_H_FILES)

debug$(O) : $(GENERAL_H_FILES) $(INC)/debug.h

method_util$(O) : $(GENERAL_H_FILES)

string$(O) : $(GENERAL_H_FILES)

longopt$(O) : $(GENERAL_H_FILES)

chartype$(O) : $(GENERAL_H_FILES)

encoding$(O) : $(GENERAL_H_FILES)

chartype/usascii$(O) : $(GENERAL_H_FILES)

chartype/unicode$(O) : $(GENERAL_H_FILES)

dynext$(O) : $(GENERAL_H_FILES)

exceptions$(O) : $(GENERAL_H_FILES)

encoding/singlebyte$(O) : $(GENERAL_H_FILES)

encoding/utf8$(O) : $(GENERAL_H_FILES)

encoding/utf16$(O) : $(GENERAL_H_FILES)

encoding/utf32$(O) : $(GENERAL_H_FILES)

events$(O) : $(GENERAL_H_FILES)

interpreter$(O) : interpreter.c $(GENERAL_H_FILES) ${jit_h}

io/io$(O) : $(GENERAL_H_FILES) io/io_private.h

io/io_buf$(O) : $(GENERAL_H_FILES) io/io_private.h

io/io_unix$(O) : $(GENERAL_H_FILES) io/io_private.h

io/io_win32$(O) : $(GENERAL_H_FILES) io/io_private.h

io/io_stdio$(O) : $(GENERAL_H_FILES) io/io_private.h

io/io_passdown$(O) : $(GENERAL_H_FILES) io/io_private.h

memory$(O) : $(GENERAL_H_FILES)

objects$(O) : $(GENERAL_H_FILES)

packfile$(O) : $(GENERAL_H_FILES)

packout$(O) : $(GENERAL_H_FILES)

parrot$(O) : $(GENERAL_H_FILES)

register$(O) : $(GENERAL_H_FILES)

rx$(O) : $(GENERAL_H_FILES)

rxstacks$(O) : $(GENERAL_H_FILES)

stacks$(O) : $(GENERAL_H_FILES)

tsq$(O) : $(GENERAL_H_FILES)

embed$(O) : $(GENERAL_H_FILES) $(INC)/debug.h

core_ops$(O) : $(GENERAL_H_FILES) core_ops.c

dataypes$(O) : $(GENERAL_H_FILES) dataypes.c

exit$(O) : $(GENERAL_H_FILES) exit.c

nci$(O) : $(GENERAL_H_FILES) nci.c

cpu_dep$(O) : $(GENERAL_H_FILES)

nci.c : call_list.txt build_nativecall.pl
	$(PERL) build_nativecall.pl call_list.txt

#core_ops depends upon config.h so that it gets updated along with updates to config.h's version numbers
core_ops.c $(INC)/oplib/core_ops.h : $(OPS_FILES) ops2c.pl lib/Parrot/OpsFile.pm lib/Parrot/Op.pm $(INC)/config.h
	$(PERL) ops2c.pl C $(OPS_FILES)

core_ops_prederef$(O) : $(GENERAL_H_FILES) core_ops_prederef.c

core_ops_prederef.c $(INC)/oplib/core_ops_prederef.h : $(OPS_FILES) ops2c.pl lib/Parrot/OpsFile.pm lib/Parrot/Op.pm $(INC)/config.h
	$(PERL) ops2c.pl CPrederef $(OPS_FILES)

core_ops_switch$(O) : $(GENERAL_H_FILES) core_ops_switch.c

core_ops_switch.c $(INC)/oplib/core_ops_switch.h : $(OPS_FILES) ops2c.pl lib/Parrot/OpsFile.pm lib/Parrot/Op.pm $(INC)/config.h
	$(PERL) ops2c.pl CSwitch $(OPS_FILES)

${cg_c}

${gc_c}

warnings$(O) : $(GENERAL_H_FILES)

misc$(O) : $(GENERAL_H_FILES)

utils$(O) : $(GENERAL_H_FILES)

spf_render$(O) : $(GENERAL_H_FILES)

spf_vtable$(O) : $(GENERAL_H_FILES)

# $(STICKY_FILES) : Configure.pl
#	$(PERL) Configure.pl

$(INC)/vtable.h : vtable.tbl vtable_h.pl
	$(PERL) vtable_h.pl

$(INC)/jit_emit.h: jit/${jitcpuarch}/jit_emit.h
	$(PERL) -MFile::Copy=cp -e ${PQ}cp q|jit/${jitcpuarch}/jit_emit.h|, q|$(INC)/jit_emit.h|${PQ}
$(INC)/exec_dep.h: jit/${jitcpuarch}/exec_dep.h
	$(PERL) -MFile::Copy=cp -e ${PQ}cp q|jit/${jitcpuarch}/exec_dep.h|, q|$(INC)/exec_dep.h|${PQ}
jit_cpu.c: lib/Parrot/OpLib/core.pm $(INC)/jit_emit.h jit/${jitcpuarch}/core.jit
	$(PERL) jit2h.pl ${jitcpuarch} jit_cpu.c
exec_cpu.c: lib/Parrot/OpLib/core.pm $(INC)/jit_emit.h jit/${jitcpuarch}/core.jit ${exec_h} $(INC)/exec_dep.h
	$(PERL) jit2h.pl ${jitcpuarch} exec_cpu.c

docs : docs/.dummy

docs/.dummy :
	cd docs && $(MAKE) && cd ..

languages : languages.dummy

languages.dummy :
	cd languages && $(MAKE) && cd ..

languages-test :
	cd languages && $(MAKE) test && cd ..

# If anything in the classes directory is out of date,
# then run `make` in sub-dir to rebuild only the out of date files.
$(CLASS_O_FILES) : $(CLASS_PMC_FILES) $(NONGEN_HEADERS)
	cd classes && $(MAKE) && cd ..


$(IMCC_PROG) : $(LIBPARROT)        \
               languages/imcc/*.c \
               languages/imcc/*.h \
               languages/imcc/*.y \
               languages/imcc/*.l
	cd languages${slash}imcc && $(MAKE) && cd ..${slash}..
	$(PERL) -MExtUtils::Command -e mv $(IMCC_PROG) $(TEST_PROG)
	cd languages${slash}imcc && $(MAKE) && cd ..${slash}..

# the chmod doesn't work here, so move imcc and make it again :-(
# $(PERL) -MExtUtils::Command -e chmod 0755 $(TEST_PROG)


###############################################################################
#
# Testing Targets:
#
###############################################################################

# The --running-make-test argument is currently used by long-running tests
# to disable GC_DEBUG.
EXTRA_TEST_ARGS = --gc-debug --running-make-test

test : $(TEST_PROG) test_prep test_dummy test_imcc

fulltest : $(TEST_PROG) test_prep fulltest_dummy fulltest_imcc

.PHONY: fulltest_dummy
fulltest_dummy :
	$(PERL) t/harness $(EXTRA_TEST_ARGS) $(TEST_PROG_ARGS)
	$(PERL) t/harness $(EXTRA_TEST_ARGS) -j $(TEST_PROG_ARGS)
	$(PERL) t/harness $(EXTRA_TEST_ARGS) -P $(TEST_PROG_ARGS)
	$(PERL) t/harness $(EXTRA_TEST_ARGS) -b $(TEST_PROG_ARGS)

quickfulltest : $(TEST_PROG) test_prep quickfulltest_dummy

.PHONY: quickfulltest_dummy
quickfulltest_dummy :
	$(PERL) t/harness $(EXTRA_TEST_ARGS) $(TEST_PROG_ARGS) quick
	$(PERL) t/harness $(EXTRA_TEST_ARGS) -j $(TEST_PROG_ARGS) quick
	$(PERL) t/harness $(EXTRA_TEST_ARGS) -P $(TEST_PROG_ARGS) quick
	$(PERL) t/harness $(EXTRA_TEST_ARGS) -b $(TEST_PROG_ARGS) quick

# Common prep for all test targets
test_prep : $(LIBPARROT) $(IMCC_PROG)

test_dummy :
	$(PERL) t/harness $(EXTRA_TEST_ARGS) $(TEST_PROG_ARGS)

testp : $(TEST_PROG) test_prep blib/lib/libcore_prederef$(SO) blib/lib/libparrot$(SO) $(TEST_PROG_SO) test_dummy_p

test_dummy_p :
	$(PERL) t/harness $(EXTRA_TEST_ARGS) $(TEST_PROG_ARGS) -P

testj : $(TEST_PROG) test_prep test_dummy_j

test_dummy_j :
	$(PERL) t/harness $(EXTRA_TEST_ARGS) $(TEST_PROG_ARGS) -j

quicktest : $(TEST_PROG) test_prep quicktest_dummy

quicktest_dummy :
	$(PERL) t/harness $(EXTRA_TEST_ARGS) $(TEST_PROG_ARGS) quick

mopstest : $(TEST_PROG) examples/assembly/mops.pbc
	$(TEST_PROG) $(TEST_PROG_ARGS) examples/assembly/mops.pbc

lifetest : $(TEST_PROG) examples/assembly/life.pbc
	$(TEST_PROG) $(TEST_PROG_ARGS) examples/assembly/life.pbc

test_imcc :
	cd languages/imcc && $(PERL) t/harness && cd ../..

fulltest_imcc :
	cd languages/imcc && $(PERL) t/harness && cd ../..
	cd languages/imcc && $(PERL) t/harness -j && cd ../..
	cd languages/imcc && $(PERL) t/harness -P && cd ../..
	cd languages/imcc && $(PERL) t/harness -b && cd ../..

# For reporting success or failure with different configurations
ok:
	$(PERL) tools/dev/genrpt.pl --ok

okfile:
	$(PERL) tools/dev/genrpt.pl --ok --File parrot.ok

nok:
	$(PERL) tools/dev/genrpt.pl --nok

nokfile:
	$(PERL) tools/dev/genrpt.pl --nok --File parrot.nok

###############################################################################
#
# Cleaning Targets:
#
###############################################################################

clean : testclean progclean
	${cg_r}
	$(RM_F) *.s *~ $(FLUID_FILES) \
	        examples/assembly/mops${exe} examples/assembly/mops.c \
	        examples/assembly/mops$(O) examples/assembly/mops.pbc \
	        examples/mops/mops$(O) examples/mops/mops${exe}
	cd docs && $(MAKE) clean && cd ..
	cd classes && $(MAKE) clean && cd ..
	cd languages && $(MAKE) clean && cd ..

progclean:
	$(RM_F) $(O_FILES) \
	        $(TEST_PROG) test_main$(O) test_main$(EXE) \
	        $(PDUMP) pdump$(O) packdump$(O) pbc_info$(O) $(PINFO) \
	        $(PDB) pdb$(O) \
	        $(DIS) disassemble$(O)
	$(RM_RF) blib
	cd classes && $(MAKE) progclean && cd ..

testclean :
	$(RM_F) t/op/*.pasm t/op/*.pbc t/op/*.out t/op/*.o t/op/*.stabs.s \
	        t/pmc/*.pasm t/pmc/*.pbc t/pmc/*.out t/pmc/*.o t/pmc/*.stabs.s \
	        t/stress/*.pasm t/stress/*.pbc t/stress/*.out t/stress/*.o t/stress/*.stabs.s \
	        t/src/*_*

realclean : clean
	$(RM_F) $(STICKY_FILES)

distclean :
	$(PERL) "-MExtUtils::Manifest=filecheck" -le ${PQ}sub ExtUtils::Manifest::_maniskip{sub{0}};$$ExtUtils::Manifest::Quiet=1;unlink $$_ for filecheck()${PQ}

cvsclean :
	$(PERL) "-MExtUtils::Manifest=filecheck" -le ${PQ}sub ExtUtils::Manifest::_maniskip{sub{0}};$$ExtUtils::Manifest::Quiet=1; do { unlink $$_ unless $$_ =~ m!(?:CVS/|\.cvs)! } for filecheck()${PQ}

reconfig :
	$(MAKE) clean; $(PERL) Configure.pl --reconfig

manitest :
	$(PERL) "-MExtUtils::Manifest=fullcheck" -e fullcheck

###############################################################################
#
# CVS Targets:
#
###############################################################################

update :
	cvs -q update -dP

rsync :
	rsync -av cvs.perl.org::parrot-HEAD .

status :
	cvs -n -q upd -dP

lint : ${test_prog}
	$(LINT) ${cc_inc} ${cc_hasjit} "-Iclasses" $(LINTFLAGS) $(LINTOPTS) `echo $(O_FILES) | sed ${PQ}s/\.o/\.c/g${PQ}`
	$(LINT) ${cc_inc} $(LINTFLAGS) $(LINTOPTS) test_main.c

lint2 : ${test_prog}
	$(LINT) ${cc_inc} ${cc_hasjit} "-Iclasses" $(LINTFLAGS2) $(LINTOPTS) `echo $(O_FILES) | sed ${PQ}s/\.o/\.c/g${PQ}`
	$(LINT) ${cc_inc} $(LINTFLAGS2) $(LINTOPTS) test_main.c


###############################################################################
#
# installation
#
###############################################################################

install :
	$(PERL) tools/dev/install_files.pl --buildprefix=$(BUILDPREFIX) --prefix=$(PREFIX) --exec-prefix=$(EXEC_PREFIX) --bindir=$(BINDIR) --libdir=$(LIBDIR) --includedir=$(INCLUDEDIR) MANIFEST MANIFEST.generated | sh

###############################################################################
#
# release targets (probably unix only)
#
###############################################################################

release : MANIFEST MANIFEST.generated
	[ -d parrot-$(VERSION) ] || ln -s . parrot-$(VERSION)
	cp MANIFEST MANIFEST.real
	grep -v DEVELOPING MANIFEST.real > MANIFEST
	tar zcvf parrot-$(VERSION).tar.gz $$(perl -lane 'print"parrot-$(VERSION)/$$F[0]"unless!length||/#/' MANIFEST)
	mv MANIFEST.real MANIFEST
	rm parrot-$(VERSION)

rpms : release
	sudo cp parrot-$(VERSION).tar.gz /usr/src/*/SOURCES
	sudo cp parrot.spec /usr/src/*/SPECS
	cd /usr/src/*/SPECS && sudo rpm -ba parrot.spec

###############################################################################
#
# miniparrot targets:
#
###############################################################################

miniparrot-prebuild : $(GEN_CONFIGS) $(FLUID_FILES)
	@tools/dev/rebuild_miniparrot.pl --action=clean
	@tools/dev/rebuild_miniparrot.pl --action=prebuild_classes $(CLASS_O_FILES)
	@tools/dev/rebuild_miniparrot.pl --action=copy_src $(GEN_CONFIGS) $(FLUID_FILES) $(ALL_H_FILES)
	@tools/dev/rebuild_miniparrot.pl --action=copy_src classes/*.h test_main.c $(INC)/debug.h
	@tools/dev/rebuild_miniparrot.pl --action=copy_src_from_obj $(O_FILES)
	@tools/dev/rebuild_miniparrot.pl --action=write_buildscripts --executable=parrot $(O_FILES) test_main$(O)

miniparrot-update :
	tools/dev/rebuild_miniparrot.pl

###############################################################################
#
# exec:
#
###############################################################################

exec : exec_start$(O) $(LIBPARROT)
	$(LINK) ${ld_out}$(EXEC) $(LINKFLAGS) $(EXEC)$(O) exec_start$(O) $(LIBPARROT) $(C_LIBS)

exec_so : exec_start$(O) blib/lib/libparrot$(SO)
	$(LINK) ${ld_out}$(EXEC) $(LINKFLAGS) $(EXEC)$(O) exec_start$(O) -lparrot $(C_LIBS) -pthread
