| @@ -1,807 +1,822 @@ | | | @@ -1,807 +1,822 @@ |
1 | #! @PERL5@ | | 1 | #! @PERL5@ |
2 | # $NetBSD: url2pkg.pl,v 1.64 2019/09/09 08:08:02 maya Exp $ | | 2 | # $NetBSD: url2pkg.pl,v 1.65 2019/09/11 05:25:55 rillig Exp $ |
3 | # | | 3 | # |
4 | | | 4 | |
5 | # Copyright (c) 2010 The NetBSD Foundation, Inc. | | 5 | # Copyright (c) 2010 The NetBSD Foundation, Inc. |
6 | # All rights reserved. | | 6 | # All rights reserved. |
7 | # | | 7 | # |
8 | # This code is derived from software contributed to The NetBSD Foundation | | 8 | # This code is derived from software contributed to The NetBSD Foundation |
9 | # by Roland Illig. | | 9 | # by Roland Illig. |
10 | # | | 10 | # |
11 | # Redistribution and use in source and binary forms, with or without | | 11 | # Redistribution and use in source and binary forms, with or without |
12 | # modification, are permitted provided that the following conditions | | 12 | # modification, are permitted provided that the following conditions |
13 | # are met: | | 13 | # are met: |
14 | # 1. Redistributions of source code must retain the above copyright | | 14 | # 1. Redistributions of source code must retain the above copyright |
15 | # notice, this list of conditions and the following disclaimer. | | 15 | # notice, this list of conditions and the following disclaimer. |
16 | # 2. Redistributions in binary form must reproduce the above copyright | | 16 | # 2. Redistributions in binary form must reproduce the above copyright |
17 | # notice, this list of conditions and the following disclaimer in the | | 17 | # notice, this list of conditions and the following disclaimer in the |
18 | # documentation and/or other materials provided with the distribution. | | 18 | # documentation and/or other materials provided with the distribution. |
19 | # | | 19 | # |
20 | # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 20 | # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
21 | # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 21 | # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
22 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 22 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
23 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 23 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
24 | # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 24 | # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
30 | # POSSIBILITY OF SUCH DAMAGE. | | 30 | # POSSIBILITY OF SUCH DAMAGE. |
31 | | | 31 | |
32 | use feature qw{ switch }; | | 32 | use feature qw{ switch }; |
33 | use strict; | | 33 | use strict; |
34 | use warnings; | | 34 | use warnings; |
35 | | | 35 | |
36 | # | | 36 | # |
37 | # Build-time Configuration. | | 37 | # Build-time Configuration. |
38 | # | | 38 | # |
39 | | | 39 | |
40 | my $make = "@MAKE@"; | | 40 | my $make = "@MAKE@"; |
41 | my $libdir = "@LIBDIR@"; | | 41 | my $libdir = "@LIBDIR@"; |
42 | my $pythonbin = "@PYTHONBIN@"; | | 42 | my $pythonbin = "@PYTHONBIN@"; |
43 | | | 43 | |
44 | use constant true => 1; | | 44 | use constant true => 1; |
45 | use constant false => 0; | | 45 | use constant false => 0; |
46 | | | 46 | |
47 | # | | 47 | # |
48 | # Some helper subroutines. | | 48 | # Some helper subroutines. |
49 | # | | 49 | # |
50 | | | 50 | |
51 | sub run_editor($$) { | | 51 | sub run_editor($$) { |
52 | my ($fname, $lineno) = @_; | | 52 | my ($fname, $lineno) = @_; |
53 | | | 53 | |
54 | my $editor = $ENV{"PKGEDITOR"} || $ENV{"EDITOR"} || "vi"; | | 54 | my $editor = $ENV{"PKGEDITOR"} || $ENV{"EDITOR"} || "vi"; |
55 | | | 55 | |
56 | my @args; | | 56 | my @args; |
57 | push(@args, $editor); | | 57 | push(@args, $editor); |
58 | push(@args, "+$lineno") if $editor =~ qr"(^|/)(mcedit|nano|pico|vi|vim)$"; | | 58 | push(@args, "+$lineno") if $editor =~ qr"(^|/)(mcedit|nano|pico|vi|vim)$"; |
59 | push(@args, $fname); | | 59 | push(@args, $fname); |
60 | | | 60 | |
61 | system { $args[0] } (@args); | | 61 | system { $args[0] } (@args); |
62 | } | | 62 | } |
63 | | | 63 | |
64 | sub get_maintainer() { | | 64 | sub get_maintainer() { |
65 | | | 65 | |
66 | return $ENV{"PKGMAINTAINER"} || $ENV{"REPLYTO"} || "INSERT_YOUR_MAIL_ADDRESS_HERE"; | | 66 | return $ENV{"PKGMAINTAINER"} || $ENV{"REPLYTO"} || "INSERT_YOUR_MAIL_ADDRESS_HERE"; |
67 | } | | 67 | } |
68 | | | 68 | |
69 | sub var($$$) { | | 69 | sub var($$$) { |
70 | my ($name, $op, $value) = @_; | | 70 | my ($name, $op, $value) = @_; |
71 | | | 71 | |
72 | return [$name, $op, $value]; | | 72 | return [$name, $op, $value]; |
73 | } | | 73 | } |
74 | | | 74 | |
75 | sub read_lines($) { | | 75 | sub read_lines($) { |
76 | my ($filename) = @_; | | 76 | my ($filename) = @_; |
77 | | | 77 | |
78 | my @lines; | | 78 | my @lines; |
79 | open(F, "<", $filename) or return @lines; | | 79 | open(F, "<", $filename) or return @lines; |
80 | while (defined(my $line = <F>)) { | | 80 | while (defined(my $line = <F>)) { |
81 | chomp($line); | | 81 | chomp($line); |
82 | push(@lines, $line); | | 82 | push(@lines, $line); |
83 | } | | 83 | } |
84 | close(F) or die; | | 84 | close(F) or die; |
85 | return @lines; | | 85 | return @lines; |
86 | } | | 86 | } |
87 | | | 87 | |
88 | sub write_lines($@) { | | 88 | sub write_lines($@) { |
89 | my ($filename, @lines) = @_; | | 89 | my ($filename, @lines) = @_; |
90 | | | 90 | |
91 | open(F, ">", "$filename.tmp") or die; | | 91 | open(F, ">", "$filename.tmp") or die; |
92 | foreach my $line (@lines) { | | 92 | foreach my $line (@lines) { |
93 | print F "$line\n"; | | 93 | print F "$line\n"; |
94 | } | | 94 | } |
95 | close(F) or die; | | 95 | close(F) or die; |
96 | rename("$filename.tmp", $filename) or die; | | 96 | rename("$filename.tmp", $filename) or die; |
97 | } | | 97 | } |
98 | | | 98 | |
99 | sub find_package($) { | | 99 | sub find_package($) { |
100 | my ($pkgbase) = @_; | | 100 | my ($pkgbase) = @_; |
101 | | | 101 | |
102 | my @candidates = <../../*/$pkgbase>; | | 102 | my @candidates = <../../*/$pkgbase>; |
103 | return scalar(@candidates) == 1 ? $candidates[0] : ""; | | 103 | return scalar(@candidates) == 1 ? $candidates[0] : ""; |
104 | } | | 104 | } |
105 | | | 105 | |
106 | # appends the given variable assignments to the lines, aligning the | | 106 | # appends the given variable assignments to the lines, aligning the |
107 | # variable values vertically. | | 107 | # variable values vertically. |
108 | sub lines_add_vars($$) { | | 108 | sub lines_add_vars($$) { |
109 | my ($lines, $vars) = @_; | | 109 | my ($lines, $vars) = @_; |
110 | | | 110 | |
111 | return if scalar(@$vars) == 0; | | 111 | return if scalar(@$vars) == 0; |
112 | | | 112 | |
113 | my $width = 0; | | 113 | my $width = 0; |
114 | foreach my $var (@$vars) { | | 114 | foreach my $var (@$vars) { |
115 | my ($name, $op, $value) = @$var; | | 115 | my ($name, $op, $value) = @$var; |
116 | next if $value eq ""; | | 116 | next if $value eq ""; |
117 | my $len = (length("$name$op\t") + 7) & -8; | | 117 | my $len = (length("$name$op\t") + 7) & -8; |
118 | $width = ($len > $width) ? $len : $width; | | 118 | $width = ($len > $width) ? $len : $width; |
119 | } | | 119 | } |
120 | | | 120 | |
121 | foreach my $var (@$vars) { | | 121 | foreach my $var (@$vars) { |
122 | my ($name, $op, $value) = @$var; | | 122 | my ($name, $op, $value) = @$var; |
123 | next if $value eq ""; | | 123 | next if $value eq ""; |
124 | my $tabs = "\t" x (($width - length("$name$op") + 7) / 8); | | 124 | my $tabs = "\t" x (($width - length("$name$op") + 7) / 8); |
125 | push(@$lines, "$name$op$tabs$value"); | | 125 | push(@$lines, "$name$op$tabs$value"); |
126 | } | | 126 | } |
127 | push(@$lines, ""); | | 127 | push(@$lines, ""); |
128 | } | | 128 | } |
129 | | | 129 | |
130 | # changes the value of an existing variable in the lines. | | 130 | # changes the value of an existing variable in the lines. |
131 | sub lines_set($$$) { | | 131 | sub lines_set($$$) { |
132 | my ($lines, $varname, $new_value) = @_; | | 132 | my ($lines, $varname, $new_value) = @_; |
133 | | | 133 | |
134 | my $i = 0; | | 134 | my $i = 0; |
135 | foreach my $line (@$lines) { | | 135 | foreach my $line (@$lines) { |
136 | if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { | | 136 | if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { |
137 | my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); | | 137 | my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); |
138 | | | 138 | |
139 | $lines->[$i] = "$varname$op$indent$new_value$space_after_value$comment"; | | 139 | $lines->[$i] = "$varname$op$indent$new_value$space_after_value$comment"; |
140 | return true; | | 140 | return true; |
141 | } | | 141 | } |
142 | $i++; | | 142 | $i++; |
143 | } | | 143 | } |
144 | | | 144 | |
145 | return false; | | 145 | return false; |
146 | } | | 146 | } |
147 | | | 147 | |
148 | # appends to the value of an existing variable in the lines. | | 148 | # appends to the value of an existing variable in the lines. |
149 | sub lines_append($$$) { | | 149 | sub lines_append($$$) { |
150 | my ($lines, $varname, $value) = @_; | | 150 | my ($lines, $varname, $value) = @_; |
151 | | | 151 | |
152 | return if $value eq ""; | | 152 | return if $value eq ""; |
153 | | | 153 | |
154 | my $i = 0; | | 154 | my $i = 0; |
155 | foreach my $line (@$lines) { | | 155 | foreach my $line (@$lines) { |
156 | if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*)(#.*|)$") { | | 156 | if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*)(#.*|)$") { |
157 | my ($op, $indent, $old_value, $comment) = ($1, $2, $3, $4); | | 157 | my ($op, $indent, $old_value, $comment) = ($1, $2, $3, $4); |
158 | | | 158 | |
159 | my $before = $old_value =~ qr"\S$" ? " " : ""; | | 159 | my $before = $old_value =~ qr"\S$" ? " " : ""; |
160 | my $after = $comment eq "" ? "" : " "; | | 160 | my $after = $comment eq "" ? "" : " "; |
161 | $lines->[$i] = "$varname$op$indent$old_value$before$value$after$comment"; | | 161 | $lines->[$i] = "$varname$op$indent$old_value$before$value$after$comment"; |
162 | return true; | | 162 | return true; |
163 | } | | 163 | } |
164 | $i++; | | 164 | $i++; |
165 | } | | 165 | } |
166 | | | 166 | |
167 | return false; | | 167 | return false; |
168 | } | | 168 | } |
169 | | | 169 | |
170 | # removes a variable assignment from the lines. | | 170 | # removes a variable assignment from the lines. |
171 | sub lines_remove($$) { | | 171 | sub lines_remove($$) { |
172 | my ($lines, $varname) = @_; | | 172 | my ($lines, $varname) = @_; |
173 | | | 173 | |
174 | my $i = 0; | | 174 | my $i = 0; |
175 | foreach my $line (@$lines) { | | 175 | foreach my $line (@$lines) { |
176 | if ($line =~ qr"^\Q$varname\E(\+?=)") { | | 176 | if ($line =~ qr"^\Q$varname\E(\+?=)") { |
177 | splice(@$lines, $i, 1); | | 177 | splice(@$lines, $i, 1); |
178 | return true; | | 178 | return true; |
179 | } | | 179 | } |
180 | $i++; | | 180 | $i++; |
181 | } | | 181 | } |
182 | | | 182 | |
183 | return false; | | 183 | return false; |
184 | } | | 184 | } |
185 | | | 185 | |
186 | # removes a variable assignment from the lines if its value is the | | 186 | # removes a variable assignment from the lines if its value is the |
187 | # expected one. | | 187 | # expected one. |
188 | sub lines_remove_if($$$) { | | 188 | sub lines_remove_if($$$) { |
189 | my ($lines, $varname, $expected_value) = @_; | | 189 | my ($lines, $varname, $expected_value) = @_; |
190 | | | 190 | |
191 | my $i = 0; | | 191 | my $i = 0; |
192 | foreach my $line (@$lines) { | | 192 | foreach my $line (@$lines) { |
193 | if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { | | 193 | if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { |
194 | my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); | | 194 | my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); |
195 | | | 195 | |
196 | if ($old_value eq $expected_value) { | | 196 | if ($old_value eq $expected_value) { |
197 | splice(@$lines, $i, 1); | | 197 | splice(@$lines, $i, 1); |
198 | return true; | | 198 | return true; |
199 | } | | 199 | } |
200 | } | | 200 | } |
201 | $i++; | | 201 | $i++; |
202 | } | | 202 | } |
203 | | | 203 | |
204 | return false; | | 204 | return false; |
205 | } | | 205 | } |
206 | | | 206 | |
207 | sub make(@) { | | 207 | sub make(@) { |
208 | my @args = @_; | | 208 | my @args = @_; |
209 | | | 209 | |
210 | (system { $make } ($make, @args)) == 0 or die; | | 210 | (system { $make } ($make, @args)) == 0 or die; |
211 | } | | 211 | } |
212 | | | 212 | |
213 | # The following adjust_* subroutines are called after the distfiles have | | 213 | # The following adjust_* subroutines are called after the distfiles have |
214 | # been downloaded and extracted. They inspect the extracted files | | 214 | # been downloaded and extracted. They inspect the extracted files |
215 | # and adjust the variable definitions in the package Makefile. | | 215 | # and adjust the variable definitions in the package Makefile. |
216 | | | 216 | |
217 | # | | 217 | # |
218 | # The following variables may be used in the adjust_* subroutines: | | 218 | # The following variables may be used in the adjust_* subroutines: |
219 | # | | 219 | # |
220 | | | 220 | |
221 | # the package name, including the version number. | | 221 | # the package name, including the version number. |
222 | my $distname; | | 222 | my $distname; |
223 | | | 223 | |
224 | # the absolute pathname to the working directory, containing | | 224 | # the absolute pathname to the working directory, containing |
225 | # the extracted distfiles. | | 225 | # the extracted distfiles. |
226 | my $abs_wrkdir; | | 226 | my $abs_wrkdir; |
227 | | | 227 | |
228 | # the absolute pathname to a subdirectory of $abs_wrkdir, typically | | 228 | # the absolute pathname to a subdirectory of $abs_wrkdir, typically |
229 | # containing package-provided Makefiles or configure scripts. | | 229 | # containing package-provided Makefiles or configure scripts. |
230 | my $abs_wrksrc; | | 230 | my $abs_wrksrc; |
231 | | | 231 | |
232 | my @wrksrc_files; | | 232 | my @wrksrc_files; |
233 | my @wrksrc_dirs; | | 233 | my @wrksrc_dirs; |
234 | # the regular files and directories relative to abs_wrksrc. | | 234 | # the regular files and directories relative to abs_wrksrc. |
235 | | | 235 | |
236 | # | | 236 | # |
237 | # The following variables may be set by the adjust_* subroutines and | | 237 | # The following variables may be set by the adjust_* subroutines and |
238 | # will later appear in the package Makefile: | | 238 | # will later appear in the package Makefile: |
239 | # | | 239 | # |
240 | | | 240 | |
241 | # categories for the package, in addition to the usual | | 241 | # categories for the package, in addition to the usual |
242 | # parent directory. | | 242 | # parent directory. |
243 | my @categories; | | 243 | my @categories; |
244 | | | 244 | |
245 | # the dependencies of the package, in the form | | 245 | # the dependencies of the package, in the form |
246 | # "package>=version:../../category/package". | | 246 | # "package>=version:../../category/package". |
247 | my @depends; | | 247 | my @depends; |
248 | my @build_depends; | | 248 | my @build_depends; |
249 | my @test_depends; | | 249 | my @test_depends; |
250 | | | 250 | |
251 | # .include, interleaved with BUILDLINK3_API_DEPENDS. | | 251 | # .include, interleaved with BUILDLINK3_API_DEPENDS. |
252 | # These lines are added at the bottom of the Makefile. | | 252 | # These lines are added at the bottom of the Makefile. |
253 | my @bl3_lines; | | 253 | my @bl3_lines; |
254 | | | 254 | |
255 | # a list of pathnames relative to the package path. | | 255 | # a list of pathnames relative to the package path. |
256 | # All these files will be included at the bottom of the Makefile. | | 256 | # All these files will be included at the bottom of the Makefile. |
257 | my @includes; | | 257 | my @includes; |
258 | | | 258 | |
259 | # a list of variable assignments that will make up the fourth | | 259 | # a list of variable assignments that will make up the fourth |
260 | # paragraph of the package Makefile, where the build configuration | | 260 | # paragraph of the package Makefile, where the build configuration |
261 | # takes place. | | 261 | # takes place. |
262 | my @build_vars; | | 262 | my @build_vars; |
263 | | | 263 | |
264 | # similar to the @build_vars, but separated by an empty line in | | 264 | # similar to the @build_vars, but separated by an empty line in |
265 | # the Makefile, thereby forming the fifth paragraph. | | 265 | # the Makefile, thereby forming the fifth paragraph. |
266 | my @extra_vars; | | 266 | my @extra_vars; |
267 | | | 267 | |
268 | # these are inserted below the second paragraph in the Makefile. | | 268 | # these are inserted below the second paragraph in the Makefile. |
269 | my @todos; | | 269 | my @todos; |
270 | | | 270 | |
271 | # the package name, in case it differs from $distname. | | 271 | # the package name, in case it differs from $distname. |
272 | my $pkgname = ""; | | 272 | my $pkgname = ""; |
273 | | | 273 | |
274 | my $regenerate_distinfo = false; | | 274 | my $regenerate_distinfo = false; |
275 | | | 275 | |
276 | # Example: | | 276 | # Example: |
277 | # add_dependency("DEPENDS", "package", ">=1", "../../category/package"); | | 277 | # add_dependency("DEPENDS", "package", ">=1", "../../category/package"); |
278 | # | | 278 | # |
279 | sub add_dependency($$$$) { | | 279 | sub add_dependency($$$$) { |
280 | my ($type, $pkgbase, $constraint, $dep_dir) = @_; | | 280 | my ($type, $pkgbase, $constraint, $dep_dir) = @_; |
281 | | | 281 | |
282 | if ($dep_dir ne "" && -f "$dep_dir/buildlink3.mk") { | | 282 | if ($dep_dir ne "" && -f "$dep_dir/buildlink3.mk") { |
283 | # TODO: add type to bl3_lines (BUILDLINK_DEPENDS) | | 283 | # TODO: add type to bl3_lines (BUILDLINK_DEPENDS) |
284 | # TODO: add constraint to bl3_lines (BUILDLINK_API_DEPENDS) | | 284 | # TODO: add constraint to bl3_lines (BUILDLINK_API_DEPENDS) |
285 | push(@bl3_lines, ".include \"$dep_dir/buildlink3.mk\""); | | 285 | push(@bl3_lines, ".include \"$dep_dir/buildlink3.mk\""); |
286 | return; | | 286 | return; |
287 | } | | 287 | } |
288 | | | 288 | |
289 | my $value = $dep_dir ne "" && -f "$dep_dir/Makefile" | | 289 | my $value = $dep_dir ne "" && -f "$dep_dir/Makefile" |
290 | ? "$pkgbase$constraint:$dep_dir" | | 290 | ? "$pkgbase$constraint:$dep_dir" |
291 | : "# TODO: $pkgbase$constraint"; | | 291 | : "# TODO: $pkgbase$constraint"; |
292 | | | 292 | |
293 | if ($type eq "DEPENDS") { | | 293 | if ($type eq "DEPENDS") { |
294 | push(@depends, $value); | | 294 | push(@depends, $value); |
295 | } elsif ($type eq "BUILD_DEPENDS") { | | 295 | } elsif ($type eq "BUILD_DEPENDS") { |
296 | push(@build_depends, $value); | | 296 | push(@build_depends, $value); |
297 | } elsif ($type eq "TEST_DEPENDS") { | | 297 | } elsif ($type eq "TEST_DEPENDS") { |
298 | push(@test_depends, $value); | | 298 | push(@test_depends, $value); |
299 | } else { | | 299 | } else { |
300 | push(@todos, "dependency $type $value"); | | 300 | push(@todos, "dependency $type $value"); |
301 | } | | 301 | } |
302 | } | | 302 | } |
303 | | | 303 | |
304 | sub adjust_configure() { | | 304 | sub adjust_configure() { |
305 | my $gnu_configure = false; | | 305 | my $gnu_configure = false; |
306 | | | 306 | |
307 | open(CONF, "<", "$abs_wrksrc/configure") or return; | | 307 | open(CONF, "<", "$abs_wrksrc/configure") or return; |
308 | while (defined(my $line = <CONF>)) { | | 308 | while (defined(my $line = <CONF>)) { |
309 | if ($line =~ qr"autoconf|Free Software Foundation"i) { | | 309 | if ($line =~ qr"autoconf|Free Software Foundation"i) { |
310 | $gnu_configure = true; | | 310 | $gnu_configure = true; |
311 | last; | | 311 | last; |
312 | } | | 312 | } |
313 | } | | 313 | } |
314 | close(CONF); | | 314 | close(CONF); |
315 | | | 315 | |
316 | my $varname = ($gnu_configure ? "GNU_CONFIGURE" : "HAS_CONFIGURE"); | | 316 | my $varname = ($gnu_configure ? "GNU_CONFIGURE" : "HAS_CONFIGURE"); |
317 | push(@build_vars, var($varname, "=", "yes")); | | 317 | push(@build_vars, var($varname, "=", "yes")); |
318 | } | | 318 | } |
319 | | | 319 | |
320 | sub adjust_cmake() { | | 320 | sub adjust_cmake() { |
321 | if (-f "$abs_wrksrc/CMakeLists.txt") { | | 321 | if (-f "$abs_wrksrc/CMakeLists.txt") { |
322 | push(@build_vars, var("USE_CMAKE", "=", "yes")); | | 322 | push(@build_vars, var("USE_CMAKE", "=", "yes")); |
323 | } | | 323 | } |
324 | } | | 324 | } |
325 | | | 325 | |
326 | sub adjust_meson() { | | 326 | sub adjust_meson() { |
327 | if (-f "$abs_wrksrc/meson.build") { | | 327 | if (-f "$abs_wrksrc/meson.build") { |
328 | push(@includes, "../../devel/py-meson/build.mk"); | | 328 | push(@includes, "../../devel/py-meson/build.mk"); |
329 | } | | 329 | } |
330 | } | | 330 | } |
331 | | | 331 | |
332 | sub adjust_gconf2_schemas() { | | 332 | sub adjust_gconf2_schemas() { |
333 | my @gconf2_files = grep(/schemas(?:\.in.*)$/, @wrksrc_files); | | 333 | my @gconf2_files = grep(/schemas(?:\.in.*)$/, @wrksrc_files); |
334 | if (@gconf2_files) { | | 334 | if (@gconf2_files) { |
335 | foreach my $f (@gconf2_files) { | | 335 | foreach my $f (@gconf2_files) { |
336 | if ($f =~ qr"(.*schemas)") { | | 336 | if ($f =~ qr"(.*schemas)") { |
337 | push(@extra_vars, var("GCONF_SCHEMAS", "+=", $1)); | | 337 | push(@extra_vars, var("GCONF_SCHEMAS", "+=", $1)); |
338 | } | | 338 | } |
339 | } | | 339 | } |
340 | push(@includes, "../../devel/GConf/schemas.mk"); | | 340 | push(@includes, "../../devel/GConf/schemas.mk"); |
341 | } | | 341 | } |
342 | } | | 342 | } |
343 | | | 343 | |
344 | sub adjust_libtool() { | | 344 | sub adjust_libtool() { |
345 | if (-f "$abs_wrksrc/ltconfig" || -f "$abs_wrksrc/ltmain.sh") { | | 345 | if (-f "$abs_wrksrc/ltconfig" || -f "$abs_wrksrc/ltmain.sh") { |
346 | push(@build_vars, var("USE_LIBTOOL", "=", "yes")); | | 346 | push(@build_vars, var("USE_LIBTOOL", "=", "yes")); |
347 | } | | 347 | } |
348 | if (-d "$abs_wrksrc/libltdl") { | | 348 | if (-d "$abs_wrksrc/libltdl") { |
349 | push(@includes, "../../devel/libltdl/convenience.mk"); | | 349 | push(@includes, "../../devel/libltdl/convenience.mk"); |
350 | } | | 350 | } |
351 | } | | 351 | } |
352 | | | 352 | |
353 | sub adjust_perl_module() { | | 353 | sub adjust_perl_module() { |
354 | | | 354 | |
355 | if (-f "$abs_wrksrc/Build.PL") { | | 355 | if (-f "$abs_wrksrc/Build.PL") { |
| | | 356 | # Example packages: |
| | | 357 | # devel/p5-Algorithm-CheckDigits |
356 | | | 358 | |
357 | # It's a Module::Build module. Dependencies cannot yet be | | 359 | # It's a Module::Build module. Dependencies cannot yet be |
358 | # extracted automatically. | | 360 | # extracted automatically. |
| | | 361 | # |
| | | 362 | # TODO: Implement this similarly to the Makefile.PL mock below. |
| | | 363 | |
359 | push(@todos, "Look for the dependencies in Build.PL."); | | 364 | push(@todos, "Look for the dependencies in Build.PL."); |
360 | | | 365 | |
361 | push(@build_vars, var("PERL5_MODULE_TYPE", "=", "Module::Build")); | | 366 | push(@build_vars, var("PERL5_MODULE_TYPE", "=", "Module::Build")); |
362 | | | 367 | |
363 | } elsif (-f "$abs_wrksrc/Makefile.PL") { | | 368 | } elsif (-f "$abs_wrksrc/Makefile.PL") { |
| | | 369 | # Example packages: |
| | | 370 | # devel/p5-Algorithm-Diff (no dependencies) |
| | | 371 | # devel/p5-Carp-Assert-More (dependencies without version numbers) |
| | | 372 | # www/p5-HTML-Quoted (dependency with version number) |
364 | | | 373 | |
365 | # To avoid fix_up_makefile error for p5-HTML-Quoted, generate Makefile first. | | 374 | # To avoid fix_up_makefile error for p5-HTML-Quoted, generate Makefile first. |
366 | system("cd '$abs_wrksrc' && perl -I. Makefile.PL < /dev/null") or do {}; | | 375 | system("cd '$abs_wrksrc' && perl -I. Makefile.PL < /dev/null") or do {}; |
367 | | | 376 | |
368 | open(DEPS, "cd '$abs_wrksrc' && perl -I$libdir -I. Makefile.PL |") or die; | | 377 | open(DEPS, "cd '$abs_wrksrc' && perl -I$libdir -I. Makefile.PL |") or die; |
369 | while (defined(my $dep = <DEPS>)) { | | 378 | while (defined(my $dep = <DEPS>)) { |
370 | chomp($dep); | | 379 | chomp($dep); |
371 | | | 380 | |
372 | if ($dep =~ qr"^(\w+)\t(\S+)(>\S+|):(\.\./\.\./\S+)$") { | | 381 | if ($dep =~ qr"^(\w+)\t(\S+)(>\S+|):(\.\./\.\./\S+)$") { |
373 | add_dependency($1, $2, $3, $4); | | 382 | add_dependency($1, $2, $3, $4); |
374 | } | | 383 | } |
375 | } | | 384 | } |
376 | close(DEPS) or die; | | 385 | close(DEPS) or die; |
377 | | | 386 | |
378 | } else { | | 387 | } else { |
379 | return; | | 388 | return; |
380 | } | | 389 | } |
381 | | | 390 | |
382 | my $packlist = $distname =~ s/-[0-9].*//r =~ s/-/\//gr; | | 391 | my $packlist = $distname =~ s/-[0-9].*//r =~ s/-/\//gr; |
383 | push(@build_vars, var("PERL5_PACKLIST", "=", "auto/$packlist/.packlist")); | | 392 | push(@build_vars, var("PERL5_PACKLIST", "=", "auto/$packlist/.packlist")); |
384 | push(@includes, "../../lang/perl5/module.mk"); | | 393 | push(@includes, "../../lang/perl5/module.mk"); |
385 | $pkgname = "p5-\${DISTNAME}"; | | 394 | $pkgname = "p5-\${DISTNAME}"; |
386 | push(@categories, "perl5"); | | 395 | push(@categories, "perl5"); |
| | | 396 | unlink("PLIST") or do {}; |
387 | } | | 397 | } |
388 | | | 398 | |
| | | 399 | # Example packages: |
| | | 400 | # |
| | | 401 | # devel/py-ZopeComponent (dependencies, test dependencies) |
389 | sub adjust_python_module() { | | 402 | sub adjust_python_module() { |
390 | | | 403 | |
391 | return unless -f "$abs_wrksrc/setup.py"; | | 404 | return unless -f "$abs_wrksrc/setup.py"; |
392 | | | 405 | |
393 | my %old_env = %ENV; | | 406 | my %old_env = %ENV; |
394 | $ENV{"PYTHONDONTWRITEBYTECODE"} = "x"; | | 407 | $ENV{"PYTHONDONTWRITEBYTECODE"} = "x"; |
395 | $ENV{"PYTHONPATH"} = $libdir; | | 408 | $ENV{"PYTHONPATH"} = $libdir; |
396 | | | 409 | |
397 | my @dep_lines; | | 410 | my @dep_lines; |
398 | open(DEPS, "cd '$abs_wrksrc' && $pythonbin setup.py build |") or die; | | 411 | open(DEPS, "cd '$abs_wrksrc' && $pythonbin setup.py build |") or die; |
399 | %ENV = %old_env; | | 412 | %ENV = %old_env; |
400 | while (defined(my $line = <DEPS>)) { | | 413 | while (defined(my $line = <DEPS>)) { |
401 | chomp($line); | | 414 | chomp($line); |
402 | if ($line =~ qr"^(\w+)\t(\S+?)(>=.*|)$") { | | 415 | if ($line =~ qr"^(\w+)\t(\S+?)(>=.*|)$") { |
403 | push(@dep_lines, [$1, $2, $3]); | | 416 | push(@dep_lines, [$1, $2, $3]); |
404 | } | | 417 | } |
405 | } | | 418 | } |
406 | close(DEPS) or die; | | 419 | close(DEPS) or die; |
407 | | | 420 | |
408 | foreach my $dep_line (@dep_lines) { | | 421 | foreach my $dep_line (@dep_lines) { |
409 | my ($type, $pkgbase, $constraint) = @$dep_line; | | 422 | my ($type, $pkgbase, $constraint) = @$dep_line; |
410 | my $dep_dir = find_package("py-$pkgbase"); | | 423 | my $dep_dir = find_package("py-$pkgbase"); |
411 | if ($dep_dir ne "") { | | 424 | if ($dep_dir ne "") { |
412 | $pkgbase = "py-$pkgbase"; | | 425 | $pkgbase = "py-$pkgbase"; |
413 | } else { | | 426 | } else { |
414 | $dep_dir = find_package($pkgbase); | | 427 | $dep_dir = find_package($pkgbase); |
415 | } | | 428 | } |
416 | | | 429 | |
417 | add_dependency($type, $pkgbase, $constraint, $dep_dir); | | 430 | add_dependency($type, $pkgbase, $constraint, $dep_dir); |
418 | } | | 431 | } |
419 | | | 432 | |
420 | push(@categories, "python"); | | 433 | push(@categories, "python"); |
421 | push(@includes, "../../lang/python/egg.mk"); | | 434 | push(@includes, "../../lang/python/egg.mk"); |
422 | } | | 435 | } |
423 | | | 436 | |
424 | sub adjust_cargo() { | | 437 | sub adjust_cargo() { |
425 | open(CONF, "<", "$abs_wrksrc/Cargo.lock") or return; | | 438 | open(CONF, "<", "$abs_wrksrc/Cargo.lock") or return; |
426 | | | 439 | |
427 | while (defined(my $line = <CONF>)) { | | 440 | while (defined(my $line = <CONF>)) { |
428 | # "checksum cargo-package-name cargo-package-version | | 441 | # "checksum cargo-package-name cargo-package-version |
429 | if ($line =~ qr"^\"checksum\s(\S+)\s(\S+)") { | | 442 | if ($line =~ qr"^\"checksum\s(\S+)\s(\S+)") { |
430 | push(@build_vars, var("CARGO_CRATE_DEPENDS", "+=", "$1-$2")); | | 443 | push(@build_vars, var("CARGO_CRATE_DEPENDS", "+=", "$1-$2")); |
431 | } | | 444 | } |
432 | } | | 445 | } |
433 | close(CONF); | | 446 | close(CONF); |
434 | | | 447 | |
435 | push(@includes, "../../lang/rust/cargo.mk"); | | 448 | push(@includes, "../../lang/rust/cargo.mk"); |
436 | } | | 449 | } |
437 | | | 450 | |
438 | | | 451 | |
439 | sub adjust_pkg_config() { | | 452 | sub adjust_pkg_config() { |
440 | my @pkg_config_files = grep { /\.pc\.in$/ && ! /-uninstalled\.pc\.in$/ } @wrksrc_files; | | 453 | my @pkg_config_files = grep { /\.pc\.in$/ && ! /-uninstalled\.pc\.in$/ } @wrksrc_files; |
441 | if (@pkg_config_files) { | | 454 | if (@pkg_config_files) { |
442 | push(@build_vars, var("USE_TOOLS", "+=", "pkg-config")); | | 455 | push(@build_vars, var("USE_TOOLS", "+=", "pkg-config")); |
443 | } | | 456 | } |
444 | foreach my $f (@pkg_config_files) { | | 457 | foreach my $f (@pkg_config_files) { |
445 | push(@extra_vars, var("PKGCONFIG_OVERRIDE", "+=", $f)); | | 458 | push(@extra_vars, var("PKGCONFIG_OVERRIDE", "+=", $f)); |
446 | } | | 459 | } |
447 | } | | 460 | } |
448 | | | 461 | |
449 | sub adjust_po() { | | 462 | sub adjust_po() { |
450 | if (grep(/\.g?mo$/, @wrksrc_files)) { | | 463 | if (grep(/\.g?mo$/, @wrksrc_files)) { |
451 | push(@build_vars, var("USE_PKGLOCALEDIR", "=", "yes")); | | 464 | push(@build_vars, var("USE_PKGLOCALEDIR", "=", "yes")); |
452 | } | | 465 | } |
453 | } | | 466 | } |
454 | | | 467 | |
455 | sub adjust_use_languages() { | | 468 | sub adjust_use_languages() { |
456 | my @languages; | | 469 | my @languages; |
457 | | | 470 | |
458 | grep(/\.(c|xs)$/, @wrksrc_files) and push(@languages, "c"); | | 471 | grep(/\.(c|xs)$/, @wrksrc_files) and push(@languages, "c"); |
459 | grep(/\.(cpp|c\+\+|cxx|cc|C)$/, @wrksrc_files) and push(@languages, "c++"); | | 472 | grep(/\.(cpp|c\+\+|cxx|cc|C)$/, @wrksrc_files) and push(@languages, "c++"); |
460 | grep(/\.f$/, @wrksrc_files) and push(@languages, "fortran"); | | 473 | grep(/\.f$/, @wrksrc_files) and push(@languages, "fortran"); |
461 | | | 474 | |
462 | my $use_languages = join(" ", @languages); | | 475 | my $use_languages = join(" ", @languages); |
463 | if ($use_languages eq "") { | | 476 | if ($use_languages eq "") { |
464 | $use_languages = "# none"; | | 477 | $use_languages = "# none"; |
465 | } | | 478 | } |
466 | if ($use_languages ne "c") { | | 479 | if ($use_languages ne "c") { |
467 | push(@build_vars, var("USE_LANGUAGES", "=", $use_languages)); | | 480 | push(@build_vars, var("USE_LANGUAGES", "=", $use_languages)); |
468 | } | | 481 | } |
469 | } | | 482 | } |
470 | | | 483 | |
471 | # | | 484 | # |
472 | # Subroutines for generating the initial package and adjusting it after | | 485 | # Subroutines for generating the initial package and adjusting it after |
473 | # the distfiles have been extracted. | | 486 | # the distfiles have been extracted. |
474 | # | | 487 | # |
475 | | | 488 | |
476 | sub generate_initial_package_Makefile_lines($) { | | 489 | sub generate_initial_package_Makefile_lines($) { |
477 | my ($url) = @_; | | 490 | my ($url) = @_; |
478 | | | 491 | |
479 | my $master_site = ""; | | 492 | my $master_site = ""; |
480 | my $master_sites = ""; | | 493 | my $master_sites = ""; |
481 | my $distfile = ""; | | 494 | my $distfile = ""; |
482 | my $homepage = ""; | | 495 | my $homepage = ""; |
483 | my $extract_sufx = ""; | | 496 | my $extract_sufx = ""; |
484 | my $categories = ""; | | 497 | my $categories = ""; |
485 | my $github_project = ""; | | 498 | my $github_project = ""; |
486 | my $github_release = ""; | | 499 | my $github_release = ""; |
487 | my $dist_subdir = ""; | | 500 | my $dist_subdir = ""; |
488 | | | 501 | |
489 | open(SITES, "<", "../../mk/fetch/sites.mk") or die; | | 502 | open(SITES, "<", "../../mk/fetch/sites.mk") or die; |
490 | while (defined(my $line = <SITES>)) { | | 503 | while (defined(my $line = <SITES>)) { |
491 | chomp($line); | | 504 | chomp($line); |
492 | | | 505 | |
493 | if ($line =~ qr"^(MASTER_SITE_.*)\+=") { | | 506 | if ($line =~ qr"^(MASTER_SITE_.*)\+=") { |
494 | $master_site = $1; | | 507 | $master_site = $1; |
495 | | | 508 | |
496 | } elsif ($line =~ qr"^\t(.*?)(?:\s+\\)?$") { | | 509 | } elsif ($line =~ qr"^\t(.*?)(?:\s+\\)?$") { |
497 | my ($site) = ($1); | | 510 | my ($site) = ($1); |
498 | | | 511 | |
499 | if (index($url, $site) == 0) { | | 512 | if (index($url, $site) == 0) { |
500 | if ($url =~ qr"^\Q$site\E(.+)/([^/]+)$") { | | 513 | if ($url =~ qr"^\Q$site\E(.+)/([^/]+)$") { |
501 | my $subdir = $1; | | 514 | my $subdir = $1; |
502 | $distfile = $2; | | 515 | $distfile = $2; |
503 | | | 516 | |
504 | $master_sites = "\${$master_site:=$subdir/}"; | | 517 | $master_sites = "\${$master_site:=$subdir/}"; |
505 | if ($master_site eq "MASTER_SITE_SOURCEFORGE") { | | 518 | if ($master_site eq "MASTER_SITE_SOURCEFORGE") { |
506 | $homepage = "http://$subdir.sourceforge.net/"; | | 519 | $homepage = "http://$subdir.sourceforge.net/"; |
507 | } elsif ($master_site eq "MASTER_SITE_GNU") { | | 520 | } elsif ($master_site eq "MASTER_SITE_GNU") { |
508 | $homepage = "http://www.gnu.org/software/$subdir/"; | | 521 | $homepage = "http://www.gnu.org/software/$subdir/"; |
509 | } else { | | 522 | } else { |
510 | $homepage = substr($url, 0, -length($distfile)); | | 523 | $homepage = substr($url, 0, -length($distfile)); |
511 | } | | 524 | } |
512 | } else { | | 525 | } else { |
513 | $master_sites = "\${$master_site}"; | | 526 | $master_sites = "\${$master_site}"; |
514 | } | | 527 | } |
515 | } | | 528 | } |
516 | } | | 529 | } |
517 | } | | 530 | } |
518 | close(SITES) or die; | | 531 | close(SITES) or die; |
519 | | | 532 | |
520 | if ($url =~ qr"^https://downloads\.sourceforge\.net/project/([^/?]+)/[^?]+/([^/?]+)(?:[?].*)?$") { | | 533 | if ($url =~ qr"^https://downloads\.sourceforge\.net/project/([^/?]+)/[^?]+/([^/?]+)(?:[?].*)?$") { |
521 | my ($project, $filename) = ($1, $2); | | 534 | my ($project, $filename) = ($1, $2); |
522 | | | 535 | |
523 | $master_sites = "\${MASTER_SITE_SOURCEFORGE:=$project/}"; | | 536 | $master_sites = "\${MASTER_SITE_SOURCEFORGE:=$project/}"; |
524 | $homepage = "https://$project.sourceforge.net/"; | | 537 | $homepage = "https://$project.sourceforge.net/"; |
525 | $distfile = $filename; | | 538 | $distfile = $filename; |
526 | } | | 539 | } |
527 | | | 540 | |
528 | if ($url =~ qr"^https://github\.com/") { | | 541 | if ($url =~ qr"^https://github\.com/") { |
529 | if ($url =~ qr"^https://github\.com/(.*)/(.*)/archive/(.*)(\.tar\.gz|\.zip)$") { | | 542 | if ($url =~ qr"^https://github\.com/(.*)/(.*)/archive/(.*)(\.tar\.gz|\.zip)$") { |
530 | my ($org, $proj, $tag, $ext) = ($1, $2, $3, $4); | | 543 | my ($org, $proj, $tag, $ext) = ($1, $2, $3, $4); |
531 | | | 544 | |
532 | $master_sites = "\${MASTER_SITE_GITHUB:=$org/}"; | | 545 | $master_sites = "\${MASTER_SITE_GITHUB:=$org/}"; |
533 | $homepage = "https://github.com/$org/$proj/"; | | 546 | $homepage = "https://github.com/$org/$proj/"; |
534 | $github_project = $proj; | | 547 | $github_project = $proj; |
535 | if (index($tag, $github_project) == -1) { | | 548 | if (index($tag, $github_project) == -1) { |
536 | $pkgname = "\${GITHUB_PROJECT}-\${DISTNAME}"; | | 549 | $pkgname = "\${GITHUB_PROJECT}-\${DISTNAME}"; |
537 | $dist_subdir = "\${GITHUB_PROJECT}"; | | 550 | $dist_subdir = "\${GITHUB_PROJECT}"; |
538 | } | | 551 | } |
539 | $distfile = "$tag$ext"; | | 552 | $distfile = "$tag$ext"; |
540 | | | 553 | |
541 | } elsif ($url =~ qr"^https://github\.com/(.*)/(.*)/releases/download/(.*)/(.*)(\.tar\.gz|\.zip)$") { | | 554 | } elsif ($url =~ qr"^https://github\.com/(.*)/(.*)/releases/download/(.*)/(.*)(\.tar\.gz|\.zip)$") { |
542 | my ($org, $proj, $tag, $base, $ext) = ($1, $2, $3, $4, $5); | | 555 | my ($org, $proj, $tag, $base, $ext) = ($1, $2, $3, $4, $5); |
543 | | | 556 | |
544 | $master_sites = "\${MASTER_SITE_GITHUB:=$org/}"; | | 557 | $master_sites = "\${MASTER_SITE_GITHUB:=$org/}"; |
545 | $homepage = "https://github.com/$org/$proj/"; | | 558 | $homepage = "https://github.com/$org/$proj/"; |
546 | if (index($base, $proj) == -1) { | | 559 | if (index($base, $proj) == -1) { |
547 | $github_project = $proj; | | 560 | $github_project = $proj; |
548 | $dist_subdir = "\${GITHUB_PROJECT}"; | | 561 | $dist_subdir = "\${GITHUB_PROJECT}"; |
549 | } | | 562 | } |
550 | $github_release = $tag eq $base ? "\${DISTNAME}" : $tag; | | 563 | $github_release = $tag eq $base ? "\${DISTNAME}" : $tag; |
551 | $distfile = "$base$ext"; | | 564 | $distfile = "$base$ext"; |
552 | | | 565 | |
553 | } else { | | 566 | } else { |
554 | print("$0: ERROR: Invalid GitHub URL: $url, handling as normal URL\n"); | | 567 | print("$0: ERROR: Invalid GitHub URL: $url, handling as normal URL\n"); |
555 | } | | 568 | } |
556 | } | | 569 | } |
557 | | | 570 | |
558 | if ($master_sites eq "") { | | 571 | if ($master_sites eq "") { |
559 | if ($url =~ qr"^(.*/)(.*)$") { | | 572 | if ($url =~ qr"^(.*/)(.*)$") { |
560 | $master_sites = $1; | | 573 | $master_sites = $1; |
561 | $distfile = $2; | | 574 | $distfile = $2; |
562 | $homepage = $master_sites; | | 575 | $homepage = $master_sites; |
563 | } else { | | 576 | } else { |
564 | die("$0: ERROR: Invalid URL: $url\n"); | | 577 | die("$0: ERROR: Invalid URL: $url\n"); |
565 | } | | 578 | } |
566 | } | | 579 | } |
567 | | | 580 | |
568 | if ($distfile =~ qr"^(.*?)((?:\.tar)?\.\w+)$") { | | 581 | if ($distfile =~ qr"^(.*?)((?:\.tar)?\.\w+)$") { |
569 | $distname = $1; | | 582 | $distname = $1; |
570 | $extract_sufx = $2; | | 583 | $extract_sufx = $2; |
571 | } else { | | 584 | } else { |
572 | $distname = $distfile; | | 585 | $distname = $distfile; |
573 | $extract_sufx = "# none"; | | 586 | $extract_sufx = "# none"; |
574 | } | | 587 | } |
575 | | | 588 | |
576 | `pwd` =~ qr".*/([^/]+)/[^/]+$" or die; | | 589 | `pwd` =~ qr".*/([^/]+)/[^/]+$" or die; |
577 | $categories = $1 eq "wip" ? "# TODO: add primary category" : $1; | | 590 | $categories = $1 eq "wip" ? "# TODO: add primary category" : $1; |
578 | | | 591 | |
579 | if ($extract_sufx eq ".tar.gz" || $extract_sufx eq ".gem") { | | 592 | if ($extract_sufx eq ".tar.gz" || $extract_sufx eq ".gem") { |
580 | $extract_sufx = ""; | | 593 | $extract_sufx = ""; |
581 | } | | 594 | } |
582 | | | 595 | |
583 | my @lines; | | 596 | my @lines; |
584 | push(@lines, "# \$" . "NetBSD\$"); | | 597 | push(@lines, "# \$" . "NetBSD\$"); |
585 | push(@lines, ""); | | 598 | push(@lines, ""); |
586 | | | 599 | |
587 | lines_add_vars(\@lines, [ | | 600 | lines_add_vars(\@lines, [ |
588 | var("GITHUB_PROJECT", "=", $github_project), | | 601 | var("GITHUB_PROJECT", "=", $github_project), |
589 | var("DISTNAME", "=", $distname), | | 602 | var("DISTNAME", "=", $distname), |
590 | var("CATEGORIES", "=", $categories), | | 603 | var("CATEGORIES", "=", $categories), |
591 | var("MASTER_SITES", "=", $master_sites), | | 604 | var("MASTER_SITES", "=", $master_sites), |
592 | var("GITHUB_RELEASE", "=", $github_release), | | 605 | var("GITHUB_RELEASE", "=", $github_release), |
593 | var("EXTRACT_SUFX", "=", $extract_sufx), | | 606 | var("EXTRACT_SUFX", "=", $extract_sufx), |
594 | var("DIST_SUBDIR", "=", $dist_subdir), | | 607 | var("DIST_SUBDIR", "=", $dist_subdir), |
595 | ]); | | 608 | ]); |
596 | | | 609 | |
597 | lines_add_vars(\@lines, [ | | 610 | lines_add_vars(\@lines, [ |
598 | var("MAINTAINER", "=", get_maintainer()), | | 611 | var("MAINTAINER", "=", get_maintainer()), |
599 | var("HOMEPAGE", "=", $homepage), | | 612 | var("HOMEPAGE", "=", $homepage), |
600 | var("COMMENT", "=", "TODO: Short description of the package"), | | 613 | var("COMMENT", "=", "TODO: Short description of the package"), |
601 | var("#LICENSE", "=", "# TODO: (see mk/license.mk)"), | | 614 | var("#LICENSE", "=", "# TODO: (see mk/license.mk)"), |
602 | ]); | | 615 | ]); |
603 | | | 616 | |
604 | push(@lines, "# url2pkg-marker (please do not remove this line.)"); | | 617 | push(@lines, "# url2pkg-marker (please do not remove this line.)"); |
605 | push(@lines, ".include \"../../mk/bsd.pkg.mk\""); | | 618 | push(@lines, ".include \"../../mk/bsd.pkg.mk\""); |
606 | | | 619 | |
607 | return @lines; | | 620 | return @lines; |
608 | } | | 621 | } |
609 | | | 622 | |
610 | sub generate_initial_package($) { | | 623 | sub generate_initial_package($) { |
611 | my ($url) = @_; | | 624 | my ($url) = @_; |
612 | | | 625 | |
613 | rename("Makefile", "Makefile-url2pkg.bak") or do {}; | | 626 | rename("Makefile", "Makefile-url2pkg.bak") or do {}; |
614 | write_lines("Makefile", generate_initial_package_Makefile_lines($url)); | | 627 | write_lines("Makefile", generate_initial_package_Makefile_lines($url)); |
615 | write_lines("PLIST", "\@comment \$" . "NetBSD\$"); | | 628 | write_lines("PLIST", "\@comment \$" . "NetBSD\$"); |
616 | write_lines("DESCR", ()); | | 629 | write_lines("DESCR", ()); |
617 | run_editor("Makefile", 5); | | 630 | run_editor("Makefile", 5); |
618 | | | 631 | |
619 | make("distinfo"); | | 632 | make("distinfo"); |
620 | make("extract"); | | 633 | make("extract"); |
621 | } | | 634 | } |
622 | | | 635 | |
623 | sub adjust_lines_python_module($$) { | | 636 | sub adjust_lines_python_module($$) { |
624 | my ($lines, $url) = @_; | | 637 | my ($lines, $url) = @_; |
625 | | | 638 | |
626 | my @initial_lines = generate_initial_package_Makefile_lines($url); | | 639 | my @initial_lines = generate_initial_package_Makefile_lines($url); |
627 | my @current_lines = read_lines("Makefile"); | | 640 | my @current_lines = read_lines("Makefile"); |
628 | | | 641 | |
629 | # don't risk to overwrite any changes made by the package developer. | | | |
630 | if (join('\n', @current_lines) ne join('\n', @initial_lines)) { | | | |
631 | splice(@$lines, -2, 0, "# TODO: Migrate MASTER_SITES to PYPI"); | | | |
632 | return; | | | |
633 | } | | | |
634 | | | | |
635 | my %old; | | 642 | my %old; |
636 | foreach my $line (@initial_lines) { | | 643 | foreach my $line (@initial_lines) { |
637 | if ($line =~ qr"^(\w+)(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { | | 644 | if ($line =~ qr"^(\w+)(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { |
638 | my ($varname, $op, $indent, $value, $space_after_value, $comment) = ($1, $2, $3, $4, $5, $6); | | 645 | my ($varname, $op, $indent, $value, $space_after_value, $comment) = ($1, $2, $3, $4, $5, $6); |
639 | | | 646 | |
640 | if ($op eq "=") { | | 647 | if ($op eq "=") { |
641 | $old{$varname} = $value; | | 648 | $old{$varname} = $value; |
642 | } | | 649 | } |
643 | } | | 650 | } |
644 | } | | 651 | } |
645 | | | 652 | |
| | | 653 | return unless $old{"CATEGORIES"} =~ qr"python"; |
646 | my $pkgbase = $old{"GITHUB_PROJECT"}; | | 654 | my $pkgbase = $old{"GITHUB_PROJECT"}; |
| | | 655 | return unless defined($pkgbase); |
647 | my $pkgbase1 = substr($pkgbase, 0, 1); | | 656 | my $pkgbase1 = substr($pkgbase, 0, 1); |
648 | my $pkgversion_norev = $old{"DISTNAME"} =~ s/^v//r; | | 657 | my $pkgversion_norev = $old{"DISTNAME"} =~ s/^v//r; |
649 | | | 658 | |
| | | 659 | # don't risk to overwrite any changes made by the package developer. |
| | | 660 | if (join('\n', @current_lines) ne join('\n', @initial_lines)) { |
| | | 661 | splice(@$lines, -2, 0, "# TODO: Migrate MASTER_SITES to PYPI"); |
| | | 662 | return; |
| | | 663 | } |
| | | 664 | |
650 | my @lines = @$lines; | | 665 | my @lines = @$lines; |
651 | if (lines_remove(\@lines, "GITHUB_PROJECT") | | 666 | if (lines_remove(\@lines, "GITHUB_PROJECT") |
652 | && lines_set(\@lines, "DISTNAME", "$pkgbase-$pkgversion_norev") | | 667 | && lines_set(\@lines, "DISTNAME", "$pkgbase-$pkgversion_norev") |
653 | && lines_set(\@lines, "PKGNAME", "\${PYPKGPREFIX}-\${DISTNAME}") | | 668 | && lines_set(\@lines, "PKGNAME", "\${PYPKGPREFIX}-\${DISTNAME}") |
654 | && lines_set(\@lines, "MASTER_SITES", "\${MASTER_SITE_PYPI:=$pkgbase1/$pkgbase/}") | | 669 | && lines_set(\@lines, "MASTER_SITES", "\${MASTER_SITE_PYPI:=$pkgbase1/$pkgbase/}") |
655 | && lines_remove(\@lines, "DIST_SUBDIR") | | 670 | && lines_remove(\@lines, "DIST_SUBDIR") |
656 | && (lines_remove_if(\@lines, "EXTRACT_SUFX", ".zip") || true)) { | | 671 | && (lines_remove_if(\@lines, "EXTRACT_SUFX", ".zip") || true)) { |
657 | | | 672 | |
658 | @$lines = @lines; | | 673 | @$lines = @lines; |
659 | $regenerate_distinfo = true | | 674 | $regenerate_distinfo = true |
660 | } | | 675 | } |
661 | } | | 676 | } |
662 | | | 677 | |
663 | sub adjust_package_from_extracted_distfiles($) | | 678 | sub adjust_package_from_extracted_distfiles($) |
664 | { | | 679 | { |
665 | my ($url) = @_; | | 680 | my ($url) = @_; |
666 | | | 681 | |
667 | chomp($abs_wrkdir = `$make show-var VARNAME=WRKDIR`); | | 682 | chomp($abs_wrkdir = `$make show-var VARNAME=WRKDIR`); |
668 | | | 683 | |
669 | # | | 684 | # |
670 | # Determine the value of WRKSRC. | | 685 | # Determine the value of WRKSRC. |
671 | # | | 686 | # |
672 | my @files = (); | | 687 | my @files = (); |
673 | opendir(WRKDIR, $abs_wrkdir) or die; | | 688 | opendir(WRKDIR, $abs_wrkdir) or die; |
674 | while (defined(my $f = readdir(WRKDIR))) { | | 689 | while (defined(my $f = readdir(WRKDIR))) { |
675 | no if $] >= 5.018, warnings => "experimental::smartmatch"; | | 690 | no if $] >= 5.018, warnings => "experimental::smartmatch"; |
676 | given ($f) { | | 691 | given ($f) { |
677 | next when qr"^\."; | | 692 | next when qr"^\."; |
678 | next when "pax_global_header"; | | 693 | next when "pax_global_header"; |
679 | next when "package.xml"; | | 694 | next when "package.xml"; |
680 | next when qr".*\.gemspec"; | | 695 | next when qr".*\.gemspec"; |
681 | default { push(@files, $f) } | | 696 | default { push(@files, $f) } |
682 | } | | 697 | } |
683 | } | | 698 | } |
684 | closedir(WRKDIR); | | 699 | closedir(WRKDIR); |
685 | if (@files == 1) { | | 700 | if (@files == 1) { |
686 | if ($files[0] ne $distname) { | | 701 | if ($files[0] ne $distname) { |
687 | push(@build_vars, var("WRKSRC", "=", "\${WRKDIR}/$files[0]")); | | 702 | push(@build_vars, var("WRKSRC", "=", "\${WRKDIR}/$files[0]")); |
688 | } | | 703 | } |
689 | $abs_wrksrc = "$abs_wrkdir/$files[0]"; | | 704 | $abs_wrksrc = "$abs_wrkdir/$files[0]"; |
690 | } else { | | 705 | } else { |
691 | push(@build_vars, var("WRKSRC", "=", "\${WRKDIR}" . | | 706 | push(@build_vars, var("WRKSRC", "=", "\${WRKDIR}" . |
692 | ((@files > 1) ? " # More than one possibility -- please check manually." : ""))); | | 707 | ((@files > 1) ? " # More than one possibility -- please check manually." : ""))); |
693 | $abs_wrksrc = $abs_wrkdir; | | 708 | $abs_wrksrc = $abs_wrkdir; |
694 | } | | 709 | } |
695 | | | 710 | |
696 | chomp(@wrksrc_files = `cd "$abs_wrksrc" && find * -type f`); | | 711 | chomp(@wrksrc_files = `cd "$abs_wrksrc" && find * -type f`); |
697 | chomp(@wrksrc_dirs = `cd "$abs_wrksrc" && find * -type d`); | | 712 | chomp(@wrksrc_dirs = `cd "$abs_wrksrc" && find * -type d`); |
698 | | | 713 | |
699 | adjust_configure(); | | 714 | adjust_configure(); |
700 | adjust_cmake(); | | 715 | adjust_cmake(); |
701 | adjust_meson(); | | 716 | adjust_meson(); |
702 | adjust_gconf2_schemas(); | | 717 | adjust_gconf2_schemas(); |
703 | adjust_libtool(); | | 718 | adjust_libtool(); |
704 | adjust_perl_module(); | | 719 | adjust_perl_module(); |
705 | adjust_python_module(); | | 720 | adjust_python_module(); |
706 | adjust_cargo(); | | 721 | adjust_cargo(); |
707 | adjust_pkg_config(); | | 722 | adjust_pkg_config(); |
708 | adjust_po(); | | 723 | adjust_po(); |
709 | adjust_use_languages(); | | 724 | adjust_use_languages(); |
710 | | | 725 | |
711 | print("url2pkg> Adjusting the Makefile\n"); | | 726 | print("url2pkg> Adjusting the Makefile\n"); |
712 | | | 727 | |
713 | my $seen_marker = false; | | 728 | my $seen_marker = false; |
714 | my @lines; | | 729 | my @lines; |
715 | | | 730 | |
716 | open(MF1, "<", "Makefile") or die; | | 731 | open(MF1, "<", "Makefile") or die; |
717 | | | 732 | |
718 | # Copy the user-edited part of the Makefile. | | 733 | # Copy the user-edited part of the Makefile. |
719 | while (defined(my $line = <MF1>)) { | | 734 | while (defined(my $line = <MF1>)) { |
720 | chomp($line); | | 735 | chomp($line); |
721 | | | 736 | |
722 | if ($line =~ qr"^# url2pkg-marker\b") { | | 737 | if ($line =~ qr"^# url2pkg-marker\b") { |
723 | $seen_marker = true; | | 738 | $seen_marker = true; |
724 | last; | | 739 | last; |
725 | } | | 740 | } |
726 | push(@lines, $line); | | 741 | push(@lines, $line); |
727 | | | 742 | |
728 | if ($pkgname ne "" && $line =~ qr"^DISTNAME=(\t+)") { | | 743 | if ($pkgname ne "" && $line =~ qr"^DISTNAME=(\t+)") { |
729 | push(@lines, "PKGNAME=$1$pkgname"); | | 744 | push(@lines, "PKGNAME=$1$pkgname"); |
730 | } | | 745 | } |
731 | } | | 746 | } |
732 | if (!$seen_marker) { | | 747 | if (!$seen_marker) { |
733 | die("$0: ERROR: didn't find the url2pkg marker in the file.\n"); | | 748 | die("$0: ERROR: didn't find the url2pkg marker in the file.\n"); |
734 | } | | 749 | } |
735 | | | 750 | |
736 | if (@todos) { | | 751 | if (@todos) { |
737 | foreach my $todo (@todos) { | | 752 | foreach my $todo (@todos) { |
738 | push(@lines, "# TODO: $todo"); | | 753 | push(@lines, "# TODO: $todo"); |
739 | } | | 754 | } |
740 | push(@lines, ""); | | 755 | push(@lines, ""); |
741 | } | | 756 | } |
742 | | | 757 | |
743 | my @depend_vars; | | 758 | my @depend_vars; |
744 | push(@depend_vars, map { var("BUILD_DEPENDS", "+=", $_) } @build_depends); | | 759 | push(@depend_vars, map { var("BUILD_DEPENDS", "+=", $_) } @build_depends); |
745 | push(@depend_vars, map { var("DEPENDS", "+=", $_) } @depends); | | 760 | push(@depend_vars, map { var("DEPENDS", "+=", $_) } @depends); |
746 | push(@depend_vars, map { var("TEST_DEPENDS", "+=", $_) } @test_depends); | | 761 | push(@depend_vars, map { var("TEST_DEPENDS", "+=", $_) } @test_depends); |
747 | lines_add_vars(\@lines, \@depend_vars); | | 762 | lines_add_vars(\@lines, \@depend_vars); |
748 | | | 763 | |
749 | lines_add_vars(\@lines, \@build_vars); | | 764 | lines_add_vars(\@lines, \@build_vars); |
750 | lines_add_vars(\@lines, \@extra_vars); | | 765 | lines_add_vars(\@lines, \@extra_vars); |
751 | | | 766 | |
752 | push(@lines, @bl3_lines); | | 767 | push(@lines, @bl3_lines); |
753 | push(@lines, map { $_ = ".include \"$_\"" } @includes); | | 768 | push(@lines, map { $_ = ".include \"$_\"" } @includes); |
754 | | | 769 | |
755 | # Copy the rest of the user-edited part of the Makefile. | | 770 | # Copy the rest of the user-edited part of the Makefile. |
756 | while (defined(my $line = <MF1>)) { | | 771 | while (defined(my $line = <MF1>)) { |
757 | chomp($line); | | 772 | chomp($line); |
758 | push(@lines, $line); | | 773 | push(@lines, $line); |
759 | } | | 774 | } |
760 | | | 775 | |
761 | close(MF1); | | 776 | close(MF1); |
762 | | | 777 | |
763 | lines_append(\@lines, "CATEGORIES", join(" ", @categories)); | | 778 | lines_append(\@lines, "CATEGORIES", join(" ", @categories)); |
764 | | | 779 | |
765 | adjust_lines_python_module(\@lines, $url); | | 780 | adjust_lines_python_module(\@lines, $url); |
766 | | | 781 | |
767 | write_lines("Makefile", @lines); | | 782 | write_lines("Makefile", @lines); |
768 | | | 783 | |
769 | if ($regenerate_distinfo) { | | 784 | if ($regenerate_distinfo) { |
770 | make("distinfo"); | | 785 | make("distinfo"); |
771 | } | | 786 | } |
772 | } | | 787 | } |
773 | | | 788 | |
774 | sub main() { | | 789 | sub main() { |
775 | my $url; | | 790 | my $url; |
776 | | | 791 | |
777 | if (!-f "../../mk/bsd.pkg.mk") { | | 792 | if (!-f "../../mk/bsd.pkg.mk") { |
778 | die("ERROR: $0 must be run from a package directory (.../pkgsrc/category/package).\n"); | | 793 | die("ERROR: $0 must be run from a package directory (.../pkgsrc/category/package).\n"); |
779 | } | | 794 | } |
780 | | | 795 | |
781 | my @extract_cookie = <w*/.extract_done>; | | 796 | my @extract_cookie = <w*/.extract_done>; |
782 | if (scalar(@extract_cookie) == 0) { | | 797 | if (scalar(@extract_cookie) == 0) { |
783 | if (scalar(@ARGV) == 0) { | | 798 | if (scalar(@ARGV) == 0) { |
784 | print("URL: "); | | 799 | print("URL: "); |
785 | if (!defined($url = <STDIN>)) { | | 800 | if (!defined($url = <STDIN>)) { |
786 | print("\n"); | | 801 | print("\n"); |
787 | exit(0); | | 802 | exit(0); |
788 | } | | 803 | } |
789 | chomp($url); | | 804 | chomp($url); |
790 | } else { | | 805 | } else { |
791 | $url = shift(@ARGV); | | 806 | $url = shift(@ARGV); |
792 | } | | 807 | } |
793 | | | 808 | |
794 | generate_initial_package($url); | | 809 | generate_initial_package($url); |
795 | } else { | | 810 | } else { |
796 | chomp($distname = `$make show-var VARNAME=DISTNAME`); | | 811 | chomp($distname = `$make show-var VARNAME=DISTNAME`); |
797 | } | | 812 | } |
798 | | | 813 | |
799 | adjust_package_from_extracted_distfiles($url); | | 814 | adjust_package_from_extracted_distfiles($url); |
800 | | | 815 | |
801 | print("\n"); | | 816 | print("\n"); |
802 | print("Remember to run pkglint when you're done.\n"); | | 817 | print("Remember to run pkglint when you're done.\n"); |
803 | print("See ../../doc/pkgsrc.txt to get some help.\n"); | | 818 | print("See ../../doc/pkgsrc.txt to get some help.\n"); |
804 | print("\n"); | | 819 | print("\n"); |
805 | } | | 820 | } |
806 | | | 821 | |
807 | main() unless caller(); | | 822 | main() unless caller(); |