#!/usr/bin/make -sf

.PHONY: build binary install clean stage control create

BINARY_PACKAGES=guide exec terminal-management service-management terminal-extras service-management-extras zsh-completion service-command-shim systemv-shims systemd-shims upstart-shims smf-shims execline-shims core-shims linux-shims debian-shims openrc-shims bsd-shims openbsd-shims freebsd-shims ucspi-tcp-shims kbd-shims net-tools-shims logrotate-shims bcron-as-cron-shims desktop-bus-shims bundles debian-crontab-no-anacron debian-crontab-anacron run-system-manager run-via-open-rc run-via-systemd run-debian-desktop-base run-debian-server-base run-kernel-vt run-user-vt run-virtualbox-guest run-freedesktop-system-bus run-freedesktop-kits run-openssh-server run-appletalk run-systemd-udev run-udev run-busybox-mdev run-suckless-mdev run-mdevd run-vdev run-local-syslog run-klog run-bcron run-publicfile run-sntpclock run-taiclock run-taiclockd run-djbdns run-fake-hwclock

# The Debian package builder targets this in order to make the package contents.
build:
	MAKEFLAGS= package/compile

# The Debian package builder targets this in order to clean the build areas.
clean:
	echo 1>&2 "Cleaning individual staged packages under debian/ ."
	${RM} debian/files debian/substvars
	for i in ${BINARY_PACKAGES} ; \
	do \
		${RM} -r debian/nosh-"$$i"/ || exit 1 ; \
	done
	echo 1>&2 "Cleaning snapshot area in debian/tmp/ ."
	${RM} -r debian/tmp/

# The Debian package builder targets this in order to make the .deb files.
binary: build stage control create

stage:
	echo 1>&2 "Snapshotting slashpackage installed directory trees."
	install -d -m 0755 debian/tmp
	pax -r -w -l command config guide manual debian/tmp/
	echo 1>&2 "Building staging areas for packages under debian/."
	package/stage debian/tmp debian

control:
	${RM} debian/files
	for i in ${BINARY_PACKAGES} ; \
	do \
		echo 1>&2 "Building control file for nosh-$$i." ; \
		debian/gencontrol nosh-"$$i" debian/nosh-"$$i" || exit 1 ; \
	done

create:
	for i in ${BINARY_PACKAGES} ; \
	do \
		dpkg -b debian/nosh-"$$i" ./ || exit 1 ; \
	done
