#!/usr/bin/env bash set -eu SCRIPT="$(dirname "${0}")" export SERENITY_ARCH="${SERENITY_ARCH:-i686}" export SERENITY_TOOLCHAIN="${SERENITY_TOOLCHAIN:-GCC}" 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_READELF="${READELF:=readelf}" export HOST_OBJCOPY="${OBJCOPY:=objcopy}" 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 READELF="${HOST_READELF}" export OBJCOPY="${HOST_OBJCOPY}" 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" makeopts=("-j$(nproc)") installopts=() configscript=configure configopts=() useconfigure=false config_sub_path=config.sub use_fresh_config_sub=false depends=() patchlevel=1 auth_type= auth_import_key= auth_opts=() launcher_name= launcher_category= launcher_command= launcher_run_in_terminal=false icon_file= . "$@" shift : "${workdir:=$port-$version}" cleanup_git() { echo "WARNING: Reverting changes to $workdir as we are in dev mode!" run git clean -xffd >/dev/null 2>&1 } # Use the local git target repo as the workdir # Make sure to clean it up afterwards if [ -n "${IN_SERENITY_PORT_DEV:-}" ]; then echo "WARNING: All changes to the workdir in the current state (inside ./package.sh dev) are temporary!" echo " They will be reverted once the command exits!" nongit_workdir="$workdir" workdir=".$workdir-git" trap "run cleanup_git" EXIT fi run_nocd() { echo "+ $@ (nocd)" >&2 ("$@") } run() { echo "+ $@" (cd "$workdir" && "$@") } run_replace_in_file() { if [ "$(uname -s)" = "SerenityOS" ]; then run sed -i "$1" $2 else run perl -p -i -e "$1" $2 fi } get_new_config_sub() { config_sub="${1:-config.sub}" if ! run grep -q serenity "$config_sub"; then run do_download_file "https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub" "${1:-config.sub}" false fi } ensure_new_config_sub() { get_new_config_sub "$config_sub_path" } 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" <