### this file is sourced not run
# source: step

repo=yad
pkgname=${repo}_ultimate # for SLACKDESC

# WHAT ABOUT YAD ULTIMATE?
#
# This recipe builds the original yad project, which goes by the package name
# and binary name "yad" in most distributions[:1], but needed an alternative
# name in Fatdog for the reasons explained below. So Fatdog's package system
# calls this package "yad_ultimate", and its binary "yadu".
#
# Fatdog's packages yad_gtk{2,3} were forked from this project at version
# 0.42.0, and continue its legacy of GTK2 support.
# Fatdog64-8xx package "fatdog-scripts" requires yad_gtk2, which installs
# /usr/bin/yad -> yad_gtk2 -- don't change this link (although -> yad_gtk3
# would be OK but it's less tested).
#
# This package installs /usr/bin/yadu (u for ultimate).  Don't link yad -> yadu
# because it will break Fatdog64-8xx. All referenced packages can be installed
# without conflicts.
#
# [:1] The legacy "yad" package (binary name "yad") is still used by woof-CE
# and easyOS derivatives, and some "Dogs" distributions as of 2022-07-08.

MD5SUM=5e48181fd25ce752a6ac1c56f7f86c15
PKGVER=12.0

TARBALL=$pkgname-$PKGVER.tar.xz
SRC_URL=https://github.com/v1cont/yad/releases/download/v$PKGVER/yad-$PKGVER.tar.xz

# # when downloading from the master branch:
# SRC_URL=https://github.com/v1cont/$repo/archive/$PKGVER.tar.gz

PKGARCH=x86_64
PKGBUILD=1
BUNDLE=

SLACKREQ='libgtksourceview3 libgspell libenchant2 gtk3'

SLACKDESC="$pkgname: $pkgname $PKGVER (GUI dialog for shell scripts)
$pkgname: YAD (Yet Another Dialog) allows you to display graphical dialogs from the
$pkgname: command line and shell scripts. This package tracks the newest upstream
$pkgname: version, which only supports GTK3 and higher. This package installs binary name
$pkgname: \"yadu\". Don't link /usr/bin/yad -> yadu or several system scripts will not
$pkgname: work correctly.
$pkgname:
$pkgname: License: GNU GPL3
$pkgname:
$pkgname: https://github.com/v1cont/yad
$pkgname:
$pkgname:
"
SLACKINSTALL='glib-compile-schemas ./usr/share/glib-2.0/schemas'
SLACKUNINSTALL='glib-compile-schemas ./usr/share/glib-2.0/schemas'

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	cd tmp/$repo-* &&

	### patch for https://github.com/v1cont/yad/pull/184 until merged upstream {{{

	patch -Np1 << 'PR184' &&
From 98c490bc975d68dea7f85c43bb82e0d98615ac01 Mon Sep 17 00:00:00 2001
From: step <step-@users.noreply.github.com>
Date: Fri, 8 Jul 2022 19:29:49 +0200
Subject: [PATCH 1/2] yad-settings.in: fix get -> set

---
 src/yad-settings.in | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/yad-settings.in b/src/yad-settings.in
index c72c3d6..191a0df 100644
--- a/src/yad-settings.in
+++ b/src/yad-settings.in
@@ -119,20 +119,20 @@ if [[ $? -eq 0 ]]; then
     gsettings set yad.settings debug ${r1[13]}
 
     # GtkSourceView settings
