# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=nerd-fonts
pkgver=3.2.1
pkgrel=0
pkgdesc="Patched developer targeted fonts with a high number of glyphs"
url="https://nerdfonts.com"
arch="noarch"
license="MIT AND OFL-1.1 AND Apache-2.0"
provides="nerd-fonts-stable=$pkgver-r$pkgrel"
replaces="nerd-fonts-stable"
options="!check"  # no testsuite provided
builddir="$srcdir"

# The following CSV has columns: <id>,<zipname>,<fontname>,<origname>
# <id> is the suffix for the resulting package.
# <fontname> is the name of the file itself.
#
# If <fontname> is empty, <zipname> will be used instead.
# <origname> is used only for pkgdesc and it may be empty.
# "~" will be replaced with a single whitespace.
_fonts="
	anonymous-pro,AnonymousPro,Anonymice,Anonymous~Pro
	arimo,Arimo,,
	bitstrom-wera-sans-mono,BitstreamVeraSansMono,BitstromWeraNerdFontMono,Bitstrom~Wera~Sans~Mono
	cascadia-code,CascadiaCode,CaskaydiaCove,Cascadia~Code
	comic-shanns-mono,ComicShannsMono,ComicShannsMono,Comic~Shanns~Mono
	dejavu-sans-mono,DejaVuSansMono,DejaVuSansM,DejaVu~Sans~Mono
	droid-sans-mono,DroidSansMono,DroidSansM,Droid~Sans~Mono
	fira-code,FiraCode,FiraCode,Fira~Code
	fira-mono,FiraMono,FiraMono,Fira~Mono
	go-mono,Go-Mono,GoMono,Go~Mono
	hack,Hack,,
	hasklig,Hasklig,Hasklug,Hasklig
	hermit,Hermit,Hurmit,Hermit
	ia-writer,iA-Writer,iMWriting,iA~Writer
	ibm-plex-mono,IBMPlexMono,BlexMono,IBM~Plex~Mono
	inconsolata,Inconsolata,,
	jetbrains-mono,JetBrainsMono,JetBrainsMono,JetBrains~Mono
	liberation-mono,LiberationMono,LiterationMono,Liberation~Mono
	meslo,Meslo,,
	monofur,Monofur,Monofur,
	mononoki,Mononoki,Mononoki,
	overpass,Overpass,,
	share-tech-mono,ShareTechMono,ShureTechMono,Share~Tech~Mono
	source-code-pro,SourceCodePro,SauceCodePro,Source~Code~Pro
	space-mono,SpaceMono,SpaceMono,Space~Mono
	terminus,Terminus,Terminess,Terminus
	tinos,Tinos,,
	ubuntu,Ubuntu,,
	ubuntu-mono,UbuntuMono,UbuntuMono,Ubuntu~Mono
	victor-mono,VictorMono,VictorMono,Victor~Mono
	"
_depends_all=""
subpackages="
	nerd-fonts-all:_all
	font-nerd-fonts-symbols:_symbols
	"
source="$pkgname-symbols-$pkgver.tar.xz::https://github.com/ryanoasis/nerd-fonts/releases/download/v$pkgver/NerdFontsSymbolsOnly.tar.xz
	10-nerd-font-symbols-$pkgver.conf::https://raw.githubusercontent.com/ryanoasis/nerd-fonts/v$pkgver/10-nerd-font-symbols.conf
	"
for _font in $_fonts; do
	_pkgname="font-${_font%%,*}-nerd"
	_filename=${_font#*,}; _filename=${_filename%%,*}

	_depends_all="$_depends_all $_pkgname"
	subpackages="$subpackages $_pkgname:_subpackage:noarch"
	source="$source $_pkgname-$pkgver.tar.xz::https://github.com/ryanoasis/nerd-fonts/releases/download/v$pkgver/$_filename.tar.xz"
done

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local id=${subpkgname#font-}; id=${id%-nerd}

	local IFS_OLD=$IFS IFS=','
	set -- $(printf '%s\n' "$_fonts" | grep "^\s*$id," | tr '~' ' ')
	if [ $# -lt 2 ]; then
		error "$id was not found in \$_fonts or wrong entry!"
		return 1
	fi
	IFS=$IFS_OLD

	local fontname=${3:-$2}
	local origname=${4-}
	depends="fontconfig"
	pkgdesc="$fontname Nerd Font${origname:+" (modified $origname Font)"}"

	# for backward compatibility (Alpine <3.16)
	case "$subpkgname" in
		font-ibm-plex-mono-nerd) provides="font-ibm-plex-nerd=$pkgver-r$pkgrel";;
		font-libertion-mono-nerd) provides="font-liberation-nerd=$pkgver-r$pkgrel";;
		font-ubuntu-nerd) depends="$depends font-ubuntu-mono-nerd";;
	esac

	cd "$builddir"
	install -Dm644 ./"$fontname"*.*tf -t "$subpkgdir"/usr/share/fonts/${subpkgname#font-}/
}

