#!/usr/bin/make -f
#
# debian/rules for Ubuntu linux-firmware
#
# Use this however you want, just give credit where credit is due.
#
# Copyright (c) 2008 Ben Collins <bcollins@ubuntu.com>
#
#

export LC_ALL=C
export SHELL=/bin/bash -e

dest_dir = $(CURDIR)/debian/linux-firmware
firm_dir = $(dest_dir)/lib/firmware
doc_dir = $(dest_dir)/usr/share/doc/linux-firmware
license_dir = $(doc_dir)/licenses

install-indep:
	dh_testdir
	dh_testroot
	dh_prep -i

	install -d $(firm_dir)

	make install DESTDIR=$(dest_dir)
	debian/scripts/remove-firmware $(firm_dir)
	# debian/scripts/compress-firmware $(firm_dir)

	install -d $(doc_dir)
	cp WHENCE $(doc_dir)/README
	cp WHENCE.ubuntu $(doc_dir)/README.ubuntu

	install -d $(license_dir)
	cp LICEN[CS]E* GPL-[23] $(license_dir)
	debian/scripts/remove-firmware $(license_dir)

	# De-dup firmwares, i.e., if there are duplicate firmware files,
	# keep only one and create symlinks for the others
	debian/scripts/symlink-duplicates $(firm_dir)

	# Check for dangling symlinks
	debian/scripts/check-symlinks $(dest_dir)

binary-indep: install-indep
	dh_testdir
	dh_testroot

	dh_install -i
	dh_installchangelogs -i
	dh_installdocs -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary: binary-indep

build:

clean:
	dh_testdir
	dh_testroot
	dh_clean

	# Ensure sanity checks are run when building packages from the
	# git repo
	if [ -d .git ] && [ -x /usr/bin/git ] ; then \
	    $(MAKE) -f debian/rules check; \
	fi

check:
	$(MAKE) check
