6 use File::Compare qw( compare );
7 use File::Copy qw( copy );
8 use File::Basename qw( dirname );
10 use feature 'signatures';
12 my $rootdir = dirname($0);
14 unshift @INC, File::Spec->catdir($rootdir, qw(cpan ExtUtils-MakeMaker t lib));
16 eval q{ use MakeMaker::Test::Utils qw( which_perl ) };
20 list => File::Spec->catfile($rootdir, 'mkppport.lst'),
24 unless ( GetOptions(\%opt, qw( clean list=s )) ) {
26 Pod::Usage::pod2usage(2);
29 my $absroot = File::Spec->rel2abs($rootdir);
30 my @destdirs = readlist($opt{list});
34 print "no destination directories found in $opt{list}\n";
38 # Remove all installed ppport.h files
40 iterdirs( sub ($dir, $fulldir) {
41 my $dest = File::Spec->catfile($fulldir, 'ppport.h');
43 print "removing ppport.h for $dir\n";
44 unlink $dest or warn "WARNING: could not remove $dest: $!\n";
45 1 while unlink $dest; # remove any remaining versions
51 # Determine full perl location
52 my $perl = which_perl();
54 # We're now changing the directory, which confuses the deferred
55 # loading in Config.pm, so we better use an absolute @INC path
56 unshift @INC, File::Spec->catdir($absroot, 'lib');
58 # Change to Devel::PPPort directory, as it needs the stuff
59 # from the parts/ directory
60 chdir File::Spec->catdir($rootdir, 'dist', 'Devel-PPPort');
62 # Capture and remove temporary files
66 for my $file (@unlink) {
67 print "removing temporary file $file\n";
68 unlink $file or warn "WARNING: could not remove $file: $!\n";
69 1 while unlink $file; # remove any remaining versions
73 # Try to create a ppport.h if it doesn't exist yet, and
74 # remember all files that need to be removed later.
75 unless (-e 'ppport.h') {
76 unless (-e 'PPPort.pm') {
78 push @unlink, 'PPPort.pm';
81 push @unlink, 'ppport.h';
84 # Now install the created ppport.h into extension directories
85 iterdirs( sub ($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 #---------------------------------------
103 for my $dir (@destdirs) {
104 my $fulldir = File::Spec->catdir($absroot, $dir);
106 $code->($dir, $fulldir);
109 warn "WARNING: no such directory: $fulldir\n";
114 #----------------------------------------
115 # Read the list of extension directories
116 #----------------------------------------
120 open LIST, $list or die "$list: $!\n";
123 /^\s*(?:$|#)/ or push @dirs, $_;
129 #----------------------------------------------
130 # Runs a script in the Devel::PPPort directory
131 #----------------------------------------------
134 my @args = ("-I" . File::Spec->catdir((File::Spec->updir) x 2, 'lib'), @_);
135 my $run = $perl =~ m/\s/ ? qq("$perl") : $perl;
137 $_ = qq("$_") if $^O eq 'VMS' && /^[^"]/;
140 print "running $run\n";
141 system $run and die "$run failed: $?\n";
148 mkppport - distribute ppport.h among extensions
152 mkppport [B<--list>=I<file>] [B<--clean>]
156 B<mkppport> generates a I<ppport.h> file using Devel::PPPort
157 and distributes it to the various extension directories that
158 need it to build. On certain Win32 builds, this script is not
159 used and an alternative mechanism is used to create I<ppport.h>.
165 =item B<--list>=I<file>
167 Name of the file that holds the list of extension directories
168 that I<ppport.h> should be distributed to.
169 This defaults to I<mkppport.lst> in the same directory as this
174 Run with this option to clean out all distributed I<ppport.h> files.
180 Copyright 2006 by Marcus Holland-Moritz <mhx@cpan.org>.
182 This program is free software; you may redistribute it
183 and/or modify it under the same terms as Perl itself.