#!/usr/bin/make -f

include Makefile.parameters

copy-base:
	-cp dkms-packaging-base/Makefile .
	-cp -r dkms-packaging-base/patches-vivid .
	-cp -r dkms-packaging-base/helper-scripts .
	-cp -r dkms-packaging-base/dkms-mkdeb-template .

move-includes:
	# Move some relevant headers into include subdir and delete the rest, to not bloat the source package
	# as the recipe can only add full directories
	-mkdir -p $(UPSTREAM_SRC_DIR)/include
	-cp include-src-from-tree/hda* $(UPSTREAM_SRC_DIR)/include
	-rm -rf include-src-from-tree

clean: copy-base move-includes
	-rm build.stamp
	$(MAKE) clean
	-rm debian/files
	-rm -rf debian/tmp

build.stamp:
	$(MAKE) fetch-src-from-directory
	$(MAKE) dkms-mkdeb-source-only
	touch build.stamp

build-arch:

build-indep: build.stamp

build: copy-base build-arch build.stamp

binary-arch: build

binary-indep: build
	# Unpack the deb generated by DKMS, and repack it again to make dpkg-buildpackage happy
	rm -rf debian/tmp
	dpkg-deb -x buildroot/$(PACKAGE_NAME)-dkms_$(PACKAGE_VERSION)_all.deb debian/tmp
	dpkg-deb -e buildroot/$(PACKAGE_NAME)-dkms_$(PACKAGE_VERSION)_all.deb debian/tmp/DEBIAN
	# the four rows below were taken from the "hello" packaging
	dpkg-gencontrol 
	chown -R root:root debian/tmp
	chmod -R u+w,go=rX debian/tmp
	dpkg --build debian/tmp ..

binary: binary-arch binary-indep

.PHONY: build-arch build-indep build binary-arch binary-indep binary clean
