diff options
author | jlam <jlam@pkgsrc.org> | 2004-01-30 10:56:11 +0000 |
---|---|---|
committer | jlam <jlam@pkgsrc.org> | 2004-01-30 10:56:11 +0000 |
commit | e2c107a7e9acda75ac20ac6232c9f680c9c3fb74 (patch) | |
tree | 36fa82b18548672f955ce032d3d418907f26d940 /mk/buildlink3 | |
parent | aa090d436699a8764c9d21e076c5786ddb1d8a30 (diff) | |
download | pkgsrc-e2c107a7e9acda75ac20ac6232c9f680c9c3fb74.tar.gz |
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 (limited to 'mk/buildlink3')
-rw-r--r-- | mk/buildlink3/bsd.buildlink3.mk | 15 | ||||
-rw-r--r-- | mk/buildlink3/buildcmd | 6 | ||||
-rw-r--r-- | mk/buildlink3/gen-transform.sh | 69 | ||||
-rw-r--r-- | mk/buildlink3/libtool.sh | 15 | ||||
-rw-r--r-- | mk/buildlink3/wrapper.sh | 12 |
5 files changed, 107 insertions, 10 deletions
diff --git a/mk/buildlink3/bsd.buildlink3.mk b/mk/buildlink3/bsd.buildlink3.mk index 2e794b6aa71..ade589dd382 100644 --- a/mk/buildlink3/bsd.buildlink3.mk +++ b/mk/buildlink3/bsd.buildlink3.mk @@ -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+= rpath:${_BLNK_MANGLE_DIR.${_dir_}}:${_dir_} _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_FAKE_LA= ${BUILDLINK_DIR}/bin/.fake-la _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 @@ _BLNK_WRAPPER_TRANSFORM_SED.${_wrappee_}= \ -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 @@ ${_BLNK_GEN_TRANSFORM}: ${.CURDIR}/../../mk/buildlink3/gen-transform.sh ${_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 @@ ${_BLNK_GEN_TRANSFORM}: ${.CURDIR}/../../mk/buildlink3/gen-transform.sh ${_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 --git a/mk/buildlink3/buildcmd b/mk/buildlink3/buildcmd index 1dfd4455ad6..d8889296809 100644 --- a/mk/buildlink3/buildcmd +++ b/mk/buildlink3/buildcmd @@ -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 @@ else ;; -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 --git a/mk/buildlink3/gen-transform.sh b/mk/buildlink3/gen-transform.sh index ace9d3198b2..4203c1ac8c2 100644 --- a/mk/buildlink3/gen-transform.sh +++ b/mk/buildlink3/gen-transform.sh @@ -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 @@ untransform="@_BLNK_UNTRANSFORM_SEDFILE@" # 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 @@ untransform="@_BLNK_UNTRANSFORM_SEDFILE@" # 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 @@ EOF 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 @@ EOF 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 @@ for arg do ;; 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 --git a/mk/buildlink3/libtool.sh b/mk/buildlink3/libtool.sh index d4e1247a003..8d2602ec55a 100644 --- a/mk/buildlink3/libtool.sh +++ b/mk/buildlink3/libtool.sh @@ -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 @@ cache="@_BLNK_WRAP_CACHE@" 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 @@ install) 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 --git a/mk/buildlink3/wrapper.sh b/mk/buildlink3/wrapper.sh index 730e2057a9d..17af9efc10d 100644 --- a/mk/buildlink3/wrapper.sh +++ b/mk/buildlink3/wrapper.sh @@ -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 @@ cache="@_BLNK_WRAP_CACHE@" 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 @@ while $test $# -gt 0 -o -n "$depth"; do # . $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@ |