RM_F    = @rm_f@
PERL    = @perl@
PARROT  = ../../parrot@exe@

PMCBUILD  = $(PERL) @build_dir@/tools/build/dynpmc.pl
DESTDIR   = @build_dir@/runtime/parrot/dynext
O         = @o@
PMCDIR    = src/pmc
LOAD_EXT  = @load_ext@

CC_INC     = @cc_inc@
CC_SHARED  = @cc_shared@
CFLAGS     = $(CC_INC) @ccflags@ @cc_debug@ @ccwarn@ @cc_hasjit@ @cg_flag@ @gc_flag@ $(CC_SHARED)
CC         = @cc@

PMCS = \
 perlarray \
 perlhash \
 perlnum \
 perlstring \
 perlenv \
 perlint \
 perlscalar \
 perlundef

all: pmcs

pmcs:
	@cd $(PMCDIR) && $(PMCBUILD) generate $(PMCS)
	@cd $(PMCDIR) && $(PMCBUILD) compile $(PMCS)
	@cd $(PMCDIR) && $(PMCBUILD) linklibs $(PMCS)
	@cd $(PMCDIR) && $(PMCBUILD) copy "--destination=$(DESTDIR)" $(PMCS)

# THIS WAS COPIED FROM THE ROOT MAKEFILE
# Passing an empty argument in @ARGV to cc_flags.pl to indicate where extra -Is
# (etc) should go. Otherwise it will insert them after the first space, which
# makes life go horribly wrong if $(CC) contains spaces but can't have -I
# arguments (etc) injected in the middle.
# There is probably a better way to do this, but I can't work it out right now.
.c$(O) :
	@$(PERL) ../../tools/dev/cc_flags.pl ../../CFLAGS $(CC) "" $(CFLAGS) -I@build_dir@@slash@include @cc_o_out@$@ -c $<

test:	pmcs
	prove -r t

TEST_CLEANERS = \
 "t\\*.pasm" \
 "t\\*.pir"

testclean:
	$(RM_F) $(TEST_CLEANERS)

BUILD_CLEANERS = \
 "$(PMCDIR)/*.c" \
 "$(PMCDIR)/*.h" \
 "$(PMCDIR)/*.dump" \
 "$(PMCDIR)/*$(LOAD_EXT)" \
 "$(PMCDIR)/*$(O)" \
 "$(PMCDIR)/*.bundle" \
 "$(PMCDIR)/*.exp" \
 "$(PMCDIR)/*.ilk" \
 "$(PMCDIR)/*.lib" \
 "$(PMCDIR)/*.pdb"

clean:
	$(RM_F) $(BUILD_CLEANERS) $(TEST_CLEANERS)

distclean: clean
	$(RM_F) Makefile

