#! /usr/bin/make -f
# debhelper rules for os-prober
# (C) 2004 Joshua Kwan <joshk@triplehelix.org>

%:
	dh $@

ARCH=$(shell dpkg-architecture -qDEB_HOST_ARCH)
ifneq (,$(findstring :$(ARCH):,:i386:amd64:))
ARCH=x86
endif

DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
CC := gcc
else
CC := $(DEB_HOST_GNU_TYPE)-gcc
endif

export DEB_CFLAGS_MAINT_APPEND := -Os -Wall

CFLAGS := $(shell dpkg-buildflags --get CPPFLAGS; dpkg-buildflags --get CFLAGS)
LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS)

override_dh_auto_build:
	$(MAKE) CC=$(CC) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"

override_dh_install:
	dh_install
	for probes in os-probes os-probes/mounted os-probes/init \
	              linux-boot-probes linux-boot-probes/mounted; do \
		dh_install $$probes/common/* usr/lib/$$probes; \
		if [ -e "$$probes/$(ARCH)" ]; then \
			dh_install $$probes/$(ARCH)/* usr/lib/$$probes; \
		fi; \
	done
ifeq ($(ARCH),x86)
	dh_install os-probes/mounted/powerpc/20macosx usr/lib/os-probes/mounted
endif
	cp -a debian/os-prober-udeb/usr/lib debian/os-prober/usr/
