perl.cvs.mod_parrot
[Top] [All Lists]

[svn:mod_parrot] r381 - in mod_parrot/branches/configure: . config/direc

Subject: [svn:mod_parrot] r381 - in mod_parrot/branches/configure: . config/directives config/gen config/gen/makefiles config/init config/probe lib/ModParrot/Configure
From: particle@xxxxxxxxxxxx
Date: Thu, 24 Jul 2008 15:28:16 -0700 (PDT)
Newsgroups: perl.cvs.mod_parrot

Author: particle
Date: Thu Jul 24 15:28:15 2008
New Revision: 381

Added:
   mod_parrot/branches/configure/config/gen/
   mod_parrot/branches/configure/config/gen/makefile.pm
   mod_parrot/branches/configure/config/gen/makefiles/
   mod_parrot/branches/configure/config/gen/makefiles/root.in
      - copied unchanged from r380, /mod_parrot/branches/configure/Makefile.in
   mod_parrot/branches/configure/lib/ModParrot/Configure/Utils.pm
Removed:
   mod_parrot/branches/configure/Makefile.in
Modified:
   mod_parrot/branches/configure/Configure.pl
   mod_parrot/branches/configure/config/directives/configure.op
   mod_parrot/branches/configure/config/init/defaults.pm
   mod_parrot/branches/configure/config/probe/apache.pm
   mod_parrot/branches/configure/config/probe/parrot.pm
   mod_parrot/branches/configure/lib/ModParrot/Configure/Messages.pm

Log:
[config] add beginning of makefile generation

Modified: mod_parrot/branches/configure/Configure.pl
==============================================================================
--- mod_parrot/branches/configure/Configure.pl  (original)
+++ mod_parrot/branches/configure/Configure.pl  Thu Jul 24 15:28:15 2008
@@ -261,28 +261,6 @@
 my $defines;
 
 
-## step probe::apache
-# apache configs
-my $apache_include_dir = `$apxs -q INCLUDEDIR`;
-my $apr_include_dir = `$apxs -q APR_INCLUDEDIR`;
-my $apu_include_dir = `$apxs -q APU_INCLUDEDIR`;
-my $extra_cppflags = `$apxs -q EXTRA_CPPFLAGS`;
-my $libexec_dir = `$apxs -q LIBEXECDIR`;
-my $cc = `$apxs -q CC`;
-my $libtool = `$apxs -q LIBTOOL`;
-
-# discover mpm -- we don't use this yet, but we might
-my $mpm = `$apxs -q MPM_NAME`;
-$mpm or die "Couldn't find Apache MPM";
-chomp($mpm);
-print "Configuring mod_parrot for $mpm MPM.\n";
-
-
-# we can't use the config verbatim -- apxs chokes on it, so we use what we can
-my $cflags = " -I$parrot_build_dir/include -Iinclude";
-$cflags .= " -DMPM_IS_THREADED" if (mpm_is_threaded($mpm));
-
-
 ## step gen::makefile
 print "Generating Makefile...";
 my $template;

Modified: mod_parrot/branches/configure/config/directives/configure.op
==============================================================================
--- mod_parrot/branches/configure/config/directives/configure.op        
(original)
+++ mod_parrot/branches/configure/config/directives/configure.op        Thu Jul 
24 15:28:15 2008
@@ -20,63 +20,7 @@
 run init::defaults
 run probe::parrot
 run probe::apache
-#run init::install
-#run init::miniparrot
-#run init::hints
-#run init::headers
-#run inter::progs
-#run inter::make
-#run inter::lex
-#run inter::yacc
-#run auto::gcc
-#run auto::msvc
-#run init::optimize
-#run inter::shlibs
-#run inter::libparrot
-#run inter::charset
-#run inter::encoding
-#run inter::types
-#run inter::ops
-### pass options to a specific config step
-##run inter::pmc --ask
-#run inter::pmc
-#run auto::alignptrs
-#run auto::headers
-#run auto::sizes
-#run auto::byteorder
-#run auto::va_ptr
-#run auto::pack
-#run auto::format
-#run auto::isreg
-#run auto::jit
-#run gen::cpu
-#run auto::funcptr
-#run auto::cgoto
-#run auto::inline
-#run auto::gc
-#run auto::memalign
-#run auto::signal
-#run auto::socklen_t
-#run auto::env
-#run auto::aio
-#run auto::gmp
-#run auto::readline
-#run auto::gdbm
-#run auto::snprintf
-#run auto::perldoc
-### look, i can easily disable one or more config steps now
-##run auto::python
-##run auto::m4
-#run auto::cpu
-#run gen::icu
-#run gen::revision
-#run gen::config_h
-#run gen::core_pmcs
-#run gen::parrot_include
-#run gen::languages
-#run gen::makefiles
-#run gen::platform
-#run gen::config_pm
+run gen::makefile
 
 
 #test build

