| 121 | pc = None |
| 122 | |
| 123 | def lib_ext_kwargs(pc, prefix_env_var, lib_name, lib_pkg_name, pc_version, lib_subdir="lib"): |
| 124 | system_prefix = os.environ.get(prefix_env_var) |
| 125 | if system_prefix: |
| 126 | print(f"Detected and preferring {lib_pkg_name} [via {prefix_env_var}]") |
| 127 | return dict( |
| 128 | include_dirs=[os.path.join(system_prefix, "include")], |
| 129 | library_dirs=[os.path.join(system_prefix, lib_subdir)], |
| 130 | libraries=[lib_name], |
| 131 | ) |
| 132 | |
| 133 | if pc and pc.installed(lib_pkg_name, pc_version): |
| 134 | print(f"Detected and preferring {lib_pkg_name} [via pkg-config]") |
| 135 | return pc.parse(lib_pkg_name) |
| 136 | raise Exception( |
| 137 | f"Could not find {lib_name} lib/headers, please set {prefix_env_var} " |
| 138 | f"or ensure {lib_pkg_name}.pc is in PKG_CONFIG_PATH." |
| 139 | ) |
| 140 | |
| 141 | if is_win32: |
| 142 | crypto_ext_lib = lib_ext_kwargs(pc, "BORG_OPENSSL_PREFIX", "libcrypto", "libcrypto", ">=1.1.1", lib_subdir="") |