blob: e21d816195f7e6e92890efe32d0f3fd7e6b3304a [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",
Adrien Béraud0a838222023-09-28 18:34:44 -040040 "-DBUILD_SHARED_LIBS=OFF",
Amna8e0e1e02023-09-25 14:12:47 -040041 "-DBUILD_TESTING=OFF",
42 "-DOPENDHT_PYTHON=OFF",
43 "-DOPENDHT_TOOLS=OFF",
44 "-DOPENDHT_DOCUMENTATION=OFF",
45 "-DOPENDHT_HTTP=ON",
46 "-DOPENDHT_PROXY_CLIENT=ON",
47 ], cwd=opendht_dir, check=True)
48
49 # Build and install OpenDHT
50 subprocess.run(["make", "install"], cwd=opendht_dir, check=True)
51 logging.info("OpenDHT installed successfully.")
52 except subprocess.CalledProcessError as e:
53 logging.error("Error building or installing OpenDHT: %s", e)
54
55def build_and_install_pjproject():
56 # Build PJSIP libraries
57 try:
58 configure_command = [
59 "./configure",
60 f"--prefix={install_dir}",
61 "--disable-sound",
62 "--enable-video",
63 "--enable-ext-sound",
64 "--disable-speex-aec",
65 "--disable-g711-codec",
66 "--disable-l16-codec",
67 "--disable-gsm-codec",
68 "--disable-g722-codec",
69 "--disable-g7221-codec",
70 "--disable-speex-codec",
71 "--disable-ilbc-codec",
72 "--disable-opencore-amr",
73 "--disable-silk",
74 "--disable-sdl",
75 "--disable-ffmpeg",
76 "--disable-v4l2",
77 "--disable-openh264",
78 "--disable-resample",
79 "--disable-libwebrtc",
80 f"--with-gnutls={install_dir}"
81 ]
82 subprocess.run(configure_command, cwd=pjproject_dir, check=True)
83 subprocess.run(["make"], cwd=pjproject_dir, check=True)
84 subprocess.run(["make", "install"], cwd=pjproject_dir, check=True)
85
86 logging.info("PJSIP libraries built successfully.")
87 except subprocess.CalledProcessError as e:
88 logging.error("Error building PJSIP libraries: %s", e)
89
90def build_and_install_restinio():
91 try:
92 restino_build_dir = restinio_dir + "/dev/"
93 cmake_command = [
94 "cmake",
95 f"-DCMAKE_INSTALL_PREFIX={install_dir}",
96 "-DRESTINIO_TEST=OFF",
97 "-DRESTINIO_SAMPLE=OFF",
98 "-DRESTINIO_INSTALL_SAMPLES=OFF",
99 "-DRESTINIO_BENCH=OFF",
100 "-DRESTINIO_INSTALL_BENCHES=OFF",
101 "-DRESTINIO_FIND_DEPS=ON",
102 "-DRESTINIO_ALLOW_SOBJECTIZER=Off",
103 "-DRESTINIO_USE_BOOST_ASIO=none",
104 "."
105 ]
106 subprocess.run(cmake_command, cwd=restino_build_dir, check=True)
107 subprocess.run(["make", "-j8"], cwd=restino_build_dir, check=True)
108 subprocess.run(["make", "install"], cwd=restino_build_dir, check=True)
109 # subprocess.run(["cd", "../.."], check=True)
110 # subprocess.run(["rm", "-rf", "restinio"], check=True)
111
112 logging.info("restinio built and installed successfully.")
113 except subprocess.CalledProcessError as e:
114 logging.error("Error building or installing restinio: %s", e)
115
116def main():
117 # Create install directory if it doesn't exist
118 if not os.path.exists(install_dir):
119 os.makedirs(install_dir)
120 # Build and install restinio
121 build_and_install_restinio()
122
123 # Build and install OpenDHT
124 build_and_install_opendht()
125
126 # Build and install pjproject
127 build_and_install_pjproject()
128
Adrien Béraud0a838222023-09-28 18:34:44 -0400129 subprocess.run([f"for p in {install_dir}/lib/pkgconfig/*.pc; do ./pkg-static.sh $p; done"], shell=True, check=True)
130
Amna8e0e1e02023-09-25 14:12:47 -0400131
132if __name__ == "__main__":
133 main()