# vim:ft=spec:

Name:           {{{git_name name="ghostty"}}}
Version:        {{{git_version}}}
Release:        {{{git_revision}}}%{?dist}
Summary:        GPU-accelerated terminal with GTK4 UI

License:        MIT
URL:            https://github.com/ghostty-org/ghostty
Source0:        {{{git_repo_pack}}}

BuildRequires: blueprint-compiler
BuildRequires: fontconfig-devel
BuildRequires: freetype-devel
BuildRequires: glib2-devel
BuildRequires: glslang-devel
BuildRequires: gtk4-devel
BuildRequires: gtk4-layer-shell-devel
BuildRequires: harfbuzz-devel
BuildRequires: libadwaita-devel
BuildRequires: libpng-devel
BuildRequires: libxml2-devel
BuildRequires: oniguruma-devel
BuildRequires: pandoc-cli
BuildRequires: pixman-devel
BuildRequires: pkg-config
BuildRequires: simdutf-devel
BuildRequires: wayland-protocols-devel
BuildRequires: zig
BuildRequires: zlib-ng-devel

Requires: fontconfig
Requires: freetype
Requires: glib2
Requires: gtk4
Requires: harfbuzz
Requires: libadwaita
Requires: libpng
Requires: oniguruma
Requires: pixman
Requires: zlib-ng

%description
Ghostty is a fast, feature-rich, and cross-platform terminal emulator that uses
platform-native UI and GPU acceleration.

%prep
{{{git_setup_macro path="$GIT_ROOT"}}}

%build
# Download deps to enable system integrations.
# https://github.com/ghostty-org/ghostty/issues/6632#issuecomment-2722745586
export ZIG_GLOBAL_CACHE_DIR="$PWD/.zig-offline-cache"
./nix/build-support/fetch-zig-cache.sh

# Replace the caret in the rpm version with something that doesn't break Zig.
v="%{version}-%{release}"
v="${v/^/+}"
DESTDIR="%{buildroot}" \
zig build \
    --summary all \
    --prefix "%{_prefix}" \
    --system "$ZIG_GLOBAL_CACHE_DIR/p" \
    -Dversion-string="$v" \
    -Doptimize=ReleaseFast \
    -Dcpu=baseline \
    -Dpie=true \
    -Demit-docs

# Resolve Fedora 42 ncurses-term conflict.
%if 0%{?fedora} >= 42
rm -rf "%{buildroot}%{_datadir}/terminfo"
%endif

# Remove libghostty which doesn't pertain yet.
rm -f "%{buildroot}/usr/lib/libghostty"*

# Find the files because manually listing them is boring.
find "%{buildroot}" -type f | \
sed 's,^%{buildroot},,' | \
grep -v '^%{_datadir}/ghostty/' > files

%files -f files
%license LICENSE
%{_datadir}/ghostty

%changelog
* {{{git_changelog_date}}} Aron Griffis <aron@scampersand.com> - {{{git_changelog_version}}}
- Nightly build from git master
