-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.sh
More file actions
executable file
·329 lines (294 loc) · 14.3 KB
/
Copy pathconfigure.sh
File metadata and controls
executable file
·329 lines (294 loc) · 14.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/usr/bin/env bash
# *
# * If not stated otherwise in this file or this component's LICENSE file the
# * following copyright and licenses apply:
# *
# * Copyright 2023 RDK Management
# *
# * Licensed under the Apache License, Version 2.0 (the "License");
# * you may not use this file except in compliance with the License.
# * You may obtain a copy of the License at
# *
# * http://www.apache.org/licenses/LICENSE-2.0
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *
set -e # error out if required
SCRIPT_EXEC="$(realpath $0)"
MY_DIR="$(dirname $SCRIPT_EXEC)"
# Decide which build target to use based on the presence of TARGET in input args(linux or arm)
if [[ "$1" != "linux" && "$1" != "arm" ]]; then
echo "Error: argument must be 'linux' or 'arm'"
exit 1
fi
TARGET=${1}
echo "[$0] TARGET [${TARGET}]"
pushd ${MY_DIR} > /dev/null
FRAMEWORK_DIR=${MY_DIR}/framework/${TARGET}
LIBYAML_DIR=${FRAMEWORK_DIR}/libfyaml-master
LIBYAML_VERSION=v0.9.6 # March 15 2026
ASPRINTF_DIR=${FRAMEWORK_DIR}/asprintf
ASPRINTF_VERSION=0.0.3
LIBWEBSOCKETS_DIR=${FRAMEWORK_DIR}/libwebsockets-4.3.3
CURL_DIR=${FRAMEWORK_DIR}/curl/curl-8.8.0
OPENSSL_DIR=${FRAMEWORK_DIR}/openssl/openssl-OpenSSL_1_1_1w
CMAKE_DIR=${MY_DIR}/host-tools/CMake-3.30.0
CMAKE_BIN_DIR=${CMAKE_DIR}/build/bin
HOST_CC=gcc
BUILD_DIR=${MY_DIR}/build/${TARGET}
LIBWEBSOCKETS_BUILD_DIR=${BUILD_DIR}/libwebsockets
OPENSSL_BUILD_DIR=${BUILD_DIR}/openssl
CURL_BUILD_DIR=${BUILD_DIR}/curl
mkdir -p ${FRAMEWORK_DIR}
mkdir -p ${BUILD_DIR}
popd > /dev/null
# Download and set up the 'asprintf' library if not already present
pushd ${FRAMEWORK_DIR} > /dev/null
if [ -d "${ASPRINTF_DIR}" ]; then
echo "Framework [asprintf] already exists"
else
echo "wget asprintf in ${ASPRINTF_DIR}"
# Pull fixed version
wget https://github.com/jwerle/asprintf.c/archive/refs/tags/${ASPRINTF_VERSION}.zip -P asprintf/. --no-check-certificate
cd asprintf
unzip ${ASPRINTF_VERSION}.zip
mv asprintf.c-${ASPRINTF_VERSION} asprintf.c-master
rm asprintf.c-master/test.c
echo "Patching Framework [${PWD}]"
cd asprintf.c-master
cp ../../../../src/asprintf/patches/FixWarningsInAsprintf.patch .
patch -i FixWarningsInAsprintf.patch -p0
fi
popd > /dev/null
# Download and set up the 'libfyaml' library if not already present
pushd ${FRAMEWORK_DIR} > /dev/null
if [ -d "${LIBYAML_DIR}" ]; then
echo "Framework [libfyaml] already exists"
else
echo "git clone libfyaml in ${LIBYAML_DIR}"
# Pull fixed version
git clone -b ${LIBYAML_VERSION} https://github.com/pantoniou/libfyaml.git libfyaml-master
# Copy the patch file from src directory
cp ../../src/libyaml/patches/CorrectWarningsAndBuildIssuesInLibYaml.patch .
patch -i CorrectWarningsAndBuildIssuesInLibYaml.patch -p0
echo "Patching Complete"
# ./bootstrap.sh
# ./configure --prefix=${LIBYAML_DIR}
# make
fi
popd > /dev/null
# Prefer system cmake if version is > 3.12
pushd ${MY_DIR}
if command -v cmake &> /dev/null && [ "$(cmake --version | head -n1 | awk '{print $3}')" \> "3.12" ]; then
echo "CMake is installed and version is 3.13 or higher"
CMAKE_BIN=$(which cmake)
else
CMAKE_BIN=${CMAKE_BIN_DIR}/cmake
if [ -d "${CMAKE_BIN_DIR}" ]; then
echo "CMake is already built"
else
echo "CMake is not installed, building it"
wget https://github.com/Kitware/CMake/archive/refs/tags/v3.30.0.zip -P host-tools/. --no-check-certificate
cd host-tools
unzip v3.30.0.zip
echo "HOST_CC:${HOST_CC}"
cd ${CMAKE_DIR}
mkdir build && cd build
../bootstrap --prefix=./. -- -DCMAKE_USE_OPENSSL=OFF
make CC=${HOST_CC} -j4 BUILD_TESTING=OFF BUILD_EXAMPLES=OFF && make install
fi
fi
popd > /dev/null
# Set up paths and search criteria based on the target architecture (linux or arm)
pushd "${FRAMEWORK_DIR}" > /dev/null
if [ "$TARGET" == "arm" ]; then
TARGET=arm
# Extract the sysroot value
if [ "${CC}" == "" ]; then
echo "CC is not set.. Exiting"
exit 1
fi
SYSROOT=$(echo "$CC" | grep -oP '(?<=--sysroot=)[^ ]+')
search_paths=$SYSROOT
else
TARGET=linux
search_paths="/usr/include /usr/local/include /usr/lib /usr/local/lib"
fi
OPENSSL_IS_SYSTEM_INSTALLED=0
# Output the path to a txt file
output_file="${MY_DIR}/file_path.txt"
# Function to search for a file and dump its path to a file if found
dump_library_path()
{
local library_name="$1"
local paths="$2"
for file_path in $(find ${paths} -iname "${library_name}" 2>/dev/null); do
# Check if the file is valid and accessible
if file "${file_path}" &> /dev/null; then
# Dump the key-value pair to the output file
echo "${library_name}=${file_path}" >> "${output_file}"
echo "${file_path}" # Return the found path
return 0 # Exit the function after finding the first match
fi
done
return 1 # Return an error code if the file was not found
}
# Check package-config file and static library for OpenSSL
OPENSSL_PC=$(dump_library_path "openssl.pc" "${search_paths}") || echo "openssl.pc not found"
OPENSSL_STATIC_SSL_LIB=$(dump_library_path "libssl.a" "${search_paths}") || echo "libssl.a not found"
OPENSSL_STATIC_CRYPTO_LIB=$(dump_library_path "libcrypto.a" "${search_paths}") || echo "libcrypto.a not found"
if [[ -n "$OPENSSL_PC" && -n "$OPENSSL_STATIC_SSL_LIB" && -n "$OPENSSL_STATIC_CRYPTO_LIB" ]]; then
echo "openssl.pc, libssl.a, and libcrypto.a are found for ${TARGET}."
OPENSSL_IS_SYSTEM_INSTALLED=1
fi
# Check for curl
CURL_LIB=$(dump_library_path "libcurl.a" "${search_paths}") || echo "libcurl.a not found"
CURL_HEADER=$(dump_library_path "curl.h" "${search_paths}") || echo "curl.h not found"
LIBCURL_IS_SYSTEM_INSTALLED=0
if [[ -n "$CURL_HEADER" && -n "$CURL_LIB" ]]; then
LIBCURL_IS_SYSTEM_INSTALLED=1
fi
popd > /dev/null # ${FRAMEWORK_DIR}
# Switch Description Effect on LWS Build
# -DLWS_WITH_SSL=OFF Disables Secure Sockets Layer (SSL) support in Reduces library size, removes dependency on OpenSSL.
# libwebsockets.
# -DLWS_WITH_ZIP_FOPS=OFF Disables support for ZIP file operations in Removes zlib dependency, reduces library size.
# libwebsockets.
# -DLWS_WITH_ZLIB=OFF Disables zlib compression support in libwebsockets. Reduces library size, disables compression for WebSocket payloads.
# -DLWS_WITHOUT_BUILTIN_GETIFADDRS=ONDisables the built-in mechanism to obtain network Relies on external libraries or system calls to get interface addresses.
# interface addresses.
# -DLWS_WITHOUT_CLIENT=ON Removes the WebSocket client functionality from the Only server-side WebSocket functionality is included.
# library.
# -DLWS_WITHOUT_EXTENSIONS=ON Disables LWS extensions (e.g., permessage-deflate, Reduces library size, potentially improves performance.
# client_no_context_takeover).
# -DLWS_WITHOUT_TESTAPPS=ON Excludes test applications from the build. Streamlines the build, focuses on core library components.
# -DLWS_WITH_SHARED=ON Builds libwebsockets as a shared library (.so file). Allows the library to be used by multiple applications.
# -DLWS_WITHOUT_TEST_SERVER=ON Excludes the test server component from the build. Streamlines the build.
# -DLWS_WITHOUT_TEST_SERVER_EXTPOLL=ONDisables the external poll mechanism in the test server. May affect testing capabilities of the library.
# -DLWS_WITH_MINIMAL_EXAMPLES=ON Includes only the minimal set of example programs. Reduces the number of example programs built.
# -DLWS_WITHOUT_DAEMONIZE=ON Prevents the LWS test server from running as a daemon. Useful for debugging and when you want to control the server process directly.
# -DCMAKE_C_FLAGS=-fPIC Adds the -fPIC flag to the C compiler, enabling Makes the generated code relocatable, necessary for shared libraries.
# Position-Independent Code (PIC).
# -DLWS_WITH_NO_LOGS=ON Disables logging in libwebsockets. Can improve performance but makes debugging more difficult.
# -DCMAKE_BUILD_TYPE=Release Configures the build for release mode (optimization Optimizes the library for performance.
# enabled, debugging symbols stripped).
# -DCMAKE_POSITION_INDEPENDENT_CODE=ON Enables Position-Independent Code (PIC) for the Makes all generated code relocatable.
# entire project, including executables and shared libraries.
# Build and configure libwebsockets if not already built
pushd ${FRAMEWORK_DIR} > /dev/null
build_libwebsockets()
{
cd ${LIBWEBSOCKETS_DIR}
mkdir -p ${LIBWEBSOCKETS_BUILD_DIR}
cd ${LIBWEBSOCKETS_BUILD_DIR}
${CMAKE_BIN} ${LIBWEBSOCKETS_DIR} -DLWS_WITH_SSL=OFF -DLWS_WITH_ZIP_FOPS=OFF -DLWS_WITH_ZLIB=OFF -DLWS_WITHOUT_BUILTIN_GETIFADDRS=ON \
-DLWS_WITHOUT_CLIENT=ON -DLWS_WITHOUT_EXTENSIONS=ON -DLWS_WITHOUT_TESTAPPS=ON -DLWS_WITH_SHARED=ON \
-DLWS_WITHOUT_TEST_SERVER=ON -DLWS_WITHOUT_TEST_SERVER_EXTPOLL=ON -DLWS_WITH_MINIMAL_EXAMPLES=ON \
-DLWS_WITHOUT_DAEMONIZE=ON -DCMAKE_C_FLAGS=-fPIC -DLWS_WITH_NO_LOGS=ON -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DLWS_HAVE_LIBCAP=0
make $@
touch ${LIBWEBSOCKETS_BUILD_DIR}/.build_complete
}
if [ -d "${LIBWEBSOCKETS_DIR}" ]; then
echo "Framework [libwebsockets] already exists"
if [ -f "${LIBWEBSOCKETS_BUILD_DIR}/.build_complete" ]; then
echo "Framework [libwebsockets] already built for ${TARGET}"
else
build_libwebsockets
fi
else
echo "Clone libwebsockets in ${LIBWEBSOCKETS_DIR}"
wget https://github.com/warmcat/libwebsockets/archive/refs/tags/v4.3.3.zip --no-check-certificate
unzip v4.3.3.zip
build_libwebsockets
fi
popd > /dev/null
pushd ${FRAMEWORK_DIR} > /dev/null
# Build and configure OpenSSL if it's not already installed
build_openssl()
{
cd ${OPENSSL_DIR}
mkdir -p ${OPENSSL_BUILD_DIR}
if [ "$TARGET" = "arm" ]; then
# Derive the OpenSSL platform from the compiler triplet in CC
# e.g. aarch64-rdk-linux-gcc -> aarch64 -> linux-aarch64
# arm-oe-linux-gnueabi-gcc -> arm -> linux-armv4
CC_BINARY=$(echo "$CC" | awk '{print $1}')
CC_ARCH=$(echo "$CC_BINARY" | cut -d'-' -f1)
case "$CC_ARCH" in
aarch64) OPENSSL_PLATFORM="linux-aarch64" ;;
arm) OPENSSL_PLATFORM="linux-armv4" ;;
*) echo "Unknown arch derived from CC: $CC_ARCH"; exit 1 ;;
esac
CROSS_COMPILE=
COMPILER_FLAGS=$(echo "$CC" | cut -d' ' -f2-)
/usr/bin/perl ./Configure "${OPENSSL_PLATFORM}" shared --prefix="${OPENSSL_BUILD_DIR}" --openssldir="${OPENSSL_BUILD_DIR}" --cross-compile-prefix="${CROSS_COMPILE}" $COMPILER_FLAGS
else
./config --prefix="${OPENSSL_BUILD_DIR}"
fi
make && make install
touch ${OPENSSL_BUILD_DIR}/.build_complete
}
if [ "$OPENSSL_IS_SYSTEM_INSTALLED" -eq 0 ]; then
if [ -d "${OPENSSL_DIR}" ]; then
echo "Framework [openssl] already exists"
if [ -f "${OPENSSL_BUILD_DIR}/.build_complete" ]; then
echo "Framework [openssl] already built for ${TARGET}"
else
echo "Building Framework [openssl] for ${TARGET}"
build_openssl
fi
else
echo "Clone openssl in ${OPENSSL_DIR} for $TARGET"
wget https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_1_1_1w.zip -P openssl --no-check-certificate
cd openssl
unzip OpenSSL_1_1_1w.zip
build_openssl
fi
fi
popd > /dev/null # ${FRAMEWORK_DIR}
pushd ${FRAMEWORK_DIR} > /dev/null
# Build and configure curl if it's not already installed
build_curl()
{
cd ${CURL_DIR}
mkdir -p ${CURL_BUILD_DIR}
if [ "$TARGET" = "arm" ]; then
# Derive the autoconf host triplet from the CC binary name
# e.g. aarch64-rdk-linux-gcc -> aarch64-rdk-linux
CC_BINARY=$(echo "$CC" | awk '{print $1}')
HOST_TRIPLET=$(echo "$CC_BINARY" | sed 's/-gcc$//')
# For arm, use the explicit triplet; for arm/aarch64 it works the same way
./configure --host=${HOST_TRIPLET} CPPFLAGS="-I${OPENSSL_BUILD_DIR}/include" LDFLAGS="-L${OPENSSL_BUILD_DIR}/lib" --prefix=${CURL_BUILD_DIR} --with-ssl=${OPENSSL_BUILD_DIR} --with-pic --without-libpsl --without-libidn2 --disable-docs --disable-libcurl-option --disable-alt-svc --disable-headers-api --disable-hsts --without-libgsasl --without-zlib
else
# For linux
if [ "$OPENSSL_IS_SYSTEM_INSTALLED" -eq 1 ]; then
./configure --prefix=${CURL_BUILD_DIR} --with-ssl --without-zlib --without-libpsl --without-libidn2 --disable-docs --disable-libcurl-option --disable-alt-svc --disable-headers-api --disable-hsts --without-libgsasl
else
./configure CPPFLAGS="-I${OPENSSL_BUILD_DIR}/include" LDFLAGS="-L${OPENSSL_BUILD_DIR}/lib" --prefix=${CURL_BUILD_DIR} --with-ssl=${OPENSSL_BUILD_DIR} --with-pic --without-zlib --without-libpsl --without-libidn2 --disable-docs --disable-libcurl-option --disable-alt-svc --disable-headers-api --disable-hsts --without-libgsasl
fi
fi
make $@; make $@ install
touch ${CURL_BUILD_DIR}/.build_complete
}
if [ "${LIBCURL_IS_SYSTEM_INSTALLED}" -eq 0 ]; then
if [ -d "${CURL_DIR}" ]; then
echo "Framework [curl] already exists"
if [ -f "${CURL_BUILD_DIR}/.build_complete" ]; then
echo "Framework [curl] already built for ${TARGET}"
else
build_curl
fi
else
echo "Clone curl in ${CURL_DIR} for $TARGET"
wget https://curl.se/download/curl-8.8.0.zip -P curl --no-check-certificate
cd curl
unzip curl-8.8.0.zip
build_curl
fi
fi
popd > /dev/null # ${FRAMEWORK_DIR}