10e3d5408SPeter Wemm#!/bin/sh 20e3d5408SPeter Wemm############################################################################## 3*21817992SBaptiste Daroussin# Copyright 2020,2021 Thomas E. Dickey # 4e1865124SBaptiste Daroussin# Copyright 1998-2005,2007 Free Software Foundation, Inc. # 50e3d5408SPeter Wemm# # 60e3d5408SPeter Wemm# Permission is hereby granted, free of charge, to any person obtaining a # 70e3d5408SPeter Wemm# copy of this software and associated documentation files (the "Software"), # 80e3d5408SPeter Wemm# to deal in the Software without restriction, including without limitation # 90e3d5408SPeter Wemm# the rights to use, copy, modify, merge, publish, distribute, distribute # 100e3d5408SPeter Wemm# with modifications, sublicense, and/or sell copies of the Software, and to # 110e3d5408SPeter Wemm# permit persons to whom the Software is furnished to do so, subject to the # 120e3d5408SPeter Wemm# following conditions: # 130e3d5408SPeter Wemm# # 140e3d5408SPeter Wemm# The above copyright notice and this permission notice shall be included in # 150e3d5408SPeter Wemm# all copies or substantial portions of the Software. # 160e3d5408SPeter Wemm# # 170e3d5408SPeter Wemm# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # 180e3d5408SPeter Wemm# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # 190e3d5408SPeter Wemm# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # 200e3d5408SPeter Wemm# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # 210e3d5408SPeter Wemm# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # 220e3d5408SPeter Wemm# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # 230e3d5408SPeter Wemm# DEALINGS IN THE SOFTWARE. # 240e3d5408SPeter Wemm# # 250e3d5408SPeter Wemm# Except as contained in this notice, the name(s) of the above copyright # 260e3d5408SPeter Wemm# holders shall not be used in advertising or otherwise to promote the sale, # 270e3d5408SPeter Wemm# use or other dealings in this Software without prior written # 280e3d5408SPeter Wemm# authorization. # 290e3d5408SPeter Wemm############################################################################## 300e3d5408SPeter Wemm# 310e3d5408SPeter Wemm# Author: Thomas E. Dickey <dickey@clark.net> 1996 320e3d5408SPeter Wemm# 33*21817992SBaptiste Daroussin# $Id: shlib,v 1.14 2021/09/04 15:55:29 tom Exp $ 340e3d5408SPeter Wemm# Use this script as a wrapper when running executables linked to shared 350e3d5408SPeter Wemm# libraries on systems that use the $LD_LIBRARY_PATH variable and don't embed 360e3d5408SPeter Wemm# the soname's path within the linked executable (such as IRIX), e.g, 370e3d5408SPeter Wemm# 380e3d5408SPeter Wemm# shlib knight 390e3d5408SPeter Wemm# 400e3d5408SPeter Wemm# Setting LD_LIBRARY_PATH, overrides/supplements the loader's normal search 410e3d5408SPeter Wemm# path, and works on most systems. The drawback is that then the environment 420e3d5408SPeter Wemm# variable has to be set to run the programs within this directory tree. 430e3d5408SPeter Wemm# 440e3d5408SPeter Wemm# For Linux (and other systems using the GNU loader), we can use the rpath 450e3d5408SPeter Wemm# directive, which embeds the pathname of the library within the executable. 460e3d5408SPeter Wemm# Using the Linux loader's rpath directive introduces a constraint, since 470e3d5408SPeter Wemm# it's embedded into the binary, and means that the binary cannot be moved 480e3d5408SPeter Wemm# around (though it'll work if the $exec_prefix convention that puts the bin 490e3d5408SPeter Wemm# and lib directories under the same parent is followed). 500e3d5408SPeter Wemm# 510e3d5408SPeter Wemm# Using the actual soname (e.g., ../lib/libncurses.so) alone, is a more 520e3d5408SPeter Wemm# flexible solution; you can link without having to set the environment 530e3d5408SPeter Wemm# variable, and on some systems (IRIX) you can even run the resulting binaries 540e3d5408SPeter Wemm# without setting LD_LIBRARY_PATH. 550e3d5408SPeter Wemm# 560e3d5408SPeter Wemm# Using a conventional link, with -L and -l options on Linux results in a 570e3d5408SPeter Wemm# statically linked executable, which we don't want at all. 580e3d5408SPeter Wemm# 5915589c42SPeter Wemm# Special cases: 6015589c42SPeter Wemm# 6115589c42SPeter Wemm# BeOS R4.5 uses $LIBRARY_PATH rather than $LD_LIBRARY_PATH. 624a1a9510SRong-En Fan# Cygwin uses $PATH 634a1a9510SRong-En Fan# Mac OS X uses $DYLD_LIBRARY_PATH 644a1a9510SRong-En Fan# 654a1a9510SRong-En Fan# Other cases not handled by this script: 664a1a9510SRong-En Fan# 674a1a9510SRong-En Fan# AIX uses $LIBPATH 684a1a9510SRong-En Fan# IRIX64 may use $LD_LIBRARY64_PATH or $LD_LIBRARYN32_PATH 694a1a9510SRong-En Fan# Solaris may use $LD_LIBRARY_PATH_64 704a1a9510SRong-En Fan# 714a1a9510SRong-En FanCDPATH= 720e3d5408SPeter Wemm# 730e3d5408SPeter Wemm# Make sure that we use the PATH that was set in run_tic.sh 744a1a9510SRong-En Fanif test -n "$SHLIB_PATH" ; then 754a1a9510SRong-En Fan PATH=$SHLIB_PATH 760e3d5408SPeter Wemm export PATH 770e3d5408SPeter Wemmfi 780e3d5408SPeter Wemm 794a1a9510SRong-En Fan# Find the lib-directory for this build tree 800e3d5408SPeter Wemmq="" 814a1a9510SRong-En Fanfor p in lib ../lib ../../lib ../../../lib 820e3d5408SPeter Wemmdo 830e3d5408SPeter Wemm if test -d $p; then 84*21817992SBaptiste Daroussin q=`cd $p || exit; pwd` 855ca44d1cSRong-En Fan break 864a1a9510SRong-En Fan elif test -f configure && test ! -d ../$p ; then 874a1a9510SRong-En Fan break 880e3d5408SPeter Wemm fi 890e3d5408SPeter Wemmdone 904a1a9510SRong-En Fan 914a1a9510SRong-En Fan# Set the environment variable. 920e3d5408SPeter Wemmif test -n "$q" ; then 934a1a9510SRong-En Fan system= 944a1a9510SRong-En Fan if test -n "$SHLIB_HOST" ; then 954a1a9510SRong-En Fan system="$SHLIB_HOST" 964a1a9510SRong-En Fan elif test -n "$PATHEXT" ; then 974a1a9510SRong-En Fan system=cygwin 9815589c42SPeter Wemm elif test -n "$LIBRARY_PATH" ; then 994a1a9510SRong-En Fan system=beos 1004a1a9510SRong-En Fan elif test -n "$DYLD_LIBRARY_PATH" ; then 1014a1a9510SRong-En Fan system=darwin 1024a1a9510SRong-En Fan elif test -n "$LD_LIBRARY_PATH"; then 1034a1a9510SRong-En Fan system=unix 1040e3d5408SPeter Wemm else 105*21817992SBaptiste Daroussin for r in "$q"/*.* 1064a1a9510SRong-En Fan do 1074a1a9510SRong-En Fan if test -f "$r" 1084a1a9510SRong-En Fan then 1094a1a9510SRong-En Fan case $r in 1104a1a9510SRong-En Fan *.dll) 1114a1a9510SRong-En Fan system=cygwin 1124a1a9510SRong-En Fan ;; 1134a1a9510SRong-En Fan *.dylib) 1144a1a9510SRong-En Fan system=darwin 1154a1a9510SRong-En Fan ;; 1164a1a9510SRong-En Fan esac 1170e3d5408SPeter Wemm fi 1184a1a9510SRong-En Fan test -n "$system" && break 1194a1a9510SRong-En Fan done 1200e3d5408SPeter Wemm fi 1214a1a9510SRong-En Fan 1224a1a9510SRong-En Fan case .$system in 1234a1a9510SRong-En Fan .cygwin*) 1244a1a9510SRong-En Fan variable=PATH 1254a1a9510SRong-En Fan ;; 1264a1a9510SRong-En Fan .beos*) 1274a1a9510SRong-En Fan variable=LIBRARY_PATH 1284a1a9510SRong-En Fan ;; 1294a1a9510SRong-En Fan .darwin*) 1304a1a9510SRong-En Fan variable=DYLD_LIBRARY_PATH 1314a1a9510SRong-En Fan ;; 1324a1a9510SRong-En Fan *) 1334a1a9510SRong-En Fan variable=LD_LIBRARY_PATH 1344a1a9510SRong-En Fan ;; 1354a1a9510SRong-En Fan esac 1364a1a9510SRong-En Fan 1374a1a9510SRong-En Fan eval 'test -z "$'$variable'" && '$variable'=":"' 1384a1a9510SRong-En Fan eval $variable'="$q:$'$variable'"' 1394a1a9510SRong-En Fan eval 'export '$variable 1404a1a9510SRong-En Fanfi 1414a1a9510SRong-En Fan 1420e3d5408SPeter Wemmeval "$*" 143