blob: 7b8868801d54f68031e85d7b7c7c282be9efd757 [file] [log] [blame]
Gilles Peskine27482f12021-11-04 12:52:14 +01001#!/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 Rodgman0f2971a2023-11-03 12:04:52 +00007# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine27482f12021-11-04 12:52:14 +01008
9set -e -u
10
David Horstmann39aee122021-11-26 17:58:05 +000011program_name="dlopen"
Gilles Peskine27482f12021-11-04 12:52:14 +010012program_dir="${0%/*}"
David Horstmann39aee122021-11-26 17:58:05 +000013program="$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
Gilles Peskine27482f12021-11-04 12:52:14 +010034top_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
Gilles Peskineeea9c742021-11-10 21:04:24 +010053echo "Running dynamic loading test program: $program"
54echo "Loading libraries from: $library_dir"
Gilles Peskine27482f12021-11-04 12:52:14 +010055"$program"