blob: 949505efec249ed9c214f67d09b35ad77ee3b7e9 [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
22import logging
23
24# Configure the logging system
25logging.basicConfig(filename='install.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
26
27# Define paths and directories
28opendht_dir = "opendht"
29pjproject_dir = "pjproject"
30restinio_dir = "restinio"
31install_dir = os.path.abspath("install")
32
33def build_and_install_opendht():
34 logging.info("Building and installing OpenDHT...")
35 try:
36 # Configure OpenDHT with CMake
37 subprocess.run(["cmake", ".",
38 "-DCMAKE_INSTALL_PREFIX=" + install_dir,
39 "-DCMAKE_BUILD_TYPE=Release",
40 "-DBUILD_TESTING=OFF",
41 "-DOPENDHT_PYTHON=OFF",
42 "-DOPENDHT_TOOLS=OFF",
43 "-DOPENDHT_DOCUMENTATION=OFF",
44 "-DOPENDHT_HTTP=ON",
45 "-DOPENDHT_PROXY_CLIENT=ON",
46 ], cwd=opendht_dir, check=True)
47
48 # Build and install OpenDHT
49 subprocess.run(["make", "install"], cwd=opendht_dir, check=True)
50 logging.info("OpenDHT installed successfully.")
51 except subprocess.CalledProcessError as e:
52 logging.error("Error building or installing OpenDHT: %s", e)
53
54def build_and_install_pjproject():
55 # Build PJSIP libraries
56 try:
57 configure_command = [
58 "./configure",
59 f"--prefix={install_dir}",
60 "--disable-sound",
61 "--enable-video",
62 "--enable-ext-sound",
63 "--disable-speex-aec",
64 "--disable-g711-codec",
65 "--disable-l16-codec",
66 "--disable-gsm-codec",
67 "--disable-g722-codec",
68 "--disable-g7221-codec",
69 "--disable-speex-codec",
70 "--disable-ilbc-codec",
71 "--disable-opencore-amr",
72 "--disable-silk",
73 "--disable-sdl",
74 "--disable-ffmpeg",
75 "--disable-v4l2",
76 "--disable-openh264",
77 "--disable-resample",
78 "--disable-libwebrtc",
79 f"--with-gnutls={install_dir}"
80 ]
81 subprocess.run(configure_command, cwd=pjproject_dir, check=True)
82 subprocess.run(["make"], cwd=pjproject_dir, check=True)
83 subprocess.run(["make", "install"], cwd=pjproject_dir, check=True)
84
85 logging.info("PJSIP libraries built successfully.")
86 except subprocess.CalledProcessError as e:
87 logging.error("Error building PJSIP libraries: %s", e)
88
89def build_and_install_restinio():
90 try:
91 restino_build_dir = restinio_dir + "/dev/"
92 cmake_command = [
93 "cmake",
94 f"-DCMAKE_INSTALL_PREFIX={install_dir}",
95 "-DRESTINIO_TEST=OFF",
96 "-DRESTINIO_SAMPLE=OFF",
97 "-DRESTINIO_INSTALL_SAMPLES=OFF",
98 "-DRESTINIO_BENCH=OFF",
99 "-DRESTINIO_INSTALL_BENCHES=OFF",
100 "-DRESTINIO_FIND_DEPS=ON",
101 "-DRESTINIO_ALLOW_SOBJECTIZER=Off",
102 "-DRESTINIO_USE_BOOST_ASIO=none",
103 "."
104 ]
105 subprocess.run(cmake_command, cwd=restino_build_dir, check=True)
106 subprocess.run(["make", "-j8"], cwd=restino_build_dir, check=True)
107 subprocess.run(["make", "install"], cwd=restino_build_dir, check=True)
108 # subprocess.run(["cd", "../.."], check=True)
109 # subprocess.run(["rm", "-rf", "restinio"], check=True)
110
111 logging.info("restinio built and installed successfully.")
112 except subprocess.CalledProcessError as e:
113 logging.error("Error building or installing restinio: %s", e)
114
115def main():
116 # Create install directory if it doesn't exist
117 if not os.path.exists(install_dir):
118 os.makedirs(install_dir)
119 # Build and install restinio
120 build_and_install_restinio()
121
122 # Build and install OpenDHT
123 build_and_install_opendht()
124
125 # Build and install pjproject
126 build_and_install_pjproject()
127
128
129if __name__ == "__main__":
130 main()