blob: a6a9022fc822ec0704edf1ad01fe129a55100a41 [file] [log] [blame]
Gilles Peskineca144592021-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
7# SPDX-License-Identifier: Apache-2.0
8#
9# Licensed under the Apache License, Version 2.0 (the "License"); you may
10# not use this file except in compliance with the License.
11# You may obtain a copy of the License at
12#
13# http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18# See the License for the specific language governing permissions and
19# limitations under the License.
20
21set -e -u
22
David Horstmann4dfa3682021-11-26 17:58:05 +000023program_name="dlopen"
Gilles Peskineca144592021-11-04 12:52:14 +010024program_dir="${0%/*}"
David Horstmann4dfa3682021-11-26 17:58:05 +000025program="$program_dir/$program_name"
26
27if [ ! -e "$program" ]; then
28 # Look for programs in the current directory and the directories above it
29 for dir in "." ".." "../.."; do
30 program_dir="$dir/programs/test"
31 program="$program_dir/$program_name"
32 if [ -e "$program" ]; then
33 break
34 fi
35 done
36 if [ ! -e "$program" ]; then
37 echo "Could not find $program_name program"
38
39 echo "Make sure that Mbed TLS is built as a shared library." \
40 "If building out-of-tree, this script must be run" \
41 "from the project build directory."
42 exit 1
43 fi
44fi
45
Gilles Peskineca144592021-11-04 12:52:14 +010046top_dir="$program_dir/../.."
47library_dir="$top_dir/library"
48
49# ELF-based Unix-like (Linux, *BSD, Solaris, ...)
50if [ -n "${LD_LIBRARY_PATH-}" ]; then
51 LD_LIBRARY_PATH="$library_dir:$LD_LIBRARY_PATH"
52else
53 LD_LIBRARY_PATH="$library_dir"
54fi
55export LD_LIBRARY_PATH
56
57# OSX/macOS
58if [ -n "${DYLD_LIBRARY_PATH-}" ]; then
59 DYLD_LIBRARY_PATH="$library_dir:$DYLD_LIBRARY_PATH"
60else
61 DYLD_LIBRARY_PATH="$library_dir"
62fi
63export DYLD_LIBRARY_PATH
64
Gilles Peskine7fb54c52021-11-10 21:04:24 +010065echo "Running dynamic loading test program: $program"
66echo "Loading libraries from: $library_dir"
Gilles Peskineca144592021-11-04 12:52:14 +010067"$program"