#!/usr/bin/env bash set -eu SCRIPT="$(dirname "${0}")" export SERENITY_ARCH="${SERENITY_ARCH:-i686}" if [ -z "${HOST_CC:=}" ]; then export HOST_CC="${CC:=cc}" export HOST_CXX="${CXX:=c++}" export HOST_AR="${AR:=ar}" export HOST_RANLIB="${RANLIB:=ranlib}" export HOST_PATH="${PATH:=}" export HOST_PKG_CONFIG_DIR="${PKG_CONFIG_DIR:=}" export HOST_PKG_CONFIG_SYSROOT_DIR="${PKG_CONFIG_SYSROOT_DIR:=}" export HOST_PKG_CONFIG_LIBDIR="${PKG_CONFIG_LIBDIR:=}" fi 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:=}" : "${launcher_run_in_terminal:=false}" : "${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 local launcher_binary="${launcher_command%% *}" install_icon "$icon_file" "${launcher_binary}" fi } install_icon() { if [ "$#" -lt 2 ]; then echo "Syntax: install_icon " exit 1 fi local icon="$1" local launcher="$2" command -v convert >/dev/null || true local convert_exists=$? command -v identify >/dev/null || true local identify_exists=$? if [ "${convert_exists}" != "0" ] || [ "${identify_exists}" != 0 ]; then echo 'Unable to install icon: missing convert or identify, did you install ImageMagick?' return fi 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[0]" -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}" } 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 local launcher_name="$1" local launcher_category="$2" local launcher_command="$3" local launcher_filename="${launcher_name,,}" launcher_filename="${launcher_filename// /}" local icon_override="" case "$launcher_command" in *\ *) mkdir -p $DESTDIR/usr/local/libexec launcher_executable="/usr/local/libexec/$launcher_filename" cat >"$DESTDIR/$launcher_executable" <