File betterbird.spec of Package betterbird

#
# spec file for package betterbird
#
Name:           betterbird
Version:        140.7.0
Release:        0
Summary:        Betterbird Email Client
License:        MPL-2.0
Group:          Productivity/Networking/Email/Clients
Url:            https://www.betterbird.eu/
Source0:        thunderbird-140.7.0esr.source.tar.xz
Source1:        thunderbird-patches-static-140.7.0esrbb17.tar.xz
Source2:        mozconfig
BuildRequires:  autoconf213
BuildRequires:  cargo
BuildRequires:  clang-devel
BuildRequires:  llvm-devel
BuildRequires:  rust >= 1.70
BuildRequires:  rust-cbindgen
BuildRequires:  nasm
BuildRequires:  yasm
BuildRequires:  python3-devel
BuildRequires:  python3-curses
BuildRequires:  pkgconfig(gtk+-3.0)
BuildRequires:  pkgconfig(dbus-glib-1)
BuildRequires:  pkgconfig(libpulse)
BuildRequires:  pkgconfig(alsa)
BuildRequires:  pkgconfig(x11-xcb)
BuildRequires:  pkgconfig(xt)
Conflicts:      MozillaThunderbird

%description
Betterbird is a fine-tuned version of Mozilla Thunderbird, Thunderbird on steroids.

%prep
# 1. Unpack main source
%setup -q -n thunderbird-140.7.0

# 2. Unpack patches
tar xf %{SOURCE1}

# 3. Find the patch directory and make it ABSOLUTE
PATCH_BASE_REL=$(find . -maxdepth 1 -type d -name "thunderbird-patches*" | head -n 1)

if [ -z "$PATCH_BASE_REL" ]; then
    echo "ERROR: Base patch directory not found!"
    exit 1
fi

PATCH_BASE=$(readlink -f "$PATCH_BASE_REL")
PATCH_ROOT="$PATCH_BASE/140"

echo "Using absolute patch root: $PATCH_ROOT"

if [ ! -d "$PATCH_ROOT" ]; then
    echo "ERROR: Directory '140' not found in patches! Available versions:"
    ls -F "$PATCH_BASE"
    exit 1
fi

# 4. Apply Mozilla-Central patches (Top Level)
SERIES_MC="$PATCH_ROOT/series-M-C"

if [ -f "$SERIES_MC" ]; then
    echo "Applying M-C patches from $SERIES_MC..."
    tr -d '\r' < "$SERIES_MC" | while read p; do
        [ -z "$p" ] && continue
        [[ "$p" =~ ^#.*$ ]] && continue
        
        # CLEANUP: Extract filename before any '#' comment
        clean_patch=$(echo "$p" | cut -d'#' -f1 | sed 's/[[:space:]]*$//')
        [ -z "$clean_patch" ] && continue

        patch_file=$(find "$PATCH_ROOT" -name "$clean_patch" | head -n 1)
        if [ -n "$patch_file" ]; then
            echo "Applying: $patch_file"
            if ! patch -p1 < "$patch_file"; then
                echo "WARNING: Patch $clean_patch failed to apply (likely binary). Skipping..."
            fi
        else
            echo "WARNING: Patch $clean_patch listed in series-M-C but not found!"
        fi
    done
else
    echo "WARNING: series-M-C not found at $SERIES_MC"
fi

# 5. Apply Comm patches (Inside comm/)
echo "Applying Comm patches..."
cd comm

SERIES_COMM="$PATCH_ROOT/series"

if [ -f "$SERIES_COMM" ]; then
    tr -d '\r' < "$SERIES_COMM" | while read p; do
        [ -z "$p" ] && continue
        [[ "$p" =~ ^#.*$ ]] && continue
        
        # CLEANUP: Extract filename before any '#' comment
        clean_patch=$(echo "$p" | cut -d'#' -f1 | sed 's/[[:space:]]*$//')
        [ -z "$clean_patch" ] && continue

        patch_file=$(find "$PATCH_ROOT" -name "$clean_patch" | head -n 1)
        if [ -n "$patch_file" ]; then
            echo "Applying: $patch_file"
            if ! patch -p1 < "$patch_file"; then
                echo "WARNING: Patch $clean_patch failed to apply (likely binary). Skipping..."
            fi
        else
             echo "WARNING: Patch $clean_patch listed in series but not found!"
        fi
    done
else
    echo "ERROR: series file missing from $PATCH_ROOT!"
    ls -F "$PATCH_ROOT"
    exit 1
fi
cd ..

# 6. Install config
cp %{SOURCE2} .mozconfig

%build
export MOZCONFIG=.mozconfig
# Use new recommended variable
export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=system
./mach build

%install
export MOZCONFIG=.mozconfig
export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=system

DESTDIR=%{buildroot} ./mach install

# Tumbleweed Fix: Move from /usr/local/lib to /usr/lib64
TARGET_LIB=%{buildroot}%{_libdir}/betterbird

if [ -d %{buildroot}/usr/local/lib ]; then
    echo "Found install in /usr/local/lib, moving..."
    mkdir -p %{buildroot}%{_libdir}
    APP_DIR=$(find %{buildroot}/usr/local/lib -maxdepth 1 -type d \( -name "thunderbird*" -o -name "betterbird*" \) | head -n 1)
    if [ -n "$APP_DIR" ]; then
        mv "$APP_DIR" "$TARGET_LIB"
    else
        echo "ERROR: Could not find application directory in /usr/local/lib"
        exit 1
    fi
    rm -rf %{buildroot}/usr/local
else
    echo "Install not found in /usr/local, assuming it went to /usr/lib..."
fi

# Rename thunderbird binary to betterbird if needed
if [ -f "$TARGET_LIB/thunderbird" ]; then
    mv "$TARGET_LIB/thunderbird" "$TARGET_LIB/betterbird"
fi

mkdir -p %{buildroot}%{_bindir}
ln -sf %{_libdir}/betterbird/betterbird %{buildroot}%{_bindir}/betterbird

%files
%defattr(-,root,root)
%{_bindir}/betterbird
%{_libdir}/betterbird
openSUSE Build Service is sponsored by