| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | #! @PERL5@ | | 1 | #! @PERL5@ |
2 | # $NetBSD: url2pkg.pl,v 1.59 2019/08/18 16:09:01 rillig Exp $ | | 2 | # $NetBSD: url2pkg.pl,v 1.60 2019/08/18 16:18:04 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. |
| @@ -115,81 +115,81 @@ sub write_lines($@) { | | | @@ -115,81 +115,81 @@ sub write_lines($@) { |
115 | print F "$line\n"; | | 115 | print F "$line\n"; |
116 | } | | 116 | } |
117 | close(F) or die; | | 117 | close(F) or die; |
118 | rename("$filename.tmp", $filename) or die; | | 118 | rename("$filename.tmp", $filename) or die; |
119 | } | | 119 | } |
120 | | | 120 | |
121 | sub find_package($) { | | 121 | sub find_package($) { |
122 | my ($pkgbase) = @_; | | 122 | my ($pkgbase) = @_; |
123 | | | 123 | |
124 | my @candidates = <../../*/$pkgbase>; | | 124 | my @candidates = <../../*/$pkgbase>; |
125 | return scalar(@candidates) == 1 ? $candidates[0] : ""; | | 125 | return scalar(@candidates) == 1 ? $candidates[0] : ""; |
126 | } | | 126 | } |
127 | | | 127 | |
128 | sub update_var_set($$$) { | | 128 | sub lines_set($$$) { |
129 | my ($lines, $varname, $new_value) = @_; | | 129 | my ($lines, $varname, $new_value) = @_; |
130 | | | 130 | |
131 | my $i = 0; | | 131 | my $i = 0; |
132 | foreach my $line (@$lines) { | | 132 | foreach my $line (@$lines) { |
133 | if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { | | 133 | if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { |
134 | my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); | | 134 | my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); |
135 | | | 135 | |
136 | $lines->[$i] = "$varname$op$indent$new_value$space_after_value$comment"; | | 136 | $lines->[$i] = "$varname$op$indent$new_value$space_after_value$comment"; |
137 | return true; | | 137 | return true; |
138 | } | | 138 | } |
139 | $i++; | | 139 | $i++; |
140 | } | | 140 | } |
141 | | | 141 | |
142 | return false; | | 142 | return false; |
143 | } | | 143 | } |
144 | | | 144 | |
145 | # appends the given value to the variable assignment. | | 145 | # appends the given value to the variable assignment. |
146 | sub update_var_append($$$) { | | 146 | sub lines_append($$$) { |
147 | my ($lines, $varname, $value) = @_; | | 147 | my ($lines, $varname, $value) = @_; |
148 | | | 148 | |
149 | return if $value eq ""; | | 149 | return if $value eq ""; |
150 | | | 150 | |
151 | my $i = 0; | | 151 | my $i = 0; |
152 | foreach my $line (@$lines) { | | 152 | foreach my $line (@$lines) { |
153 | if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*)(#.*|)$") { | | 153 | if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*)(#.*|)$") { |
154 | my ($op, $indent, $old_value, $comment) = ($1, $2, $3, $4); | | 154 | my ($op, $indent, $old_value, $comment) = ($1, $2, $3, $4); |
155 | | | 155 | |
156 | my $before = $old_value =~ qr"\S$" ? " " : ""; | | 156 | my $before = $old_value =~ qr"\S$" ? " " : ""; |
157 | my $after = $comment eq "" ? "" : " "; | | 157 | my $after = $comment eq "" ? "" : " "; |
158 | $lines->[$i] = "$varname$op$indent$old_value$before$value$after$comment"; | | 158 | $lines->[$i] = "$varname$op$indent$old_value$before$value$after$comment"; |
159 | return true; | | 159 | return true; |
160 | } | | 160 | } |
161 | $i++; | | 161 | $i++; |
162 | } | | 162 | } |
163 | | | 163 | |
164 | return false; | | 164 | return false; |
165 | } | | 165 | } |
166 | | | 166 | |
167 | sub update_var_remove($$) { | | 167 | sub lines_remove($$) { |
168 | my ($lines, $varname) = @_; | | 168 | my ($lines, $varname) = @_; |
169 | | | 169 | |
170 | my $i = 0; | | 170 | my $i = 0; |
171 | foreach my $line (@$lines) { | | 171 | foreach my $line (@$lines) { |
172 | if ($line =~ qr"^\Q$varname\E(\+?=)") { | | 172 | if ($line =~ qr"^\Q$varname\E(\+?=)") { |
173 | splice(@$lines, $i, 1); | | 173 | splice(@$lines, $i, 1); |
174 | return true; | | 174 | return true; |
175 | } | | 175 | } |
176 | $i++; | | 176 | $i++; |
177 | } | | 177 | } |
178 | | | 178 | |
179 | return false; | | 179 | return false; |
180 | } | | 180 | } |
181 | | | 181 | |
182 | sub update_var_remove_if($$$) { | | 182 | sub lines_remove_if($$$) { |
183 | my ($lines, $varname, $expected_value) = @_; | | 183 | my ($lines, $varname, $expected_value) = @_; |
184 | | | 184 | |
185 | my $i = 0; | | 185 | my $i = 0; |
186 | foreach my $line (@$lines) { | | 186 | foreach my $line (@$lines) { |
187 | if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { | | 187 | if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { |
188 | my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); | | 188 | my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); |
189 | | | 189 | |
190 | if ($old_value eq $expected_value) { | | 190 | if ($old_value eq $expected_value) { |
191 | splice(@$lines, $i, 1); | | 191 | splice(@$lines, $i, 1); |
192 | return true; | | 192 | return true; |
193 | } | | 193 | } |
194 | } | | 194 | } |
195 | $i++; | | 195 | $i++; |
| @@ -632,32 +632,32 @@ sub adjust_lines_python_module($$) { | | | @@ -632,32 +632,32 @@ sub adjust_lines_python_module($$) { |
632 | my ($varname, $op, $indent, $value, $space_after_value, $comment) = ($1, $2, $3, $4, $5, $6); | | 632 | my ($varname, $op, $indent, $value, $space_after_value, $comment) = ($1, $2, $3, $4, $5, $6); |
633 | | | 633 | |
634 | if ($op eq "=") { | | 634 | if ($op eq "=") { |
635 | $old{$varname} = $value; | | 635 | $old{$varname} = $value; |
636 | } | | 636 | } |
637 | } | | 637 | } |
638 | } | | 638 | } |
639 | | | 639 | |
640 | my $pkgbase = $old{"GITHUB_PROJECT"}; | | 640 | my $pkgbase = $old{"GITHUB_PROJECT"}; |
641 | my $pkgbase1 = substr($pkgbase, 0, 1); | | 641 | my $pkgbase1 = substr($pkgbase, 0, 1); |
642 | my $pkgversion_norev = $old{"DISTNAME"} =~ s/^v//r; | | 642 | my $pkgversion_norev = $old{"DISTNAME"} =~ s/^v//r; |
643 | | | 643 | |
644 | my @tx_lines = @$lines; | | 644 | my @tx_lines = @$lines; |
645 | if (update_var_remove(\@tx_lines, "GITHUB_PROJECT") | | 645 | if (lines_remove(\@tx_lines, "GITHUB_PROJECT") |
646 | && update_var_set(\@tx_lines, "DISTNAME", "$pkgbase-$pkgversion_norev") | | 646 | && lines_set(\@tx_lines, "DISTNAME", "$pkgbase-$pkgversion_norev") |
647 | && update_var_set(\@tx_lines, "PKGNAME", "\${PYPKGPREFIX}-\${DISTNAME}") | | 647 | && lines_set(\@tx_lines, "PKGNAME", "\${PYPKGPREFIX}-\${DISTNAME}") |
648 | && update_var_set(\@tx_lines, "MASTER_SITES", "\${MASTER_SITE_PYPI:=$pkgbase1/$pkgbase/}") | | 648 | && lines_set(\@tx_lines, "MASTER_SITES", "\${MASTER_SITE_PYPI:=$pkgbase1/$pkgbase/}") |
649 | && update_var_remove(\@tx_lines, "DIST_SUBDIR") | | 649 | && lines_remove(\@tx_lines, "DIST_SUBDIR") |
650 | && (update_var_remove_if(\@tx_lines, "EXTRACT_SUFX", ".zip") || true)) { | | 650 | && (lines_remove_if(\@tx_lines, "EXTRACT_SUFX", ".zip") || true)) { |
651 | | | 651 | |
652 | @$lines = @tx_lines; | | 652 | @$lines = @tx_lines; |
653 | $regenerate_distinfo = true | | 653 | $regenerate_distinfo = true |
654 | } | | 654 | } |
655 | } | | 655 | } |
656 | | | 656 | |
657 | sub adjust_package_from_extracted_distfiles($) | | 657 | sub adjust_package_from_extracted_distfiles($) |
658 | { | | 658 | { |
659 | my ($url) = @_; | | 659 | my ($url) = @_; |
660 | | | 660 | |
661 | chomp($abs_wrkdir = `$make show-var VARNAME=WRKDIR`); | | 661 | chomp($abs_wrkdir = `$make show-var VARNAME=WRKDIR`); |
662 | | | 662 | |
663 | # | | 663 | # |
| @@ -744,27 +744,27 @@ sub adjust_package_from_extracted_distfi | | | @@ -744,27 +744,27 @@ sub adjust_package_from_extracted_distfi |
744 | add_section(\@lines, \@extra_vars); | | 744 | add_section(\@lines, \@extra_vars); |
745 | | | 745 | |
746 | push(@lines, @bl3_lines); | | 746 | push(@lines, @bl3_lines); |
747 | push(@lines, map { $_ = ".include \"$_\"" } @includes); | | 747 | push(@lines, map { $_ = ".include \"$_\"" } @includes); |
748 | | | 748 | |
749 | # Copy the rest of the user-edited part of the Makefile. | | 749 | # Copy the rest of the user-edited part of the Makefile. |
750 | while (defined(my $line = <MF1>)) { | | 750 | while (defined(my $line = <MF1>)) { |
751 | chomp($line); | | 751 | chomp($line); |
752 | push(@lines, $line); | | 752 | push(@lines, $line); |
753 | } | | 753 | } |
754 | | | 754 | |
755 | close(MF1); | | 755 | close(MF1); |
756 | | | 756 | |
757 | update_var_append(\@lines, "CATEGORIES", join(" ", @categories)); | | 757 | lines_append(\@lines, "CATEGORIES", join(" ", @categories)); |
758 | | | 758 | |
759 | adjust_lines_python_module(\@lines, $url); | | 759 | adjust_lines_python_module(\@lines, $url); |
760 | | | 760 | |
761 | write_lines("Makefile", @lines); | | 761 | write_lines("Makefile", @lines); |
762 | | | 762 | |
763 | if ($regenerate_distinfo) { | | 763 | if ($regenerate_distinfo) { |
764 | make("distinfo"); | | 764 | make("distinfo"); |
765 | } | | 765 | } |
766 | } | | 766 | } |
767 | | | 767 | |
768 | sub main() { | | 768 | sub main() { |
769 | my $url; | | 769 | my $url; |
770 | | | 770 | |