7 use File::Copy qw( copy );
8 use File::Basename qw( dirname );
12 my $rootdir = dirname($0);
14 unshift @INC, File::Spec->catfile($rootdir, 't', 'lib');
16 eval q{ use MakeMaker::Test::Utils qw( which_perl ) };
20 list => File::Spec->catfile($rootdir, 'mkppport.lst'),
24 GetOptions(\%opt, qw( clean list=s )) or pod2usage(2);
26 my $absroot = File::Spec->rel2abs($rootdir);
27 my @destdirs = readlist($opt{list});
31 print "no destination directories found in $opt{list}\n";
35 # Remove all installed ppport.h files
38 my($dir, $fulldir) = @_;
39 my $dest = File::Spec->catfile($fulldir, 'ppport.h');
41 print "removing ppport.h for $dir\n";
42 unlink $dest or warn "WARNING: could not remove $dest: $!\n";
43 1 while unlink $dest; # remove any remaining versions
49 # Determine full perl location
50 my $perl = which_perl();
52 # We're now changing the directory, which confuses the deferred
53 # loading in Config.pm, so we better use an absolute @INC path
54 unshift @INC, File::Spec->catdir($absroot, 'lib');
56 # Change to Devel::PPPort directory, as it needs the stuff
57 # from the parts/ directory
58 chdir File::Spec->catdir($rootdir, 'ext', 'Devel', 'PPPort');
60 # Capture and remove temporary files
64 for my $file (@unlink) {
65 print "removing temporary file $file\n";
66 unlink $file or warn "WARNING: could not remove $file: $!\n";
67 1 while unlink $file; # remove any remaining versions
71 # Try to create a ppport.h if it doesn't exist yet, and
72 # remember all files that need to be removed later.
73 unless (-e 'ppport.h') {
74 unless (-e 'PPPort.pm') {
76 push @unlink, 'PPPort.pm';
79 push @unlink, 'ppport.h';
82 # Now install the created ppport.h into extension directories
84 my($dir, $fulldir) = @_;
85 print "installing ppport.h for $dir\n";
86 my $dest = File::Spec->catfile($fulldir, 'ppport.h');
87 copy('ppport.h', $dest) or die "copying ppport.h to $dest failed: $!\n";
92 #---------------------------------------
93 # Iterate through extension directories
94 #---------------------------------------
99 for my $dir (@destdirs) {
100 my $fulldir = File::Spec->catdir($absroot, $dir);
102 $code->($dir, $fulldir);
105 warn "WARNING: no such directory: $fulldir\n";
110 #----------------------------------------
111 # Read the list of extension directories
112 #----------------------------------------
117 open LIST, $list or die "$list: $!\n";
120 /^\s*(?:$|#)/ or push @dirs, $_;
126 #----------------------------------------------
127 # Runs a script in the Devel::PPPort directory
128 #----------------------------------------------
131 my @args = ("-I" . File::Spec->catdir((File::Spec->updir) x 3, 'lib'), @_);
132 my $run = $perl =~ m/\s/ ? qq("$perl") : $perl;
134 $_ = qq("$_") if $^O eq 'VMS' && /^[^"]/;
137 print "running $run\n";
138 system $run and die "$run failed: $?\n";
145 mkppport - distribute ppport.h among extensions
149 mkppport [B<--list>=I<file>] [B<--clean>]
153 B<mkppport> generates a I<ppport.h> file using Devel::PPPort
154 and distributes it to the various extension directories that
161 =item B<--list>=I<file>
163 Name of the file that holds the list of extension directories
164 that I<ppport.h> should be distributed to.
165 This defaults to I<mkppport.lst> in the same directory as this
170 Run with this option to clean out all distributed I<ppport.h> files.
176 Copyright 2006 by Marcus Holland-Moritz <mhx@cpan.org>.
178 This program is free software; you may redistribute it
179 and/or modify it under the same terms as Perl itself.