Sigh, try this patch instead that actually works on new ports as well.
On Thu, May 09, 2019 at 02:42:08PM -0700, Andrew Hewus Fresh wrote:
> This patch relies on the previous one to have the Makefile.orig actually
> exist. That's the one in the email with:
> Subject: portgen(1) copy old port when updating
>
> What this one does is that if we're updating a port (that is, the
> Makefile.orig from the previous patch exists) we will use that as the
> template to copy from which means that if the port has variables that
> aren't in the default template we will put the new values for them in
> those positions. It also knows about some important values that need to
> be copied over, for example the "EPOCH".
>
> Rather than rewrite this to make it do what I want, I instead stole the
> version I had previously written and have been using and then modified
> it to work with portgen. So although this is a "patch", good luck
> reading it. The original code is here:
>
> https://github.com/afresh1/openbsd-module-ports/blob/master/lib/OpenBSD/PackageModule/MakePort.pm#L80
>
> Comments, Questions, OK?
>
> Be careful, as because I haven't committed the previous patch, this one
> comes from git, based in /usr/ports/infrastructure, instead of cvs.
---
lib/OpenBSD/PortGen/Port.pm | 155 +++-
1 file changed, 101 insertions(+), 54 deletions(-)
diff --git a/lib/OpenBSD/PortGen/Port.pm b/lib/OpenBSD/PortGen/Port.pm
index 907728d..c8e6503 100644
--- a/lib/OpenBSD/PortGen/Port.pm
+++ b/lib/OpenBSD/PortGen/Port.pm
@@ -1,6 +1,7 @@
# $OpenBSD: Port.pm,v 1.5 2019/04/21 03:47:40 afresh1 Exp $
#
# Copyright (c) 2015 Giannis Tsaraias
+# Copyright (c) 2019 Andrew Hewus Fresh
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -210,77 +211,123 @@ sub name_new_port
return $name;
}
-sub write_makefile
+sub parse_makefile
{
- my $self = shift;
+ my ( $self, $path ) = @_;
- open my $tmpl, '<',
- ports_dir() . '/infrastructure/templates/Makefile.template'
- or die $!;
- open my $mk, '>', 'Makefile' or die $!;
+ return unless -e $path;
- my $output = "# \$OpenBSD\$\n";
- my %vars_found;
+ my @makefile;
- # such a mess, should fix
- while ( defined( my $line = <$tmpl> ) ) {
- my ( $value, $other_stuff );
+ my $parse = sub {
+ state $line = '';
+ $line .= shift;
+ return if /\\\n$/x;
- # copy MAINTAINER line as is
- if ( $line =~ /^MAINTAINER/ ) {
- $output .= $line and next;
+ if ( $line =~ /^
+ (? \#? ) \s*
+ (? [A-Z_]+ )
+ (? \s* \?? = )
+ (? \s* )
+ (? .*)
+ /xms ) {
+ my %line = %+;
+ my $spaces = delete $line{spaces};
+ $line{tabs} = $spaces =~ tr/\t/\t/;
+ $line{commented} = $line{comment} ? 1 : 0;
+
+ push @makefile, \%line;
+ } else {
+ chomp $line;
+ push @makefile, $line;
}
+ $line = '';
+ };
- if ( $line =~ /(^#?([A-Z_]+)\s+\??=\s+)/ ) {
- next unless defined $self->{$2};
- $vars_found{$2} = 1;
-
- ( $value, $other_stuff ) = ( $self->{$2}, $1 );
-
- $other_stuff =~ s/^#//;
- $other_stuff =~ s/(\?\?\?|$)/$value\n/;
-
- # handle cases where replacing '???' isn't enough
- if ( $other_stuff =~ /^PERMIT_PACKAGE_CDROM/ ) {
- $output .= "# $self->{license}\n";
- } elsif ( $other_stuff =~ /_DEPENDS/ ) {
- $other_stuff = "\n" . $other_stuff;
- } elsif ( $other_stuff =~ /^COMMENT/ ) {
- $output .= "# original: $self->{full_comment}\n"
- if $self->{full_comment};
- } elsif ( $other_stuff =~ /^WANTLIB/ ) {
- $other_stuff =~ s/=/+=/;
- }
+ open my $fh, '<', $path or croak("Couldn't open $path: $!");
+ $parse->($_) while <$fh>;
+ close $fh;
- $output .= $other_stuff;
- }
+ return @makefile;
+}
- $output .= $line if $line =~ /^\s+$/;
- }
+sub write_makefile
+{
+ my ( $self, $di ) = @_;
+
+ my %configs = %{$self};
+ my $license = delete $configs{license};
- # also write variables not found in the template
- my