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 | |
François-Simon Fauteux-Chapleau | c385551 | 2024-04-29 11:39:04 -0400 | [diff] [blame] | 20 | import argparse |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 21 | import subprocess |
| 22 | import os |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 23 | |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 24 | # Define paths and directories |
| 25 | opendht_dir = "opendht" |
| 26 | pjproject_dir = "pjproject" |
| 27 | restinio_dir = "restinio" |
François-Simon Fauteux-Chapleau | c385551 | 2024-04-29 11:39:04 -0400 | [diff] [blame] | 28 | msgpack_dir = "msgpack" |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 29 | install_dir = os.path.abspath("install") |
| 30 | |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 31 | def build_and_install_restinio(): |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 32 | # Setting flush=True because this script is called by CMake via the |
| 33 | # execute_process function, which by default doesn't print the content |
| 34 | # of standard output until the executed process returns. |
| 35 | print("\nBuilding and installing RESTinio...", flush=True) |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 36 | try: |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 37 | restino_build_dir = os.path.join(restinio_dir, "dev", "cmake_build") |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 38 | cmake_command = [ |
| 39 | "cmake", |
| 40 | f"-DCMAKE_INSTALL_PREFIX={install_dir}", |
Amna | c9da2d7 | 2024-07-02 11:14:19 -0400 | [diff] [blame] | 41 | "-DRESTINIO_TEST=Off", |
| 42 | "-DRESTINIO_SAMPLE=Off", |
| 43 | "-DRESTINIO_BENCHMARK=Off", |
| 44 | "-DRESTINIO_WITH_SOBJECTIZER=Off", |
| 45 | "-DRESTINIO_DEP_STANDALONE_ASIO=system", |
| 46 | "-DRESTINIO_DEP_LLHTTP=system", |
| 47 | "-DRESTINIO_DEP_FMT=system", |
| 48 | "-DRESTINIO_DEP_EXPECTED_LITE=system", |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 49 | ".." |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 50 | ] |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 51 | os.makedirs(restino_build_dir, exist_ok=True) |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 52 | subprocess.run(cmake_command, cwd=restino_build_dir, check=True) |
| 53 | subprocess.run(["make", "-j8"], cwd=restino_build_dir, check=True) |
| 54 | subprocess.run(["make", "install"], cwd=restino_build_dir, check=True) |
| 55 | |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 56 | print("RESTinio built and installed successfully.") |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 57 | return True |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 58 | except (subprocess.CalledProcessError, OSError) as e: |
| 59 | print("Error building or installing restinio:", e) |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 60 | return False |
| 61 | |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 62 | def build_and_install_opendht(): |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 63 | print("\nBuilding and installing OpenDHT...", flush=True) |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 64 | try: |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 65 | opendht_build_dir = os.path.join(opendht_dir, "build") |
| 66 | cmake_command = [ |
| 67 | "cmake", "..", |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 68 | "-DCMAKE_INSTALL_PREFIX=" + install_dir, |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 69 | "-DCMAKE_PREFIX_PATH=" + install_dir, # For finding restinio |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 70 | "-DCMAKE_BUILD_TYPE=Release", |
Amna | 2eb254c | 2024-07-23 14:03:23 -0400 | [diff] [blame] | 71 | "-DCMAKE_POSITION_INDEPENDENT_CODE=ON", |
Adrien Béraud | 0a83822 | 2023-09-28 18:34:44 -0400 | [diff] [blame] | 72 | "-DBUILD_SHARED_LIBS=OFF", |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 73 | "-DBUILD_TESTING=OFF", |
| 74 | "-DOPENDHT_PYTHON=OFF", |
| 75 | "-DOPENDHT_TOOLS=OFF", |
| 76 | "-DOPENDHT_DOCUMENTATION=OFF", |
| 77 | "-DOPENDHT_HTTP=ON", |
| 78 | "-DOPENDHT_PROXY_CLIENT=ON", |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 79 | ] |
| 80 | os.makedirs(opendht_build_dir, exist_ok=True) |
| 81 | subprocess.run(cmake_command, cwd=opendht_build_dir, check=True) |
| 82 | subprocess.run(["make", "install"], cwd=opendht_build_dir, check=True) |
Amna | 43b66c8 | 2023-10-03 10:39:22 -0400 | [diff] [blame] | 83 | print("OpenDHT installed successfully.") |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 84 | return True |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 85 | except (subprocess.CalledProcessError, OSError) as e: |
| 86 | print("Error building or installing OpenDHT:", e) |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 87 | return False |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 88 | |
| 89 | def build_and_install_pjproject(): |
François-Simon Fauteux-Chapleau | 9bfc343 | 2024-03-22 17:07:33 -0400 | [diff] [blame] | 90 | print("\nBuilding and installing PJSIP...", flush=True) |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 91 | try: |
| 92 | configure_command = [ |
| 93 | "./configure", |
| 94 | f"--prefix={install_dir}", |
| 95 | "--disable-sound", |
| 96 | "--enable-video", |
| 97 | "--enable-ext-sound", |
| 98 | "--disable-speex-aec", |
| 99 | "--disable-g711-codec", |
| 100 | "--disable-l16-codec", |
| 101 | "--disable-gsm-codec", |
| 102 | "--disable-g722-codec", |
| 103 | "--disable-g7221-codec", |
| 104 | "--disable-speex-codec", |
| 105 | "--disable-ilbc-codec", |
| 106 | "--disable-opencore-amr", |
| 107 | "--disable-silk", |
| 108 | "--disable-sdl", |
| 109 | "--disable-ffmpeg", |
| 110 | "--disable-v4l2", |
| 111 | "--disable-openh264", |
| 112 | "--disable-resample", |
| 113 | "--disable-libwebrtc", |
Amna | 2eb254c | 2024-07-23 14:03:23 -0400 | [diff] [blame] | 114 | f"--with-gnutls={install_dir}", |
| 115 | 'CFLAGS=-fPIC', |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 116 | ] |
| 117 | subprocess.run(configure_command, cwd=pjproject_dir, check=True) |
| 118 | subprocess.run(["make"], cwd=pjproject_dir, check=True) |
| 119 | subprocess.run(["make", "install"], cwd=pjproject_dir, check=True) |
| 120 | |
Amna | 43b66c8 | 2023-10-03 10:39:22 -0400 | [diff] [blame] | 121 | print("PJSIP libraries built successfully.") |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 122 | return True |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 123 | except subprocess.CalledProcessError as e: |
Amna | 43b66c8 | 2023-10-03 10:39:22 -0400 | [diff] [blame] | 124 | print("Error building PJSIP libraries: %s", e) |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 125 | return False |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 126 | |
François-Simon Fauteux-Chapleau | c385551 | 2024-04-29 11:39:04 -0400 | [diff] [blame] | 127 | def build_and_install_msgpack(): |
| 128 | print("\nBuilding and installing msgpack...", flush=True) |
| 129 | try: |
| 130 | msgpack_build_dir = os.path.join(msgpack_dir, "build") |
| 131 | cmake_command = [ |
| 132 | "cmake", "..", |
| 133 | "-DCMAKE_INSTALL_PREFIX=" + install_dir, |
| 134 | "-DCMAKE_BUILD_TYPE=Release", |
Amna | 2eb254c | 2024-07-23 14:03:23 -0400 | [diff] [blame] | 135 | "-DCMAKE_POSITION_INDEPENDENT_CODE=ON", |
François-Simon Fauteux-Chapleau | c385551 | 2024-04-29 11:39:04 -0400 | [diff] [blame] | 136 | "-DMSGPACK_CXX17=ON", |
| 137 | "-DMSGPACK_USE_BOOST=OFF", |
| 138 | "-DMSGPACK_BUILD_EXAMPLES=OFF", |
| 139 | ] |
| 140 | os.makedirs(msgpack_build_dir, exist_ok=True) |
| 141 | subprocess.run(cmake_command, cwd=msgpack_build_dir, check=True) |
| 142 | subprocess.run(["make", "install"], cwd=msgpack_build_dir, check=True) |
| 143 | print("msgpack installed successfully.") |
| 144 | return True |
| 145 | except (subprocess.CalledProcessError, OSError) as e: |
| 146 | print("Error building or installing msgpack:", e) |
| 147 | return False |
| 148 | |
Amna | c9da2d7 | 2024-07-02 11:14:19 -0400 | [diff] [blame] | 149 | def download_and_install_expected_lite(): |
| 150 | print("\nDownloading and installing expected-lite...", flush=True) |
| 151 | os.makedirs(f"{install_dir}/include/nonstd", exist_ok=True) |
| 152 | subprocess.run([f"wget https://raw.githubusercontent.com/martinmoene/expected-lite/master/include/nonstd/expected.hpp -O {install_dir}/include/nonstd/expected.hpp"], shell=True, check=True) |
| 153 | |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 154 | def main(): |
François-Simon Fauteux-Chapleau | c385551 | 2024-04-29 11:39:04 -0400 | [diff] [blame] | 155 | # Parse arguments |
| 156 | parser = argparse.ArgumentParser(description="DHTNet dependencies build script") |
| 157 | parser.add_argument('--build-msgpack', default=False, action='store_true') |
| 158 | args = parser.parse_args() |
| 159 | |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 160 | # Create install directory if it doesn't exist |
| 161 | if not os.path.exists(install_dir): |
| 162 | os.makedirs(install_dir) |
Amna | c9da2d7 | 2024-07-02 11:14:19 -0400 | [diff] [blame] | 163 | |
| 164 | # Download and install expected-lite |
| 165 | download_and_install_expected_lite() |
| 166 | |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 167 | # Build and install restinio |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 168 | if not build_and_install_restinio(): |
| 169 | print("Error building or installing restinio.") |
| 170 | return |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 171 | |
François-Simon Fauteux-Chapleau | c385551 | 2024-04-29 11:39:04 -0400 | [diff] [blame] | 172 | # Build and install msgpack if necessary |
| 173 | if args.build_msgpack: |
| 174 | if not build_and_install_msgpack(): |
| 175 | print("Error building or installing msgpack.") |
| 176 | return |
| 177 | |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 178 | # Build and install OpenDHT |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 179 | if not build_and_install_opendht(): |
| 180 | print("Error building or installing OpenDHT.") |
| 181 | return |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 182 | |
| 183 | # Build and install pjproject |
Sébastien Blin | 55be5da | 2024-02-12 11:29:54 -0500 | [diff] [blame] | 184 | if not build_and_install_pjproject(): |
| 185 | print("Error building or installing PJSIP libraries.") |
| 186 | return |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 187 | |
Adrien Béraud | 0a83822 | 2023-09-28 18:34:44 -0400 | [diff] [blame] | 188 | subprocess.run([f"for p in {install_dir}/lib/pkgconfig/*.pc; do ./pkg-static.sh $p; done"], shell=True, check=True) |
| 189 | |
Amna | 8e0e1e0 | 2023-09-25 14:12:47 -0400 | [diff] [blame] | 190 | |
| 191 | if __name__ == "__main__": |
| 192 | main() |