From naddy@unix-ag.uni-kl.de Thu Oct  7 07:40:32 1999
Return-Path: <naddy@unix-ag.uni-kl.de>
Received: from news.uni-kl.de (news.uni-kl.de [131.246.137.51])
	by hub.freebsd.org (Postfix) with SMTP id 9390315182
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  7 Oct 1999 07:40:24 -0700 (PDT)
	(envelope-from naddy@unix-ag.uni-kl.de)
Received: from sushi.unix-ag.uni-kl.de
           ( root@sushi.unix-ag.uni-kl.de [131.246.89.13] ) by news.uni-kl.de
          id aa24603 for <FreeBSD-gnats-submit@freebsd.org>;
          7 Oct 1999 16:39 MESZ
Received: from fettuccini.unix-ag.uni-kl.de (fettuccini.unix-ag.uni-kl.de [131.246.89.27])
	by sushi.unix-ag.uni-kl.de (8.9.1a/8.9.1) with ESMTP id QAA21672
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 7 Oct 1999 16:37:37 +0200
Received: (from naddy@localhost)
	by fettuccini.unix-ag.uni-kl.de (8.9.3/8.9.3) id QAA25375;
	Thu, 7 Oct 1999 16:37:45 +0200 (CEST)
	(envelope-from naddy)
Message-Id: <199910071437.QAA25375@fettuccini.unix-ag.uni-kl.de>
Date: Thu, 7 Oct 1999 16:37:45 +0200 (CEST)
From: Christian Weisgerber <naddy@unix-ag.uni-kl.de>
Reply-To: naddy@unix-ag.uni-kl.de
To: FreeBSD-gnats-submit@freebsd.org
Subject: Patch: bsd.port.mk: add plist target
X-Send-Pr-Version: 3.2

>Number:         14182
>Category:       ports
>Synopsis:       Patch: bsd.port.mk: add plist target
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    portmgr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct  7 07:50:00 PDT 1999
>Closed-Date:    Sat Feb 14 22:09:42 PST 2004
>Last-Modified:  Sat Feb 14 22:09:42 PST 2004
>Originator:     Christian Weisgerber
>Release:        FreeBSD 4.0-CURRENT i386
>Organization:
Unix-AG, Uni Kaiserslautern
>Environment:

n/a

>Description:

The appended patch adds support for a target "plist" to bsd.port.mk.
"make plist" will assist in creating the pkg/PLIST file for a new
port. A manual perusal of the generated file is still required.

This patch carries over work done by Marc Espie <espie@openbsd.org>
on the OpenBSD port system.

The modifications to bsd.port.mk are minor; an additional cookie
is introduced along with a "plist" target that calls Marc Espie's
make-plist Perl script. That script again required only small
changes. The main difference to OpenBSD is that they include the
man pages in the PLIST. We skip ${MANPREFIX}/man in the find.

>How-To-Repeat:

n/a

>Fix:

--- Mk/bsd.port.mk.orig	Wed Sep 22 06:12:55 1999
+++ Mk/bsd.port.mk	Wed Sep 22 19:05:21 1999
@@ -675,6 +675,7 @@
 # there is no way to refer to them cleanly from within the macro AFAIK.
 EXTRACT_COOKIE?=	${WRKDIR}/.extract_done
 CONFIGURE_COOKIE?=	${WRKDIR}/.configure_done
+INSTALL_PRE_COOKIE?=${WRKDIR}/.install_started
 INSTALL_COOKIE?=	${WRKDIR}/.install_done
 BUILD_COOKIE?=		${WRKDIR}/.build_done
 PATCH_COOKIE?=		${WRKDIR}/.patch_done
@@ -1771,7 +1772,8 @@
 .endif
 	@if [ -d ${PREFIX}/info -a ! -f ${PREFIX}/info/dir -a -f /usr/share/info/dir ]; then \
 	  ${SED} -ne '1,/Menu:/p' /usr/share/info/dir > ${PREFIX}/info/dir; \
