#!/usr/bin/make -f

UPSTREAM_GIT = https://github.com/lyonel/lshw
-include /usr/share/openstack-pkg-tools/pkgos.make

include /usr/share/dpkg/architecture.mk
ifeq ($(origin CC),default)
CC = $(DEB_HOST_GNU_TYPE)-gcc
endif
ifeq ($(origin CXX),default)
CXX = $(DEB_HOST_GNU_TYPE)-g++
endif
export PKG_CONFIG = $(DEB_HOST_GNU_TYPE)-pkg-config

CXX_DEB_FLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	export CXX_DEB_FLAGS += -O0
else
	export CXX_DEB_FLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	export INSTALL_PROGRAM += -s
endif

ifeq ($(DEB_BUILD_GNU_TYPE),alpha-linux-gnu)
	export CXX_DEB_FLAGS = -Wall -g
endif


srcdir=src

configure: configure-stamp
configure-stamp:
	dh_testdir
	#Add here commands to configure the package.

	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp patch
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE) -C $(srcdir) VERSION=$(uver) core CC="$(CC)" CXX="$(CXX)"
	$(MAKE) -C $(srcdir) gui CC="$(CC)" CXX="$(CXX)"
	#/usr/bin/docbook-to-man debian/lshw.sgml > lshw.1
	touch build-stamp

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	$(MAKE) -C $(srcdir) clean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/lshw.
	$(MAKE) -C $(srcdir) install DESTDIR=$(CURDIR)/debian/lshw CC="$(CC)" CXX="$(CXX)"
	$(MAKE) -C $(srcdir) install-gui DESTDIR=$(CURDIR)/debian/lshw-gtk CC="$(CC)" CXX="$(CXX)"

	# data files supplied by pciutils and usbutils
	rm -rf $(CURDIR)/debian/lshw/usr/share/lshw
	#pod2man --lax $(CURDIR)/debian/patches/lshw-gtk.pod > $(CURDIR)/debian/patches/lshw-gtk.1
	cp $(CURDIR)/debian/patches/lshw-gtk.desktop $(CURDIR)/debian/lshw-gtk/usr/share/applications/lshw-gtk.desktop
	cp $(CURDIR)/debian/patches/logo.svg $(CURDIR)/debian/lshw-gtk/usr/share/pixmaps/lshw-gtk.svg
	chmod 644 $(CURDIR)/debian/lshw/usr/share/locale/fr/LC_MESSAGES/lshw.mo

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installexamples
	dh_installmenu
	dh_installcron
	dh_installman
	dh_installinfo
	dh_installchangelogs
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installexamples
	dh_installmenu
	dh_installcron
	dh_installman
	dh_installinfo
	dh_installchangelogs
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure patch unpatch
