blob: 2a3c890d6177d02dcfca7ddd602e621c8564fe6d [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
4# Copyright (C) 2023 Savoir-faire Linux Inc.
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
20import subprocess
21import os
Amna8e0e1e02023-09-25 14:12:47 -040022
Amna8e0e1e02023-09-25 14:12:47 -040023
24# Define paths and directories
25opendht_dir = "opendht"
26pjproject_dir = "pjproject"
27restinio_dir = "restinio"
28install_dir = os.path.abspath("install")
29
30def build_and_install_opendht():
Amna43b66c82023-10-03 10:39:22 -040031 print("Building and installing OpenDHT...")
Amna8e0e1e02023-09-25 14:12:47 -040032 try:
33 # Configure OpenDHT with CMake
34 subprocess.run(["cmake", ".",
35 "-DCMAKE_INSTALL_PREFIX=" + install_dir,
36 "-DCMAKE_BUILD_TYPE=Release",
Adrien Béraud0a838222023-09-28 18:34:44 -040037 "-DBUILD_SHARED_LIBS=OFF",
Amna8e0e1e02023-09-25 14:12:47 -040038 "-DBUILD_TESTING=OFF",
39 "-DOPENDHT_PYTHON=OFF",
40 "-DOPENDHT_TOOLS=OFF",
41 "-DOPENDHT_DOCUMENTATION=OFF",
42 "-DOPENDHT_HTTP=ON",
43 "-DOPENDHT_PROXY_CLIENT=ON",
44 ], cwd=opendht_dir, check=True)
45
46 # Build and install OpenDHT
47 subprocess.run(["make", "install"], cwd=opendht_dir, check=True)
Amna43b66c82023-10-03 10:39:22 -040048 print("OpenDHT installed successfully.")
Amna8e0e1e02023-09-25 14:12:47 -040049 except subprocess.CalledProcessError as e:
Amna43b66c82023-10-03 10:39:22 -040050 print("Error building or installing OpenDHT: %s", e)
Amna8e0e1e02023-09-25 14:12:47 -040051
52def build_and_install_pjproject():
53 # Build PJSIP libraries
54 try:
55 configure_command = [
56 "./configure",
57 f"--prefix={install_dir}",
58 "--disable-sound",
59 "--enable-video",
60 "--enable-ext-sound",
61 "--disable-speex-aec",
62 "--disable-g711-codec",
63 "--disable-l16-codec",
64 "--disable-gsm-codec",
65 "--disable-g722-codec",
66 "--disable-g7221-codec",
67 "--disable-speex-codec",
68 "--disable-ilbc-codec",
69 "--disable-opencore-amr",
70 "--disable-silk",
71 "--disable-sdl",
72 "--disable-ffmpeg",
73 "--disable-v4l2",
74 "--disable-openh264",
75 "--disable-resample",
76 "--disable-libwebrtc",
77 f"--with-gnutls={install_dir}"
78 ]
79 subprocess.run(configure_command, cwd=pjproject_dir, check=True)
80 subprocess.run(["make"], cwd=pjproject_dir, check=True)
81 subprocess.run(["make", "install"], cwd=pjproject_dir, check=True)
82
Amna43b66c82023-10-03 10:39:22 -040083 print("PJSIP libraries built successfully.")
Amna8e0e1e02023-09-25 14:12:47 -040084 except subprocess.CalledProcessError as e:
Amna43b66c82023-10-03 10:39:22 -040085 print("Error building PJSIP libraries: %s", e)
Amna8e0e1e02023-09-25 14:12:47 -040086
87def build_and_install_restinio():
88 try:
89 restino_build_dir = restinio_dir + "/dev/"
90 cmake_command = [
91 "cmake",
92 f"-DCMAKE_INSTALL_PREFIX={install_dir}",
93 "-DRESTINIO_TEST=OFF",
94 "-DRESTINIO_SAMPLE=OFF",
95 "-DRESTINIO_INSTALL_SAMPLES=OFF",
96 "-DRESTINIO_BENCH=OFF",
97 "-DRESTINIO_INSTALL_BENCHES=OFF",
98 "-DRESTINIO_FIND_DEPS=ON",
99 "-DRESTINIO_ALLOW_SOBJECTIZER=Off",
100 "-DRESTINIO_USE_BOOST_ASIO=none",
101 "."
102 ]
103 subprocess.run(cmake_command, cwd=restino_build_dir, check=True)
104 subprocess.run(["make", "-j8"], cwd=restino_build_dir, check=True)
105 subprocess.run(["make", "install"], cwd=restino_build_dir, check=True)
Amna8e0e1e02023-09-25 14:12:47 -0400106
Amna43b66c82023-10-03 10:39:22 -0400107 print("restinio built and installed successfully.")
Amna8e0e1e02023-09-25 14:12:47 -0400108 except subprocess.CalledProcessError as e:
Amna43b66c82023-10-03 10:39:22 -0400109 print("Error building or installing restinio: %s", e)
Amna8e0e1e02023-09-25 14:12:47 -0400110
111def main():
112 # Create install directory if it doesn't exist
113 if not os.path.exists(install_dir):
114 os.makedirs(install_dir)
115 # Build and install restinio
116 build_and_install_restinio()
117
118 # Build and install OpenDHT
119 build_and_install_opendht()
120
121 # Build and install pjproject
122 build_and_install_pjproject()
123
Adrien Béraud0a838222023-09-28 18:34:44 -0400124 subprocess.run([f"for p in {install_dir}/lib/pkgconfig/*.pc; do ./pkg-static.sh $p; done"], shell=True, check=True)
125
Amna8e0e1e02023-09-25 14:12:47 -0400126
127if __name__ == "__main__":
128 main()