-    gsettings get yad.sourceview theme "${r2[0]}"
-    gsettings get yad.sourceview line-num ${r2[1]}
-    gsettings get yad.sourceview line-hl ${r2[2]}
-    gsettings get yad.sourceview line-marks ${r2[3]}
-    gsettings get yad.sourceview mark1-color ${r2[4]}
-    gsettings get yad.sourceview mark2-color ${r2[5]}
-    gsettings get yad.sourceview right-margin ${r2[6]}
-    gsettings get yad.sourceview brackets ${r2[7]}
-    gsettings get yad.sourceview indent ${r2[8]}
-    gsettings get yad.sourceview homend ${r2[9]}
-    gsettings get yad.sourceview smart-bs ${r2[10]}
-    gsettings get yad.sourceview tab-width ${r2[11]}
-    gsettings get yad.sourceview indent-width ${r2[12]}
-    gsettings get yad.sourceview spaces ${r2[13]}
+    gsettings set yad.sourceview theme "${r2[0]}"
+    gsettings set yad.sourceview line-num ${r2[1]}
+    gsettings set yad.sourceview line-hl ${r2[2]}
+    gsettings set yad.sourceview line-marks ${r2[3]}
+    gsettings set yad.sourceview mark1-color ${r2[4]}
+    gsettings set yad.sourceview mark2-color ${r2[5]}
+    gsettings set yad.sourceview right-margin ${r2[6]}
+    gsettings set yad.sourceview brackets ${r2[7]}
+    gsettings set yad.sourceview indent ${r2[8]}
+    gsettings set yad.sourceview homend ${r2[9]}
+    gsettings set yad.sourceview smart-bs ${r2[10]}
+    gsettings set yad.sourceview tab-width ${r2[11]}
+    gsettings set yad.sourceview indent-width ${r2[12]}
+    gsettings set yad.sourceview spaces ${r2[13]}
 elif [[ $? -eq 3 ]]; then
     # Load default settings
     gsettings reset-recursively yad.settings

From 579720b844f470fecbfd6997eebe0f42314b8ff8 Mon Sep 17 00:00:00 2001
From: step <step-@users.noreply.github.com>
Date: Thu, 14 Jul 2022 07:54:25 +0200
Subject: [PATCH 2/2] fix typo in yad-settings.in

---
 src/yad-settings.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/yad-settings.in b/src/yad-settings.in
index 191a0df..b6f5c64 100644
--- a/src/yad-settings.in
+++ b/src/yad-settings.in
@@ -80,7 +80,7 @@ yad --plug=$KEY --tabnum=2 --bool-fmt=t --quoted-output --separator=" " --form -
     --field=$"Default theme for text-info dialog::CB" ${themes%?} \
     --field=$"Show line numbers:CHK" $(gsettings get yad.sourceview line-num) \
     --field=$"Hightlight current line:CHK" $(gsettings get yad.sourceview line-hl) \
-    --field=$"Enable line mars mode:CHK" $(gsettings get yad.sourceview line-marks) \
+    --field=$"Enable line marks mode:CHK" $(gsettings get yad.sourceview line-marks) \
     --field=$"Color of first type marks::CLR" "$(eval echo $(gsettings get yad.sourceview mark1-color))" \
     --field=$"Color of second type marks::CLR" "$(eval echo $(gsettings get yad.sourceview mark2-color))" \
     --field=$"Right margin position::NUM" $(gsettings get yad.sourceview right-margin) \
PR184
#}}}

	# rename translation files yad.mo -> yadu.mo
	# and change TEXTDOMAIN yad -> yadu
	sed -i -e 's/^GETTEXT_PACKAGE=yad/&u/' configure.ac &&

	### no need to rename gschema file yad.gschema.xml
	# Since yad_gtk{2,3} share the same configuration file
	# ~/.config/yad.conf building yadu with the default gschema poses no
	# conflicts.  However, we do need to change the gettext-domain to avoid
	# conflicts with yad_gtk{2,3}

	sed -i -e '/<schema/ { s/domain="yad"/domain="yadu"/ }' \
		data/yad.gschema.xml.in &&

	### patch some self-references
	# sh-4.4# grep -- -icon-browser src/*[ch]
	sed -i -e 's/"yad-icon-browser"/"yadu-icon-browser"/g' src/form.c &&
	# sh-4.4# grep -- -tools src/*[ch]
	sed -i -e '
		s/yad-tools/yadu-tools/g
		/^[ \t]*yad --/ s/yad/yadu/
	' src/yad-settings.in &&

	: " chained && end"

}

### default pkg_package

