pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/mk/buildlink3 Teach buildlink3 how to reorder librarie...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/7743ea90d01c
branches:  trunk
changeset: 467369:7743ea90d01c
user:      jlam <jlam%pkgsrc.org@localhost>
date:      Fri Jan 30 10:56:11 2004 +0000

description:
Teach buildlink3 how to reorder libraries on the command line.  You
specify library orderings with:

        BUILDLINK_TRANSFORM+=   reorder:l:crypt:crypto

The wrapper scripts then reorder the libraries so that -lcrypt will
always come before -lcrypto.  If there are lots of reorder:l:...
commands, then the algorithm looks a bit like a topological sort.

diffstat:

 mk/buildlink3/bsd.buildlink3.mk |  15 +++++++-
 mk/buildlink3/buildcmd          |   6 +-
 mk/buildlink3/gen-transform.sh  |  69 ++++++++++++++++++++++++++++++++++++++++-
 mk/buildlink3/libtool.sh        |  15 +++++++-
 mk/buildlink3/wrapper.sh        |  12 ++++++-
 5 files changed, 107 insertions(+), 10 deletions(-)

diffs (274 lines):

diff -r 9fa1fa4a6d97 -r 7743ea90d01c mk/buildlink3/bsd.buildlink3.mk
--- a/mk/buildlink3/bsd.buildlink3.mk   Fri Jan 30 10:54:36 2004 +0000
+++ b/mk/buildlink3/bsd.buildlink3.mk   Fri Jan 30 10:56:11 2004 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.buildlink3.mk,v 1.64 2004/01/27 12:19:03 jlam Exp $
+# $NetBSD: bsd.buildlink3.mk,v 1.65 2004/01/30 10:56:11 jlam Exp $
 #
 # An example package buildlink3.mk file:
 #
@@ -876,6 +876,13 @@
 _BLNK_TRANSFORM+=      mangle:${_BLNK_MANGLE_DIR.${_dir_}}:${_dir_}
 .endfor
 
+# Only do the (expensive) reordering step if we have reordering
+# transformations.
+#
+.if !empty(_BLNK_TRANSFORM:Mreorder\:*)
+MAKE_ENV+=     BUILDLINK_REORDER=yes
+.endif
+
 _BLNK_TRANSFORM_SED+=  -f ${_BLNK_TRANSFORM_SEDFILE}
 _BLNK_UNTRANSFORM_SED+=        -f ${_BLNK_UNTRANSFORM_SEDFILE}
 
@@ -991,6 +998,7 @@
 _BLNK_GEN_TRANSFORM=           ${BUILDLINK_DIR}/bin/.gen-transform
 _BLNK_TRANSFORM_SEDFILE=       ${BUILDLINK_DIR}/bin/.transform.sed
 _BLNK_UNTRANSFORM_SEDFILE=     ${BUILDLINK_DIR}/bin/.untransform.sed
+_BLNK_REORDERLIBS=             ${BUILDLINK_DIR}/bin/.reorderlibs
 
 .for _wrappee_ in ${_BLNK_WRAPPEES}
 #
@@ -1154,6 +1162,7 @@
        -e "s|@TEST@|${TEST:Q}|g"                                       \
        -e "s|@TOUCH@|${TOUCH:Q}|g"                                     \
        -e "s|@_BLNK_LIBTOOL_FIX_LA@|${_BLNK_LIBTOOL_FIX_LA:Q}|g"       \
+       -e "s|@_BLNK_REORDERLIBS@|${_BLNK_REORDERLIBS:Q}|g"             \
        -e "s|@_BLNK_WRAP_LOG@|${_BLNK_WRAP_LOG:Q}|g"                   \
        -e "s|@_BLNK_WRAP_EXTRA_FLAGS@|${_BLNK_WRAP_EXTRA_FLAGS.${_wrappee_}:Q}|g" \
        -e "s|@_BLNK_WRAP_BUILDCMD@|${_BLNK_WRAP_BUILDCMD.${_wrappee_}:Q}|g" \
@@ -1618,6 +1627,7 @@
        ${_PKG_SILENT}${_PKG_DEBUG}${SED}                               \
                -e "s|@_BLNK_TRANSFORM_SEDFILE@|${_BLNK_TRANSFORM_SEDFILE:Q}|g" \
                -e "s|@_BLNK_UNTRANSFORM_SEDFILE@|${_BLNK_UNTRANSFORM_SEDFILE:Q}|g" \
+               -e "s|@_BLNK_REORDERLIBS@|${_BLNK_REORDERLIBS:Q}|g"     \
                -e "s|@_COMPILER_LD_FLAG@|${_COMPILER_LD_FLAG:Q}|g"     \
                -e "s|@_OPSYS_RPATH_NAME@|${_OPSYS_RPATH_NAME:Q}|g"     \
                -e "s|@BUILDLINK_SHELL@|${BUILDLINK_SHELL:Q}|g"         \
