dlopen_demo.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/sh
  2. # Run the shared library dynamic loading demo program.
  3. # This is only expected to work when Mbed TLS is built as a shared library.
  4. # Copyright The Mbed TLS Contributors
  5. # SPDX-License-Identifier: Apache-2.0
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. # not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. set -e -u
  19. program_dir="${0%/*}"
  20. program="$program_dir/dlopen"
  21. top_dir="$program_dir/../.."
  22. library_dir="$top_dir/library"
  23. # ELF-based Unix-like (Linux, *BSD, Solaris, ...)
  24. if [ -n "${LD_LIBRARY_PATH-}" ]; then
  25. LD_LIBRARY_PATH="$library_dir:$LD_LIBRARY_PATH"
  26. else
  27. LD_LIBRARY_PATH="$library_dir"
  28. fi
  29. export LD_LIBRARY_PATH
  30. # OSX/macOS
  31. if [ -n "${DYLD_LIBRARY_PATH-}" ]; then
  32. DYLD_LIBRARY_PATH="$library_dir:$DYLD_LIBRARY_PATH"
  33. else
  34. DYLD_LIBRARY_PATH="$library_dir"
  35. fi
  36. export DYLD_LIBRARY_PATH
  37. echo "Running dynamic loading test program: $program"
  38. echo "Loading libraries from: $library_dir"
  39. "$program"