Skip to content

Commit

Permalink
build: Move common definitions/actions from ports to a single spot
Browse files Browse the repository at this point in the history
JIRA: NIL-595, CI-339
  • Loading branch information
Darchiv committed Jul 25, 2024
1 parent b659aa2 commit 348ea3c
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 43 deletions.
88 changes: 45 additions & 43 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# Shell script for building Phoenix-RTOS ports
#
# Copyright 2019 Phoenix Systems
# Author: Pawel Pisarczyk
# Copyright 2019, 2024 Phoenix Systems
# Author: Pawel Pisarczyk, Daniel Sawka
#

set -e
Expand All @@ -29,53 +29,55 @@ LDFLAGS="$EXPORT_LDFLAGS"
STRIP="$EXPORT_STRIP"
export CFLAGS LDFLAGS STRIP

export PORTS_MIRROR_BASEURL="https://files.phoesys.com/ports/"

if [ -n "$PORTS_INSTALL_STRIPPED" ] && [ "$PORTS_INSTALL_STRIPPED" = "n" ]; then
export PREFIX_PORTS_INSTALL="$PREFIX_PROG"
else
export PREFIX_PORTS_INSTALL="$PREFIX_PROG_STRIPPED"
fi

[ "${PORTS_MBEDTLS}" = "y" ] && ./phoenix-rtos-ports/mbedtls/build.sh

[ "${PORTS_BUSYBOX}" = "y" ] && ./phoenix-rtos-ports/busybox/build.sh

[ "${PORTS_PCRE}" = "y" ] && ./phoenix-rtos-ports/pcre/build.sh

[ "${PORTS_OPENSSL}" = "y" ] && ./phoenix-rtos-ports/openssl/build.sh

[ "${PORTS_ZLIB}" = "y" ] && ./phoenix-rtos-ports/zlib/build.sh

[ "${PORTS_LIGHTTPD}" = "y" ] && ./phoenix-rtos-ports/lighttpd/build.sh

[ "${PORTS_DROPBEAR}" = "y" ] && ./phoenix-rtos-ports/dropbear/build.sh

[ "${PORTS_LUA}" = "y" ] && ./phoenix-rtos-ports/lua/build.sh

[ "${PORTS_LZO}" = "y" ] && ./phoenix-rtos-ports/lzo/build.sh

[ "${PORTS_OPENVPN}" = "y" ] && ./phoenix-rtos-ports/openvpn/build.sh

[ "${PORTS_CURL}" = "y" ] && ./phoenix-rtos-ports/curl/build.sh

[ "${PORTS_JANSSON}" = "y" ] && ./phoenix-rtos-ports/jansson/build.sh

[ "${PORTS_MICROPYTHON}" = "y" ] && ./phoenix-rtos-ports/micropython/build.sh

[ "${PORTS_SSCEP}" = "y" ] && ./phoenix-rtos-ports/sscep/build.sh

[ "${PORTS_WPA_SUPPLICANT}" = "y" ] && ./phoenix-rtos-ports/wpa_supplicant/build.sh

[ "${PORTS_LIBEVENT}" = "y" ] && ./phoenix-rtos-ports/libevent/build.sh

[ "${PORTS_OPENIKED}" = "y" ] && ./phoenix-rtos-ports/openiked/build.sh

[ "${PORTS_AZURE_SDK}" = "y" ] && ./phoenix-rtos-ports/azure_sdk/build.sh

[ "${PORTS_PICOCOM}" = "y" ] && ./phoenix-rtos-ports/picocom/build.sh

[ "${PORTS_FS_MARK}" = "y" ] && ./phoenix-rtos-ports/fs_mark/build.sh

[ "${PORTS_COREMARK}" = "y" ] && ./phoenix-rtos-ports/coremark/build.sh
# List of directories with ports. Built in this order
ports=(
"mbedtls"
"busybox"
"pcre"
"openssl"
"zlib"
"lighttpd"
"dropbear"
"lua"
"lzo"
"openvpn"
"curl"
"jansson"
"micropython"
"sscep"
"wpa_supplicant"
"libevent"
"openiked"
"azure_sdk"
"picocom"
"fs_mark"
"coremark"
)


for port in "${ports[@]}"; do
(
port_env_name="PORTS_${port^^}"
if [ "${!port_env_name}" = "y" ]; then
export PREFIX_PORT="${PREFIX_PROJECT}/phoenix-rtos-ports/${port}"
# TODO: Maybe "${PREFIX_BUILD}/ports/${port}" to avoid any potential name clashes?
export PREFIX_PORT_BUILD="${PREFIX_BUILD}/${port}"

source "${PREFIX_PROJECT}/phoenix-rtos-ports/build.subr"

b_log "Building ${port}"
mkdir -p "${PREFIX_PORT_BUILD}"
./phoenix-rtos-ports/"${port}"/build.sh
fi
)
done

exit 0
79 changes: 79 additions & 0 deletions build.subr
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
#
# Shell script for building Phoenix-RTOS ports
#
# Common functions
#
# Copyright 2024 Phoenix Systems
# Author: Daniel Sawka
#

# Variables needed for the functions below
: "${PREFIX_PORT:?variable unset}"
: "${PREFIX_PORT_BUILD:?variable unset}"
: "${PORTS_MIRROR_BASEURL:?variable unset}"


# b_port_download(baseurl, filename, [orig_filename])
# Fetch a file from ${baseurl}${filename} (or ${baseurl}${orig_filename} if provided) and save as ${filename}
# in current port's directory. If this fails, try ${PORTS_MIRROR_BASEURL}${filename}. Also verifies checksums
# if checksums.sha256 file exists (opt-in).
b_port_download() {
local baseurl="$1"
local filename="$2"
local orig_filename="${3:-$filename}"

if [ ! -f "${PREFIX_PORT}/${filename}" ]; then
if ! wget "${baseurl}${orig_filename}" -O "${PREFIX_PORT}/${filename}.part" --no-check-certificate; then
wget "${PORTS_MIRROR_BASEURL}${filename}" -O "${PREFIX_PORT}/${filename}.part" --no-check-certificate
fi

if [ -f "${PREFIX_PORT}/checksums.sha256" ]; then
while read -r line; do
local expected_checksum="${line%% *}"
local line_file="${line#*\*}" # shasum binary mode (*) expected

if [ -n "${expected_checksum}" ] && [ "${line_file}" = "${filename}" ]; then
local actual_checksum="$(shasum -b -a 256 "${PREFIX_PORT}/${filename}.part")"
actual_checksum="${actual_checksum%% *}"

if [ "${expected_checksum}" = "${actual_checksum}" ]; then
echo "Checksum OK for \"${filename}\""
else
b_die "Checksum INVALID for \"${filename}\": expected \"${expected_checksum}\", got \"${actual_checksum}\""
fi
fi
done < "${PREFIX_PORT}/checksums.sha256"
fi

mv -f "${PREFIX_PORT}/${filename}.part" "${PREFIX_PORT}/${filename}"
fi
}

# b_port_apply_patches(srcdir, [patch_subdir])
# Apply patches to files in ${srcdir}. Non-recursive - use multiple calls with
# ${patch_subdir} if you group patches into separate directories.
b_port_apply_patches() {
local srcdir="$1"
local patch_subdir="${2:-.}"

local patch_dir="${PREFIX_PORT}/patches/${patch_subdir}"
local marker_dir="${PREFIX_PORT_BUILD}/markers/${patch_subdir}"
if [ -d "${patch_dir}" ]; then
mkdir -p "${marker_dir}"
fi

# Restores the initial value of nullglob option upon function return
trap "$(shopt -p nullglob)" RETURN
shopt -s nullglob

for patchfile in "${patch_dir}"/*.patch; do
if [ ! -f "${marker_dir}/$(basename "${patchfile}").applied" ]; then
echo "applying patch: ${patchfile}"
patch -d "${srcdir}" -p1 < "${patchfile}"
touch "${marker_dir}/$(basename "${patchfile}").applied"
fi
done
}

export -f b_port_download b_port_apply_patches

0 comments on commit 348ea3c

Please sign in to comment.