8 use File::Compare qw( compare );
9 use File::Copy qw( copy );
10 use File::Basename qw( dirname );
12 use feature 'signatures';
14 my $rootdir = dirname($0);
16 unshift @INC, File::Spec->catdir($rootdir, qw(cpan ExtUtils-MakeMaker t lib));
18 eval q{ use MakeMaker::Test::Utils qw( which_perl ) };
22 list => File::Spec->catfile($rootdir, 'mkppport.lst'),
26 unless ( GetOptions(\%opt, qw( clean list=s )) ) {
28 Pod::Usage::pod2usage(2);
31 my $absroot = File::Spec->rel2abs($rootdir);
32 my @destdirs = readlist($opt{list});
36 print "no destination directories found in $opt{list}\n";
40 # Remove all installed ppport.h files
42 iterdirs( sub ($dir, $fulldir) {
43 my $dest = File::Spec->catfile($fulldir, 'ppport.h');
45 print "removing ppport.h for $dir\n";
46 unlink $dest or warn "WARNING: could not remove $dest: $!\n";
47 1 while unlink $dest; # remove any remaining versions
53 # Determine full perl location
54 my $perl = which_perl();
56 # We're now changing the directory, which confuses the deferred
57 # loading in Config.pm, so we better use an absolute @INC path
58 unshift @INC, File::Spec->catdir($absroot, 'lib');
60 # Change to Devel::PPPort directory, as it needs the stuff
61 # from the parts/ directory
62 chdir File::Spec->catdir($rootdir, 'dist', 'Devel-PPPort');
64 # Capture and remove temporary files
68 for my $file (@unlink) {
69 print "removing temporary file $file\n";
70 unlink $file or warn "WARNING: could not remove $file: $!\n";
71 1 while unlink $file; # remove any remaining versions
75 # Try to create a ppport.h if it doesn't exist yet, and
76 # remember all files that need to be removed later.
77 unless (-e 'ppport.h') {
78 unless (-e 'PPPort.pm') {
80 push @unlink, 'PPPort.pm';
83 push @unlink, 'ppport.h';
86 # Now install the created ppport.h into extension directories
87 iterdirs( sub ($dir, $fulldir) {
88 my $dest = File::Spec->catfile($fulldir, 'ppport.h');
89 if (compare('ppport.h', $dest)) {
90 print "installing ppport.h for $dir\n";
91 copy('ppport.h', $dest) or die "copying ppport.h to $dest failed: $!\n";
94 print "ppport.h in $dir is up-to-date\n";
100 #---------------------------------------
101 # Iterate through extension directories
102 #---------------------------------------
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 #----------------------------------------
122 open LIST, $list or die "$list: $!\n";
125 /^\s*(?:$|#)/ or push @dirs, $_;
131 #----------------------------------------------
132 # Runs a script in the Devel::PPPort directory
133 #----------------------------------------------
136 my @args = ("-I" . File::Spec->catdir((File::Spec->updir) x 2, 'lib'), @_);
137 my $run = $perl =~ m/\s/ ? qq("$perl") : $perl;
139 $_ = qq("$_") if $^O eq 'VMS' && /^[^"]/;
142 print "running $run\n";
143 system $run and die "$run failed: $?\n";
150 mkppport - distribute ppport.h among extensions
154 mkppport [B<--list>=I<file>] [B<--clean>]
158 B<mkppport> generates a I<ppport.h> file using Devel::PPPort
159 and distributes it to the various extension directories that
160 need it to build. On certain Win32 builds, this script is not
161 used and an alternative mechanism is used to create I<ppport.h>.
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.
184 This program is free software; you may redistribute it
185 and/or modify it under the same terms as Perl itself.