blob: b8ddb6f6957631637ad6385f5a79cc1198376b67 [file] [log] [blame]
Amna8e0e1e02023-09-25 14:12:47 -04001#!/usr/bin/env python3
2# build.py --- Convenience script for building and running DHTNET dependencies
3
Sébastien Blin55be5da2024-02-12 11:29:54 -05004# Copyright (C) 2023-2024 Savoir-faire Linux Inc.
Amna8e0e1e02023-09-25 14:12:47 -04005#
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-Chapleauc3855512024-04-29 11:39:04 -040020import argparse
Amna8e0e1e02023-09-25 14:12:47 -040021import subprocess
22import os
Amna8e0e1e02023-09-25 14:12:47 -040023
Amna8e0e1e02023-09-25 14:12:47 -040024# Define paths and directories
25opendht_dir = "opendht"
26pjproject_dir = "pjproject"
27restinio_dir = "restinio"
François-Simon Fauteux-Chapleauc3855512024-04-29 11:39:04 -040028msgpack_dir = "msgpack"
Amna8e0e1e02023-09-25 14:12:47 -040029install_dir = os.path.abspath("install")
30
Sébastien Blin55be5da2024-02-12 11:29:54 -050031def build_and_install_restinio():
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040032 # 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 Blin55be5da2024-02-12 11:29:54 -050036 try:
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040037 restino_build_dir = os.path.join(restinio_dir, "dev", "cmake_build")
Sébastien Blin55be5da2024-02-12 11:29:54 -050038 cmake_command = [
39 "cmake",
40 f"-DCMAKE_INSTALL_PREFIX={install_dir}",
Amnac9da2d72024-07-02 11:14:19 -040041 "-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-Chapleau9bfc3432024-03-22 17:07:33 -040049 ".."
Sébastien Blin55be5da2024-02-12 11:29:54 -050050 ]
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040051 os.makedirs(restino_build_dir, exist_ok=True)
Sébastien Blin55be5da2024-02-12 11:29:54 -050052 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-Chapleau9bfc3432024-03-22 17:07:33 -040056 print("RESTinio built and installed successfully.")
Sébastien Blin55be5da2024-02-12 11:29:54 -050057 return True
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040058 except (subprocess.CalledProcessError, OSError) as e:
59 print("Error building or installing restinio:", e)
Sébastien Blin55be5da2024-02-12 11:29:54 -050060 return False
61
Amna8e0e1e02023-09-25 14:12:47 -040062def build_and_install_opendht():
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040063 print("\nBuilding and installing OpenDHT...", flush=True)
Amna8e0e1e02023-09-25 14:12:47 -040064 try:
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040065 opendht_build_dir = os.path.join(opendht_dir, "build")
66 cmake_command = [
67 "cmake", "..",
Amna8e0e1e02023-09-25 14:12:47 -040068 "-DCMAKE_INSTALL_PREFIX=" + install_dir,
Sébastien Blin55be5da2024-02-12 11:29:54 -050069 "-DCMAKE_PREFIX_PATH=" + install_dir, # For finding restinio
Amna8e0e1e02023-09-25 14:12:47 -040070 "-DCMAKE_BUILD_TYPE=Release",
Adrien Béraud0a838222023-09-28 18:34:44 -040071 "-DBUILD_SHARED_LIBS=OFF",
Amna8e0e1e02023-09-25 14:12:47 -040072 "-DBUILD_TESTING=OFF",
73 "-DOPENDHT_PYTHON=OFF",
74 "-DOPENDHT_TOOLS=OFF",
75 "-DOPENDHT_DOCUMENTATION=OFF",
76 "-DOPENDHT_HTTP=ON",
77 "-DOPENDHT_PROXY_CLIENT=ON",
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040078 ]
79 os.makedirs(opendht_build_dir, exist_ok=True)
80 subprocess.run(cmake_command, cwd=opendht_build_dir, check=True)
81 subprocess.run(["make", "install"], cwd=opendht_build_dir, check=True)
Amna43b66c82023-10-03 10:39:22 -040082 print("OpenDHT installed successfully.")
Sébastien Blin55be5da2024-02-12 11:29:54 -050083 return True
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040084 except (subprocess.CalledProcessError, OSError) as e:
85 print("Error building or installing OpenDHT:", e)
Sébastien Blin55be5da2024-02-12 11:29:54 -050086 return False
Amna8e0e1e02023-09-25 14:12:47 -040087
88def build_and_install_pjproject():
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040089 print("\nBuilding and installing PJSIP...", flush=True)
Amna8e0e1e02023-09-25 14:12:47 -040090 try:
91 configure_command = [
92 "./configure",
93 f"--prefix={install_dir}",
94 "--disable-sound",
95 "--enable-video",
96 "--enable-ext-sound",
97 "--disable-speex-aec",
98 "--disable-g711-codec",
99 "--disable-l16-codec",
100 "--disable-gsm-codec",
101 "--disable-g722-codec",
102 "--disable-g7221-codec",
103 "--disable-speex-codec",
104 "--disable-ilbc-codec",
105 "--disable-opencore-amr",
106 "--disable-silk",
107 "--disable-sdl",
108 "--disable-ffmpeg",
109 "--disable-v4l2",
110 "--disable-openh264",
111 "--disable-resample",
112 "--disable-libwebrtc",
113 f"--with-gnutls={install_dir}"
114 ]
115 subprocess.run(configure_command, cwd=pjproject_dir, check=True)
116 subprocess.run(["make"], cwd=pjproject_dir, check=True)
117 subprocess.run(["make", "install"], cwd=pjproject_dir, check=True)
118
Amna43b66c82023-10-03 10:39:22 -0400119 print("PJSIP libraries built successfully.")
Sébastien Blin55be5da2024-02-12 11:29:54 -0500120 return True
Amna8e0e1e02023-09-25 14:12:47 -0400121 except subprocess.CalledProcessError as e:
Amna43b66c82023-10-03 10:39:22 -0400122 print("Error building PJSIP libraries: %s", e)
Sébastien Blin55be5da2024-02-12 11:29:54 -0500123 return False
Amna8e0e1e02023-09-25 14:12:47 -0400124
François-Simon Fauteux-Chapleauc3855512024-04-29 11:39:04 -0400125def build_and_install_msgpack():
126 print("\nBuilding and installing msgpack...", flush=True)
127 try:
128 msgpack_build_dir = os.path.join(msgpack_dir, "build")
129 cmake_command = [
130 "cmake", "..",
131 "-DCMAKE_INSTALL_PREFIX=" + install_dir,
132 "-DCMAKE_BUILD_TYPE=Release",
133 "-DMSGPACK_CXX17=ON",
134 "-DMSGPACK_USE_BOOST=OFF",
135 "-DMSGPACK_BUILD_EXAMPLES=OFF",
136 ]
137 os.makedirs(msgpack_build_dir, exist_ok=True)
138 subprocess.run(cmake_command, cwd=msgpack_build_dir, check=True)
139 subprocess.run(["make", "install"], cwd=msgpack_build_dir, check=True)
140 print("msgpack installed successfully.")
141 return True
142 except (subprocess.CalledProcessError, OSError) as e:
143 print("Error building or installing msgpack:", e)
144 return False
145
Amnac9da2d72024-07-02 11:14:19 -0400146def download_and_install_expected_lite():
147 print("\nDownloading and installing expected-lite...", flush=True)
148 os.makedirs(f"{install_dir}/include/nonstd", exist_ok=True)
149 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)
150
Amna8e0e1e02023-09-25 14:12:47 -0400151def main():
François-Simon Fauteux-Chapleauc3855512024-04-29 11:39:04 -0400152 # Parse arguments
153 parser = argparse.ArgumentParser(description="DHTNet dependencies build script")
154 parser.add_argument('--build-msgpack', default=False, action='store_true')
155 args = parser.parse_args()
156
Amna8e0e1e02023-09-25 14:12:47 -0400157 # Create install directory if it doesn't exist
158 if not os.path.exists(install_dir):
159 os.makedirs(install_dir)
Amnac9da2d72024-07-02 11:14:19 -0400160
161 # Download and install expected-lite
162 download_and_install_expected_lite()
163
Amna8e0e1e02023-09-25 14:12:47 -0400164 # Build and install restinio
Sébastien Blin55be5da2024-02-12 11:29:54 -0500165 if not build_and_install_restinio():
166 print("Error building or installing restinio.")
167 return
Amna8e0e1e02023-09-25 14:12:47 -0400168
François-Simon Fauteux-Chapleauc3855512024-04-29 11:39:04 -0400169 # Build and install msgpack if necessary
170 if args.build_msgpack:
171 if not build_and_install_msgpack():
172 print("Error building or installing msgpack.")
173 return
174
Amna8e0e1e02023-09-25 14:12:47 -0400175 # Build and install OpenDHT
Sébastien Blin55be5da2024-02-12 11:29:54 -0500176 if not build_and_install_opendht():
177 print("Error building or installing OpenDHT.")
178 return
Amna8e0e1e02023-09-25 14:12:47 -0400179
180 # Build and install pjproject
Sébastien Blin55be5da2024-02-12 11:29:54 -0500181 if not build_and_install_pjproject():
182 print("Error building or installing PJSIP libraries.")
183 return
Amna8e0e1e02023-09-25 14:12:47 -0400184
Adrien Béraud0a838222023-09-28 18:34:44 -0400185 subprocess.run([f"for p in {install_dir}/lib/pkgconfig/*.pc; do ./pkg-static.sh $p; done"], shell=True, check=True)
186
Amna8e0e1e02023-09-25 14:12:47 -0400187
188if __name__ == "__main__":
189 main()