-	 fi
+	fi
+	@touch ${INSTALL_PRE_COOKIE}
 .endif
 	@cd ${.CURDIR} && ${MAKE} ${__softMAKEFLAGS} ${.TARGET:S/^real-/pre-/}
 	@if [ -f ${SCRIPTDIR}/${.TARGET:S/^real-/pre-/} ]; then \
@@ -1947,7 +1949,7 @@
 
 .if !target(reinstall)
 reinstall:
-	@${RM} -f ${INSTALL_COOKIE} ${PACKAGE_COOKIE}
+	@${RM} -f ${INSTALL_PRE_COOKIE} ${INSTALL_COOKIE} ${PACKAGE_COOKIE}
 	@DEPENDS_TARGET="${DEPENDS_TARGET}" ${MAKE} install
 .endif
 
@@ -2117,6 +2119,18 @@
 			exit 1; \
 		  fi) ; \
 	fi
+.endif
+
+# Packing list utilities.  This generates a packing list from a recently
+# installed port.  Not perfect, but pretty close.  The generated file
+# will have to have some tweaks done by hand.
+#
+.if !target(plist)
+plist: install
+	@PREFIX=${PREFIX} LDCONFIG="${LDCONFIG}" MTREE_FILE=${MTREE_FILE} \
+	INSTALL_PRE_COOKIE=${INSTALL_PRE_COOKIE} \
+	SETENV="${SETENV}" MANPREFIX=${MANPREFIX} \
+	${PERL} ${PORTSDIR}/Tools/make-plist > ${PLIST}-auto
 .endif
 
 ################################################################
