diff --git a/NEWS b/NEWS index f97c5e45..39e75bae 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,9 @@ NEWS - list of user-visible changes between releases of GNU Libtool - New libtool command line flag, --no-finish, to skip executing finish_cmds that would alter the shared library cache during testing. + - New libtool command line flag, --reorder-cache=DIRS, to reorder the + shared library cache, only on OpenBSD. + ** Bug fixes: - Fix incorrect use of workarounds designed for Darwin versions that diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in index 76ee77c9..1599fe74 100644 --- a/build-aux/ltmain.in +++ b/build-aux/ltmain.in @@ -142,6 +142,7 @@ usage_message="Options: --no-finish don't update shared library cache --no-warnings equivalent to '-Wnone' --preserve-dup-deps don't remove duplicate dependency libraries + --reorder-cache=DIRS reorder shared library cache for preferred DIRS --quiet, --silent don't print informational messages --tag=TAG use configuration variables from tag TAG -v, --verbose print more informational messages than default @@ -376,6 +377,7 @@ libtool_options_prep () opt_dry_run=false opt_help=false opt_mode= + opt_reorder_cache=false opt_preserve_dup_deps=false opt_quiet=false opt_finishing=true @@ -496,6 +498,24 @@ libtool_parse_options () func_append preserve_args " $_G_opt" ;; + --reorder-cache) + opt_reorder_cache=true + shared_lib_dirs=$1 + if test -n "$shared_lib_dirs"; then + case $1 in + # Must begin with /: + /*) ;; + + # Catch anything else as an error (relative paths) + *) func_warning "invalid argument '$1' for $_G_opt" + func_warning "absolute paths are required for $_G_opt" + exit_cmd=exit + break + ;; + esac + fi + ;; + --silent|--quiet) opt_quiet=: opt_verbose=false @@ -1061,6 +1081,15 @@ func_convert_path_front_back_pathsep () # end func_convert_path_front_back_pathsep +# func_convert_delimited_path PATH ORIG_DELIMITER NEW_DELIMITER +# Replaces a delimiter for a given path. +func_convert_delimited_path () +{ + converted_path=`$ECHO "$1" | $SED "s#$2#$3#g"` +} +# end func_convert_delimited_path + + ################################################## # $build to $host FILE NAME CONVERSION FUNCTIONS # ################################################## @@ -1395,6 +1424,65 @@ func_dll_def_p () } +# func_reorder_shared_lib_cache DIRS +# Reorder the shared library cache by unconfiguring previous shared library cache +# and configuring preferred search directories before previous search directories. +# Previous shared library cache: /usr/lib /usr/local/lib +# Preferred search directories: /tmp/testing +# Reordered shared library cache: /tmp/testing /usr/lib /usr/local/lib +func_reorder_shared_lib_cache () +{ + $debug_cmd + + case $host_os in + openbsd*) + get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"` + func_convert_delimited_path "$get_search_directories" ':' '\ ' + save_search_directories=$converted_path + func_convert_delimited_path "$1" ':' '\ ' + + # Ensure directories exist + for dir in $converted_path; do + # Ensure each directory is an absolute path + case $dir in + /*) ;; + *) func_warning "Directory '$dir' is not an absolute path" + exit $EXIT_FAILURE ;; + esac + # Ensure no trailing slashes + func_stripname '' '/' "$dir" + dir=$func_stripname_result + if test -d "$dir"; then + if test -n "$preferred_search_directories"; then + preferred_search_directories="$preferred_search_directories $dir" + else + preferred_search_directories=$dir + fi + else + func_warning "Directory '$dir' does not exist" + exit $EXIT_FAILURE + fi + done + + PATH="$PATH:/sbin" ldconfig -U $save_search_directories + PATH="$PATH:/sbin" ldconfig -m $preferred_search_directories $save_search_directories + get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"` + func_convert_delimited_path "$get_search_directories" ':' '\ ' + reordered_search_directories=$converted_path + + $ECHO "Original: $save_search_directories" + $ECHO "Reordered: $reordered_search_directories" + exit $EXIT_SUCCESS + ;; + *) + func_warning "--reorder-cache is not supported for host_os=$host_os." + exit $EXIT_FAILURE + ;; + esac +} +# end func_reorder_shared_lib_cache + + # func_mode_compile arg... func_mode_compile () { @@ -1967,6 +2055,12 @@ if $opt_help; then fi +# If option '--reorder-cache', reorder the shared library cache and exit. +if $opt_reorder_cache; then + func_reorder_shared_lib_cache $shared_lib_dirs +fi + + # func_mode_execute arg... func_mode_execute () { diff --git a/doc/libtool.texi b/doc/libtool.texi index 953abb36..57212021 100644 --- a/doc/libtool.texi +++ b/doc/libtool.texi @@ -1280,7 +1280,53 @@ is an issue observed on OpenBSD 7.5. This option should be combined with the usage of @option{--mode=install} and @option{--mode=finish} to have any effect. Prior to utilizing this option, the shared library cache must not contain links to the listed install directory for shared libraries -undergoing testing; otherwise, it will have no useful effect. +undergoing testing; otherwise, it will have no useful effect. In OpenBSD, +the shared library cache can be reordered to prefer directories for +testing shared libraries over the directories already listed in the shared +library cache with @option{--reorder-cache=@var{shared_lib_dirs}}. + +@item --reorder-cache=@var{shared_lib_dirs} +Reorder the shared library cache by providing the preferred directories +(@var{shared_lib_dirs}) to link shared libraries from. The previous +shared library cache is unconfigured, and the preferred directories are +configured with the previous directories appended to the end (if not in +the preferred directory list)@footnote{Additionally, all directories +that no longer exist will be removed from the shared library cache.}. +This option is currently only available on OpenBSD where @code{make +install} has been required before @code{make check} for the shared +library cache to be updated. + +This option is essentially a wrapper for executing @command{ldconfig}, +and it should be used as an independent option before and after testing +changes to shared libraries. Below are some usage examples: + +@example +$ @kbd{libtool --reorder-cache=/tmp/testing} +Original: /usr/lib /usr/X11R6/lib /usr/local/lib +Reordered: /tmp/testing /usr/lib /usr/X11R6/lib /usr/local/lib +$ @kbd{libtool --reorder-cache=/usr/lib:/usr/X11R6/lib:/usr/local/lib} +Original: /tmp/testing /usr/lib /usr/X11R6/lib /usr/local/lib +Reordered: /usr/lib /usr/X11R6/lib /usr/local/lib /tmp/testing +@end example + +@example +$ @kbd{libtool --reorder-cache=/tmp/testing} +Original: /usr/lib /usr/X11R6/lib /usr/local/lib +Reordered: /tmp/testing /usr/lib /usr/X11R6/lib /usr/local/lib +$ @kbd{rm -rf /tmp/testing} +$ @kbd{libtool --reorder-cache=/usr/lib:/usr/X11R6/lib:/usr/local/lib} +Original: /tmp/testing /usr/lib /usr/X11R6/lib /usr/local/lib +Reordered: /usr/lib /usr/X11R6/lib /usr/local/lib +@end example + +@example +$ @kbd{libtool --reorder-cache=/tmp/testing:/usr/local/lib:/home/user/dir} +Original: /usr/lib /usr/X11R6/lib /usr/local/lib +Reordered: /tmp/testing /usr/local/lib /home/user/dir /usr/lib /usr/X11R6/lib +$ @kbd{libtool --reorder-cache=/usr/lib /usr/X11R6/lib /usr/local/lib} +Original: /tmp/testing /usr/local/lib /home/user/dir /usr/lib /usr/X11R6/lib +Reordered: /usr/lib /usr/X11R6/lib /usr/local/lib /tmp/testing /home/user/dir +@end example @item --quiet @itemx --silent diff --git a/tests/bug_71489.at b/tests/bug_71489.at index ef4f51f7..08196966 100644 --- a/tests/bug_71489.at +++ b/tests/bug_71489.at @@ -382,6 +382,16 @@ echo "Building local copy of the project" cd build_local LT_AT_CONFIGURE([--prefix=$prefix], [$ltb2/configure]) LT_AT_MAKE([]) + + case $host_os in + openbsd*) + build_local_dir=$(pwd) + AT_CHECK( + [ + $LIBTOOL --reorder-cache="$build_local_dir/liba/.libs:$build_local_dir/libb/.libs" + ], 0, ignore, ignore);; + *) ;; + esac ) # Although we have installed ltb2, we still expect that we are using the local