blob: eeadb078caaa6073b92ff988a69484a5d856d1c0 [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():
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
Amna8e0e1e02023-09-25 14:12:47 -040055def build_and_install_opendht():
Amna43b66c82023-10-03 10:39:22 -040056 print("Building and installing OpenDHT...")
Amna8e0e1e02023-09-25 14:12:47 -040057 try:
58 # Configure OpenDHT with CMake
59 subprocess.run(["cmake", ".",
60 "-DCMAKE_INSTALL_PREFIX=" + install_dir,
Sébastien Blin55be5da2024-02-12 11:29:54 -050061 "-DCMAKE_PREFIX_PATH=" + install_dir, # For finding restinio
Amna8e0e1e02023-09-25 14:12:47 -040062 "-DCMAKE_BUILD_TYPE=Release",
Adrien Béraud0a838222023-09-28 18:34:44 -040063 "-DBUILD_SHARED_LIBS=OFF",
Amna8e0e1e02023-09-25 14:12:47 -040064 "-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)
Amna43b66c82023-10-03 10:39:22 -040074 print("OpenDHT installed successfully.")
Sébastien Blin55be5da2024-02-12 11:29:54 -050075 return True
Amna8e0e1e02023-09-25 14:12:47 -040076 except subprocess.CalledProcessError as e:
Amna43b66c82023-10-03 10:39:22 -040077 print("Error building or installing OpenDHT: %s", e)
Sébastien Blin55be5da2024-02-12 11:29:54 -050078 return False
Amna8e0e1e02023-09-25 14:12:47 -040079
80def 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
Amna43b66c82023-10-03 10:39:22 -0400111 print("PJSIP libraries built successfully.")
Sébastien Blin55be5da2024-02-12 11:29:54 -0500112 return True
Amna8e0e1e02023-09-25 14:12:47 -0400113 except subprocess.CalledProcessError as e:
Amna43b66c82023-10-03 10:39:22 -0400114 print("Error building PJSIP libraries: %s", e)
Sébastien Blin55be5da2024-02-12 11:29:54 -0500115 return False
Amna8e0e1e02023-09-25 14:12:47 -0400116
117def 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 Blin55be5da2024-02-12 11:29:54 -0500122 if not build_and_install_restinio():
123 print("Error building or installing restinio.")
124 return
Amna8e0e1e02023-09-25 14:12:47 -0400125
126 # Build and install OpenDHT
Sébastien Blin55be5da2024-02-12 11:29:54 -0500127 if not build_and_install_opendht():
128 print("Error building or installing OpenDHT.")
129 return
Amna8e0e1e02023-09-25 14:12:47 -0400130
131 # Build and install pjproject
Sébastien Blin55be5da2024-02-12 11:29:54 -0500132 if not build_and_install_pjproject():
133 print("Error building or installing PJSIP libraries.")
134 return
Amna8e0e1e02023-09-25 14:12:47 -0400135
Adrien Béraud0a838222023-09-28 18:34:44 -0400136 subprocess.run([f"for p in {install_dir}/lib/pkgconfig/*.pc; do ./pkg-static.sh $p; done"], shell=True, check=True)
137
Amna8e0e1e02023-09-25 14:12:47 -0400138
139if __name__ == "__main__":
140 main()