Gilles Peskine | 27482f1 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 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 |
Dave Rodgman | 0f2971a | 2023-11-03 12:04:52 +0000 | [diff] [blame] | 7 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Gilles Peskine | 27482f1 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 8 | |
| 9 | set -e -u |
| 10 | |
David Horstmann | 39aee12 | 2021-11-26 17:58:05 +0000 | [diff] [blame] | 11 | program_name="dlopen" |
Gilles Peskine | 27482f1 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 12 | program_dir="${0%/*}" |
David Horstmann | 39aee12 | 2021-11-26 17:58:05 +0000 | [diff] [blame] | 13 | program="$program_dir/$program_name" |
| 14 | |
| 15 | if [ ! -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 |
| 32 | fi |
| 33 | |
Gilles Peskine | 27482f1 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 34 | top_dir="$program_dir/../.." |
| 35 | library_dir="$top_dir/library" |
| 36 | |
| 37 | # ELF-based Unix-like (Linux, *BSD, Solaris, ...) |
| 38 | if [ -n "${LD_LIBRARY_PATH-}" ]; then |
| 39 | LD_LIBRARY_PATH="$library_dir:$LD_LIBRARY_PATH" |
| 40 | else |
| 41 | LD_LIBRARY_PATH="$library_dir" |
| 42 | fi |
| 43 | export LD_LIBRARY_PATH |
| 44 | |
| 45 | # OSX/macOS |
| 46 | if [ -n "${DYLD_LIBRARY_PATH-}" ]; then |
| 47 | DYLD_LIBRARY_PATH="$library_dir:$DYLD_LIBRARY_PATH" |
| 48 | else |
| 49 | DYLD_LIBRARY_PATH="$library_dir" |
| 50 | fi |
| 51 | export DYLD_LIBRARY_PATH |
| 52 | |
Gilles Peskine | eea9c74 | 2021-11-10 21:04:24 +0100 | [diff] [blame] | 53 | echo "Running dynamic loading test program: $program" |
| 54 | echo "Loading libraries from: $library_dir" |
Gilles Peskine | 27482f1 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 55 | "$program" |