--- /dev/null	Wed Sep 22 19:07:42 1999
+++ Tools/make-plist	Wed Sep 22 19:00:03 1999
@@ -0,0 +1,163 @@
+#!/usr/bin/perl -w
+
+# $FreeBSD$
+# $OpenBSD: make-plist,v 1.2 1999/07/29 14:01:12 espie Exp $
+
+#  Copyright (c) 1999 Marc Espie
+# 
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions
+#  are met:
+#  1. Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#  2. Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#  3. All advertising materials mentioning features or use of this software
+#     must display the following acknowledgement:
+# 	This product includes software developed by the OpenBSD project
+#
+#  4. Neither the name of the OpenBSD project nor the names of its contributors
+#     may be used to endorse or promote products derived from this software
+#     without specific prior written permission.
+# 
+#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+#  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
+#  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+#  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+#  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+#  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+#  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+#  SUCH DAMAGE.
+# 
+
+
+use strict;
+
+
+use File::Find;
+
+my (%newdir, %occupied, %ldconfig, %infodir, @files);
+
+# compare all files against this date
+my $date = (stat $ENV{INSTALL_PRE_COOKIE})[10];
+
+# prefix to remove from everything
+my $base = $ENV{PREFIX};
+
+# skip man pages
+my $manprefix = "$ENV{MANPREFIX}/man";
+
+
+# read an mtree file, and produce the corresponding directory hierarchy
+sub parse_mtree {
+	# start under current PREFIX, usually
+	my $current = shift;
+	local(*FILE);
+	my %mtree;
+	open FILE, $ENV{MTREE_FILE};
+	while(<FILE>) {
+		chomp;
+		s/^\s*//;
+		next if /^\#/ || /^\//;
+		s/\s.*$//;
+		next if /^$/;
+		if ($_ eq '..') {
+			$current =~ s|/[^/]*$||;
+			next;
+		} else {
+			$current.="/$_";
+		}
+		$_ = $current;
+		while (s|/\./|/|)	{}
+		$mtree{$_} = 1;
+	}
+	close FILE;
+	return \%mtree;
+}
+
+sub strip {
+	local($_) = shift;
+	s|^\Q$base\E/||;
+	return $_;
+}
+
+sub add_info {
+	my ($header, $infodir) = @_;
+	for my $d (sort (keys %$infodir) ) {
+		for my $f (sort @{$infodir->{$d}}) {
+			my $d2 = strip($d);
+			print "$header --info-dir=\%D/$d2 \%D/$d2/$f\n";
+		}
+	}
+}
+
+
+# recursive traversal: mark specific `info' dirs, `ldconfig' dirs,
+# and potentially modified dirs
+
+find(
+	sub {
+		if ($File::Find::dir eq $manprefix) {
+			$File::Find::prune = 1;
+			return;
+		}
+		my $cdate = (lstat $_)[10];
+		if ($cdate >= $date) {
+			if (-d _) {
+				$newdir{$File::Find::name} = 1;
+			} else {
+				push(@files, $File::Find::name);
+				if (/\.so\.\d+(\.\d+)?$/) {
+					$ldconfig{$File::Find::dir} = 1;
+				}
+				if (/\.info$/) {
+					my $d = $File::Find::dir;
+					$infodir{$d} = [] unless defined $infodir{$d};
+					push(@{$infodir{$d}}, $_);
+				}
+			}
+		} else {
+			$occupied{$File::Find::dir} = 1;
+		}
+	}, $base);
+
+
+# occupied marks a dir that was already there... 
+# so all parents had to be around too
+for my $d (keys %occupied) {
+	while ($d ne '') {
+		undef $newdir{$d} if defined $newdir{$d};
+		$d =~ s|/.*?/?$||;
+	}
+}
+
+# make sure mtree is removed 
+my $mtree = parse_mtree($base);
+for my $d (keys %$mtree) {
+	undef $newdir{$d}
+}
+
+add_info('@unexec install-info --delete', \%infodir);
+
+for my $f (sort @files) {
+	print strip($f), "\n" unless ($f =~ m|/dir$|) && (defined $infodir{$`});
+}
+
+for my $d (sort { $b cmp $a } (grep { $newdir{$_} } (keys %newdir) ) ) {
+	print "\@dirrm ",strip($d), "\n";
+}
+	
+my $setenv = $ENV{SETENV};
+my $ldconfig = $ENV{LDCONFIG};
+
+for my $d (sort (keys %ldconfig)) {
+	print "\@exec $setenv OBJFORMAT=%%PORTOBJFORMAT%% $ldconfig -m %D/", strip($d), "\n";
+	print "\@unexec $setenv OBJFORMAT=%%PORTOBJFORMAT%% $ldconfig -R\n";
+}
+	
+add_info('@exec install-info', \%infodir);
+

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports->asami  
Responsible-Changed-By: cpiazza 
Responsible-Changed-When: Thu Oct 7 11:04:02 PDT 1999 
Responsible-Changed-Why:  
Over to maintainer 
Responsible-Changed-From-To: asami->portmgr 
Responsible-Changed-By: will 
Responsible-Changed-When: Wed Apr 4 01:06:55 PDT 2001 
Responsible-Changed-Why:  
Over to new maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=14182 

From: Ernst de Haan <ernst@jollem.com>
To: freebsd-gnats-submit@FreeBSD.org, naddy@unix-ag.uni-kl.de
Cc:  
Subject: Re: ports/14182: Patch: bsd.port.mk: add plist target
Date: Wed, 16 May 2001 14:14:01 +0200

 This "plist" make target sounds like a very good idea. Perhaps I should look 
 into the patch, make sure it works with the current bsd.port.mk and see if it 
 works correctly.
 
 Why wasn't this patch committed back in '99? I wrote the plist-builder 
 utility myself ( http://www.FreeBSD.org/cgi/query-pr.cgi?pr=25219 ) but I 
 would prefer having a target in the make file, ofcourse.
 
 Any comments?
 
 /Ernst
 

From: Ernst de Haan <znerd@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org, naddy@unix-ag.uni-kl.de
Cc: ports@FreeBSD.org
Subject: Re: ports/14182: Patch: bsd.port.mk: add plist target
Date: Tue, 19 Mar 2002 20:47:00 +0100

 This idea of a 'plist' target in bsd.port.mk sounds like a very good idea to 
 me. Anyone else have comments on it? Why hasn't this been committed yet?
 
 /Ernst
 
State-Changed-From-To: open->closed 
State-Changed-By: marcus 
State-Changed-When: Sat Feb 14 22:09:19 PST 2004 
State-Changed-Why:  
This has been taken care of in PLIST_FILES and PLIST_DIRS. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=14182 
>Unformatted:
