This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Replace utils/Makefile.SH with utils/Makefile.PL
[perl5.git] / Porting / add-package.pl
old mode 100644 (file)
new mode 100755 (executable)
index 67b5b62..fc2161d
@@ -8,15 +8,16 @@ use File::Basename;
 use FindBin;
 
 my $Opts = {};
-getopts( 'r:p:e:vudn', $Opts );
+getopts( 'r:p:e:c:vudn', $Opts );
 
-my $Cwd         = cwd(); 
+my $Cwd         = cwd();
 my $Verbose     = 1;
 my $ExcludeRe   = $Opts->{e} ? qr/$Opts->{e}/i : undef;
 my $Debug       = $Opts->{v} || 0;
 my $RunDiff     = $Opts->{d} || 0;
 my $PkgDir      = $Opts->{p} || cwd();
 my $Repo        = $Opts->{r} or die "Need repository!\n". usage();
+my $Changes     = $Opts->{c} || 'Changes ChangeLog';
 my $NoBranch    = $Opts->{n} || 0;
 
 ### strip trailing slashes;
@@ -33,7 +34,7 @@ if ( $NoBranch ) {
     ### create a copy of the repo directory
     my $RepoCopy = "$Repo-$BranchName";
     print "Copying repository to $RepoCopy ..." if $Verbose;
-    
+
     ### --archive == -dPpR, but --archive is not portable, and neither
     ### is -d, so settling for -PpR
     system( "cp -PpR -f $Repo $RepoCopy" )
@@ -71,7 +72,7 @@ my @LibFiles;
         if -d '.git' || -d '.svn';
     die "No lib/ directory found\n" unless -d 'lib';
     system( "cp -fR $CPV lib $Repo" ) and die "Copy of lib/ failed: $?";
-    
+
     @LibFiles =    map { chomp; $_ }
                     ### should we get rid of this file?
                     grep { $ExcludeRe && $_ =~ $ExcludeRe
@@ -82,7 +83,7 @@ my @LibFiles;
                         : 1
                      } `find lib -type f`
         or die "Could not detect library files\n";
-      
+
     print "done\n" if $Verbose;
 }
 
