The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

makepatch - create script to update a source tree

SYNOPSIS

makepatch [ options ] old-src new-src

DESCRIPTION

Makepatch generates a set of differences between two files or two sets of files maintained in two different directories and prints the results to stdout in the form of a script. When the script is run, it uses the patch(1) program to update every file in the source tree from the old to the new version.

Features of this utility include:

  • Generates a perl program, optionally a shell script.

    The generated perl program will take care of verification that the source tree to be updated is indeed the right one. It also verifies that the patch information was not truncated or corrupted during transfer.

  • Generation of commands to remove obsolete files and directories.

    Files and directories that were present in the old version but not in the new version, are removed.

  • Automatic handling of the patchlevel.h file first.

    If a file named "patchlevel.h" exists, it is checked first to verify that the version matches.

  • Automatic generation of Index: and Prereq: lines.

    This information will allow the patch program to verify correctness of files, and allow for the creation of new files.

  • Selection using manifest files, wildcards or regular expression patterns.

    The list of files to be processed can be controlled by so called manifest files, and further restricted using shell filename patterns and perls regular expression patterns.

  • The source trees can be takes from standard archive files, like gzipped tar files and zip files.

General usage

Suppose you have a directory tree `pkg-1.6' containing the sources for package `pkg' version 1.6, and a directory tree `pkg-1.7' containing the sources for version 1.7. The following command will generate a perl program that updates the 1.6 sources into their 1.7 versions:

    makepatch pkg-1.6 pkg-1.7 > pkg-1.6-1.7.pl

To apply this script, go to the pkg-1.6 directory and feed the script to perl:

    cd pkg-1.6
    perl pkg-1.6-1.7.pl

The script will verify that it is executing in the right place and make all neccessary updates.

Makepatch arguments

makepatch requires two arguments: old_src and new_src.

old-src

This is the name of either a single file or a directory that contains copies of the older version of the target files; in other words, copies of the files prior to any modifications.

