| @@ -1,29 +1,29 @@ | | | @@ -1,29 +1,29 @@ |
1 | #!@PERL5@ | | 1 | #!@PERL5@ |
2 | # | | 2 | # |
3 | # $NetBSD: mkpatches.pl,v 1.19 2015/02/03 22:50:27 abs Exp $ | | 3 | # $NetBSD: mkpatches.pl,v 1.20 2015/09/15 08:36:07 wiz Exp $ |
4 | # | | 4 | # |
5 | # mkpatches: creates a set of patches patch-aa, patch-ab, ... | | 5 | # mkpatches: creates a set of patches patch-aa, patch-ab, ... |
6 | # in work/.newpatches by looking for *.orig files in and below | | 6 | # in work/.newpatches by looking for *.orig files in and below |
7 | # WRKDIR and comparing them to the corresponding changed file. All | | 7 | # WRKDIR and comparing them to the corresponding changed file. All |
8 | # files are then referrenced relative to WRKSRC. | | 8 | # files are then referrenced relative to WRKSRC. |
9 | # | | 9 | # |
10 | # It should be called from the packages directory, | | 10 | # It should be called from the packages directory, |
11 | # e.g. /usr/pkgsrc/example/test | | 11 | # e.g. /usr/pkgsrc/example/test |
12 | # | | 12 | # |
13 | # It retains the naming and header (RCS Id and comment) from the | | 13 | # It retains the naming and header (RCS Id and comment) from the |
14 | # patches directory. | | 14 | # patches directory. |
15 | # | | 15 | # |
16 | # Copyright (c) 2000, 2011 by Thomas Klausner <wiz@NetBSD.org> | | 16 | # Copyright (c) 2000, 2011, 2015 by Thomas Klausner <wiz@NetBSD.org> |
17 | # 2004 by Dieter Baron <dillo@NetBSD.org> | | 17 | # 2004 by Dieter Baron <dillo@NetBSD.org> |
18 | # All rights reserved. | | 18 | # All rights reserved. |
19 | # | | 19 | # |
20 | # Redistribution and use in source and binary forms, with or without | | 20 | # Redistribution and use in source and binary forms, with or without |
21 | # modification, are permitted provided that the following conditions | | 21 | # modification, are permitted provided that the following conditions |
22 | # are met: | | 22 | # are met: |
23 | # 1. Redistributions of source code must retain the above copyright | | 23 | # 1. Redistributions of source code must retain the above copyright |
24 | # notice, this list of conditions and the following disclaimer. | | 24 | # notice, this list of conditions and the following disclaimer. |
25 | # 2. Redistributions in binary form must reproduce the above copyright | | 25 | # 2. Redistributions in binary form must reproduce the above copyright |
26 | # notice, this list of conditions and the following disclaimer in the | | 26 | # notice, this list of conditions and the following disclaimer in the |
27 | # documentation and/or other materials provided with the distribution. | | 27 | # documentation and/or other materials provided with the distribution. |
28 | # | | 28 | # |
29 | # THIS SOFTWARE IS PROVIDED BY THE AUTHORS | | 29 | # THIS SOFTWARE IS PROVIDED BY THE AUTHORS |
| @@ -51,26 +51,38 @@ my %old_filename; | | | @@ -51,26 +51,38 @@ my %old_filename; |
51 | my %old_header; | | 51 | my %old_header; |
52 | | | 52 | |
53 | # create patchdir, or empty it if already existing | | 53 | # create patchdir, or empty it if already existing |
54 | | | 54 | |
55 | sub create_patchdir { | | 55 | sub create_patchdir { |
56 | if (! -d $patchdir) { | | 56 | if (! -d $patchdir) { |
57 | mkdir($patchdir, 0755); | | 57 | mkdir($patchdir, 0755); |
58 | if (-d $origpatchdir && "$origpatchdir" != "$patchdir") { | | 58 | if (-d $origpatchdir && "$origpatchdir" != "$patchdir") { |
59 | system("cp", "$origpatchdir/p*", "$patchdir"); | | 59 | system("cp", "$origpatchdir/p*", "$patchdir"); |
60 | } | | 60 | } |
61 | } | | 61 | } |
62 | } | | 62 | } |
63 | | | 63 | |
| | | 64 | sub get_variable { |
| | | 65 | my ($variable) = shift; |
| | | 66 | my ($value); |
| | | 67 | |
| | | 68 | $value = `@MAKE@ show-var VARNAME=$variable`; |
| | | 69 | if (${^CHILD_ERROR_NATIVE} == 0) { |
| | | 70 | chomp($value); |
| | | 71 | return $value; |
| | | 72 | } |
| | | 73 | die("error executing \"make show-var VARNAME=$variable\": returned with exit code " . (${^CHILD_ERROR_NATIVE} >> 8)); |
| | | 74 | } |
| | | 75 | |
64 | # read command line arguments | | 76 | # read command line arguments |
65 | | | 77 | |
66 | undef($opt_c); | | 78 | undef($opt_c); |
67 | undef($opt_D); | | 79 | undef($opt_D); |
68 | undef($opt_d); | | 80 | undef($opt_d); |
69 | undef($opt_h); | | 81 | undef($opt_h); |
70 | undef($opt_r); | | 82 | undef($opt_r); |
71 | undef($opt_v); | | 83 | undef($opt_v); |
72 | undef($opt_w); | | 84 | undef($opt_w); |
73 | | | 85 | |
74 | getopts('cDd:hrvw'); | | 86 | getopts('cDd:hrvw'); |
75 | | | 87 | |
76 | if ($opt_h) { | | 88 | if ($opt_h) { |
| @@ -85,35 +97,29 @@ usage: $prog [-hvw] [-c | -r] [-D | -d d | | | @@ -85,35 +97,29 @@ usage: $prog [-hvw] [-c | -r] [-D | -d d |
85 | -v verbose - list .orig files as processed | | 97 | -v verbose - list .orig files as processed |
86 | -w look for changes in \$WRKDIR instead of \$WRKSRC | | 98 | -w look for changes in \$WRKDIR instead of \$WRKSRC |
87 | EOF | | 99 | EOF |
88 | exit 0; | | 100 | exit 0; |
89 | }; | | 101 | }; |
90 | | | 102 | |
91 | if ($opt_d && $opt_D) { | | 103 | if ($opt_d && $opt_D) { |
92 | print STDERR "-D and -d conflict, choose one\n"; | | 104 | print STDERR "-D and -d conflict, choose one\n"; |
93 | exit 1; | | 105 | exit 1; |
94 | } | | 106 | } |
95 | | | 107 | |
96 | # get some pkgsrc variables | | 108 | # get some pkgsrc variables |
97 | | | 109 | |
98 | $wrksrc=`@MAKE@ show-var VARNAME=WRKSRC` or | | 110 | $wrksrc = get_variable("WRKSRC"); |
99 | die ("can't find WRKSRC -- wrong dir?"); | | 111 | $wrkdir = get_variable("WRKDIR"); |
100 | chomp($wrksrc); | | 112 | $origpatchdir = get_variable("PATCHDIR"); |
101 | $wrkdir=`@MAKE@ show-var VARNAME=WRKDIR` or | | | |
102 | die ("can't find WRKDIR -- wrong dir?"); | | | |
103 | chomp($wrkdir); | | | |
104 | $origpatchdir=`@MAKE@ show-var VARNAME=PATCHDIR` or | | | |
105 | die ("can't find PATCHDIR -- wrong dir?"); | | | |
106 | chomp($origpatchdir); | | | |
107 | | | 113 | |
108 | if ($opt_D) { | | 114 | if ($opt_D) { |
109 | $patchdir = "$wrkdir/.newpatches"; | | 115 | $patchdir = "$wrkdir/.newpatches"; |
110 | } elsif ($opt_d) { | | 116 | } elsif ($opt_d) { |
111 | if (-d "/$opt_d") { | | 117 | if (-d "/$opt_d") { |
112 | $patchdir = $opt_d; | | 118 | $patchdir = $opt_d; |
113 | } else { | | 119 | } else { |
114 | my $pwd = cwd(); | | 120 | my $pwd = cwd(); |
115 | chomp($pwd); | | 121 | chomp($pwd); |
116 | $patchdir = "$pwd/$opt_d"; | | 122 | $patchdir = "$pwd/$opt_d"; |
117 | } | | 123 | } |
118 | } else { | | 124 | } else { |
119 | $patchdir = $origpatchdir; | | 125 | $patchdir = $origpatchdir; |