#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk
# used in debian/camx-dkms.install
export DEB_VERSION_UPSTREAM

DKMS_STAGED := debian/camx-dkms/usr/src/camx-$(DEB_VERSION_UPSTREAM)

%:
	dh $@

override_dh_install:
	# camx-dkms.install file installs "*", so exclude debian dir
	dh_install -X./debian
	# manually copy these excluded scripts
	cp -a debian/dkms-build debian/dkms-clean $(DKMS_STAGED)

# dh_dkms installs dkms.conf and generates the postinst/prerm maintainer
# scripts that register and build the module on the target system.
# After dh_dkms runs, append per-target BUILT_MODULE_NAME entries derived
# from SUPPORTED_TARGETS found in debian/camx-dkms.dkms.
execute_after_dh_dkms:
	. debian/camx-dkms.dkms && \
	    i=0 && \
	    for t in $$SUPPORTED_TARGETS; do \
	        printf 'BUILT_MODULE_NAME[%d]="camera_%s"\n' \
	            "$$i" "$$t" >> $(DKMS_STAGED)/dkms.conf && \
	        printf 'BUILT_MODULE_LOCATION[%d]="."\n' \
	            "$$i" >> $(DKMS_STAGED)/dkms.conf && \
	        printf 'DEST_MODULE_LOCATION[%d]="/updates/camera"\n' \
	            "$$i" >> $(DKMS_STAGED)/dkms.conf && \
	        i=$$((i+1)); \
	    done

override_dh_auto_clean:
override_dh_auto_build:
override_dh_auto_test:
override_dh_auto_install:
