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(): |
| 30 | try: |
| 31 | restino_build_dir = restinio_dir + "/dev/" |
| 32 | cmake_command = [ |
| 33 | "cmake", |
| 34 | f"-DCMAKE_INSTALL_PREFIX={install_dir}", |
| 35 | "-DRESTINIO_TEST=OFF", |
| 36 | "-DRESTINIO_SAMPLE=OFF", |
| 37 | "-DRESTINIO_INSTALL_SAMPLES=OFF", |
| 38 | "-DRESTINIO_BENCH=OFF", |
| 39 | "-DRESTINIO_INSTALL_BENCHES=OFF", |
| 40 | "-DRESTINIO_FIND_DEPS=ON", |
| 41 | "-DRESTINIO_ALLOW_SOBJECTIZER=Off", |
| 42 | "-DRESTINIO_USE_BOOST_ASIO=none", |
| 43 | "." |
| 44 | ] |
| 45 | subprocess.run(cmake_command, cwd=restino_build_dir, check=True) |
| 46 | subprocess.run(["make", "-j8"], cwd=restino_build_dir, check=True) |
| 47 | subprocess.run(["make", "install"], cwd=restino_build_dir, check=True) |
| 48 | |
| 49 | print("restinio built and installed successfully.") |
| 50 | return True |
| 51 | except subprocess.CalledProcessError as e: |
| 52 | print("Error building or installing restinio: %s", e) |
| 53 | return False |
| 54 | |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 55 | def build_and_install_opendht(): |
Amna | 43b66c8 | 2023-10-03 10:39:22 -0400 | [diff] [blame] | 56 | print("Building and installing OpenDHT...") |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 57 | try: |
| 58 | # Configure OpenDHT with CMake |
| 59 | subprocess.run(["cmake", ".", |
| 60 | "-DCMAKE_INSTALL_PREFIX=" + install_dir, |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 61 | "-DCMAKE_PREFIX_PATH=" + install_dir, # For finding restinio |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 62 | "-DCMAKE_BUILD_TYPE=Release", |
Adrien Béraud | 0a83822 | 2023-09-28 18:34:44 -0400 | [diff] [blame] | 63 | "-DBUILD_SHARED_LIBS=OFF", |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 64 | "-DBUILD_TESTING=OFF", |
| 65 | "-DOPENDHT_PYTHON=OFF", |
| 66 | "-DOPENDHT_TOOLS=OFF", |
| 67 | "-DOPENDHT_DOCUMENTATION=OFF", |
| 68 | "-DOPENDHT_HTTP=ON", |
| 69 | "-DOPENDHT_PROXY_CLIENT=ON", |
| 70 | ], cwd=opendht_dir, check=True) |
| 71 | |
| 72 | # Build and install OpenDHT |
| 73 | subprocess.run(["make", "install"], cwd=opendht_dir, check=True) |
Amna | 43b66c8 | 2023-10-03 10:39:22 -0400 | [diff] [blame] | 74 | print("OpenDHT installed successfully.") |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 75 | return True |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 76 | except subprocess.CalledProcessError as e: |
Amna | 43b66c8 | 2023-10-03 10:39:22 -0400 | [diff] [blame] | 77 | print("Error building or installing OpenDHT: %s", e) |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 78 | return False |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 79 | |
| 80 | def build_and_install_pjproject(): |
| 81 | # Build PJSIP libraries |
| 82 | try: |
| 83 | configure_command = [ |
| 84 | "./configure", |
| 85 | f"--prefix={install_dir}", |
| 86 | "--disable-sound", |
| 87 | "--enable-video", |
| 88 | "--enable-ext-sound", |
| 89 | "--disable-speex-aec", |
| 90 | "--disable-g711-codec", |
| 91 | "--disable-l16-codec", |
| 92 | "--disable-gsm-codec", |
| 93 | "--disable-g722-codec", |
| 94 | "--disable-g7221-codec", |
| 95 | "--disable-speex-codec", |
| 96 | "--disable-ilbc-codec", |
| 97 | "--disable-opencore-amr", |
| 98 | "--disable-silk", |
| 99 | "--disable-sdl", |
| 100 | "--disable-ffmpeg", |
| 101 | "--disable-v4l2", |
| 102 | "--disable-openh264", |
| 103 | "--disable-resample", |
| 104 | "--disable-libwebrtc", |
| 105 | f"--with-gnutls={install_dir}" |
| 106 | ] |
| 107 | subprocess.run(configure_command, cwd=pjproject_dir, check=True) |
| 108 | subprocess.run(["make"], cwd=pjproject_dir, check=True) |
| 109 | subprocess.run(["make", "install"], cwd=pjproject_dir, check=True) |
| 110 | |
Amna | 43b66c8 | 2023-10-03 10:39:22 -0400 | [diff] [blame] | 111 | print("PJSIP libraries built successfully.") |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 112 | return True |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 113 | except subprocess.CalledProcessError as e: |
Amna | 43b66c8 | 2023-10-03 10:39:22 -0400 | [diff] [blame] | 114 | print("Error building PJSIP libraries: %s", e) |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 115 | return False |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 116 | |
| 117 | def main(): |
| 118 | # Create install directory if it doesn't exist |
| 119 | if not os.path.exists(install_dir): |
| 120 | os.makedirs(install_dir) |
| 121 | # Build and install restinio |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 122 | if not build_and_install_restinio(): |
| 123 | print("Error building or installing restinio.") |
| 124 | return |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 125 | |
| 126 | # Build and install OpenDHT |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 127 | if not build_and_install_opendht(): |
| 128 | print("Error building or installing OpenDHT.") |
| 129 | return |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 130 | |
| 131 | # Build and install pjproject |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 132 | if not build_and_install_pjproject(): |
| 133 | print("Error building or installing PJSIP libraries.") |
| 134 | return |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 135 | |
Adrien Béraud | 0a83822 | 2023-09-28 18:34:44 -0400 | [diff] [blame] | 136 | subprocess.run([f"for p in {install_dir}/lib/pkgconfig/*.pc; do ./pkg-static.sh $p; done"], shell=True, check=True) |
| 137 | |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 138 | |
| 139 | if __name__ == "__main__": |
| 140 | main() |