blob: e3c3499523e4e6d864872d166b2ec93f313ef6f8 [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
20import subprocess
21import os
Amna8e0e1e02023-09-25 14:12:47 -040022
Amna8e0e1e02023-09-25 14:12:47 -040023# Define paths and directories
24opendht_dir = "opendht"
25pjproject_dir = "pjproject"
26restinio_dir = "restinio"
27install_dir = os.path.abspath("install")
28
Sébastien Blin55be5da2024-02-12 11:29:54 -050029def build_and_install_restinio():
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040030 # 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 Blin55be5da2024-02-12 11:29:54 -050034 try:
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040035 restino_build_dir = os.path.join(restinio_dir, "dev", "cmake_build")
Sébastien Blin55be5da2024-02-12 11:29:54 -050036 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-Chapleau9bfc3432024-03-22 17:07:33 -040047 ".."
Sébastien Blin55be5da2024-02-12 11:29:54 -050048 ]
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040049 os.makedirs(restino_build_dir, exist_ok=True)
Sébastien Blin55be5da2024-02-12 11:29:54 -050050 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-Chapleau9bfc3432024-03-22 17:07:33 -040054 print("RESTinio built and installed successfully.")
Sébastien Blin55be5da2024-02-12 11:29:54 -050055 return True
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040056 except (subprocess.CalledProcessError, OSError) as e:
57 print("Error building or installing restinio:", e)
Sébastien Blin55be5da2024-02-12 11:29:54 -050058 return False
59
Amna8e0e1e02023-09-25 14:12:47 -040060def build_and_install_opendht():
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040061 print("\nBuilding and installing OpenDHT...", flush=True)
Amna8e0e1e02023-09-25 14:12:47 -040062 try:
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040063 opendht_build_dir = os.path.join(opendht_dir, "build")
64 cmake_command = [
65 "cmake", "..",
Amna8e0e1e02023-09-25 14:12:47 -040066 "-DCMAKE_INSTALL_PREFIX=" + install_dir,
Sébastien Blin55be5da2024-02-12 11:29:54 -050067 "-DCMAKE_PREFIX_PATH=" + install_dir, # For finding restinio
Amna8e0e1e02023-09-25 14:12:47 -040068 "-DCMAKE_BUILD_TYPE=Release",
Adrien Béraud0a838222023-09-28 18:34:44 -040069 "-DBUILD_SHARED_LIBS=OFF",
Amna8e0e1e02023-09-25 14:12:47 -040070 "-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-Chapleau9bfc3432024-03-22 17:07:33 -040076 ]
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)
Amna43b66c82023-10-03 10:39:22 -040080 print("OpenDHT installed successfully.")
Sébastien Blin55be5da2024-02-12 11:29:54 -050081 return True
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040082 except (subprocess.CalledProcessError, OSError) as e:
83 print("Error building or installing OpenDHT:", e)
Sébastien Blin55be5da2024-02-12 11:29:54 -050084 return False
Amna8e0e1e02023-09-25 14:12:47 -040085
86def build_and_install_pjproject():
François-Simon Fauteux-Chapleau9bfc3432024-03-22 17:07:33 -040087 print("\nBuilding and installing PJSIP...", flush=True)
Amna8e0e1e02023-09-25 14:12:47 -040088 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
Amna43b66c82023-10-03 10:39:22 -0400117 print("PJSIP libraries built successfully.")
Sébastien Blin55be5da2024-02-12 11:29:54 -0500118 return True
Amna8e0e1e02023-09-25 14:12:47 -0400119 except subprocess.CalledProcessError as e:
Amna43b66c82023-10-03 10:39:22 -0400120 print("Error building PJSIP libraries: %s", e)
Sébastien Blin55be5da2024-02-12 11:29:54 -0500121 return False
Amna8e0e1e02023-09-25 14:12:47 -0400122
123def 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 Blin55be5da2024-02-12 11:29:54 -0500128 if not build_and_install_restinio():
129 print("Error building or installing restinio.")
130 return
Amna8e0e1e02023-09-25 14:12:47 -0400131
132 # Build and install OpenDHT
Sébastien Blin55be5da2024-02-12 11:29:54 -0500133 if not build_and_install_opendht():
134 print("Error building or installing OpenDHT.")
135 return
Amna8e0e1e02023-09-25 14:12:47 -0400136
137 # Build and install pjproject
Sébastien Blin55be5da2024-02-12 11:29:54 -0500138 if not build_and_install_pjproject():
139 print("Error building or installing PJSIP libraries.")
140 return
Amna8e0e1e02023-09-25 14:12:47 -0400141
Adrien Béraud0a838222023-09-28 18:34:44 -0400142 subprocess.run([f"for p in {install_dir}/lib/pkgconfig/*.pc; do ./pkg-static.sh $p; done"], shell=True, check=True)
143
Amna8e0e1e02023-09-25 14:12:47 -0400144
145if __name__ == "__main__":
146 main()