summaryrefslogtreecommitdiff
path: root/mk/plist/shlib-dylib.awk
diff options
context:
space:
mode:
authorjlam <jlam@pkgsrc.org>2006-01-12 23:43:56 +0000
committerjlam <jlam@pkgsrc.org>2006-01-12 23:43:56 +0000
commit8e0e10d3faa21afcadcb62ad06e910bae8750a48 (patch)
tree549e889f813ac3835ae3b1d7708def459c235461 /mk/plist/shlib-dylib.awk
parent30e5711ea4afb02f54e4eeba5cf1abc88bbaec78 (diff)
downloadpkgsrc-8e0e10d3faa21afcadcb62ad06e910bae8750a48.tar.gz
Initial commit of a new module that encapsulates all of the code
for manipulating PLISTs. This module is not used by default pending more widespread testing -- currently the variable _USE_PLIST_MODULE must be defined in /etc/mk.conf to enable its use. The main features of the new PLIST module are: (1) Splits out the PLIST-handling code from bsd.pkg.mk into a separate "plist" module. (2) Splits out giant, multi-line awk scripts stored in make variables into separate awk scripts that may be joined together to post-process PLISTs. Each of these awk scripts consolidates the processing for one set of files, e.g., man pages, info pages, etc., and is more easily commented than a make variable. (3) Splits out the print-PLIST code from the regular PLIST code since they have no common pieces (print-plist.mk vs. plist.mk). (4) Completely re-implements the shared-library handling to be more efficient. Along the way, this also fixes a problem for Mac OS X users where the PLISTs incorrectly contained absolute paths. (5) Completely re-implements the info-file handling so that we can migrate from INFO_FILES definitions to just adding info/foo.info entries in the static PLISTs. (6) Adds commented-out support for automatically compressed or decompressed info page entries based on the value of MANZ. These changes will be activated after texinfo.mk has been replaced by something that is built using the more modern primitives now available in pkgsrc. (7) Move the file compression logic into a separate script "doc-compress" that compresses or decompresses files while minding symlinks. This script is now called by bsd.pkg.mk to do the "autmoatic man page handling". In the future, it will also handle the "automatic info page handling" and possible others. In general, the idea is to move stuff out of the Makefiles and into separate files where we don't need to worry about quoting rules and where each file can have a separate history of commits. This simplifies the makefile logic (especially in terms of readability) and also simplifies maintenance of the code.
Diffstat (limited to 'mk/plist/shlib-dylib.awk')
-rw-r--r--mk/plist/shlib-dylib.awk182
1 files changed, 182 insertions, 0 deletions
diff --git a/mk/plist/shlib-dylib.awk b/mk/plist/shlib-dylib.awk
new file mode 100644
index 00000000000..1c99c37a026
--- /dev/null
+++ b/mk/plist/shlib-dylib.awk
@@ -0,0 +1,182 @@
+# $NetBSD: shlib-dylib.awk,v 1.1 2006/01/12 23:43:57 jlam Exp $
+#
+# Copyright (c) 2006 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# 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 NetBSD
+# Foundation, Inc. and its contributors.
+# 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``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 FOUNDATION OR CONTRIBUTORS
+# 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.
+
+#
+# This awk script is a filter that reads PLIST entries and transforms
+# and expands entries that match ELF library into the appropriate Mach-O
+# dylib names.
+#
+
+BEGIN {
+ LIBTOOL_EXPAND = ENVIRON["LIBTOOL_EXPAND"]
+ LIBTOOLIZE_PLIST = ENVIRON["LIBTOOLIZE_PLIST"]
+ PREFIX = ENVIRON["PREFIX"]
+ TEST = ENVIRON["TEST"]
+ nentries = 0
+}
+
+###
+### add_dylib(lib) adds the named "lib" to the PLIST entries list and
+### to the dylibs list if we haven't already seen it.
+###
+function add_dylib(lib) {
+ if (dylibs[lib] == "") {
+ dylibs[lib] = lib
+ entries[++nentries] = lib
+ }
+}
+
+###
+### Stored special PLIST commands, e.g. @comment, @exec, etc., verbatim
+### in the entries array.
+###
+/^@/ {
+ entries[++nentries] = $0
+ next
+}
+
+###
+### Record all of the library names associated with a libtool archive
+### in the "ltnames" array. Also, record the libtool archive in the
+### "entries" array.
+###
+(LIBTOOLIZE_PLIST ~ /[yY][eE][sS]/) && /.*\/[^\/]+\.la$/ {
+ entries[++nentries] = $0
+ cmd = TEST " -f " PREFIX "/" $0
+ if (system(cmd) == 0) {
+ cmd = "cd " PREFIX " && " LIBTOOL_EXPAND " " $0
+ while (cmd | getline) {
+ ltnames[$0] = $0
+ }
+ close(cmd)
+ }
+ next
+}
+
+###
+### Convert each ELF shlib entry into a dylib entry. Also, record all
+### dylib names that can be derived from this entry as dylibs.
+###
+/.*\/lib[^\/]+\.so(\.[0-9]+)+$/ {
+ lib = $0; sub("\.so\.", ".", lib); sub("\.so$", "", lib)
+ lib = lib ".dylib"
+ add_dylib(lib)
+ while (sub("\.[0-9]+$", "")) {
+ lib = $0; sub("\.so\.", ".", lib); sub("\.so$", "", lib)
+ lib = lib ".dylib"
+ add_dylib(lib)
+ }
+ if (sub("\.so$", "")) {
+ lib = $0 ".dylib"
+ add_dylib(lib)
+ }
+ if (sub("-([0-9.]+)$", "")) {
+ lib = $0 ".dylib"
+ add_dylib(lib)
+ }
+ next
+}
+
+###
+### If the ".so" file actually exists, then it's a dynamically loadable
+### module, so the entry should stay. Convert it into a dylib name as
+### well and record it as a dylib.
+###
+/.*\/lib[^\/]+\.so$/ {
+ cmd = TEST " -f " PREFIX "/" $0
+ if (system(cmd) == 0) {
+ entries[++nentries] = $0
+ }
+ lib = $0; sub("\.so$", "", lib)
+ lib = lib ".dylib"
+ add_dylib(lib)
+ if (sub("-([0-9.]+)$", "")) {
+ lib = $0 ".dylib"
+ add_dylib(lib)
+ }
+ next
+}
+
+###
+### All other entries are stored verbatim in the entries array.
+###
+{
+ entries[++nentries] = $0
+}
+
+###
+### Print out the PLIST entries to standard output.
+###
+END {
+ # Drop valid library names associated with a libtool archive from
+ # the list of dylibs that will be removed from the PLIST.
+ #
+ for (j in dylibs) {
+ for (k in ltnames) {
+ if (dylibs[j] == ltnames[k]) {
+ delete dylibs[j]
+ break
+ }
+ }
+ }
+
+ # Remove dylib entries that *do* exist on the filesystem from the
+ # list of dylibs that will be removed from the PLIST.
+ #
+ for (j in dylibs) {
+ cmd = TEST " -f " PREFIX "/" dylibs[j]
+ if (system(cmd) == 0) {
+ delete dylibs[j]
+ }
+ }
+
+ # Remove PLIST entries that match a non-existent dylib.
+ for (i in entries) {
+ for (j in dylibs) {
+ if (entries[i] == dylibs[j]) {
+ delete entries[i]
+ break
+ }
+ }
+ }
+
+ # Output the PLIST entries in order.
+ for (i = 1; i <= nentries; i++) {
+ if (entries[i]) {
+ print entries[i]
+ }
+ }
+}