Added: mod_parrot/branches/configure/config/gen/makefile.pm
==============================================================================
--- (empty file)
+++ mod_parrot/branches/configure/config/gen/makefile.pm        Thu Jul 24 
15:28:15 2008
@@ -0,0 +1,68 @@
+# $Id$
+
+=head1 NAME
+
+config/gen/makefile.pm - Build the mod_parrot Makefile
+
+=head1 DESCRIPTION
+
+Generates the F<Makefile> needed to build mod_parrot.
+
+=cut
+
+package gen::makefile;
+
+use strict;
+use warnings;
+
+
+use base qw(ModParrot::Configure::Step);
+
+use ModParrot::Configure::Utils ':gen';
+
+sub _init {
+    my $self = shift;
+    my %data;
+    $data{description} = q{Generating the makefile};
+    $data{result}      = q{};
+    return \%data;
+}
+
+my %makefiles = (
+    'Makefile' => { SOURCE => 'config/gen/makefiles/root.in' },
+);
+
+sub runstep {
+    my ( $self, $conf ) = @_;
+
+    $self->makefiles($conf);
+
+    return 1;
+}
+
+sub makefiles {
+    my ( $self, $conf ) = @_;
+
+    my $targets = $conf->options->get('target');
+    my @targets =
+        defined $targets
+        ? split ' ', $targets
+        : keys %makefiles;
+
+    foreach my $target (@targets) {
+        my $args   = $makefiles{$target};
+        my $source = delete $args->{SOURCE};
+
+        $conf->genfile($source => $target, %$args );
+    }
+    return;
+}
+
+1;
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Modified: mod_parrot/branches/configure/config/init/defaults.pm
==============================================================================
--- mod_parrot/branches/configure/config/init/defaults.pm       (original)
+++ mod_parrot/branches/configure/config/init/defaults.pm       Thu Jul 24 
15:28:15 2008
@@ -17,11 +17,6 @@
 
 use base qw(ModParrot::Configure::Step);
 
-##  TODO this hardcoded setup *must* be replaced with something smarter
-##  probably split out the parrot config stuff into a probe at a later time
-use lib '../lib', '/usr/local/parrot/trunk/lib';
-use Parrot::Config;
-
 
 sub _init {
     my $self = shift;
@@ -37,10 +32,6 @@
 
     # We need a Glossary somewhere!
     $conf->data->set(
-        parrot_build_dir => $conf->options->get('parrot_build_dir')
-                            || '../parrot',
-        apxs             => $conf->options->get('apxs')
-                            || '/usr/local/apache/bin/apxs',
         perl             => $^X,
 
         debug            => ( $conf->options->get('debug') || $ENV{'MP_DEBUG'} 
)
@@ -48,27 +39,10 @@
         optimize         => '',
         verbose          => $conf->options->get('verbose'),
 
-        cflags           => $PConfig{cflags},
-        make             => $PConfig{make},
-
-        libs             => $PConfig{libs} . ' -lparrot',
-        blib_dir         => $PConfig{blib_dir},
-    );
-
-    $conf->data->set( ldflags =>
-        $conf->data->get('parrot_build_dir')
-        . '/' . $conf->data->get('blib_dir')
     );
 
     return $self;
 }
 
 
-sub _mpm_is_threaded {
-    return !!grep $_ => qw/
-        worker winnt beos mpmt_os2 netware leader perchild threadpool
-    /;
-}
-
-
 1;

