#!/usr/bin/make -f

NUMJOBS = $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	MAKEFLAGS += -j$(NUMJOBS)
else
	DEB_BUILD_OPTIONS += parallel=$(NUMJOBS)
	export DEB_BUILD_OPTIONS
endif

%:
	dh $@ \
		--with autoreconf \
		--parallel

override_dh_auto_configure:
	CXXFLAGS="$(dpkg-buildflags --get CXXFLAGS) -fpermissive" dh_auto_configure -- --with-contrib-plugins=all

override_dh_strip:
	dh_strip -k
	# Move the debugging symbols into the proper packages
	mkdir -p $(CURDIR)/debian/codeblocks-dbg/usr/lib/
	mv $(CURDIR)/debian/codeblocks/usr/lib/debug/ \
	    $(CURDIR)/debian/codeblocks-dbg/usr/lib/
	mv $(CURDIR)/debian/libcodeblocks0/usr/lib/debug/usr/lib/* \
	    $(CURDIR)/debian/codeblocks-dbg/usr/lib/debug/usr/lib/
	rm -vrf $(CURDIR)/debian/codeblocks/usr/lib/debug/ \
	    $(CURDIR)/debian/libcodeblocks0/usr/lib/debug/

	mkdir -p $(CURDIR)/debian/codeblocks-contrib-dbg/usr/lib/
	mv $(CURDIR)/debian/codeblocks-contrib/usr/lib/debug/ \
	    $(CURDIR)/debian/codeblocks-contrib-dbg/usr/lib/
	mv $(CURDIR)/debian/libwxsmithlib0/usr/lib/debug/usr/lib/* \
	    $(CURDIR)/debian/codeblocks-contrib-dbg/usr/lib/debug/usr/lib/
	rm -vrf $(CURDIR)/debian/codeblocks-contrib/usr/lib/debug/ \
	    $(CURDIR)/debian/libwxsmithlib0/usr/lib/debug/

overide_dh_makeshlibs:
	dh_makeshlibs -Xusr/lib/codeblocks/plugins -Xusr/lib/wxSmithContribItems

override_dh_shlibdeps:
	dh_shlibdeps -Xusr/lib/codeblocks/plugins
