#!/usr/bin/make -f

# Downloaded from:
# http://www.lsi.com/support/Pages/Download-Results.aspx?keyword=megacli

DESTDIR=$(CURDIR)/debian/lsi-megacli

%:
	dh $@

override_dh_auto_build:
	dh_auto_build
	# megacli files
	mkdir -p megacli
	(cd megacli; ZIPFILE=$$(find $(CURDIR) -type f -name "*MegaCLI.zip"); \
		unzip $$ZIPFILE; \
		RPM=$$(find . -type f -name "MegaCli-*.noarch.rpm"); \
		rpm2cpio $$RPM | cpio -idm)

override_dh_auto_install:
	dh_auto_install
	# megacli files
	if [ $(DEB_BUILD_ARCH) = i386 ]; then \
		install -D -m 0755 $(CURDIR)/megacli/opt/MegaRAID/MegaCli/MegaCli \
			$(DESTDIR)/opt/MegaRAID/MegaCli/MegaCli; \
	fi
	if [ $(DEB_BUILD_ARCH) = amd64 ]; then \
		install -D -m 0755 $(CURDIR)/megacli/opt/MegaRAID/MegaCli/MegaCli64 \
			$(DESTDIR)/opt/MegaRAID/MegaCli/MegaCli64; \
		dh_link --package=lsi-megacli opt/MegaRAID/MegaCli/MegaCli64 opt/MegaRAID/MegaCli/MegaCli; \
		dh_link --package=lsi-megacli opt/MegaRAID/MegaCli/MegaCli usr/sbin/MegaCli64; \
	fi
	dh_link --package=lsi-megacli opt/MegaRAID/MegaCli/MegaCli usr/sbin/MegaCli;
	dh_link --package=lsi-megacli opt/MegaRAID/MegaCli/MegaCli usr/sbin/megacli;
	TXTFILE=$$(find $(CURDIR) -type f -name "*MegaCLI.txt"); \
		install -D -m 0644 $$TXTFILE \
		$(DESTDIR)/usr/share/doc/lsi-megacli/$$(basename $$(find $(CURDIR) -type f -name "*MegaCLI.txt"));

override_dh_auto_clean:
	dh_auto_clean
	rm -rf megacli
