#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

CFLAGS = -Wall -g -DXF86VIDMODE
CFLAGS += $(shell dpkg-buildflags --get CFLAGS)
CFLAGS += $(shell dpkg-buildflags --get CPPFLAGS)
LDFLAGS = $(shell dpkg-buildflags --get LDFLAGS)

ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	MAKEFLAGS += -j$(NUMJOBS)
endif

%:
	dh $@ --without autoreconf

override_dh_auto_configure:
	ln -sf /usr/share/misc/config.sub
	ln -sf /usr/share/misc/config.guess
	LIBS=-lXxf86vm ./configure \
	        --build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE) \
		--prefix=/usr/share/games/xgalaga \
		--exec-prefix=/usr/games CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"

override_dh_auto_build:
	# hack SOUNDDEFS so we don't need symlinks
	$(MAKE) SOUNDDEFS=-DSOUNDSERVER=\\\"/usr/lib/games/xgalaga/$$\(SOUNDSRV\)\\\"

execute_after_dh_auto_install:
	# move the sound-server binary out of usr/share
ifneq ($(DEB_HOST_ARCH_OS), hurd)
	mkdir -p debian/xgalaga/usr/lib/games/xgalaga/
	mv debian/xgalaga/usr/share/games/xgalaga/xgal.sndsrv.* \
		debian/xgalaga/usr/lib/games/xgalaga/
endif
	find debian/xgalaga/usr/share/games/xgalaga -type f | xargs chmod 644

override_dh_installchangelogs:
	dh_installchangelogs CHANGES