@@ -1626,7 +1636,8 @@
        ${_PKG_SILENT}${_PKG_DEBUG}${CHMOD} +x ${.TARGET}.tmp
        ${_PKG_SILENT}${_PKG_DEBUG}${MV} -f ${.TARGET}.tmp ${.TARGET}
 
-${_BLNK_TRANSFORM_SEDFILE} ${_BLNK_UNTRANSFORM_SEDFILE}: ${_BLNK_GEN_TRANSFORM}
+${_BLNK_TRANSFORM_SEDFILE} ${_BLNK_UNTRANSFORM_SEDFILE} ${_BLNK_REORDERLIBS}: \
+               ${_BLNK_GEN_TRANSFORM}
        ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H}
        ${_PKG_SILENT}${_PKG_DEBUG}${_BLNK_GEN_TRANSFORM}               \
                ${_BLNK_TRANSFORM}
diff -r 9fa1fa4a6d97 -r 7743ea90d01c mk/buildlink3/buildcmd
--- a/mk/buildlink3/buildcmd    Fri Jan 30 10:54:36 2004 +0000
+++ b/mk/buildlink3/buildcmd    Fri Jan 30 10:56:11 2004 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: buildcmd,v 1.3 2004/01/29 06:06:41 jlam Exp $
+# $NetBSD: buildcmd,v 1.4 2004/01/30 10:56:11 jlam Exp $
 #
 # Append $arg to $cmd to build up the command line to be executed, but
 # directly add the next few arguments to $cmd if $skipargs > 0.
@@ -40,8 +40,8 @@
                ;;
        -l*)
                #
-               # Extra libraries are suppressed only if they're
-               # repeated, e.g. "-lm -lm -lm -lm" -> "-lm".
+               # Suppressed sequentially repeated libraries,
+               # e.g. "-lm -lm -lm -lm" -> "-lm".
                #
                case "$libs" in
                *" "$arg)            ;;
diff -r 9fa1fa4a6d97 -r 7743ea90d01c mk/buildlink3/gen-transform.sh
--- a/mk/buildlink3/gen-transform.sh    Fri Jan 30 10:54:36 2004 +0000
+++ b/mk/buildlink3/gen-transform.sh    Fri Jan 30 10:56:11 2004 +0000
@@ -1,9 +1,10 @@
 #!@BUILDLINK_SHELL@
 #
-# $NetBSD: gen-transform.sh,v 1.17 2004/01/21 08:04:29 jlam Exp $
+# $NetBSD: gen-transform.sh,v 1.18 2004/01/30 10:56:11 jlam Exp $
 
 transform="@_BLNK_TRANSFORM_SEDFILE@"
 untransform="@_BLNK_UNTRANSFORM_SEDFILE@"
+reorderlibs="@_BLNK_REORDERLIBS@"
 
 # Mini-language for translating wrapper arguments into their buildlink
 # equivalents:
@@ -17,6 +18,7 @@
 #      abs-rpath               removes all rpath options that try to add
 #                                      relative paths
 #      no-rpath                removes "-R*", "-Wl,-R", and "-Wl,-rpath,*"
+#      reorder:l:foo:bar       reorders libs to ensure that "-lfoo"
 #      depot:src:dst           translates "src/<dir>/" into "dst/"
 #      I:src:dst               translates "-Isrc" into "-Idst"
 #      L:src:dst               translates "-Lsrc" into "-Ldst"
@@ -28,6 +30,7 @@
 #      r:dir                   removes "dir" and "dir/*"
 #      S:foo:bar               translates word "foo" into "bar"
 #      s:foo:bar               translates "foo" into "bar"
+#                              occurs before "-lbar"
 #
 # Some transformations only make sense in one direction, so if a command
 # is prefixed with either "transform:" or "untransform:", then the
@@ -116,6 +119,33 @@
                gen $action _r:-Wl,-R
                gen $action _r:-R
                ;;
+       reorder)
+               case "$action" in
+               transform)
+                       shift
+                       case $1 in
+                       l)
+                               @CAT@ >> $reorderlibs << EOF
+               # -l$2 comes before -l$3
+               -l$2)
+                       case "\${_libs}" in
+                       -l$3" "*|*" "-l$3" "*)
+                               _libs="\${_libs%%-l$3 *}-l$2 -l$3 \${_libs#*-lb }"
+                               ;;
+                       -l$3|*" "-l$3)
+                               _libs="\${_libs%%-l$3}-l$2 -l$3"
+                               ;;
+                       *)
+                               _libs="\${_libs} \$l"
+                               ;;
+                       esac
+                       ;;
+EOF
+                               ;;
+                       esac
+                       ;;
+               esac
+               ;;
        depot)
                case "$action" in
                transform|untransform)
@@ -276,6 +306,16 @@
        esac
 }
 
+# Write out header for reorderlibs 
+@CAT@ > $reorderlibs << EOF
+prevlibs=
+while \$test "\$libs" != "\$prevlibs" -a -n "\$libs"; do
+       _libs=
+       for l in \$libs; do
+               case \$l in
+EOF
+
+# Parse arguments
 for arg do
        case $arg in
        transform:*)
