Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # build.py --- Convenience script for building and running DHTNET dependencies |
| 3 | |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 4 | # Copyright (C) 2023-2024 Savoir-faire Linux Inc. |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation; either version 3 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program; if not, write to the Free Software |
| 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | |
| 20 | import subprocess |
| 21 | import os |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 22 | |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 23 | # Define paths and directories |
| 24 | opendht_dir = "opendht" |
| 25 | pjproject_dir = "pjproject" |
| 26 | restinio_dir = "restinio" |
| 27 | install_dir = os.path.abspath("install") |
| 28 | |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 29 | def build_and_install_restinio(): |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 30 | # Setting flush=True because this script is called by CMake via the |
| 31 | # execute_process function, which by default doesn't print the content |
| 32 | # of standard output until the executed process returns. |
| 33 | print("\nBuilding and installing RESTinio...", flush=True) |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 34 | try: |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 35 | restino_build_dir = os.path.join(restinio_dir, "dev", "cmake_build") |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 36 | cmake_command = [ |
| 37 | "cmake", |
| 38 | f"-DCMAKE_INSTALL_PREFIX={install_dir}", |
| 39 | "-DRESTINIO_TEST=OFF", |
| 40 | "-DRESTINIO_SAMPLE=OFF", |
| 41 | "-DRESTINIO_INSTALL_SAMPLES=OFF", |
| 42 | "-DRESTINIO_BENCH=OFF", |
| 43 | "-DRESTINIO_INSTALL_BENCHES=OFF", |
| 44 | "-DRESTINIO_FIND_DEPS=ON", |
| 45 | "-DRESTINIO_ALLOW_SOBJECTIZER=Off", |
| 46 | "-DRESTINIO_USE_BOOST_ASIO=none", |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 47 | ".." |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 48 | ] |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 49 | os.makedirs(restino_build_dir, exist_ok=True) |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 50 | subprocess.run(cmake_command, cwd=restino_build_dir, check=True) |
| 51 | subprocess.run(["make", "-j8"], cwd=restino_build_dir, check=True) |
| 52 | subprocess.run(["make", "install"], cwd=restino_build_dir, check=True) |
| 53 | |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 54 | print("RESTinio built and installed successfully.") |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 55 | return True |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 56 | except (subprocess.CalledProcessError, OSError) as e: |
| 57 | print("Error building or installing restinio:", e) |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 58 | return False |
| 59 | |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 60 | def build_and_install_opendht(): |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 61 | print("\nBuilding and installing OpenDHT...", flush=True) |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 62 | try: |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 63 | opendht_build_dir = os.path.join(opendht_dir, "build") |
| 64 | cmake_command = [ |
| 65 | "cmake", "..", |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 66 | "-DCMAKE_INSTALL_PREFIX=" + install_dir, |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 67 | "-DCMAKE_PREFIX_PATH=" + install_dir, # For finding restinio |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 68 | "-DCMAKE_BUILD_TYPE=Release", |
Adrien Béraud | 0a83822 | 2023-09-28 18:34:44 -0400 | [diff] [blame] | 69 | "-DBUILD_SHARED_LIBS=OFF", |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 70 | "-DBUILD_TESTING=OFF", |
| 71 | "-DOPENDHT_PYTHON=OFF", |
| 72 | "-DOPENDHT_TOOLS=OFF", |
| 73 | "-DOPENDHT_DOCUMENTATION=OFF", |
| 74 | "-DOPENDHT_HTTP=ON", |
| 75 | "-DOPENDHT_PROXY_CLIENT=ON", |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 76 | ] |
| 77 | os.makedirs(opendht_build_dir, exist_ok=True) |
| 78 | subprocess.run(cmake_command, cwd=opendht_build_dir, check=True) |
| 79 | subprocess.run(["make", "install"], cwd=opendht_build_dir, check=True) |
Amna | 43b66c8 | 2023-10-03 10:39:22 -0400 | [diff] [blame] | 80 | print("OpenDHT installed successfully.") |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 81 | return True |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 82 | except (subprocess.CalledProcessError, OSError) as e: |
| 83 | print("Error building or installing OpenDHT:", e) |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 84 | return False |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 85 | |
| 86 | def build_and_install_pjproject(): |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 87 | print("\nBuilding and installing PJSIP...", flush=True) |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 88 | try: |
| 89 | configure_command = [ |
| 90 | "./configure", |
| 91 | f"--prefix={install_dir}", |
| 92 | "--disable-sound", |
| 93 | "--enable-video", |
| 94 | "--enable-ext-sound", |
| 95 | "--disable-speex-aec", |
| 96 | "--disable-g711-codec", |
| 97 | "--disable-l16-codec", |
| 98 | "--disable-gsm-codec", |
| 99 | "--disable-g722-codec", |
| 100 | "--disable-g7221-codec", |
| 101 | "--disable-speex-codec", |
| 102 | "--disable-ilbc-codec", |
| 103 | "--disable-opencore-amr", |
| 104 | "--disable-silk", |
| 105 | "--disable-sdl", |
| 106 | "--disable-ffmpeg", |
| 107 | "--disable-v4l2", |
| 108 | "--disable-openh264", |
| 109 | "--disable-resample", |
| 110 | "--disable-libwebrtc", |
| 111 | f"--with-gnutls={install_dir}" |
| 112 | ] |
| 113 | subprocess.run(configure_command, cwd=pjproject_dir, check=True) |
| 114 | subprocess.run(["make"], cwd=pjproject_dir, check=True) |
| 115 | subprocess.run(["make", "install"], cwd=pjproject_dir, check=True) |
| 116 | |
Amna | 43b66c8 | 2023-10-03 10:39:22 -0400 | [diff] [blame] | 117 | print("PJSIP libraries built successfully.") |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 118 | return True |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 119 | except subprocess.CalledProcessError as e: |
Amna | 43b66c8 | 2023-10-03 10:39:22 -0400 | [diff] [blame] | 120 | print("Error building PJSIP libraries: %s", e) |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 121 | return False |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 122 | |
| 123 | def main(): |
| 124 | # Create install directory if it doesn't exist |
| 125 | if not os.path.exists(install_dir): |
| 126 | os.makedirs(install_dir) |
| 127 | # Build and install restinio |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 128 | if not build_and_install_restinio(): |
| 129 | print("Error building or installing restinio.") |
| 130 | return |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 131 | |
| 132 | # Build and install OpenDHT |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 133 | if not build_and_install_opendht(): |
| 134 | print("Error building or installing OpenDHT.") |
| 135 | return |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 136 | |
| 137 | # Build and install pjproject |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 138 | if not build_and_install_pjproject(): |
| 139 | print("Error building or installing PJSIP libraries.") |
| 140 | return |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 141 | |
Adrien Béraud | 0a83822 | 2023-09-28 18:34:44 -0400 | [diff] [blame] | 142 | subprocess.run([f"for p in {install_dir}/lib/pkgconfig/*.pc; do ./pkg-static.sh $p; done"], shell=True, check=True) |
| 143 | |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 144 | |
| 145 | if __name__ == "__main__": |
| 146 | main() |