@@generated_notice@@

PREFIX?=/usr
UDEVDIR=$(shell pkg-config --variable=udevdir udev)
SBINDIR=$(PREFIX)/sbin
CONFDIR=/etc/mdevctl.d
SCRIPTDIR=$(PREFIX)/lib/mdevctl/scripts.d
CALLOUTS_DIR=$(SCRIPTDIR)/callouts
NOTIFIERS_DIR=$(SCRIPTDIR)/notifiers
DATADIR=$(PREFIX)/share
MANDIR=$(DATADIR)/man
BASH_COMPLETION_DIR=$(DATADIR)/bash-completion/completions

all:
	@echo "Run 'make install' to install the program"

# since we generate a Makefile, we have to use --no-verify to stop cargo from
# complaining that we modified the source directory during build.
archive:
	cargo package --allow-dirty --no-verify
	cargo vendor
	tar -caf target/package/mdevctl-@@mdevctl_version@@-vendor.crate vendor/

mdevctl.spec: mdevctl.spec.in
	cargo build

srpm: mdevctl.spec archive
	rpmbuild -bs --define "_sourcedir $(PWD)/target/package" \
		--define "_specdir $(PWD)" \
		--define "_builddir $(PWD)" \
		--define "_srcrpmdir $(PWD)" \
		--define "_rpmdir $(PWD)" $<

rpm: mdevctl.spec archive
	rpmbuild -bb --define "_sourcedir $(PWD)/target/package" \
		--define "_specdir $(PWD)" \
		--define "_builddir $(PWD)" \
		--define "_srcrpmdir $(PWD)" \
		--define "_rpmdir $(PWD)" $<

install:
	mkdir -p $(DESTDIR)$(CONFDIR)
	mkdir -p $(DESTDIR)$(UDEVDIR)/rules.d/
	install -m 644 60-mdevctl.rules $(DESTDIR)$(UDEVDIR)/rules.d/
	mkdir -p $(DESTDIR)$(SBINDIR)
	# mdevctl binary is already installed by dh_cargo
	# install -m 755 @@mdevctl@@ $(DESTDIR)$(SBINDIR)/
	# Furthermore this (read actions) is useful for non-root -> bin
	ln -sf mdevctl $(DESTDIR)$(PREFIX)/bin/lsmdev
	mkdir -p $(DESTDIR)$(MANDIR)/man8
	install -m 644 @@outdir@@/mdevctl.8 $(DESTDIR)$(MANDIR)/man8/
	ln -sf mdevctl.8  $(DESTDIR)$(MANDIR)/man8/lsmdev.8
	mkdir -p $(DESTDIR)$(BASH_COMPLETION_DIR)/
	install -m 644 -T @@outdir@@/mdevctl.bash $(DESTDIR)$(BASH_COMPLETION_DIR)/mdevctl
	install -m 644 -T @@outdir@@/lsmdev.bash $(DESTDIR)$(BASH_COMPLETION_DIR)/lsmdev
	mkdir -p $(DESTDIR)$(CALLOUTS_DIR)
	mkdir -p $(DESTDIR)$(NOTIFIERS_DIR)
