#!/usr/bin/make -f

names := WhiteSur WhiteSur-light WhiteSur-dark WhiteSur-morning \
	Monterey Monterey-light Monterey-dark Monterey-morning
wallpapers := debian/whitesur-wallpapers/usr/share/wallpapers
backgrounds := debian/whitesur-wallpapers/usr/share/backgrounds/whitesur

%:
	dh $@

# Upstream's render-wallpapers.sh at its 4k setting (the 1920x1080 sources at
# twice their size), with rsvg-convert instead of Inkscape and the same JPEG
# step; the PNG rasters upstream commits are what the repack drops.
override_dh_auto_build:
	mkdir -p build
	for name in $(names); do \
		rsvg-convert -w 3840 -h 2160 -o "build/$$name.png" "src/$$name.svg" || exit 1; \
		convert "build/$$name.png" -strip -quality 92 "build/$$name.jpg" || exit 1; \
	done

# One Plasma wallpaper package per picture, laid out as upstream's WhiteSur-kde
# wallpaper/ directory does it: the unsuffixed WhiteSur and Monterey carry the
# dark render as images_dark, which the image wallpaper plugin picks under a
# dark colour scheme. The backgrounds directory is the same pictures by path.
override_dh_auto_install:
	install -d $(backgrounds)
	for name in $(names); do \
		install -d "$(wallpapers)/$$name/contents/images" || exit 1; \
		install -m 0644 "build/$$name.jpg" "$(wallpapers)/$$name/contents/images/3840x2160.jpg" || exit 1; \
		sed "s/@NAME@/$$name/g" debian/metadata.json.in > "$(wallpapers)/$$name/metadata.json" || exit 1; \
		ln -s "../../wallpapers/$$name/contents/images/3840x2160.jpg" "$(backgrounds)/$$name.jpg" || exit 1; \
	done
	for name in WhiteSur Monterey; do \
		install -d "$(wallpapers)/$$name/contents/images_dark" || exit 1; \
		install -m 0644 "build/$$name-dark.jpg" "$(wallpapers)/$$name/contents/images_dark/3840x2160.jpg" || exit 1; \
	done