### build
pkg_build() {
	export LDFLAGS="$LDFLAGS -Wl,--as-needed"

	# build without htlm widget because it depends on webkit2gtk-4.0
	CONFFLAGS="$CONFFLAGS \
		--enable-nls \
		--disable-html \
		--enable-tray \
		--enable-icon-browser \
		--enable-spell \
		--enable-sourceview \
		--disable-standalone \
		--enable-tools \
			`# compile schemas in doinst.sh` \
		--disable-schemas-compile \
		\
		--with-rgb=/usr/share/X11/rgb.txt \
			`# what a savior` \
		--program-transform-name=s/yad/yadu/g \
		"

	cd /tmp/$repo-* &&

	autoreconf -fiv &&
	intltoolize --force &&

	pkg_build_autoconf &&

	### provide gsettings with persistent storage back end
	# for an OOTB working yadu.

	# Fatdog only has the gconf and memory back ends but only gconf
	# persists.  /etc/profile sets GSETTINGS_BACKEND=memory for all
	# programs (c.f. fossil check-in [8543fd02fd]
	# http://localhost:8080/info/8543fd02fdc95677)
	# So we set up symlinks to start each yadu* application
	# with GSETTINGS=gconf.

	err=0
	for p in /usr/bin/yadu{,-tools,-settings,-icon-browser}; do
		mv -v "$p" "$p.bin" &&
			ln -s yadu_launcher "$p" || err=1
	done
	[ $err = 0 ] &&
	echo > /usr/bin/yadu_launcher '#!/bin/bash
# provide yadu programs with a persistent gsettings back end
GSETTINGS_BACKEND=gconf exec -a "$0" "$0.bin" "$@"
' &&
	chmod 755 /usr/bin/yadu_launcher &&

	### rename shared files

	err=0 &&
	for p in \
		/usr/share/applications/yad-{settings,icon-browser}.desktop \
		/usr/share/aclocal/yad.m4 \
	; do
		if [ -e "$p" ]; then
			sed -i -e '
				/Exec=/ s/yad/yadu/
				s/YAD/YADU/g
			' "$p" &&
			mv -v "$p" "${p/yad/yadu}" || err=1
		fi
	done &&
	[ $err = 0 ] &&

	### reasoned [sic] effort to fix program names in manuals
	# changing yad -> yadu indiscriminately would generates confusion
	sed -i -e '
		/^\.TH / { s/yad/yady/g; s/YAD/YADU/g }
		s/yad-tools/yadu-tools/g
		s/YAD-TOOLS/YADU-TOOLS/g
		s/yad-i?con-browser/yadu-icon-browser/g

		/^\.SH SYNOPSIS/,+1 s/yad/yadu/
		/^.RI \[ \?OPTIONS/ a \
.PP\
\\fBNOTE\\fP: Fatdog64 renames the binary program \\fByadu\\fP [sic].\
Therefore to run the example commands in this manual substitute\
\\fByadu\\fP for "yad". All other references to "yad" and "YAD" in this manual\
are unchanged, e.g. use "yad" or "YAD" as directed for settings, special\
variables, etc..

		' /usr/share/man/man1/yadu.1 &&

	sed -i -e '
		s/yad-tools/yadu-tools/g
		s/YAD-TOOLS/YADU-TOOLS/g
		' /usr/share/man/man1/yadu-tools.1 &&

	pkg_build_slackdesc
	: " chained && end"
}

: << 'EOF'
--disable-option-checking  ignore unrecognized --enable/--with options
--disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
--enable-silent-rules   less verbose build output (undo: "make V=1")
--disable-silent-rules  verbose build output (undo: "make V=0")
--enable-maintainer-mode enable make rules and dependencies not useful (and sometimes confusing) to the casual installer
--disable-nls           do not use Native Language Support
--enable-dependency-tracking do not reject slow dependency extractors
--disable-dependency-tracking speeds up one-time build
--enable-html           Build YAD with HTML widget
--enable-tray           Build YAD with status icon
--enable-spell          Build YAD with Spell check support (default - yes)
--enable-sourceview     Build YAD with GtkSourceView support (default - yes)
--enable-standalone     Build standalone YAD binary (wihtout gsettings)
--enable-tools          Build yad-tools utility
--enable-icon-browser   Build YAD icon browser
--disable-schemas-compile Disable regeneration of gschemas.compiled on install
EOF

# vim:ft=sh:

