Sun Apr 8 20:13:55 2018 UTC ()
pkgtools/url2pkg: refactor variable alignment code

The new code is more expressive and uses fewer magic numbers.


(rillig)
diff -r1.87 -r1.88 pkgsrc/pkgtools/url2pkg/Makefile
diff -r1.35 -r1.36 pkgsrc/pkgtools/url2pkg/files/url2pkg.pl

cvs diff -r1.87 -r1.88 pkgsrc/pkgtools/url2pkg/Makefile (expand / switch to unified diff)

--- pkgsrc/pkgtools/url2pkg/Makefile 2018/01/07 11:20:18 1.87
+++ pkgsrc/pkgtools/url2pkg/Makefile 2018/04/08 20:13:54 1.88
@@ -1,37 +1,38 @@ @@ -1,37 +1,38 @@
1# $NetBSD: Makefile,v 1.87 2018/01/07 11:20:18 rillig Exp $ 1# $NetBSD: Makefile,v 1.88 2018/04/08 20:13:54 rillig Exp $
2 2
3PKGNAME= url2pkg-2.29 3PKGNAME= url2pkg-2.29
4CATEGORIES= pkgtools 4CATEGORIES= pkgtools
5 5
6MAINTAINER= pkgsrc-users@NetBSD.org 6MAINTAINER= pkgsrc-users@NetBSD.org
7HOMEPAGE= http://www.NetBSD.org/docs/pkgsrc/creating.html 7HOMEPAGE= http://www.NetBSD.org/docs/pkgsrc/creating.html
8COMMENT= Tool to automate initial steps in building a package 8COMMENT= Tool to automate initial steps in building a package
9LICENSE= original-bsd 9LICENSE= original-bsd
10 10
11WRKSRC= ${WRKDIR} 11WRKSRC= ${WRKDIR}
12NO_CHECKSUM= yes 12NO_CHECKSUM= yes
13NO_BUILD= yes 13NO_BUILD= yes
14USE_LANGUAGES= # none 14USE_LANGUAGES= # none
15USE_TOOLS+= perl:run 15USE_TOOLS+= perl:run
16AUTO_MKDIRS= yes 16AUTO_MKDIRS= yes
17 17
18do-extract: 18do-extract:
19 cd ${FILESDIR} && cp *.pl *.pm ${WRKSRC}/ 19 cd ${FILESDIR} && cp *.pl *.pm ${WRKSRC}/
20 20
21.include "../../mk/bsd.prefs.mk" 21.include "../../mk/bsd.prefs.mk"
22 22
23SUBST_CLASSES+= up 23SUBST_CLASSES+= up
24SUBST_STAGE.up= do-configure 24SUBST_STAGE.up= do-configure
 25SUBST_MESSAGE.up= Replacing variable placeholders
25SUBST_FILES.up= url2pkg.pl MakeMaker.pm 26SUBST_FILES.up= url2pkg.pl MakeMaker.pm
26SUBST_SED.up= -e 's,@MAKE@,'${MAKE:Q}',g' 27SUBST_SED.up= -e 's,@MAKE@,'${MAKE:Q}',g'
27SUBST_SED.up+= -e 's,@PERL@,${PERL5},g' 28SUBST_SED.up+= -e 's,@PERL@,${PERL5},g'
28SUBST_SED.up+= -e 's,@PERLLIBDIR@,${PREFIX}/lib/url2pkg,g' 29SUBST_SED.up+= -e 's,@PERLLIBDIR@,${PREFIX}/lib/url2pkg,g'
29.if defined(BATCH) 30.if defined(BATCH)
30SUBST_SED.up+= -e 's,@PKGSRCDIR@,/usr/pkgsrc,g' 31SUBST_SED.up+= -e 's,@PKGSRCDIR@,/usr/pkgsrc,g'
31.else 32.else
32SUBST_SED.up+= -e 's,@PKGSRCDIR@,${PKGSRCDIR},g' 33SUBST_SED.up+= -e 's,@PKGSRCDIR@,${PKGSRCDIR},g'
33.endif 34.endif
34 35
35do-install: 36do-install:
36 ${INSTALL_SCRIPT} ${WRKSRC}/url2pkg.pl ${DESTDIR}${PREFIX}/bin/url2pkg 37 ${INSTALL_SCRIPT} ${WRKSRC}/url2pkg.pl ${DESTDIR}${PREFIX}/bin/url2pkg
37 ${INSTALL_MAN} ${FILESDIR}/url2pkg.8 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man8 38 ${INSTALL_MAN} ${FILESDIR}/url2pkg.8 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man8

