Subject: Alternative PLIST expansion of libtool archives
To: None <tech-pkg@NetBSD.org>
From: Johnny C. Lam <jlam@NetBSD.org>
List: tech-pkg
Date: 09/08/2004 22:26:58
--C7zPtVaVf+AK4Oqc
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

I've attached a patch that contains an alternative implementation of
the highly excellent idea that Todd Vierling put forth about having
bsd.pkg.mk automatically expand libtool archive entries in PLIST into
the shared and static libraries that they represent.  The differences
between this implementation and the one that was committed are:

   (1) It uses the existing _PLIST_AWK_SCRIPT framework.

This is either good or bad depending on how one feels about the
_PLIST_AWK_SCRIPT framework :)

   (2) It's not required that the libtool archives be explicitly
       listed in LIBTOOL_LA_FILES in the package Makefiles.

The awk script fragment looks for files that end in ".la" and checks
that they're libtool archives before trying to extract the library
names from inside them.  I think that not needing to list files in
LIBTOOL_LA_FILES is a very good thing since we would only need to
record the files in the usual place (in the PLIST) instead of duplicating
the information in two separate places.

The patch adds a toggle, LIBTOOLIZE_PLIST, that defaults to "no".
After the 2004Q3 branch, we can fix up all the PLISTs and default
LIBTOOLIZE_PLIST to "yes" in a single commit.

Please review and comment.

	Thanks!

	-- Johnny Lam <jlam@NetBSD.org>

--C7zPtVaVf+AK4Oqc
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="plist_libtool.diff"

Index: bsd.pkg.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.mk,v
retrieving revision 1.1495
diff -u -r1.1495 bsd.pkg.mk
--- bsd.pkg.mk	1 Sep 2004 00:10:58 -0000	1.1495
+++ bsd.pkg.mk	8 Sep 2004 22:23:09 -0000
@@ -407,12 +407,7 @@
 CONFIGURE_ENV+=		LIBTOOL="${LIBTOOL} ${LIBTOOL_FLAGS}"
 MAKE_ENV+=		LIBTOOL="${LIBTOOL} ${LIBTOOL_FLAGS}"
 LIBTOOL_OVERRIDE?=	libtool */libtool */*/libtool
-.if defined(LIBTOOL_LA_FILES)
-_DUMP_LIBTOOL_LA_FILES=	${SH} ../../mk/scripts/transform-la ${PREFIX} ${LIBTOOL_LA_FILES}
-_FILTER_LIBTOOL_LA_FILES=| ${GREP} -vxF `${_DUMP_LIBTOOL_LA_FILES} | ${SED} -e 's,^,-e ,'`
 .endif
-.endif
-_DUMP_LIBTOOL_LA_FILES?=${TRUE}
 
 .if defined(BUILD_USES_MSGFMT) && \
     (!exists(/usr/bin/msgfmt) || ${_USE_GNU_GETTEXT} == "yes")
@@ -4925,6 +4920,44 @@
 .  endif
 .endif
 
+# plist awk pattern-action statement to expand libtool archives into
+# shared and/or static libraries.
+#
+LIBTOOLIZE_PLIST?=	no
+.if ${PLIST_TYPE} == "dynamic"
+_PLIST_AWK_LIBTOOL?=	# empty
+.else
+.  if !empty(LIBTOOLIZE_PLIST:M[yY][eE][sS])
+_PLIST_LIBTOOL_SUBSCRIPT=						\
+	"( lapath=\"" lapath "\"; "					\
+	"  lafile=\"" lafile "\"; "					\
+	"  ladir=\"" ladir "\"; "					\
+	"  if ${TEST} -r \"$$lapath\" && "				\
+	"     ${GREP} -q \"libtool library file\" \"$$lapath\"; then "	\
+	"	. \"$$lapath\"; "					\
+	"	if ${TEST} \"$installed\" = \"no\"; then "		\
+	"		${ECHO} \"$lapath was not properly installed\" >&2; " \
+	"		exit 1; "					\
+	"	fi; "							\
+	"	for lib in $$library_names $$old_library; do "		\
+	"		${ECHO} \"$$ladir/$$lib\"; "			\
+	"	done; "							\
+	"  else "							\
+	"	${ECHO} \"Cannot read libtool archive $$lapath\" >&2; "	\
+	"	exit 1; "						\
+	"  fi; "							\
+	") | ${SORT} -u"
+_PLIST_AWK_LIBTOOL?=							\
+/\.la$$/ {								\
+	lapath = "${PREFIX}/" $$0;					\
+	lafile = $$0;							\
+	ladir = $$0;							\
+	sub("/[^/]*\.la$$", "", ladir);					\
+	system(${_PLIST_LIBTOOL_SUBSCRIPT});				\
+}
+.  endif
+.endif
+
 # _PLIST_AWK_SCRIPT hold the complete awk script for plist target.
 #
 _PLIST_AWK_SCRIPT=	'
@@ -4934,8 +4967,10 @@
 _PLIST_AWK_SCRIPT+=	${_PLIST_AWK_SUBST}
 # Generated entries for info files
 .if !empty(INFO_FILES)
-_PLIST_AWK_SCRIPT+=    ${_PLIST_AWK_INFO}
+_PLIST_AWK_SCRIPT+=	${_PLIST_AWK_INFO}
 .endif
+# Expand libtool archives
+_PLIST_AWK_SCRIPT+=	${_PLIST_AWK_LIBTOOL}
 # Strip the '.gz' suffixes on man entries
 _PLIST_AWK_SCRIPT+=	${_PLIST_AWK_STRIP_MANZ}
 # Deal with MANINSTALL and man entries
@@ -4979,9 +5014,7 @@
 		${SED} -e "s|^${PREFIX}/|@unexec ${RMDIR} -p %D/|"	\
 		       -e "s,$$, 2>/dev/null || ${TRUE},";
 .else
-_GENERATE_PLIST=	${_DUMP_LIBTOOL_LA_FILES}; \
-			${CAT} ${_PLIST_SRC}; \
-			${GENERATE_PLIST}
+_GENERATE_PLIST=	${CAT} ${_PLIST_SRC}; ${GENERATE_PLIST}
 .endif
 
 .PHONY: plist

--C7zPtVaVf+AK4Oqc--