1#!/bin/sh 2 3# Run the shared library dynamic loading demo program. 4# This is only expected to work when Mbed TLS is built as a shared library. 5 6# Copyright The Mbed TLS Contributors 7# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 8 9set -e -u 10 11program_name="dlopen" 12program_dir="${0%/*}" 13program="$program_dir/$program_name" 14 15if [ ! -e "$program" ]; then 16 # Look for programs in the current directory and the directories above it 17 for dir in "." ".." "../.."; do 18 program_dir="$dir/programs/test" 19 program="$program_dir/$program_name" 20 if [ -e "$program" ]; then 21 break 22 fi 23 done 24 if [ ! -e "$program" ]; then 25 echo "Could not find $program_name program" 26 27 echo "Make sure that Mbed TLS is built as a shared library." \ 28 "If building out-of-tree, this script must be run" \ 29 "from the project build directory." 30 exit 1 31 fi 32fi 33 34top_dir="$program_dir/../.." 35library_dir="$top_dir/library" 36 37# ELF-based Unix-like (Linux, *BSD, Solaris, ...) 38if [ -n "${LD_LIBRARY_PATH-}" ]; then 39 LD_LIBRARY_PATH="$library_dir:$LD_LIBRARY_PATH" 40else 41 LD_LIBRARY_PATH="$library_dir" 42fi 43export LD_LIBRARY_PATH 44 45# OSX/macOS 46if [ -n "${DYLD_LIBRARY_PATH-}" ]; then 47 DYLD_LIBRARY_PATH="$library_dir:$DYLD_LIBRARY_PATH" 48else 49 DYLD_LIBRARY_PATH="$library_dir" 50fi 51export DYLD_LIBRARY_PATH 52 53echo "Running dynamic loading test program: $program" 54echo "Loading libraries from: $library_dir" 55"$program" 56