cvs diff -r1.35 -r1.36 pkgsrc/pkgtools/url2pkg/files/Attic/url2pkg.pl (expand / switch to unified diff)

--- pkgsrc/pkgtools/url2pkg/files/Attic/url2pkg.pl 2018/01/07 11:20:18 1.35
+++ pkgsrc/pkgtools/url2pkg/files/Attic/url2pkg.pl 2018/04/08 20:13:55 1.36
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1#! @PERL@ 1#! @PERL@
2# $NetBSD: url2pkg.pl,v 1.35 2018/01/07 11:20:18 rillig Exp $ 2# $NetBSD: url2pkg.pl,v 1.36 2018/04/08 20:13: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.
@@ -66,35 +66,35 @@ sub get_maintainer() { @@ -66,35 +66,35 @@ sub get_maintainer() {
66 66
67 return $ENV{"PKGMAINTAINER"} || $ENV{"REPLYTO"} || "INSERT_YOUR_MAIL_ADDRESS_HERE"; 67 return $ENV{"PKGMAINTAINER"} || $ENV{"REPLYTO"} || "INSERT_YOUR_MAIL_ADDRESS_HERE";
68} 68}
69 69
70sub print_section($$) { 70sub print_section($$) {
71 my ($f, $vars) = @_; 71 my ($f, $vars) = @_;
72 72
73 if (scalar(@{$vars}) == 0) { 73 if (scalar(@{$vars}) == 0) {
74 return; 74 return;
75 } 75 }
76 76
77 my $width = 0; 77 my $width = 0;
78 foreach my $var (@{$vars}) { 78 foreach my $var (@{$vars}) {
79 my $len = length($var->[0]); 79 my $varname = $var->[0];
 80 my $len = (length("$varname= ") + 7) & -8;
80 $width = ($len > $width) ? $len : $width; 81 $width = ($len > $width) ? $len : $width;
81 } 82 }
82 83
83 foreach my $var (@{$vars}) { 84 foreach my $var (@{$vars}) {
84 my $len = length($var->[0]) + 1; 85 my ($varname, $varvalue) = @$var;
85 my $adjlen = (($width + 1 + 1) + 7) &-8; 86 my $ntabs = ($width - length("$varname=") + 7) / 8;
86 my $ntabs = (7 + $adjlen - $len) / 8; 87 printf $f ("%s=%s%s\n", $varname, "\t" x $ntabs, $varvalue);
87 printf $f ("%s=%s%s\n", $var->[0], "\t" x $ntabs, $var->[1]); 
88 } 88 }
89 printf $f ("\n"); 89 printf $f ("\n");
90} 90}
91 91
92# The following magic_* subroutines are called after the distfiles have 92# The following magic_* subroutines are called after the distfiles have
93# been downloaded and extracted. They inspect the extracted files 93# been downloaded and extracted. They inspect the extracted files
94# to automatically define some variables in the package Makefile. 94# to automatically define some variables in the package Makefile.
95# 95#
96# The following variables may be used in the magic_* subroutines: 96# The following variables may be used in the magic_* subroutines:
97# 97#
98# $distname 98# $distname
99# contains the package name, including the version number. 99# contains the package name, including the version number.
100# $abs_wrkdir 100# $abs_wrkdir