Modified: mod_parrot/branches/configure/config/probe/apache.pm
==============================================================================
--- mod_parrot/branches/configure/config/probe/apache.pm        (original)
+++ mod_parrot/branches/configure/config/probe/apache.pm        Thu Jul 24 
15:28:15 2008
@@ -35,37 +35,51 @@
 sub runstep {
     my ( $self, $conf ) = @_;
 
-    # We need a Glossary somewhere!
     $conf->data->set(
-        parrot_build_dir => $conf->options->get('parrot_build_dir')
-                            || '../parrot',
-        apxs             => $conf->options->get('apxs')
-                            || '/usr/local/apache/bin/apxs',
-        perl             => $^X,
-
-        debug            => ( $conf->options->get('debug') || $ENV{'MP_DEBUG'} 
)
-                            ? 1 : 0,
-        optimize         => '',
-        verbose          => $conf->options->get('verbose'),
+        apxs => $conf->options->get('apxs')
+        || '/usr/local/apache/bin/apxs',
+    );
+    ##  TODO test for existence of apxs, since we're gonna run it below
 
-        cflags           => $PConfig{cflags},
-        make             => $PConfig{make},
 
-        libs             => $PConfig{libs} . ' -lparrot',
-        blib_dir         => $PConfig{blib_dir},
+    $conf->data->set(
+        apache_include_dir => apxs_config($conf, 'INCLUDEDIR'),
+        apr_include_dir    => apxs_config($conf, 'APR_INCLUDEDIR'),
+        apu_include_dir    => apxs_config($conf, 'APU_INCLUDEDIR'),
+        extra_cppflags     => apxs_config($conf, 'EXTRA_CPPFLAGS'),
+        libexec_dir        => apxs_config($conf, 'LIBEXECDIR'),
+        ##  TODO these three are *required* or Bad Things happen
+        cc                 => apxs_config($conf, 'CC'),
+        libtool            => apxs_config($conf, 'LIBTOOL'),
+        mpm                => apxs_config($conf, 'MPM_NAME'),
     );
 
-    $conf->data->set( ldflags =>
-        $conf->data->get('parrot_build_dir')
-        . '/' . $conf->data->get('blib_dir')
+    $conf->data->set(
+        mpm_is_threaded    => mpm_is_threaded( $conf->data->get('mpm') ),
     );
 
+    my $cflags = $conf->data->get('parrot_build_dir') . '/include -Iinclude';
+    $cflags .= ' -DMPM_IS_THREADED'
+        if $conf->data->get('mpm_is_threaded');
+
+    $conf->data->set( cflags => $cflags );
+
     return $self;
 }
 
 
-sub _mpm_is_threaded {
-    return !!grep $_ => qw/
+sub apxs_config {
+    my ( $conf, $key ) = @_;
+    my @cmd = ( $conf->data->get('apxs'), '-q', $key );
+    my $value = qx{@cmd};
+    chomp($value);
+    return $value;
+
+}
+
+
+sub mpm_is_threaded {
+    return !!grep $_[0] => qw/
         worker winnt beos mpmt_os2 netware leader perchild threadpool
     /;
 }

Modified: mod_parrot/branches/configure/config/probe/parrot.pm
==============================================================================
--- mod_parrot/branches/configure/config/probe/parrot.pm        (original)
+++ mod_parrot/branches/configure/config/probe/parrot.pm        Thu Jul 24 
15:28:15 2008
@@ -35,18 +35,9 @@
 sub runstep {
     my ( $self, $conf ) = @_;
 
-    # We need a Glossary somewhere!
     $conf->data->set(
         parrot_build_dir => $conf->options->get('parrot_build_dir')
                             || '../parrot',
-        apxs             => $conf->options->get('apxs')
-                            || '/usr/local/apache/bin/apxs',
-        perl             => $^X,
-
-        debug            => ( $conf->options->get('debug') || $ENV{'MP_DEBUG'} 
)
-                            ? 1 : 0,
-        optimize         => '',
-        verbose          => $conf->options->get('verbose'),
 
         cflags           => $PConfig{cflags},
         make             => $PConfig{make},

Modified: mod_parrot/branches/configure/lib/ModParrot/Configure/Messages.pm
==============================================================================
--- mod_parrot/branches/configure/lib/ModParrot/Configure/Messages.pm   
(original)
+++ mod_parrot/branches/configure/lib/ModParrot/Configure/Messages.pm   Thu Jul 
24 15:28:15 2008
@@ -60,6 +60,7 @@
     my $make = shift;
     return <<CONCLUSION;
 
+
 Use "$make" to build mod_parrot, and use "$make test" to run the test suite.
 
 CONCLUSION

Added: mod_parrot/branches/configure/lib/ModParrot/Configure/Utils.pm
==============================================================================
--- (empty file)
+++ mod_parrot/branches/configure/lib/ModParrot/Configure/Utils.pm      Thu Jul 
24 15:28:15 2008
@@ -0,0 +1,337 @@
+# Copyright (C) 2001-2008, The Perl Foundation.
+# $Id: Utils.pm 26761 2008-04-05 02:32:23Z jkeenan $
+
+=head1 NAME
+
+ModParrot::Configure::Utils - Configuration Step Utilities
+
+=head1 DESCRIPTION
+
+The C<ModParrot::Configure::Utils> module contains utility functions for use by
+the configuration step classes found under F<config/>.
+
+The subroutines found in this module do B<not> require the ModParrot::Configure
+object as an argument.  Those subroutines formerly found in this module which
+B<do> require the ModParrot::Configure object as an argument have been moved 
into
+ModParrot::Configure::Compiler.
+
+=head2 Functions
+
+=over 4
+
+=cut
+
+package ModParrot::Configure::Utils;
+
+use strict;
+use warnings;
+
+use base qw( Exporter );
+
+use Carp;
+use File::Copy ();
+use File::Spec;
+use File::Which;
+use lib ("lib");
+our @EXPORT    = ();
+our @EXPORT_OK = qw(
+    prompt copy_if_diff move_if_diff integrate
+    capture_output check_progs _slurp
+    _run_command _build_compile_command
+);
+our %EXPORT_TAGS = (
+    inter => [qw(prompt integrate)],
+    auto  => [
+        qw(capture_output check_progs)
+    ],
+    gen => [qw( copy_if_diff move_if_diff )]
+);
+
+=item C<_run_command($command, $out, $err)>
+
+Runs the specified command. Output is directed to the file specified by
+C<$out>, warnings and errors are directed to the file specified by C<$err>.
+
+=cut
+
+sub _run_command {
+    my ( $command, $out, $err, $verbose ) = @_;
+
+    if ($verbose) {
+        print "$command\n";
+    }
+
+    # Mostly copied from ModParrot::Test.pm
+    foreach ( $out, $err ) {
+        $_ = File::Spec->devnull
+            if $_ and $_ eq '/dev/null';
+    }
+
+    if ( $out and $err and $out eq $err ) {
+        $err = "&STDOUT";
+    }
+
+    # Save the old filehandles; we must not let them get closed.
+    open my $OLDOUT, '>&', \*STDOUT or die "Can't save     stdout" if $out;
+    open my $OLDERR, '>&', \*STDERR or die "Can't save     stderr" if $err;
+
+    open STDOUT, '>', $out or die "Can't redirect stdout" if $out;
+
+    # See 'Obscure Open Tricks' in perlopentut
+    open STDERR, ">$err"    ## no critic InputOutput::ProhibitTwoArgOpen
+        or die "Can't redirect stderr"
+        if $err;
+
+    system $command;
+    my $exit_code = $? >> 8;
+
+    close STDOUT or die "Can't close    stdout" if $out;
+    close STDERR or die "Can't close    stderr" if $err;
+
+    open STDOUT, '>&', $OLDOUT or die "Can't restore  stdout" if $out;
+    open STDERR, '>&', $OLDERR or die "Can't restore  stderr" if $err;
+
+    if ($verbose) {
+        foreach ( $out, $err ) {
+            if (   ( defined($_) )
+                && ( $_ ne File::Spec->devnull )
+                && ( !m/^&/ ) )
+            {
+                open( my $verbose_handle, '<', $_ );
+                print <$verbose_handle>;
+                close $verbose_handle;
+            }
+        }
+    }
+
+    return $exit_code;
+}
+
+=item C<_build_compile_command( $cc, $ccflags, $cc_args )>
+
+Constructs a command-line to do the compile.
+
+=cut
+
+sub _build_compile_command {
+    my ( $cc, $ccflags, $cc_args ) = @_;
+    $_ ||= '' for ( $cc, $ccflags, $cc_args );
+
+    return "$cc $ccflags $cc_args -I./include -c test.c";
+}
+
+=item C<integrate($orig, $new)>
+
+Integrates C<$new> into C<$orig>.  Returns C<$orig> if C<$new> is undefined.
+
+=cut
+
+sub integrate {
+    my ( $orig, $new ) = @_;
+
+    # Rather than sprinkling "if defined(...)", everywhere,
+    # various inter::* steps (coded in config/inter/*.pm) permit simply
+    # passing in potentially undefined strings.
+    # In these instances, we simply pass back the original string without
+    # generating a warning.
+    return $orig unless defined $new;
+
+    if ( $new =~ /\S/ ) {
+        $orig = $new;
+    }
+
+    return $orig;
+}
+
+=item C<prompt($message, $value)>
+
+Prints out "message [default] " and waits for the user's response. Returns the
+response, or the default if the user just hit C<ENTER>.
+
+=cut
+
+sub prompt {
+    my ( $message, $value ) = @_;
+
+    print("$message [$value] ");
+
+    chomp( my $input = <STDIN> );
+
+    if ($input) {
+        $value = $input;
+    }
+
+    return integrate( $value, $input );
+}
+
+=item C<file_checksum($filename, $ignore_pattern)>
+
+Creates a checksum for the specified file. This is used to compare files.
+
+Any lines matching the regular expression specified by C<$ignore_pattern> are
+not included in the checksum.
+
+=cut
+
+sub file_checksum {
+    my ( $filename, $ignore_pattern ) = @_;
+    open( my $file, '<', $filename ) or die "Can't open $filename: $!";
+    my $sum = 0;
+    while (<$file>) {
+        next if defined($ignore_pattern) && /$ignore_pattern/;
+        $sum += unpack( "%32C*", $_ );
+    }
+    close($file) or die "Can't close $filename: $!";
+    return $sum;
+}
+
+=item C<copy_if_diff($from, $to, $ignore_pattern)>
+
+Copies the file specified by C<$from> to the location specified by C<$to> if
+its contents have changed.
+
+The regular expression specified by C<$ignore_pattern> is passed to
+C<file_checksum()> when comparing the files.
+
+=cut
+
+sub copy_if_diff {
+    my ( $from, $to, $ignore_pattern ) = @_;
+
+    # Don't touch the file if it didn't change (avoid unnecessary rebuilds)
+    if ( -r $to ) {
+        my $from_sum = file_checksum( $from, $ignore_pattern );
+        my $to_sum   = file_checksum( $to,   $ignore_pattern );
+        return if $from_sum == $to_sum;
+    }
+
+    File::Copy::copy( $from, $to );
+
+    # Make sure the timestamp is updated
+    my $now = time;
+    utime $now, $now, $to;
+
+    return 1;
+}
+
+=item C<move_if_diff($from, $to, $ignore_pattern)>
+
+Moves the file specified by C<$from> to the location specified by C<$to> if
+its contents have changed.
+
+=cut
+
+sub move_if_diff {    ## no critic Subroutines::RequireFinalReturn
+    my ( $from, $to, $ignore_pattern ) = @_;
+    copy_if_diff( $from, $to, $ignore_pattern );
+    unlink $from;
+}
+
+=item C<capture_output($command)>
+
+Executes the given command. The command's output (both stdout and stderr), and
+its return status is returned as a 3-tuple. B<STDERR> is redirected to
+F<test.err> during the execution, and deleted after the command's run.
+
+=cut
+
+sub capture_output {
+    my $command = join ' ', @_;
+
+    # disable STDERR
+    open my $OLDERR, '>&', \*STDERR;
+    open STDERR, '>', 'test.err';
+
+    my $output = `$command`;
+    my $retval = ( $? == -1 ) ? -1 : ( $? >> 8 );
+
+    # reenable STDERR
+    close STDERR;
+    open STDERR, '>&', $OLDERR;
+
+    # slurp stderr
+    my $out_err = _slurp('./test.err');
+
+    # cleanup
+    unlink "test.err";
+
+    return ( $output, $out_err, $retval ) if wantarray;
+    return $output;
+}
+
+=item C<check_progs([$programs])>
+
+Where C<$programs> may be either a scalar with the name of a single program or
+an array ref of programs to search the current C<PATH> for.  The first matching
+program name is returned or C<undef> on failure.  Note: this function only
+returns the name of the program and not its complete path.
+
+This function is similar to C<autoconf>'s C<AC_CHECK_PROGS> macro.
+
+=cut
+
+sub check_progs {
+    my ( $progs, $verbose ) = @_;
+
+    $progs = [$progs] unless ref $progs eq 'ARRAY';
+
+    print "checking for program: ", join( " or ", @$progs ), "\n" if $verbose;
+    foreach my $prog (@$progs) {
+        my $util = $prog;
+
+        # use the first word in the string to ignore any options
+        ($util) = $util =~ /(\S+)/;
+        my $path = which($util);
+
+        if ($verbose) {
+            print "$path is executable\n" if $path;
+        }
+
+        return $prog if $path;
+    }
+
+    return;
+}
+
+=item C<_slurp($filename)>
+
+Slurps C<$filename> into memory and returns it as a string.
+
+=cut
+
+sub _slurp {
+    my $filename = shift;
+
+    open( my $fh, '<', $filename ) or die "Can't open $filename: $!";
+    my $text = do { local $/; <$fh> };
+    close($fh) or die "Can't close $filename: $!";
+
+    return $text;
+}
+
+=back
+
+=cut
+
+=head1 SEE ALSO
+
+=over 4
+
+=item C<ModParrot::Configure::runsteps()>
+
+=item F<docs/configuration.pod>
+
+=item F<lib/ModParrot/Configure/Compiler.pm>
+
+=back
+
+=cut
+
+1;
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

<Prev in Thread] Current Thread [Next in Thread>
  • [svn:mod_parrot] r381 - in mod_parrot/branches/configure: . config/directives config/gen config/gen/makefiles config/init config/probe lib/ModParrot/Configure, particle <=