From 9c33add1c3456689b9ee06c6c8568a819a4aeb22 Mon Sep 17 00:00:00 2001 From: Carl Masak Date: Sun, 5 Apr 2009 16:18:22 +0200 Subject: [PATCH] remade the build model to be more proto-friendly I started by copying proto's model right off, but there were a number of subtle improvements that I wanted to make, namely: - Renamed Configure.p6 -> configure - Copied Configure.pm from proto into druid, so that druid doesn't have to depend on proto. See commit 7cff8e945cf30a2cac9794d01a803f688050f0bb in proto. - I don't care for the lib/Test.pir target. Instead, I added RAKUDO_DIR to PERL6LIB; feels cleaner. - I don't care for Configure.pm running make. Changed the comment to let the user do it herself. - added 'env' commands to set the PERL6LIB variable both in target 'all' and in target 'test'. --- Makefile.PL | 45 --------------- Makefile.in | 14 +++-- README | 6 +- configure | 3 + lib/Configure.pm | 141 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 55 deletions(-) delete mode 100644 Makefile.PL create mode 100644 configure create mode 100644 lib/Configure.pm diff --git a/Makefile.PL b/Makefile.PL deleted file mode 100644 index fc162b1..0000000 --- a/Makefile.PL +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/perl -$|++; - -use strict; -use warnings; - -use File::Spec; - -my $parrot_dir = $ENV{PARROT_DIR} - or die 'Please set $PARROT_DIR (see README).'."\n"; - -$ENV{PERL6LIB} - or die 'Please set $PERL6LIB (see README).'."\n"; - -if ( ! -d $parrot_dir ) { - print STDERR "Not a directory $parrot_dir, exiting...\n"; - exit 1; -} elsif ( ! -x File::Spec->catfile( $parrot_dir, 'parrot' )) { - print STDERR "Couldn't find parrot executable in $parrot_dir, " - . "have you compiled?"; - exit 1; -} - -my @infiles = map { $_.'.in' } qw< Makefile >; - -my %replacements = ( - PARROT_DIR => $parrot_dir, -); - -for my $infile (@infiles) { - if ((my $outfile = $infile) =~ s/\.in$//g) { - open my $IN, '<', $infile or die "Couldn't open $infile, $!, $?"; - open my $OUT, '>', $outfile or die "Couldn't open $outfile, $!, $?"; - while (my $line = <$IN>) { - while ( $line =~ /<(.*?)>/g ) { - my $repl = $1; - if (exists $replacements{$repl}) { - $line =~ s/<$repl>/$replacements{$repl}/g; - } - } - print $OUT $line; - } - print "Created $outfile \n"; - } -} diff --git a/Makefile.in b/Makefile.in index dee79c1..93c4ad7 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,4 +1,6 @@ -PARROT_DIR= +PERL6= +RAKUDO_DIR= +PERL6LIB=':$(RAKUDO_DIR)' SOURCES=lib/Druid/Base.pm lib/Druid/Game/Observer.pm \ lib/Druid/Game/Subject.pm lib/Druid/Game.pm lib/Druid/View.pm \ @@ -11,10 +13,10 @@ PIRS=$(SOURCES:.pm=.pir) all: $(PIRS) %.pir: %.pm - $(PARROT_DIR)/parrot \ - $(PARROT_DIR)/languages/rakudo/perl6.pbc \ - --target=pir --output=$@ \ - $< + env PERL6LIB=$(PERL6LIB) $(PERL6) --target=pir --output=$@ $< clean: - rm -f $(PIRS) Makefile + rm -f $(PIRS) + +test: all + env PERL6LIB=$(PERL6LIB) prove -e '$(PERL6)' -r --nocolor t/ diff --git a/README b/README index 864ccab..3f72808 100644 --- a/README +++ b/README @@ -42,13 +42,11 @@ Yup, you're ready to go. (After all, compilation does make startup a little faster.) -% perl Makefile.PL +% perl6 configure % make Remember that you still need to set $PERL6LIB and $PARROT_DIR as above. The -file Makefile.PL will complain if you don't. The 'make' process, should you -foolishly proceed to it without heeding Makefile.PL's advice, will not -complain, just fail. +configure script will complain if you don't. == Installing via proto diff --git a/configure b/configure new file mode 100644 index 0000000..af81f34 --- /dev/null +++ b/configure @@ -0,0 +1,3 @@ +#!perl6 +use v6; +use Configure; diff --git a/lib/Configure.pm b/lib/Configure.pm new file mode 100644 index 0000000..ffbaa10 --- /dev/null +++ b/lib/Configure.pm @@ -0,0 +1,141 @@ +# Configure.pm + +.say for + '', + 'Configure.pm is preparing to make your Makefile.', + ''; + +# Determine how this Configure.p6 was invoked, to write the same paths +# and executables into the Makefile variables. The variables are: +# PERL6 how to execute a Perl 6 script +# PERL6LIB initial value of @*INC, where 'use ;' searches +# PERL6BIN directory where executables such as 'prove' reside +# RAKUDO_DIR (deprecated) currently the location of Rakudo's Test.pm + +my $parrot_dir = %*VM; +my $rakudo_dir; +my $perl6; + +regex parrot_in_rakudo { ( .* '/rakudo' ) '/parrot' } + +# There are two possible relationships between the parrot and rakudo +# directories: rakudo/parrot or parrot/languages/rakudo +if $parrot_dir ~~ / / { + # first case, rakudo/parrot for example if installed using new + # 'git clone ...rakudo.git' then 'perl Configure.pl --gen-parrot' + $rakudo_dir = $parrot_dir.subst( / '/parrot' $ /, ''); #' +} +elsif "$parrot_dir/languages/rakudo" ~~ :d { + # second case, parrot/languages/rakudo if installed the old way + $rakudo_dir = "$parrot_dir/languages/rakudo"; +} +else { # anything else + .say for + "Found a PARROT_DIR to be $parrot_dir", + 'but there is no Rakudo nearby. Please contact the proto people.', + ''; + exit(1); +} +if "$rakudo_dir/perl6" ~~ :f or "$rakudo_dir/perl6.exe" ~~ :f { + $perl6 = "$rakudo_dir/perl6"; # the fake executable from pbc_to_exe +} +else { + $perl6 = "$parrot_dir/parrot $rakudo_dir/perl6.pbc"; +} + +say "PERL6 $perl6"; +my $perl6lib = %*ENV ~ '/lib'; +say "PERL6LIB $perl6lib"; +# The perl6-examples/bin directory is a sibling of PERL6LIB +my $perl6bin = $perl6lib.subst( '/lib', '/bin' ); +say "PERL6BIN $perl6bin"; +say "RAKUDO_DIR $rakudo_dir"; + +# Read Makefile.in, edit, write Makefile +my $maketext = slurp( 'Makefile.in' ); +$maketext .= subst( .key, .value ) for + 'Makefile.in' => 'Makefile', + 'To be read' => 'Written', + 'replaces ' => 'defined these', +# Maintainer note: keep the following in sync with pod#VARIABLES below + '' => $perl6, + '' => $perl6lib, + '' => $perl6bin, + '' => $rakudo_dir; +squirt( 'Makefile', $maketext ); + +# Job done. +.say for + '', + q[Makefile is ready. Ready to run 'make'.]; + + +# The opposite of slurp +sub squirt( Str $filename, Str $text ) { + my $handle = open( $filename, :w ) + or die $!; + $handle.print: $text; + $handle.close; +} + +# This Configure.pm can work with the following ways of starting up: +# 1. The explicit way Parrot runs any Parrot Byte Code: +# /my/parrot/parrot /my/rakudo/perl6.pbc Configure.p6 +# 2. The Rakudo "Fake Executable" made by pbc_to_exe: +# /my/rakudo/perl6 Configure.p6 +# The rest are variations of 1. and 2. to sugar the command line: +# 3. A shell script perl6 for 1: '/my/parrot/parrot /my/rakudo/perl6.pbc $*': +# /my/perl6 Configure.p6 # or 'perl6 Configure.p6' with search path +# 4. A shell alias for 1: perl6='/my/parrot/parrot /my/rakudo/perl6.pbc': +# perl6 Configure.p6 +# 5. A symbolic link for 2: 'sudo ln -s /my/rakudo/perl6 /bin': +# perl6 Configure.p6 + +# Do you know of another way to execute Perl 6 scripts? Please tell the +# maintainers. + +=begin pod + +=head1 NAME +Makefile.pm - common code for Makefile builder and runner + +=head1 SYNOPSIS + + perl6 Configure.p6 + +Where F generally has only these lines: + + # Configure.p6 - installer - see documentation in ../Configure.pm + use v6; BEGIN { @*INC.push( '../..' ); }; use Configure; # proto dir + +=head1 DESCRIPTION +A Perl module often needs a Makefile to specify how to build, test and +install it. A Makefile must make sense to the Unix C utility. +Makefiles must often be adjusted slightly to alter the context in which +they will work. There are various tools to "make Makefiles" and this +F and F combination run purely in Perl 6. + +Configure.p6 resides in the module top level directory. For covenience, +Configure.p6 usually contains only the lines shown in L +above, namely a comment and one line of code to pass execution to +F. Any custom actions to prepare the module can be called +by the default target in Makefile.in. + +Configure.pm reads F from the module top level directory, +replaces certain variables marked like , and writes the updated +text to Makefile in the same directory. Finally it runs the standard +'make' utility, which builds the first target defined in Makefile. + +=head1 VARIABLES +C will cause the following tokens to be substituted when +creating the new F: + + pathname of Perl 6 (fake)executable + lib/ directory of the installed project + bin/ directory of the installed project + whence Rakudo's Test.pm can be compiled + +=head1 AUTHOR +Martin Berends (mberends on CPAN github #perl6 and @autoexec.demon.nl). + +=end pod