Alternatively, it may be the name of an archive that holds the files to be processed. Allowable archive formats are gzipped tar (name ends in ".tar.gz" or ".tgz"), bzipped tar (name ends in ".tar.bz2"), plain tar (name ends in ".tar" and zip (name ends in ".zip").

new-src

This is the name of either a single file or a directory that contains copies of the newer version of the target files; in other words, copies of the files after the modifications have been made.

Alternatively, it may be the name of an archive that holds the files to be processed.

The patch script generated by makepatch will take care of creating new files and directories, update existing files, and remove files and directories that are no longer present in the new-src directory.

MANIFEST files

The purpose of a manifest file is to provide the list of files that constitute a package. Manifest files are traditionally called "MANIFEST" and reside in the top level directory of the package.

Although there is no formal standard for the contents of manifest files, makepatch uses the following rules:

  • If the second line from the manifest file looks like a separator line (e.g. it is empty, or contains only dashes), it is discarded and so is the first line.

  • Empty lines and lines that start with a # are ignored.

  • If there are multiple space-separated "words" on a line, the first word is considered to be the filename.

Default treatment

By default, makepatch looks for files named "MANIFEST" in the top level directories of the old and the new source trees. If these files (or one of them) are found, they are used. If no manifest file could be found, the package is assumed to consist of all files in the directory.

The default name of the default manifest file can be modified with the command line option "-automanifest", see Section "Command line options".

Explicitly naming of manifest files

Command line options "-oldmanifest" and "-newmanifest" can be used to explicitly designate old and new manifest files. Option "-manifest" is a short way to set one manifest file for both the old and new source trees.

Suppress manifest file processing

Command line option "-nomanifest" can be used to suppress all manifest file processing. The package is assumed to consist of all files in the source directories.

Makepatch options

makepatch takes several options to control its behaviour. Options are usually specified on the command line, but makepatch can take options from three sources in the following order:

  • Environment variable MAKEPATCHINIT.

    When this environment variable is set its contents are considered to be command line options that are processed upon startup. All normal options are allowed, plus one: -rcfile filename. Option -rcfile can be used to specify an alternate option file, see below.

  • An options file.

    By default, makepatch looks for a file named .makepatchrc in the user's home directory.

    Empty lines and lines starting with ; or # are ignored. All other lines are considered to contain options exactly as if they had been supplied on the command line.

    An alternative options file can be specified with option -rcfile in environment variable MAKEPATCHINIT. This is the only way to specify an alternative options file name.

  • The command line.

Command line options

Options are matched case insensitive, and may be abbreviated to uniqueness.

-generate type

This can be used to select the type of script to generate. Default is a perl program. Alternatively, a script to be executed under the standard Unix shell sh, can be generated.

type can be perl to designate that a perl program is required, or sh or shell to designate a shell script.

-diff cmd

If specified, cmd is the command to be used to generate the differences between the two versions of the files. If not specified, this command defaults to "diff -c".

-patchlevel pfile

If specified, pfile indicates an alternate file that is to be used in lieu of "patchlevel.h".

-automanifest mfile

makepatch will automatically use manifest files of the given name if they appear in the directories. The default name is "MANIFEST".

-nomanifest

Suppress using manifest files.

-manifest mfile

If specified, mfile indicates the name of the manifest file which consists of a list of the files contained in both the old and the new directories.

-oldmanifest omfile

If specified, omfile indicates the name of the manifest file which consists of a list of the files contained in the old directory. This option is designed to be used in conjunction with the -newmanifest option. Note that the old and new directories must still be indicated.

-newmanifest nmfile

If specified, nmfile indicates the name of the manifest file which consists of a list of the files contained in the new directory. This option is designed to be used in conjunction with the -oldmanifest option. Note that the old and new directories must still be indicated.

-[no]recurse

makepatch recurses through directories by default. Option -norecurse prevents recursion beyond the initial directories.

-[no]follow

If set, symbolic links to directories are traversed as if they were real directories.

-infocmd command

If specified, the output of running command will be added before each patch chunk. command will undergo the following substitutions first: %oP will be replaced by the name of the old file, %nP will be replaced by the name of the new file. %% will be replaced by a single %; other % sequences may be added in future versions.

Note that %oP and %nP are modeled after the % sequences of find -printf.

-exclude pattern

If specified, files that match the shell pattern pattern will be excluded. Only wildcard characters * and ?, and character classes [...] are handled. Multiple -exclude options may be supplied.

-exclude-regex pattern

If specified, files and directories that match the Perl regular expression pattern pattern will be excluded. Multiple -exclude-regex options may be supplied.

-[no]exclude-vc

If set, files and directories that are usually part of version control systems are excluded. Supported version control systems are CVS, RCS and SCCS.

-exclude-vc is a quick way to enable exclusion by the following regular expressions:

             (\A|.*/)CVS(/.*|\Z)
             (\A|.*/)RCS(/.*|\Z)
             ,v\Z
             (\A|.*/)SCCS(/.*|\Z)
             (\A|.*/)[sp]\..+\Z
-[no]ident

If set, the program name and version is reported.

-[no]verbose

This is set by default, making makepatch display information concerning itsactivity to stderr.

-[no]quiet

The opposite of -verbose. If set, this instructs makepatch to suppress the display of activity information.

-[no]help

If set, this causes a short help message to be displayed, after which the program immediately exits.

Environment variables

MAKEPATCHINIT

When this environment variable is set its contents is considered to be command line options that are processed upon startup. All normal options are allowed, plus one: -rcfile filename. If -rcfile is specified, the file is read and all lines of it are considered to contain option settings as described in section "Makepatch options".

TMPDIR

TMPDIR can be used to designate the area where temporary files are placed. It defaults to /usr/tmp.

Examples

Suppose you have a directory tree `pkg-1.6' containing the sources for package `pkg' version 1.6, and a directory tree `pkg-1.7' containing the sources for version 1.7. The following command will generate a perl program that updates the 1.6 sources into their 1.7 versions:

    makepatch pkg-1.6 pkg-1.7 > pkg-1.6-1.7.pl

To apply this script, go to the pkg-1.6 directory and feed the script to perl:

    cd pkg-1.6
    perl pkg-1.6-1.7.pl

The script will verify that it is executing in the right place and make all neccessary updates.

This is one way to generate and use manifest files:

    (cd pkg-1.6; find . -type f -print > OLDMANIFEST)

    (cd pkg-1.7; find . -type f -print > NEWMANIFEST)

    makepatch \
      -oldmanifest pkg-1.6/OLDMANIFEST \
      -newmanifest pkg-1.7/NEWMANIFEST \
      pkg-1.6 pkg-1.7 > pkg-1.6-1.7.diff

Bugs and restrictions

Filenames thet contain single quotes may confuse the process.

makepatch does not know about symbolic links. These will be treated like plain files.

SEE ALSO

diff(1), patch(1), perl(1), rm(1).

AUTHOR AND CREDITS

Johan Vromans (jvromans@squirrel.nl) wrote the program, with a little help and inspiration from: Jeffery Small (jeff@cjsa.uucp), Ulrich Pfeifer (pfeifer@ls6.informatik.uni-dortmund.de), Nigel Metheringham <Nigel.Metheringham@ThePLAnet.net>, Julian Yip <julian@computer.org>, Tim Bunce <Tim.Bunce@ig.co.uk>, Rob Browning <rlb@cs.utexas.edu>, and others.

COPYRIGHT AND DISCLAIMER

This program is Copyright 1992,1998 by Johan Vromans. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

If you do not have a copy of the GNU General Public License write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.