@@ -290,3 +330,30 @@
                ;;
        esac
 done
+
+# Write out footer for reorderlibs 
+@CAT@ >> $reorderlibs << EOF
+               *)
+                       _libs="\${_libs} \$l"
+                       ;;
+               esac
+               _libs="\${_libs# }"
+               _libs="\${_libs% }"
+       done
+       prevlibs="\$libs"
+       libs="\${_libs}"
+       echo "==> reorderlibs (\$libs) <<==" 1>&2       # !!!
+done
+
+# This section suppress duplicate libraries in sequence.
+_libs=
+for l in \$libs; do
+        case "\${_libs}" in
+        \$l|*" "\$l) ;;
+        *) _libs="\${_libs} \$l" ;;
+        esac
+done
+_libs="\${_libs# }"
+_libs="\${_libs% }"
+libs="\${_libs}"
+EOF
diff -r 9fa1fa4a6d97 -r 7743ea90d01c mk/buildlink3/libtool.sh
--- a/mk/buildlink3/libtool.sh  Fri Jan 30 10:54:36 2004 +0000
+++ b/mk/buildlink3/libtool.sh  Fri Jan 30 10:56:11 2004 +0000
@@ -1,6 +1,6 @@
 #!@BUILDLINK_SHELL@
 #
-# $NetBSD: libtool.sh,v 1.13 2004/01/29 07:14:30 jlam Exp $
+# $NetBSD: libtool.sh,v 1.14 2004/01/30 10:56:11 jlam Exp $
 
 Xsed='@SED@ -e 1s/^X//'
 sed_quote_subst='s/\([\\`\\"$\\\\]\)/\\\1/g'
@@ -19,14 +19,16 @@
 post_cache="@_BLNK_WRAP_POST_CACHE@"
 logic="@_BLNK_WRAP_LOGIC@"
 post_logic="@_BLNK_WRAP_POST_LOGIC@"
+reorderlibs="@_BLNK_REORDERLIBS@"
 
 wrapperlog="${BUILDLINK_WRAPPER_LOG-@_BLNK_WRAP_LOG@}"
 
 libtool_fix_la="@_BLNK_LIBTOOL_FIX_LA@"
 fixlibpath=${BUILDLINK_FIX_IMPROPER_LIBTOOL_LIBPATH-yes}
 
-updatecache=${BUILDLINK_UPDATE_CACHE-yes}
-cacheall=${BUILDLINK_CACHE_ALL-no}
+updatecache="${BUILDLINK_UPDATE_CACHE-yes}"
+cacheall="${BUILDLINK_CACHE_ALL-no}"
+reorder="${BUILDLINK_REORDER-no}"
 
 cat="@CAT@"
 echo="@ECHO@"
@@ -163,6 +165,13 @@
        done
        ;;
 esac
+
+# Reorder the libraries so that the library dependencies are correct.
+case $reorder in
+yes)
+       . $reorderlibs
+esac
+
 cmd="$cmd $ldflags $libs"
 
 @_BLNK_WRAP_ENV@
diff -r 9fa1fa4a6d97 -r 7743ea90d01c mk/buildlink3/wrapper.sh
--- a/mk/buildlink3/wrapper.sh  Fri Jan 30 10:54:36 2004 +0000
+++ b/mk/buildlink3/wrapper.sh  Fri Jan 30 10:56:11 2004 +0000
@@ -1,6 +1,6 @@
 #!@BUILDLINK_SHELL@
 #
-# $NetBSD: wrapper.sh,v 1.9 2004/01/29 07:14:30 jlam Exp $
+# $NetBSD: wrapper.sh,v 1.10 2004/01/30 10:56:11 jlam Exp $
 
 Xsed='@SED@ -e 1s/^X//'
 sed_quote_subst='s/\([\\`\\"$\\\\]\)/\\\1/g'
@@ -19,11 +19,13 @@
 post_cache="@_BLNK_WRAP_POST_CACHE@"
 logic="@_BLNK_WRAP_LOGIC@"
 post_logic="@_BLNK_WRAP_POST_LOGIC@"
+reorderlibs="@_BLNK_REORDERLIBS@"
 
 wrapperlog="${BUILDLINK_WRAPPER_LOG-@_BLNK_WRAP_LOG@}"
 
 updatecache="${BUILDLINK_UPDATE_CACHE-yes}"
 cacheall="${BUILDLINK_CACHE_ALL-no}"
+reorder="${BUILDLINK_REORDER-no}"
 
 cat="@CAT@"
 echo="@ECHO@"
@@ -74,6 +76,14 @@
        #
        . $buildcmd
 done
+
+# Reorder the libraries so that the library dependencies are correct.
+case $reorder in
+yes)
+       . $reorderlibs
+       ;;
+esac
+
 cmd="$cmd $ldflags $libs"
 
 @_BLNK_WRAP_ENV@



Home | Main Index | Thread Index | Old Index