_symbols() {
	depends="fontconfig"
	pkgdesc="Nerd Font (Symbols Only)"

	install -Dm644 "$srcdir"/SymbolsNerdFont*.ttf -t "$subpkgdir"/usr/share/fonts/nerd-fonts/
	install -Dm644 "$srcdir"/10-nerd-font-symbols-$pkgver.conf \
		"$subpkgdir"/usr/share/fontconfig/conf.avail/10-nerd-font-symbols.conf
}

_all() {
	pkgdesc="Meta package for all patched Nerd Fonts"
	depends="$_depends_all"

	mkdir -p "$subpkgdir"
}

sha512sums="
ac61c1d4153049f1a3009fb6ec4f89073770a09d70b7236b9e0eca07da593e57c14afe2a0c9d7bfb315389c878afcdfdb23c1c19a23c3950e7de52a8ce3099de  nerd-fonts-symbols-3.2.1.tar.xz
cede5368ea6014b3e6e4cc7207ffd6cd0765803debc735c5bdef456ae1f938f94d3fbb7c4bcfec9d5cc422a76b7cb12c3f22d54b4c4610adc14807c5a80ae134  10-nerd-font-symbols-3.2.1.conf
4c89a879a455395d31848b0d1181a1768ff5cfa3384a8a2a89e7f50cfc602e2efe35f893a5b445f0750ff4d9277eae702477bf14717e74886c7485e1c5a2eed2  font-anonymous-pro-nerd-3.2.1.tar.xz
d6aca4dc2d5f8d01f2f44a625eb671107e3d11f3e317198eaa226aed91e027509e81f3eee1e97299a3f53472043f2a9517f7ad653d439c8d8410e0c401f218d2  font-arimo-nerd-3.2.1.tar.xz
7b5a7d24af09004b0a67eabaf29bcdb0ca8e171fcfdbb632ffe3dfca7cfe5b43c773a467d079869d4ddd7824475e65233eac49092967f5e26b3a45dee9132b18  font-bitstrom-wera-sans-mono-nerd-3.2.1.tar.xz
4bcf50c1a1f30abef930b092bff02c4e5e74633d723aae04012e2c217afb4bae9c7cf91f4204e6cd7d554b8ff342e3dc32ec231bce71f33064592d96c08deab0  font-cascadia-code-nerd-3.2.1.tar.xz
e704d3fbd7fcacdd0695bad0329604ebffa86747cd41f7071101204b3e661911fe893c577fb62d038ec8d71d6f6671ac521bbf6b43966b332f41bb6ed06fd30a  font-comic-shanns-mono-nerd-3.2.1.tar.xz
4bf5fa45d1f57ab785655c0574ba236750b7688f30266e328179d2804e5fb2e764f1b915d1c35c9fb63db73ed8812257920bc758a926f6de3d61b2327720a94b  font-dejavu-sans-mono-nerd-3.2.1.tar.xz
2c883477543ae94eb627f25e885f52233867f67326055e02460e120e8b444d27d07c8d1d7d292b3b9ed5c8475b2297675a4d132c06fd8caf858ae015671bb75d  font-droid-sans-mono-nerd-3.2.1.tar.xz
b8261cf2df5a9195fa106e3d17d91499a7099762e6d2c013e1ac292388a639e96268e289319964b7da5d68a873fe460f44002c246bed560f6a97dcd853511831  font-fira-code-nerd-3.2.1.tar.xz
00d1a03ce3c97fc504b1c3b2ae2a6a6e8b5241a83771e1c5c19739c0f6421a6b107fa20f7d776fffecb160039e52c340f4f74922072169928db9b357c64e1e01  font-fira-mono-nerd-3.2.1.tar.xz
aa450f425533b7b69612805b17867ef99aa8de9dd0e47133a2adbb383efa8a1868421309c24cc8335912742b29d7c25733666e9dbe0f293d9007a9981d9e72a8  font-go-mono-nerd-3.2.1.tar.xz
ee9ce9dc1c41de11f092fd36f85ec23ce1dbb870f38103e393750b08b85407a7135ad1022e9db01abe64245f1557646c3e95700124ef9d0a66d2b9d5368aac10  font-hack-nerd-3.2.1.tar.xz
e7625a28bffdb73e96aef21c47186bf75b7c7884aadba37e0b5beca5f34b6f25d0f458907e4ddccb6bf33080a5e13dc85520ab3a9f19daf168091c9dc5b9335d  font-hasklig-nerd-3.2.1.tar.xz
3718d56c185a7d245f314f753272c7a0a747351b09d24da474f0f443fc759fb631f673403ce4d4b2cd289293b04253ccdf4917a4d1f15368296f733937d80e2a  font-hermit-nerd-3.2.1.tar.xz
2e4368f8285531fa0b27e2d55bd079126aeb54371ffc5623d8980f9f3ef6ca479f6f3709b58a62682e6bce04eaaba1a29cff39a4a85b47e9a1c6fff966b64527  font-ia-writer-nerd-3.2.1.tar.xz
ac465368f72f93e7ce44c43b6fccca3f434245ab11b7f4f4cf75bd0330c1ab008017adac1278f620a1342eb3d9188a45f18fcaf3b47d5eff65c9682a9477fe93  font-ibm-plex-mono-nerd-3.2.1.tar.xz
a47ee99edd1490319bd9e19860b326b4d9b2a7c05e63917d99ca1817f58964545f935b1531c79f3179e95caf32d073ad899591dfc11278e0361cf1345fde2ffc  font-inconsolata-nerd-3.2.1.tar.xz
b4eb3d2e95881de683d655d5b4f40d681d138a08450a366bd5778ea1103d29153b7ddabe320c44ff569c10bed4f825531ac2ce2c44235c0e488713828d143c27  font-jetbrains-mono-nerd-3.2.1.tar.xz
5b9bb855e1b98adab1b65e02ccb4593f692248c6ebc64f0976e0380c09b7a2c0140f0867d852f070643b3cc5a4a17e0811c3162613a6380cc9ff19e594a02d2d  font-liberation-mono-nerd-3.2.1.tar.xz
5364b31502e54884e4dc0dac61e19c026cfac5b1f9a02053d57ecdba2ec249851e2766f252952ff3afdf51ca59bc705422715f6942836312333f6b2000e3402a  font-meslo-nerd-3.2.1.tar.xz
d50f5765a4a2baf7d0c76df729c3b828f87dcd25cbbd99fc731d2e760e9a0a02a01ae70439a288f24f9522584077d2983ef23ca6d5c8fd7bc5f199fd82c289af  font-monofur-nerd-3.2.1.tar.xz
d85536d84a94b5703d215e89a12e596c7431db9cda067ce68f24be11e81a349a63a58a09519521e3995fc4fd1833f39541e76b2d3e00612cad66ef3992069f04  font-mononoki-nerd-3.2.1.tar.xz
35f92d6b270e8cab600a5bedf03bb92f9c8ea53ef05468ba312f4ac9aa92c355a67433eeebdc8936e6162c1901d8ef469a447ef8e8aa438d4a39e773b3a5a711  font-overpass-nerd-3.2.1.tar.xz
0f109de045b33bb9726d33934ae36b61281fa169784d6998b3db2d7331e92709b3ff9afcf8714dc0c71da81817f2f260087a21000dd451baab11e121a5c5d720  font-share-tech-mono-nerd-3.2.1.tar.xz
ffa831caaaa252427a227e5a9efd9360b01f12d7d15adb3dcee1af2f3a9acc9685aed9a08d5a99a15e343c3cb7f3d6cb4544cedabbdfe3a6531982ea6a1835ae  font-source-code-pro-nerd-3.2.1.tar.xz
21eb46b35754a923048ee1fc8ffbf1c38bbb0f6b1ad7c7b4d4582f4a6655b3c9bc8334810ceaddc3d1e7409132226cd86c1125d5667b4f911686ca3b56ff6f62  font-space-mono-nerd-3.2.1.tar.xz
fa2ebd49e20b28bb9820caa7ca04d96958b260d64345789dc2d9d85984e84cd6dd84dc45c8f9dc50b5dbd622764b70b9a3afeb4f98a3316bf6960d4c8fa9b04a  font-terminus-nerd-3.2.1.tar.xz
0ab19ef4b08b6768beca0e75bc8e1ab53368adf1159b1236083bb1ef91607b40176da75ea419329ad023486370ed238df23d66c6ca86bdda1c68a30f3529bbe9  font-tinos-nerd-3.2.1.tar.xz
9d385f9683f4803547c1048cf90bc97cab2e38d5c52bc6183b4ac3767173dd8ba34c92fe99bb9718db51fef9622042aed55b8e84b9227196ec055cd793f0e626  font-ubuntu-nerd-3.2.1.tar.xz
dc3e5c1d86aca54049a1d175c33453715baa37e58e04671b051690c616115ea7fe3fdefb96714751cadb20eee48c96b614017fbb3e93692498e783619dd919fd  font-ubuntu-mono-nerd-3.2.1.tar.xz
a81db43ea05061111f7e87eb8ef0df45b46ef2a5256911e05aa130472f00bdb141d996d095c9b6a2cc83e11bf477fa3195b151f011305497ed5d26f52c346d83  font-victor-mono-nerd-3.2.1.tar.xz
"
