6 use File::Compare qw( compare );
7 use File::Copy qw( copy );
8 use File::Basename qw( dirname );
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
41 my($dir, $fulldir) = @_;
42 my $dest = File::Spec->catfile($fulldir, 'ppport.h');
44 print "removing ppport.h for $dir\n";
45 unlink $dest or warn "WARNING: could not remove $dest: $!\n";
46 1 while unlink $dest; # remove any remaining versions
52 # Determine full perl location
53 my $perl = which_perl();
55 # We're now changing the directory, which confuses the deferred
56 # loading in Config.pm, so we better use an absolute @INC path
57 unshift @INC, File::Spec->catdir($absroot, 'lib');
59 # Change to Devel::PPPort directory, as it needs the stuff
60 # from the parts/ directory
61 chdir File::Spec->catdir($rootdir, 'cpan', 'Devel-PPPort');
63 # Capture and remove temporary files
67 for my $file (@unlink) {
68 print "removing temporary file $file\n";
69 unlink $file or warn "WARNING: could not remove $file: $!\n";
70 1 while unlink $file; # remove any remaining versions
74 # Try to create a ppport.h if it doesn't exist yet, and
75 # remember all files that need to be removed later.
76 unless (-e 'ppport.h') {
77 unless (-e 'PPPort.pm') {
79 push @unlink, 'PPPort.pm';
82 push @unlink, 'ppport.h';
85 # Now install the created ppport.h into extension directories
87 my($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 #---------------------------------------
107 for my $dir (@destdirs) {
108 my $fulldir = File::Spec->catdir($absroot, $dir);
110 $code->($dir, $fulldir);
113 warn "WARNING: no such directory: $fulldir\n";
118 #----------------------------------------
119 # Read the list of extension directories
120 #----------------------------------------
125 open LIST, $list or die "$list: $!\n";
128 /^\s*(?:$|#)/ or push @dirs, $_;
134 #----------------------------------------------
135 # Runs a script in the Devel::PPPort directory
136 #----------------------------------------------
139 my @args = ("-I" . File::Spec->catdir((File::Spec->updir) x 2, 'lib'), @_);
140 my $run = $perl =~ m/\s/ ? qq("$perl") : $perl;
142 $_ = qq("$_") if $^O eq 'VMS' && /^[^"]/;
145 print "running $run\n";
146 system $run and die "$run failed: $?\n";
153 mkppport - distribute ppport.h among extensions
157 mkppport [B<--list>=I<file>] [B<--clean>]
161 B<mkppport> generates a I<ppport.h> file using Devel::PPPort
162 and distributes it to the various extension directories that
169 =item B<--list>=I<file>
171 Name of the file that holds the list of extension directories
172 that I<ppport.h> should be distributed to.
173 This defaults to I<mkppport.lst> in the same directory as this
178 Run with this option to clean out all distributed I<ppport.h> files.
184 Copyright 2006 by Marcus Holland-Moritz <mhx@cpan.org>.
186 This program is free software; you may redistribute it
187 and/or modify it under the same terms as Perl itself.