@@ -93,7 +94,7 @@ my $ModName;        # name of the module
 my @ModFiles;       # the .PMs in this package
 {   print "Creating top level dir..." if $Verbose;
 
-    ### make sure we get the shortest file, so we dont accidentally get
+    ### make sure we get the shortest file, so we don't accidentally get
     ### a subdir
     @ModFiles   =  sort { length($a) <=> length($b) }
                    map  { chomp; $_ }
@@ -153,7 +154,7 @@ my @TestFiles;
 
 my $BinDir;
 my @BinFiles;
-my $TopBinDir; 
+my $TopBinDir;
 BIN: {
     $BinDir = -d 'bin'      ? 'bin' :
               -d 'scripts'  ? 'scripts' : undef ;
@@ -183,6 +184,18 @@ BIN: {
     print "done\n" if $Verbose;
 }
 
+### copy over change log
+my @Changes;
+foreach my $cl (split m/\s+/ => $Changes) {
+    -f $cl or next;
+    push @Changes, $cl;
+    print "Copying $cl files to $TopDir..." if $Verbose;
+
+    system( "cp -f $CPV $cl $TopDir" )
+        and die "Copy of $cl failed: $?";
+}
+
+
 ### add files where they are required
 my @NewFiles;
 my @ChangedFiles;
@@ -270,8 +283,8 @@ my @ChangedFiles;
             push @NewFiles, $file;
         }
 
-        ### add an entry to utils/Makefile.SH for $bin
-        {   my $file = "utils/Makefile.SH";
+        ### add an entry to utils/Makefile.PL for $bin
+        {   my $file = "utils/Makefile.PL";
 
             ### not there already?
             unless( `grep $bin $Repo/$file` ) {
@@ -331,7 +344,7 @@ my @ChangedFiles;
         }
 
         ### we need some entries in a vms specific file as well..
-        ### except, i dont understand how it works or what it does, and it
+        ### except, I don't understand how it works or what it does, and it
         ### looks all a bit odd... so lets just print a warning...
         ### the entries look something like this:
         # ./vms/descrip_mms.template:utils4 = [.utils]enc2xs.com
@@ -345,8 +358,8 @@ my @ChangedFiles;
                 print $/.$/;
                 print "    WARNING! You should add entries like the following\n"
                     . "    to $file (Using $TestBin as an example)\n"
-                    . "    Unfortunately I dont understand what these entries\n"
-                    . "    do, so I wont change them automatically:\n\n";
+                    . "    Unfortunately I don't understand what these entries\n"
+                    . "    do, so I won't change them automatically:\n\n";
 
                 print `grep -nC1 $TestBin $Repo/$file`;
                 print $/.$/;
@@ -358,49 +371,6 @@ my @ChangedFiles;
     }
 }
 
-### binary files must be encoded!
-### XXX use the new 'uupacktool.pl'
-{   my $pack = "$Repo/uupacktool.pl";
-
-    ### pack.pl encodes binary files for us
-    -e $pack or die "Need $pack to encode binary files!";
-
-    ### chdir, so uupacktool writes relative files properly
-    ### into it's header...
-    my $curdir = cwd();
-    chdir($Repo) or die "Could not chdir to '$Repo': $!";
-
-    for my $aref ( \@ModFiles, \@TestFiles, \@BinFiles ) {
-        for my $file ( @$aref ) {
-            my $full = -e $file                 ? $file              :
-                       -e "$RelTopDir/$file"    ? "$RelTopDir/$file" :
-                       die "Can not find $file in $Repo or $TopDir\n";
-
-            if( -f $full && -s _ && -B _ ) {
-                print "Binary file $file needs encoding\n" if $Verbose;
-
-                my $out = $full . '.packed';
-
-                ### does the file exist already?
-                ### and doesn't have +w
-                if( -e $out && not -w _ ) {
-                    system("chmod +w $out")
-                        and die "Could not set chmod +w to '$out': $!";
-                }
-
-                ### -D to remove the original
-                system("$^X $pack -D -p $full $out")
-                    and die "Could not encode $full to $out";
-
-
-                $file .= '.packed';
-            }
-        }
-    }
-
-    chdir($curdir) or die "Could not chdir back to '$curdir': $!";
-}
-
 ### update the manifest
 {   my $file        = $Repo . '/MANIFEST';
     my @manifest;
@@ -424,6 +394,10 @@ my @ChangedFiles;
                                             basename($_) ." utility\n";
     }
 
+    for ( @Changes ) {
+        $pkg_files{"$RelTopDir/$_"} = "$RelTopDir/$_\t$ModName change log\n";
+    }
+
     for ( @NewFiles ) {
         $pkg_files{$_}              = "$_\tthe ".
                                         do { m/(.+?)\.PL$/; basename($1) } .
@@ -503,9 +477,9 @@ if( $RunDiff ) {
 # add files to git index
 unless ( $NoBranch ) {
     chdir $Repo;
-    system( "git add $CPV $_" ) 
-        for ( @LibFiles, @NewFiles, @ChangedFiles, 
-              map { "$RelTopDir/$_" } @TestFiles, @BinFiles );
+    system( "git add $CPV $_" )
+        for ( @LibFiles, @NewFiles, @ChangedFiles,
+              map { "$RelTopDir/$_" } @TestFiles, @BinFiles, @Changes );
 }
 
 # return to original directory
@@ -520,6 +494,7 @@ Usage: $me -r PERL_REPO_DIR [-p PACKAGE_DIR] [-v] [-d] [-e REGEX]
 Options:
   -r    Path to perl-core git repository
   -v    Run verbosely
+  -c    File containing changelog (default 'Changes' or 'ChangeLog')
   -e    Perl regex matching files that shouldn't be included
   -d    Create a diff as patch file
   -p    Path to the package to add. Defaults to cwd()