diff --git a/build.sh b/build.sh index 16af358..0a25562 100755 --- a/build.sh +++ b/build.sh @@ -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 @@ -29,6 +29,7 @@ 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" @@ -36,46 +37,44 @@ 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" +) + +source "${PREFIX_PROJECT}/phoenix-rtos-ports/build.subr" + +for port in "${ports[@]}"; do + 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}" + + port_env_name="PORTS_${port^^}" + if [ "${!port_env_name}" = "y" ]; then + b_log "Building ${port}" + mkdir -p "${PREFIX_PORT_BUILD}" + ./phoenix-rtos-ports/"${port}"/build.sh + fi +done exit 0 diff --git a/build.subr b/build.subr new file mode 100644 index 0000000..72e53d7 --- /dev/null +++ b/build.subr @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# +# Shell script for building Phoenix-RTOS ports +# +# Common functions +# +# Copyright 2024 Phoenix Systems +# Author: Daniel Sawka +# + +# b_port_download(baseurl, filename, [url_filename]) +b_port_download() { + local baseurl="$1" + local filename="$2" + local url_filename="${3:-$filename}" + + if [ ! -f "${PREFIX_PORT}/${filename}" ]; then + if ! wget "${baseurl}${url_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" ]; then + local cksum_pattern='^(\S+)\s*\(([^\)]+)\)\s*\=\s*(\S+)\s*$' + # Verify checksums one after another. `cksum -c` it too limited + while read -r line; do + if [[ "$line" =~ $cksum_pattern ]] && [ "${BASH_REMATCH[2]}" = "${filename}" ]; then + local expected_checksum="${BASH_REMATCH[3]}" + local actual_checksum=$(cksum --untagged -a "${BASH_REMATCH[1],,}" "${PREFIX_PORT}/${BASH_REMATCH[2]}.part" | cut -d' ' -f1) + + 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" + fi + + mv -f "${PREFIX_PORT}/${filename}.part" "${PREFIX_PORT}/${filename}" + fi +} + +# b_port_apply_patches(srcdir, [patch_subdir]) +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