# Copyright (C) 2007, The Perl Foundation.
# $Id: parrot_embed.in 17134 2007-02-22 03:52:41Z particle $
#
# cross-platform commands and paths
RM_F            = @rm_f@
RM_RF           = @rm_rf@
MKPATH          = @mkpath@
CP              = @cp@
PERL            = @perl@
PARROTDIR       = ../..
PARROT          = $(PARROTDIR)/parrot$(EXE)

# compilation options
A               = @a@
O               = @o@
SHARE_EXT       = @share_ext@
C_LIBS          = @libs@
#CONDITIONED_LINE(win32):ALL_PARROT_LIBS = $(PARROTDIR)/@libparrot_ldflags@ $(ICU_SHARED) $(C_LIBS)
#INVERSE_CONDITIONED_LINE(win32):ALL_PARROT_LIBS = @libparrot_ldflags@ $(ICU_SHARED) $(C_LIBS)
LINKFLAGS       = @linkflags@ @link_debug@ @ld_debug@
LINK            = @link@
LD_SHARE_FLAGS  = @ld_share_flags@
CC_INC          = -I@perl_inc@ -I../../include
CFLAGS          = $(CC_INC) @ccflags@ @cc_debug@ @ccwarn@ @cc_hasjit@ @cg_flag@ @gc_flag@ $(CC_SHARED)
#CONDITIONED_LINE(win32):LD_FLAGS        = -def:lib\Parrot\Embed.def $(LD_SHARE_FLAGS)
#INVERSE_CONDITIONED_LINE(win32):LD_FLAGS        = $(LD_SHARE_FLAGS)

# files needing compilation
C_FILE          = lib/Parrot/Embed.c
SO_FILE         = blib/arch/auto/Parrot/Embed/Embed$(SHARE_EXT)
O_FILE          = lib/Parrot/Embed$(O)

# other useful files
PM              = blib/lib/Parrot/Embed.pm
PBC             = t/greet.pbc
TEST_FILES      = t/*.t

all : $(SO_FILE) $(PM) $(PBC)

.c$(O) :
	@$(PERL) $(PARROTDIR)\tools\dev\cc_flags.pl $(PARROTDIR)\CFLAGS $(CC) "" $(CFLAGS) -I$(@D) -Fo$@ -c $<

$(PM) : lib/Parrot/Embed.pm
	$(MKPATH) blib/lib/Parrot
	$(CP) lib/Parrot/Embed.pm blib/lib/Parrot

$(SO_FILE) : $(O_FILE)
	$(PERL) -MExtUtils::Mksymlists -e "eval { Mksymlists( NAME => \"Parrot::Embed\" ) }"
	$(MKPATH) blib/arch/auto/Parrot/Embed
	$(LINK) $(LD_SHARE_FLAGS) @ld_out@$(SO_FILE) $(O_FILE) @rpath_blib@ $(ALL_PARROT_LIBS) $(LINKFLAGS)

$(C_FILE) : lib/Parrot/Embed.xs
	$(PERL) tools/write_typemap.pl

$(PBC) : t/greet.pir
	$(PARROT) -o $(PBC) t/greet.pir

test : $(TEST_FILES)
	prove -b $(TEST_FILES)

clean :
	$(RM_RF) blib $(C_FILE) $(O_FILE)
