#!/usr/bin/env bash set -eu SCRIPT="$(dirname "${0}")" export SERENITY_ARCH="${SERENITY_ARCH:-i686}" HOST_CC="${CC:=cc}" HOST_CXX="${CXX:=c++}" HOST_AR="${AR:=ar}" HOST_RANLIB="${RANLIB:=ranlib}" HOST_PATH="${PATH:=}" HOST_PKG_CONFIG_DIR="${PKG_CONFIG_DIR:=}" HOST_PKG_CONFIG_SYSROOT_DIR="${PKG_CONFIG_SYSROOT_DIR:=}" HOST_PKG_CONFIG_LIBDIR="${PKG_CONFIG_LIBDIR:=}" DESTDIR="/" maybe_source() { if [ -f "$1" ]; then . "$1" fi } enable_ccache() { if command -v ccache &>/dev/null; then ccache_tooldir="${SERENITY_BUILD_DIR}/ccache" mkdir -p "$ccache_tooldir" for tool in gcc g++ c++; do ln -sf "$(command -v ccache)" "${ccache_tooldir}/${SERENITY_ARCH}-pc-serenity-${tool}" done export PATH="${ccache_tooldir}:$PATH" fi } target_env() { maybe_source "${SCRIPT}/.hosted_defs.sh" } target_env host_env() { export CC="${HOST_CC}" export CXX="${HOST_CXX}" export AR="${HOST_AR}" export RANLIB="${HOST_RANLIB}" export PATH="${HOST_PATH}" export PKG_CONFIG_DIR="${HOST_PKG_CONFIG_DIR}" export PKG_CONFIG_SYSROOT_DIR="${HOST_PKG_CONFIG_SYSROOT_DIR}" export PKG_CONFIG_LIBDIR="${HOST_PKG_CONFIG_LIBDIR}" enable_ccache } packagesdb="${DESTDIR}/usr/Ports/packages.db" . "$@" shift : "${makeopts:=-j$(nproc)}" : "${installopts:=}" : "${workdir:=$port-$version}" : "${configscript:=configure}" : "${configopts:=}" : "${useconfigure:=false}" : "${depends:=}" : "${patchlevel:=1}" : "${auth_type:=}" : "${auth_import_key:=}" : "${auth_opts:=}" : "${launcher_name:=}" : "${launcher_category:=}" : "${launcher_command:=}" : "${icon_file:=}" run_nocd() { echo "+ $@ (nocd)" ("$@") } run() { echo "+ $@" (cd "$workdir" && "$@") } run_replace_in_file() { run perl -p -i -e "$1" $2 } ensure_build() { # Sanity check. if [ ! -f "${DESTDIR}/usr/lib/libc.so" ]; then echo "libc.so could not be found. This likely means that SerenityOS:" echo "- has not been built and/or installed yet" echo "- has been installed in an unexpected location" echo "The currently configured build directory is ${SERENITY_BUILD_DIR}. Resolve this issue and try again." exit 1 fi } install_main_icon() { if [ -n "$icon_file" ] && [ -n "$launcher_command" ]; then install_icon "$icon_file" "$launcher_command" fi } install_icon() { if [ "$#" -lt 2 ]; then echo "Syntax: install_icon " exit 1 fi icon="$1" launcher="$2" command -v convert >/dev/null 2>&1 convert_exists=$? command -v identify >/dev/null 2>&1 identify_exists=$? if [ "$convert_exists" == "0" ] && [ "$identify_exists" == "0" ]; then for icon_size in "16x16" "32x32"; do index=$(run identify "$icon" | grep "$icon_size" | grep -oE "\[[0-9]+\]" | tr -d "[]" | head -n1) if [ -n "$index" ]; then run convert "${icon}[${index}]" "app-${icon_size}.png" else run convert "$icon" -resize $icon_size "app-${icon_size}.png" fi done run objcopy --add-section serenity_icon_s="app-16x16.png" "${DESTDIR}${launcher}" run objcopy --add-section serenity_icon_m="app-32x32.png" "${DESTDIR}${launcher}" fi } install_main_launcher() { if [ -n "$launcher_name" ] && [ -n "$launcher_category" ] && [ -n "$launcher_command" ]; then install_launcher "$launcher_name" "$launcher_category" "$launcher_command" fi } install_launcher() { if [ "$#" -lt 3 ]; then echo "Syntax: install_launcher " exit 1 fi launcher_name="$1" launcher_category="$2" launcher_command="$3" launcher_filename="${launcher_name,,}" launcher_filename="${launcher_filename// /}" case "$launcher_command" in *\ *) mkdir -p $DESTDIR/usr/local/libexec launcher_executable="/usr/local/libexec/$launcher_filename" cat >"$DESTDIR/$launcher_executable" <