1#!/usr/bin/env bash
2# shellcheck disable=SC1090
3# shellcheck disable=SC1091
4
5: "${GPG_VERSION:=stable}"
6: "${BUILD_SHARED_LIBS:=off}"
7: "${USE_STATIC_DEPENDENCIES:=}"
8: "${OS:=}"
9: "${DIST:=}"
10: "${DIST_VERSION:=}"
11: "${DIST_VERSION_ID:=}"
12: "${MINIMUM_RUBY_VERSION:=2.5.0}"
13: "${RECOMMENDED_RUBY_VERSION:=2.5.8}"
14: "${MINIMUM_CMAKE_VERSION:=3.20.0}"
15: "${RECOMMENDED_CMAKE_VERSION:=3.20.5}"
16: "${RECOMMENDED_PYTHON_VERSION:=3.9.2}"
17: "${RECOMMENDED_JSONC_VERSION:=0.12.1}"
18
19: "${VERBOSE:=1}"
20
21
22if [[ "${OS}" = "freebsd" ]] || \
23   [[ "${DIST}" = "ubuntu" ]] || \
24   [[ "${DIST}" = "centos" ]] || \
25   [[ "${DIST}" = "fedora" ]]
26then
27  SUDO="${SUDO:-sudo}"
28else
29  SUDO="${SUDO:-run}"
30fi
31
32# Simply run its arguments.
33run() {
34  "$@"
35}
36
37. ci/lib/cacheable_install_functions.inc.sh
38
39macos_install() {
40  brew update-reset
41  # homebrew fails because `openssl` is a symlink while it tries to remove a directory.
42  rm /usr/local/Cellar/openssl || true
43  # homebrew fails to update python 3.9.1 to 3.9.1.1 due to unlinking failure
44  rm /usr/local/bin/2to3 || true
45  brew bundle
46}
47
48freebsd_install() {
49  local packages=(
50    git
51    readline
52    bash
53    gnupg
54    devel/pkgconf
55    wget
56    cmake
57    gmake
58    autoconf
59    automake
60    libtool
61    gettext-tools
62    python
63    ruby26
64  )
65
66  # Note: we assume sudo is already installed
67  "${SUDO}" pkg install -y "${packages[@]}"
68
69  cd /usr/ports/devel/ruby-gems
70  "${SUDO}" make -DBATCH RUBY_VER=2.5 install
71  cd
72
73  mkdir -p ~/.gnupg
74  echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf
75  dirmngr </dev/null
76  dirmngr --daemon
77}
78
79openbsd_install() {
80  echo ""
81}
82
83netbsd_install() {
84  echo ""
85}
86
87linux_prepare_ribose_yum_repo() {
88  "${SUDO}" rpm --import https://github.com/riboseinc/yum/raw/master/ribose-packages.pub
89  "${SUDO}" curl -L https://github.com/riboseinc/yum/raw/master/ribose.repo \
90    -o /etc/yum.repos.d/ribose.repo
91}
92
93# Prepare the system by updating and optionally installing repos
94yum_prepare_repos() {
95  yum_install "${util_depedencies_yum[@]}"
96  linux_prepare_ribose_yum_repo
97  "${SUDO}" "${YUM}" -y update
98  if [[ $# -gt 0 ]]; then
99    yum_install "$@"
100  fi
101}
102
103linux_install_fedora() {
104  yum_prepare_repos
105  yum_install_build_dependencies \
106    cmake
107  yum_install_dynamic_build_dependencies_if_needed
108
109  ensure_cmake
110  ensure_ruby
111  rubygem_install_build_dependencies
112}
113
114linux_install_centos() {
115  case "${DIST_VERSION}" in
116    centos-7)
117      linux_install_centos7
118      ;;
119    centos-8)
120      linux_install_centos8
121      ;;
122    *)
123      >&2 echo "Error: unsupported CentOS version \"${DIST_VERSION_ID}\" (supported: 7, 8).  Aborting."
124      exit 1
125  esac
126}
127
128declare util_depedencies_yum=(
129  sudo # NOTE: Needed to avoid "sudo: command not found"
130  wget
131  git
132)
133
134declare basic_build_dependencies_yum=(
135  # cmake3 # XXX: Fedora 22+ only has cmake
136  clang
137  gcc
138  gcc-c++
139  make
140  autoconf
141  automake
142  libtool
143  bzip2
144  gzip
145)
146
147declare build_dependencies_yum=(
148  ncurses-devel
149  bzip2-devel
150  zlib-devel
151  byacc
152  gettext-devel
153  bison
154  ribose-automake116
155  python3
156  ruby-devel
157)
158
159declare dynamic_build_dependencies_yum=(
160  botan2-devel
161  json-c12-devel
162  python2-devel # TODO: needed?
163)
164
165
166apt_install() {
167  local apt_command=(apt -y -q install "$@")
168  if command -v sudo >/dev/null; then
169    sudo "${apt_command[@]}"
170  else
171    "${apt_command[@]}"
172  fi
173}
174
175yum_install() {
176  local yum_command=("${YUM}" -y -q install "$@")
177  if command -v sudo >/dev/null; then
178    sudo "${yum_command[@]}"
179  else
180    "${yum_command[@]}"
181  fi
182}
183
184prepare_build_tool_env() {
185  case "${DIST}" in
186    centos)
187      post_build_tool_install_set_env
188      ;;
189  esac
190
191  prepare_rbenv_env
192}
193
194yum_install_build_dependencies() {
195  yum_install \
196    "${basic_build_dependencies_yum[@]}" \
197    "${build_dependencies_yum[@]}" \
198    "$@"
199}
200
201linux_install_centos7() {
202  yum_prepare_repos epel-release centos-release-scl
203  yum_install_build_dependencies \
204    cmake3 \
205    rh-ruby25 rh-ruby25-ruby-devel \
206    llvm-toolset-7.0
207
208  yum_install_dynamic_build_dependencies_if_needed
209
210  ensure_cmake
211  ensure_ruby
212  rubygem_install_build_dependencies
213}
214
215linux_install_centos8() {
216  yum_prepare_repos epel-release
217  yum_install_build_dependencies \
218    cmake
219
220  yum_install_dynamic_build_dependencies_if_needed
221
222  ensure_cmake
223  ensure_ruby
224  rubygem_install_build_dependencies
225}
226
227is_use_static_dependencies() {
228  [[ -n "${USE_STATIC_DEPENDENCIES}" ]] && \
229    [[ no  != "${USE_STATIC_DEPENDENCIES}" ]] && \
230    [[ off != "${USE_STATIC_DEPENDENCIES}" ]] && \
231    [[ 0   != "${USE_STATIC_DEPENDENCIES}" ]]
232}
233
234yum_install_dynamic_build_dependencies_if_needed() {
235  if ! is_use_static_dependencies; then
236    yum_install_dynamic_build_dependencies
237  fi
238}
239
240install_static_noncacheable_build_dependencies_if_needed() {
241  if is_use_static_dependencies; then
242    install_static_noncacheable_build_dependencies "$@"
243  fi
244}
245
246install_static_cacheable_build_dependencies_if_needed() {
247  if is_use_static_dependencies || [[ "$#" -gt 0 ]]; then
248    install_static_cacheable_build_dependencies "$@"
249  fi
250}
251
252install_static_cacheable_build_dependencies() {
253  prepare_build_tool_env
254
255  mkdir -p "$LOCAL_BUILDS"
256
257  local default=(botan jsonc gpg)
258  local items=("${@:-${default[@]}}")
259  for item in "${items[@]}"; do
260    install_"$item"
261  done
262}
263
264install_static_noncacheable_build_dependencies() {
265  mkdir -p "$LOCAL_BUILDS"
266
267  local default=(bundler asciidoctor)
268  local items=("${@:-${default[@]}}")
269  for item in "${items[@]}"; do
270    install_"$item"
271  done
272}
273
274rubygem_install_build_dependencies() {
275  install_bundler
276  install_asciidoctor
277}
278
279yum_install_dynamic_build_dependencies() {
280  yum_install \
281    "${dynamic_build_dependencies_yum[@]}"
282
283  # Work around pkg-config giving out wrong include path for json-c:
284  ensure_symlink_to_target /usr/include/json-c12 /usr/include/json-c
285}
286
287# Make sure cmake is at least 3.14+ as required by rnp
288# Also make sure ctest is available.
289# If not, build cmake from source.
290ensure_cmake() {
291  ensure_symlink_to_target /usr/bin/cmake3 /usr/bin/cmake
292  ensure_symlink_to_target /usr/bin/cpack3 /usr/bin/cpack
293
294  local cmake_version
295  cmake_version=$({
296    command -v cmake  >/dev/null && command cmake --version || \
297    command -v cmake3 >/dev/null && command cmake3 --version
298    } | head -n1 | cut -f3 -d' '
299  )
300
301  local need_to_build_cmake=
302
303  # Make sure ctest is also in PATH.  If not, build cmake from source.
304  # TODO: Check CentOS7 tests in GHA.
305  if ! command -v ctest >/dev/null; then
306    >&2 echo "ctest not found."
307    need_to_build_cmake=1
308  elif ! is_version_at_least cmake "${MINIMUM_CMAKE_VERSION}" echo "${cmake_version}"; then
309    >&2 echo "cmake version lower than ${MINIMUM_CMAKE_VERSION}."
310    need_to_build_cmake=1
311  fi
312
313  if [[ "${need_to_build_cmake}" != 1 ]]; then
314    CMAKE="$(command -v cmake)"
315    >&2 echo "cmake rebuild is NOT needed."
316    return
317  fi
318
319  >&2 echo "cmake rebuild is needed."
320
321  pushd "$(mktemp -d)" || return 1
322
323  install_prebuilt_cmake Linux-x86_64
324
325  command -v cmake
326
327  popd
328
329  # Abort if ctest still not found.
330  if ! command -v ctest >/dev/null; then
331    >&2 echo "Error: ctest not found.  Aborting."
332    exit 1
333  fi
334}
335
336# E.g. for i386
337# NOTE: Make sure cmake's build prerequisites are installed.
338build_and_install_cmake() {
339  local cmake_build=${LOCAL_BUILDS}/cmake
340  mkdir -p "${cmake_build}"
341  pushd "${cmake_build}"
342  wget https://github.com/Kitware/CMake/releases/download/v"${RECOMMENDED_CMAKE_VERSION}"/cmake-"${RECOMMENDED_CMAKE_VERSION}".tar.gz -O cmake.tar.gz
343  tar xzf cmake.tar.gz --strip 1
344
345  PREFIX="${PREFIX:-/usr}"
346  mkdir -p "${PREFIX}"
347  ./configure --prefix="${PREFIX}" && ${MAKE} -j"${MAKE_PARALLEL}" && "${SUDO}" make install
348  popd
349  CMAKE="${PREFIX}"/bin/cmake
350}
351
352# 'arch' corresponds to the last segment of GitHub release URL
353install_prebuilt_cmake() {
354  local arch="${1:?Missing architecture}"
355  local cmake_build=${LOCAL_BUILDS}/cmake
356  mkdir -p "${cmake_build}"
357  pushd "${cmake_build}"
358  curl -L -o \
359    cmake.sh \
360    https://github.com/Kitware/CMake/releases/download/v"${RECOMMENDED_CMAKE_VERSION}"/cmake-"${RECOMMENDED_CMAKE_VERSION}"-"${arch}".sh
361
362  PREFIX="${PREFIX:-/usr}"
363  mkdir -p "${PREFIX}"
364  "${SUDO}" sh cmake.sh --skip-license --prefix="${PREFIX}"
365  popd
366  CMAKE="${PREFIX}"/bin/cmake
367}
368
369build_and_install_python() {
370  python_build=${LOCAL_BUILDS}/python
371  mkdir -p "${python_build}"
372  pushd ${python_build}
373  curl -L -o python.tar.xz https://www.python.org/ftp/python/"${RECOMMENDED_PYTHON_VERSION}"/Python-"${RECOMMENDED_PYTHON_VERSION}".tar.xz
374  tar -xf python.tar.xz --strip 1
375  ./configure --enable-optimizations --prefix=/usr && ${MAKE} -j"${MAKE_PARALLEL}" && "${SUDO}" make install
376  ${SUDO} ln -sf /usr/bin/python3 /usr/bin/python
377  popd
378}
379
380build_and_install_automake() {
381  # automake
382  automake_build=${LOCAL_BUILDS}/automake
383  mkdir -p "${automake_build}"
384  pushd ${automake_build}
385  curl -L -o automake.tar.xz https://ftp.gnu.org/gnu/automake/automake-1.16.1.tar.xz
386  tar -xf automake.tar.xz --strip 1
387  ./configure --enable-optimizations --prefix=/usr && ${MAKE} -j${MAKE_PARALLEL} && ${SUDO} make install
388  popd
389}
390
391# json-c is installed with install_jsonc
392# asciidoctor is installed with install_asciidoctor
393linux_install_ubuntu() {
394  "${SUDO}" apt-get update
395  "${SUDO}" apt-get -y install ruby-dev g++-8 cmake libbz2-dev zlib1g-dev build-essential gettext \
396    ruby-bundler libncurses-dev
397}
398
399declare util_dependencies_deb=(
400  sudo
401  wget
402  git
403)
404
405declare basic_build_dependencies_deb=(
406  autoconf
407  automake
408  make
409  build-essential
410  cmake
411  libtool
412)
413
414declare build_dependencies_deb=(
415  bison
416  byacc
417  curl
418  gettext
419  libbz2-dev
420  libncurses5-dev
421  libssl-dev
422  python3
423  python3-venv
424  ruby-dev
425  zlib1g-dev
426)
427
428declare ruby_build_dependencies_deb=(
429  bison
430  curl
431  libbz2-dev
432  libssl-dev
433  ruby-bundler
434  rubygems
435  zlib1g-dev
436)
437
438linux_install_debian() {
439  "${SUDO}" apt-get update
440  apt_install \
441    "${util_dependencies_deb[@]}" \
442    "${basic_build_dependencies_deb[@]}" \
443    "${build_dependencies_deb[@]}" \
444    "$@"
445
446  build_and_install_automake
447  build_and_install_cmake
448}
449
450linux_install() {
451  if type "linux_install_${DIST}" | grep -qwi 'function'; then
452    "linux_install_${DIST}"
453  fi
454}
455
456msys_install() {
457  local packages=(
458    tar
459    zlib-devel
460    libbz2-devel
461    git
462    automake
463    autoconf
464    libtool
465    automake-wrapper
466    gnupg2
467    make
468    pkg-config
469    mingw64/mingw-w64-x86_64-cmake
470    mingw64/mingw-w64-x86_64-gcc
471    mingw64/mingw-w64-x86_64-json-c
472    mingw64/mingw-w64-x86_64-python3
473  )
474
475  pacman --noconfirm -S --needed "${packages[@]}"
476
477  # any version starting with 2.14 up to 2.17.3 caused the application to hang
478  # as described in https://github.com/randombit/botan/issues/2582
479  # fixed with https://github.com/msys2/MINGW-packages/pull/7640/files
480  botan_pkg="mingw-w64-x86_64-libbotan-2.17.3-2-any.pkg.tar.zst"
481  pacman --noconfirm -U https://repo.msys2.org/mingw/x86_64/${botan_pkg} || \
482  pacman --noconfirm -U https://sourceforge.net/projects/msys2/files/REPOS/MINGW/x86_64/${botan_pkg}
483
484  # msys includes ruby 2.6.1 while we need lower version
485  #wget http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-ruby-2.5.3-1-any.pkg.tar.xz -O /tmp/ruby-2.5.3.pkg.tar.xz
486  #pacman --noconfirm --needed -U /tmp/ruby-2.5.3.pkg.tar.xz
487  #rm /tmp/ruby-2.5.3.pkg.tar.xz
488}
489
490# Mainly for all python scripts with shebangs pointing to
491# 'python', which is
492# unavailable in CentOS 8 by default.
493#
494# This creates an environment where straight 'python' is available.
495prepare_python_virtualenv() {
496  python3 -m venv ~/.venv
497}
498
499# Run its arguments inside a python-virtualenv-enabled sub-shell.
500run_in_python_venv() {
501  if [[ ! -e ~/.venv ]] || [[ ! -f ~/.venv/bin/activate ]]; then
502    prepare_python_virtualenv
503  fi
504
505  (
506    # Avoid issues like '_OLD_VIRTUAL_PATH: unbound variable'
507    set +u
508    . ~/.venv/bin/activate
509    set -u
510    "$@"
511  )
512}
513
514# ruby-rnp
515install_bundler() {
516  gem_install bundler bundle
517}
518
519install_asciidoctor() {
520  gem_install asciidoctor
521}
522
523declare ruby_build_dependencies_yum=(
524  git-core
525  zlib
526  zlib-devel
527  gcc-c++
528  patch
529  readline
530  readline-devel
531  libyaml-devel
532  libffi-devel
533  openssl-devel
534  make
535  bzip2
536  autoconf
537  automake
538  libtool
539  bison
540  curl
541  sqlite-devel
542  which # for rbenv-doctor
543)
544
545
546ensure_ruby() {
547  if is_version_at_least ruby "${MINIMUM_RUBY_VERSION}" command ruby -e 'puts RUBY_VERSION'; then
548    return
549  fi
550
551  # XXX: Fedora20 seems to have problems installing ruby build dependencies in
552  # yum?
553  # "${YUM}" repolist all
554  # "${SUDO}" rpm -qa | sort
555
556  if [[ "${DIST_VERSION}" = fedora-20 ]]; then
557    ruby_build_dependencies_yum+=(--enablerepo=updates-testing)
558  fi
559
560  case "${DIST}" in
561    centos|fedora)
562      yum_install "${ruby_build_dependencies_yum[@]}"
563      setup_rbenv
564      rbenv install -v "${RECOMMENDED_RUBY_VERSION}"
565      rbenv global "${RECOMMENDED_RUBY_VERSION}"
566      rbenv rehash
567      sudo chown -R "$(whoami)" "$(rbenv prefix)"
568      ;;
569    debian)
570      apt_install "${ruby_build_dependencies_deb[@]}"
571      ;;
572    *)
573      # TODO: handle ubuntu?
574      >&2 echo Error: Need to install ruby ${MINIMUM_RUBY_VERSION}+
575      exit 1
576  esac
577}
578
579
580# shellcheck disable=SC2016
581setup_rbenv() {
582  pushd "$(mktemp -d)" || return 1
583  local rbenv_rc=$HOME/setup_rbenv.sh
584  git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
585  echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> "${rbenv_rc}"
586  echo 'eval "$($HOME/.rbenv/bin/rbenv init -)"' >> "${rbenv_rc}"
587
588  git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
589  echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> "${rbenv_rc}"
590  echo ". \"${rbenv_rc}\"" >> ~/.bash_profile
591  prepare_rbenv_env
592
593  # Verify rbenv is set up correctly
594  curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
595  popd || return 1
596}
597
598prepare_rbenv_env() {
599  case "${DIST}" in
600    centos|fedora)
601      local rbenv_rc=$HOME/setup_rbenv.sh
602      [[ ! -r "${rbenv_rc}" ]] || . "${rbenv_rc}"
603      ;;
604  esac
605
606  if command -v rbenv >/dev/null; then
607    rbenv rehash
608  fi
609}
610
611is_version_at_least() {
612  local bin_name="${1:?Missing bin name}"; shift
613  local version_constraint="${1:?Missing version constraint}"; shift
614  local need_to_build=0
615
616  if ! command -v "${bin_name}"; then
617    >&2 echo "Warning: ${bin_name} not installed."
618    need_to_build=1
619  fi
620
621  local installed_version installed_version_major installed_version_minor #version_patch
622  installed_version="$("$@")"
623
624  # shellcheck disable=SC2181
625  if [[ $? -ne 0 ]]; then
626    need_to_build=1
627  else
628    installed_version_major="${installed_version%%.*}"
629    installed_version_minor="${installed_version#*.}"
630    installed_version_minor="${installed_version_minor%%.*}"
631
632    local need_version_major
633    need_version_major="${version_constraint%%.*}"
634    need_version_minor="${version_constraint#*.}"
635    need_version_minor="${need_version_minor%%.*}"
636
637    # Naive semver comparison
638    if [[ "${installed_version_major}" -lt "${need_version_major}" ]] || \
639       [[ "${installed_version_major}" = "${need_version_major}" && "${installed_version_minor}" -lt "${need_version_minor}" ]]; then
640      need_to_build=1
641    fi
642  fi
643
644  if [[ 1 = "${need_to_build}" ]]; then
645    >&2 echo "Warning: Need to build ${bin_name} since version constraint ${version_constraint} not met."
646  fi
647
648  return "${need_to_build}"
649}
650
651# Install specified gem.
652# Use rbenv when available.  Otherwise use system 'gem', and use 'sudo'
653# depending on OS.
654# Set SUDO_GEM to 'sudo' to force use of sudo.
655# Set SUDO_GEM to 'run' to disable sudo.
656gem_install() {
657  local gem_name="${1:?Missing gem name}"
658  local bin_name="${2:-${gem_name}}"
659  if ! command -v "${bin_name}" >/dev/null; then
660    if command -v rbenv >/dev/null; then
661      gem install "${gem_name}"
662      rbenv rehash
663    else
664      "${SUDO_GEM:-${SUDO:-run}}" gem install "${gem_name}"
665    fi
666  fi
667}
668
669# build+install
670build_and_install() {
671
672  export cmakeopts=(
673    -DBUILD_SHARED_LIBS="${BUILD_SHARED_LIBS}"
674    -DBUILD_TESTING=no
675    -DCMAKE_INSTALL_PREFIX="${1:-/tmp}"
676  )
677
678  if [[ $# -gt 0 ]]; then
679    shift
680  fi
681
682  build_rnp "$@"
683  make_install VERBOSE="${VERBOSE}"
684}
685
686build_rnp() {
687  "${CMAKE:-cmake}" "${cmakeopts[@]}" "${1:-.}"
688}
689
690make_install() {
691  make -j"${MAKE_PARALLEL}" install "$@"
692}
693
694is_true_cmake_bool() {
695  local arg="${1:?Missing parameter}"
696  case "${arg}" in
697    yes|on|true|y)
698      true
699      ;;
700    no|off|false|n)
701      false
702      ;;
703    *)
704      >&2 echo "Warning: unrecognized boolean expression ($arg).  Continuing and interpreting as 'false' anyway."
705      false
706  esac
707}
708
709# check for install issues
710check_build() {
711  if is_true_cmake_bool "${BUILD_SHARED_LIBS}"; then
712    export pkgflags=
713    export gccflags=
714    if ! find /usr/lib64/ -maxdepth 1 -type f -name 'librnp*.so' | grep -q . || \
715         find /usr/lib64/ -maxdepth 1 -type f -name 'librnp*.a'  | grep -q .; then
716      >&2 echo "librnp installed libraries incorrect"
717    fi
718  else
719    export pkgflags=--static
720    export gccflags=-lstdc++
721    if  find /usr/lib64/ -maxdepth 1 -type f -name 'librnp*.so' | grep -q . || \
722      ! find /usr/lib64/ -maxdepth 1 -type f -name 'librnp*.a'  | grep -q .; then
723      >&2 echo "librnp installed libraries incorrect"
724    fi
725  fi
726}
727
728# build an example using pkg-config
729build_example_pkgconfig() {
730  local rnpsrc="$PWD"
731  pushd "$(mktemp -d)" || return 1
732
733  gcc "${rnpsrc}/src/examples/generate.c" -ogenerate $(pkg-config --cflags --libs $pkgflags librnp) $gccflags
734  ./generate
735  readelf -d generate
736  if is_true_cmake_bool "${BUILD_SHARED_LIBS}"; then
737    readelf -d generate | grep -q 'librnp\>'
738  else
739    readelf -d generate | grep -qv 'librnp\>'
740  fi
741
742  # remove the pkgconfig for the next test
743  >&2 echo "Checking if librnp- is found in pkg-config list:"
744  pkg-config --list-all
745  pkg-config --list-all | grep -q '^librnp\>'
746
747  # XXX: debug
748  find /usr/lib64 -type f -name 'librnp*'
749  find /usr/lib -type f -name 'librnp*'
750
751  find /usr/lib64/pkgconfig -regextype sed -regex '.*librnp\>.*' -exec rm {} +
752
753  # XXX: debug
754  find /usr/lib64 -type f -name 'librnp*'
755  find /usr/lib -type f -name 'librnp*'
756
757  # should not be found
758  >&2 echo "Checking if librnp- is NOT found in pkg-config list:"
759  pkg-config --list-all
760  pkg-config --list-all | grep -qv '^librnp\>'
761
762  # build an example using cmake targets
763  mkdir rnp-project
764  pushd rnp-project || return 1
765
766  cat <<"EOF" > mytest.cpp
767  #include <rnp/rnp.h>
768
769  int main(int argc, char *argv[]) {
770      printf("RNP version: %s\n", rnp_version_string());
771      return 0;
772  }
773EOF
774
775  cat <<"EOF" > CMakeLists.txt
776  set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}")
777  find_package(BZip2 REQUIRED)
778  find_package(ZLIB REQUIRED)
779  find_package(JSON-C 0.11 REQUIRED)
780  find_package(Botan2 2.14.0 REQUIRED)
781  find_package(rnp REQUIRED)
782
783  cmake_minimum_required(VERSION 3.12)
784  add_executable(mytest mytest.cpp)
785  target_link_libraries(mytest rnp::librnp)
786EOF
787
788  cp "${rnpsrc}"/cmake/Modules/* .
789  cmake .
790  make VERBOSE="${VERBOSE}"
791  ./mytest
792  popd
793  popd
794}
795