7 use File::Compare qw( compare );
8 use File::Copy qw( copy );
9 use File::Basename qw( dirname );
13 my $rootdir = dirname($0);
15 unshift @INC, File::Spec->catfile($rootdir, 't', 'lib');
17 eval q{ use MakeMaker::Test::Utils qw( which_perl ) };
21 list => File::Spec->catfile($rootdir, 'mkppport.lst'),
25 GetOptions(\%opt, qw( clean list=s )) or pod2usage(2);
27 my $absroot = File::Spec->rel2abs($rootdir);
28 my @destdirs = readlist($opt{list});
32 print "no destination directories found in $opt{list}\n";
36 # Remove all installed ppport.h files
39 my($dir, $fulldir) = @_;
40 my $dest = File::Spec->catfile($fulldir, 'ppport.h');
42 print "removing ppport.h for $dir\n";
43 unlink $dest or warn "WARNING: could not remove $dest: $!\n";
44 1 while unlink $dest; # remove any remaining versions
50 # Determine full perl location
51 my $perl = which_perl();
53 # We're now changing the directory, which confuses the deferred
54 # loading in Config.pm, so we better use an absolute @INC path
55 unshift @INC, File::Spec->catdir($absroot, 'lib');
57 # Change to Devel::PPPort directory, as it needs the stuff
58 # from the parts/ directory
59 chdir File::Spec->catdir($rootdir, 'ext', 'Devel', 'PPPort');
61 # Capture and remove temporary files
65 for my $file (@unlink) {
66 print "removing temporary file $file\n";
67 unlink $file or warn "WARNING: could not remove $file: $!\n";
68 1 while unlink $file; # remove any remaining versions
72 # Try to create a ppport.h if it doesn't exist yet, and
73 # remember all files that need to be removed later.
74 unless (-e 'ppport.h') {
75 unless (-e 'PPPort.pm') {
77 push @unlink, 'PPPort.pm';
80 push @unlink, 'ppport.h';
83 # Now install the created ppport.h into extension directories
85 my($dir, $fulldir) = @_;
86 my $dest = File::Spec->catfile($fulldir, 'ppport.h');
87 if (compare('ppport.h', $dest)) {
88 print "installing ppport.h for $dir\n";
89 copy('ppport.h', $dest) or die "copying ppport.h to $dest failed: $!\n";
92 print "ppport.h in $dir is up-to-date\n";
98 #---------------------------------------
99 # Iterate through extension directories
100 #---------------------------------------
105 for my $dir (@destdirs) {
106 my $fulldir = File::Spec->catdir($absroot, $dir);
108 $code->($dir, $fulldir);
111 warn "WARNING: no such directory: $fulldir\n";
116 #----------------------------------------
117 # Read the list of extension directories
118 #----------------------------------------
123 open LIST, $list or die "$list: $!\n";
126 /^\s*(?:$|#)/ or push @dirs, $_;
132 #----------------------------------------------
133 # Runs a script in the Devel::PPPort directory
134 #----------------------------------------------
137 my @args = ("-I" . File::Spec->catdir((File::Spec->updir) x 3, 'lib'), @_);
138 my $run = $perl =~ m/\s/ ? qq("$perl") : $perl;
140 $_ = qq("$_") if $^O eq 'VMS' && /^[^"]/;
143 print "running $run\n";
144 system $run and die "$run failed: $?\n";
151 mkppport - distribute ppport.h among extensions
155 mkppport [B<--list>=I<file>] [B<--clean>]
159 B<mkppport> generates a I<ppport.h> file using Devel::PPPort
160 and distributes it to the various extension directories that
167 =item B<--list>=I<file>
169 Name of the file that holds the list of extension directories
170 that I<ppport.h> should be distributed to.
171 This defaults to I<mkppport.lst> in the same directory as this
176 Run with this option to clean out all distributed I<ppport.h> files.
182 Copyright 2006 by Marcus Holland-Moritz <mhx@cpan.org>.
184 This program is free software; you may redistribute it
185 and/or modify it under the same terms as Perl itself.