summaryrefslogtreecommitdiff
path: root/pkgtools/pkgdiff/files/mkpatches.pl
blob: 400ccf2491e54d1e9ea9d94ef694de2b7c0876f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!@PREFIX@/bin/perl
#
# $NetBSD: mkpatches.pl,v 1.8 2002/11/04 23:07:37 wiz Exp $
#
# mkpatches: creates a set of patches patch-aa, patch-ab, ...
#   in work/.newpatches by looking for *.orig files in and below
#   WRKDIR and comparing them to the corresponding changed file. All
#   files are then referrenced relative to WRKSRC.
#
#   It should be called from the packages directory,
#   e.g. /usr/pkgsrc/example/test
#
# Copyright (c) 2000 by Thomas Klausner <wiz@netbsd.org>
# All Rights Reserved.  Absolutely no warranty.
#

use Getopt::Std;
use Cwd;
use File::Spec;

my $patchdir;
my $wrkdir;
my $l=0;

# create patchdir, or empty it if already existing

sub create_patchdir {
    if ( -d $patchdir ) {
	unlink "$patchdir/*";
    } else {
	mkdir($patchdir, 0755);
    }
}

# read command line arguments

getopts('d:hv');

if ($opt_h) {
		($prog) = ($0 =~ /([^\/]+)$/);
		print STDERR <<EOF;
usage: $prog [-d output-directory]
    -d dirname	directory to put the resulting patches into;
		defaults to \$WRKDIR/.newpatches
    -v   	verbose - list .orig files as processed
EOF
		exit 0;
};

# get WRKDIR

$wrkdir=`@MAKE@ show-var VARNAME=WRKDIR` or
    die ("can't find WRKDIR -- wrong dir?");
chomp($wrkdir);

if ($opt_d) {
    $patchdir = cwd()."/$opt_d";
} 
else {
    $patchdir="$wrkdir"."/.newpatches";
}

create_patchdir();

# get WRKSRC

$wrksrc=`@MAKE@ show-var VARNAME=WRKSRC` or 
    die ("can't find WRKSRC -- wrong dir?");
chomp($wrksrc);

chdir $wrksrc or die ("can't cd to WRKSRC ($wrksrc)");

# find files

open(handle, "find ${wrkdir} -type f -name \\\*.orig |");

# create patches

foreach (sort <handle>) {
    my $path, $complete;
    my $new, $old;
    chomp();
    $path = $_;
    $complete = $path;
    $complete =~ s/.orig$//;
    $new = File::Spec->abs2rel( $complete, $wrksrc );
    $old = File::Spec->abs2rel( $path, $wrksrc );
    if ( -f $complete ) {
	$patchfile = ("aa".."zz")[$l];
	$patchfile =~ s/^/patch-/;
	if ($opt_v) {
	    print "$patchfile -> $complete\n";
	}
	$diff=`pkgdiff $old $new`;
	if ( $? ) {
		print "$old: $diff";
	}
	if ( "$diff" eq "" ) {
		print ("$new and $old don't differ\n");
	} else {
		system("pkgdiff $old $new > $patchdir/$patchfile");
	}
    } else {
	print ("$new doesn't exist, though $old does\n");
    }
    $l++;
}