blob: 7d5221e293702a5045da85bcd24bde34b7a14d71 [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",
Amna2eb254c2024-07-23 14:03:23 -040071 "-DCMAKE_POSITION_INDEPENDENT_CODE=ON",
Adrien Béraud0a838222023-09-28 18:34:44 -040072 "-DBUILD_SHARED_LIBS=OFF",
Amna8e0e1e02023-09-25 14:12:47 -040073 "-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-Chapleau9bfc3432024-03-22 17:07:33 -040079 ]
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)
Amna43b66c82023-10-03 10:39:22 -040083 print("OpenDHT installed successfully.")
Sébastien Blin55be5da2024-02-12 11:29:54 -050084 return True
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040085 except (subprocess.CalledProcessError, OSError) as e:
86 print("Error building or installing OpenDHT:", e)
Sébastien Blin55be5da2024-02-12 11:29:54 -050087 return False
Amna8e0e1e02023-09-25 14:12:47 -040088
89def build_and_install_pjproject():
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040090 print("\nBuilding and installing PJSIP...", flush=True)
Amna8e0e1e02023-09-25 14:12:47 -040091 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",
Amna2eb254c2024-07-23 14:03:23 -0400114 f"--with-gnutls={install_dir}",
115 'CFLAGS=-fPIC',
Amna8e0e1e02023-09-25 14:12:47 -0400116 ]
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
Amna43b66c82023-10-03 10:39:22 -0400121 print("PJSIP libraries built successfully.")
Sébastien Blin55be5da2024-02-12 11:29:54 -0500122 return True
Amna8e0e1e02023-09-25 14:12:47 -0400123 except subprocess.CalledProcessError as e:
Amna43b66c82023-10-03 10:39:22 -0400124 print("Error building PJSIP libraries: %s", e)
Sébastien Blin55be5da2024-02-12 11:29:54 -0500125 return False
Amna8e0e1e02023-09-25 14:12:47 -0400126
François-Simon Fauteux-Chapleauc3855512024-04-29 11:39:04 -0400127def 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",
Amna2eb254c2024-07-23 14:03:23 -0400135 "-DCMAKE_POSITION_INDEPENDENT_CODE=ON",
François-Simon Fauteux-Chapleauc3855512024-04-29 11:39:04 -0400136 "-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
Amnac9da2d72024-07-02 11:14:19 -0400149def 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
Amna8e0e1e02023-09-25 14:12:47 -0400154def main():
François-Simon Fauteux-Chapleauc3855512024-04-29 11:39:04 -0400155 # 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
Amna8e0e1e02023-09-25 14:12:47 -0400160 # Create install directory if it doesn't exist
161 if not os.path.exists(install_dir):
162 os.makedirs(install_dir)
Amnac9da2d72024-07-02 11:14:19 -0400163
164 # Download and install expected-lite
165 download_and_install_expected_lite()
166
Amna8e0e1e02023-09-25 14:12:47 -0400167 # Build and install restinio
Sébastien Blin55be5da2024-02-12 11:29:54 -0500168 if not build_and_install_restinio():
169 print("Error building or installing restinio.")
170 return
Amna8e0e1e02023-09-25 14:12:47 -0400171
François-Simon Fauteux-Chapleauc3855512024-04-29 11:39:04 -0400172 # 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
Amna8e0e1e02023-09-25 14:12:47 -0400178 # Build and install OpenDHT
Sébastien Blin55be5da2024-02-12 11:29:54 -0500179 if not build_and_install_opendht():
180 print("Error building or installing OpenDHT.")
181 return
Amna8e0e1e02023-09-25 14:12:47 -0400182
183 # Build and install pjproject
Sébastien Blin55be5da2024-02-12 11:29:54 -0500184 if not build_and_install_pjproject():
185 print("Error building or installing PJSIP libraries.")
186 return
Amna8e0e1e02023-09-25 14:12:47 -0400187
Adrien Béraud0a838222023-09-28 18:34:44 -0400188 subprocess.run([f"for p in {install_dir}/lib/pkgconfig/*.pc; do ./pkg-static.sh $p; done"], shell=True, check=True)
189
Amna8e0e1e02023-09-25 14:12:47 -0400190
191if __name__ == "__main__":
192 main()