Raw File
#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS

# Enable hardening build flags
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_BUILD_ARCH      ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
DEB_BUILD_MULTIARCH ?= $(shell dpkg-architecture -qDEB_BUILD_MULTIARCH)
QT_PLUGIN_DIR = usr/lib/$(DEB_BUILD_MULTIARCH)/qt4/plugins

DEB_TEST_TARGET ?= Experimental
QGIS_BUILDDIR ?= debian/build

QGIS_VERSION=$(shell dpkg-parsechangelog | sed -ne 's/^Version: \([0-9]\+:\)\?\([^+-]\+\).*$$/\2/p')

ifeq (,$(DIST))
	DISTRIBUTION := $(shell dpkg-parsechangelog --format rfc822 | sed -ne "s/^Distribution: //p")
else
	DISTRIBUTION := $(DIST)
endif

ifneq (,$(findstring -oracle,$(DISTRIBUTION)))
	DISTRIBUTION := $(subst -oracle,,$(DISTRIBUTION))
	WITH_ORACLE=1
endif

ifneq ($(DISTRIBUTION),$(findstring $(DISTRIBUTION),"wheezy jessie stretch precise trusty wily xenial"))
	DISTRIBUTION := sid
endif

DEB_BUILD_NAME ?= $(DISTRIBUTION)-$(DEB_BUILD_ARCH)

ifeq (,$(DISPLAY))
TESTMAKE=xvfb-run -a -n 1 -s "-screen 0 1280x1024x24 -dpi 96" $(MAKE)
else
TESTMAKE=$(MAKE)
endif

QGIS_MAJOR=$(shell sed -ne 's/SET(CPACK_PACKAGE_VERSION_MAJOR "\([0-9]*\)")/\1/p' CMakeLists.txt)
QGIS_MINOR=$(shell sed -ne 's/SET(CPACK_PACKAGE_VERSION_MINOR "\([0-9]*\)")/\1/p' CMakeLists.txt)
QGIS_PATCH=$(shell sed -ne 's/SET(CPACK_PACKAGE_VERSION_PATCH "\([0-9]*\)")/\1/p' CMakeLists.txt)
QGIS_ABI=$(QGIS_MAJOR).$(QGIS_MINOR).$(QGIS_PATCH)
GRASS=grass$(subst .,,$(shell pkg-config --modversion grass|cut -d. -f1,2))
GRASSVER=$(subst .,,$(shell pkg-config --modversion grass|cut -d. -f1))

WITH_GLOBE=$(shell dpkg --compare-versions "$$(dpkg-query -W --showformat='$${Version}' libosgearth-dev)" ge 2.7 && echo 1)

CMAKE_OPTS := \
	-DBUILDNAME=$(DEB_BUILD_NAME) \
	-DCMAKE_VERBOSE_MAKEFILE=1 \
	-DCMAKE_INSTALL_PREFIX=/usr \
	-DBINDINGS_GLOBAL_INSTALL=TRUE \
	-DPEDANTIC=TRUE \
	-DWITH_QSPATIALITE=TRUE \
	-DWITH_SERVER=TRUE \
	-DWITH_SERVER_PLUGINS=TRUE \
	-DSERVER_SKIP_ECW=TRUE \
	-DQGIS_CGIBIN_SUBDIR=/usr/lib/cgi-bin \
	-DWITH_APIDOC=TRUE \
	-DGENERATE_QHP=TRUE \
	-DWITH_CUSTOM_WIDGETS=TRUE \
	-DWITH_INTERNAL_HTTPLIB2=FALSE \
	-DWITH_INTERNAL_JINJA2=FALSE \
	-DWITH_INTERNAL_MARKUPSAFE=FALSE \
	-DWITH_INTERNAL_PYGMENTS=FALSE \
	-DWITH_INTERNAL_DATEUTIL=FALSE \
	-DWITH_INTERNAL_PYTZ=FALSE \
	-DWITH_INTERNAL_YAML=FALSE \
	-DQT_TAG_FILE=/usr/share/qt4/doc/html/qt.tags \
	-DQT_DOC_URL=/usr/share/qt4/doc/html/

ifneq ($(SHA),)
	CMAKE_OPTS += -DSHA=$(SHA)
endif

ifeq ($(GRASSVER),7)
	CMAKE_OPTS += \
		-DWITH_GRASS=TRUE \
		-DWITH_GRASS7=TRUE \
		-DGRASS_PREFIX7=/usr/lib/$(GRASS)
else
	CMAKE_OPTS += \
		-DWITH_GRASS=TRUE \
		-DWITH_GRASS6=TRUE \
		-DGRASS_PREFIX=/usr/lib/$(GRASS)
endif

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	MAKEFLAGS += -j$(NUMJOBS)
endif

ifneq (,$(findstring $(DISTRIBUTION),"precise"))
	CMAKE_OPTS += -DWITH_INTERNAL_NOSE2=TRUE -DWITH_INTERNAL_SIX=TRUE
else
	CMAKE_OPTS += -DWITH_INTERNAL_NOSE2=FALSE -DWITH_INTERNAL_SIX=FALSE
endif

ifeq (,$(findstring $(DISTRIBUTION),"stretch sid wily xenial"))
	CMAKE_OPTS += -DWITH_INTERNAL_FUTURE=TRUE
else
	CMAKE_OPTS += -DWITH_INTERNAL_FUTURE=FALSE
endif

ifneq (,$(WITH_GLOBE))
	CMAKE_OPTS += -DWITH_GLOBE=TRUE
endif

ifneq (,$(findstring $(DISTRIBUTION),"wheezy precise"))
	CMAKE_OPTS += -DWITH_PYSPATIALITE=TRUE
endif

ifneq (,$(findstring $(DISTRIBUTION),"sid stretch"))
	CMAKE_OPTS += -DPOSTGRES_LIBRARY=/usr/lib/$(DEB_BUILD_MULTIARCH)/libpq.so
endif

ifneq (,$(findstring $(DISTRIBUTION),"sid stretch xenial"))
	CMAKE_OPTS += -DWITH_QTWEBKIT=FALSE
endif

ifneq (,$(findstring $(DISTRIBUTION),"sid"))
	CMAKE_OPTS += -DGEOS_LIBRARY=/usr/lib/$(DEB_BUILD_MULTIARCH)/libgeos_c.so
endif

ifneq (,$(findstring $(DISTRIBUTION),"jessie stretch trusty wily xenial sid"))
	CMAKE_OPTS += -DPYTHON_LIBRARY=/usr/lib/$(DEB_BUILD_MULTIARCH)/libpython2.7.so
endif

ifneq (,$(WITH_ORACLE))
ifeq ($(DEB_BUILD_ARCH),amd64)
	ORACLE_INCLUDEDIR=/usr/include/oracle/12.1/client64/
	ORACLE_LIBDIR=/usr/lib/oracle/12.1/client64/lib/
endif
ifeq ($(DEB_BUILD_ARCH),i386)
	ORACLE_INCLUDEDIR=/usr/include/oracle/12.1/client/
	ORACLE_LIBDIR=/usr/lib/oracle/12.1/client/lib/
endif

	CMAKE_OPTS += \
		-DWITH_ORACLE=TRUE \
		-DORACLE_LIBDIR=$(ORACLE_LIBDIR) \
		-DORACLE_INCLUDEDIR=$(ORACLE_INCLUDEDIR)
endif

ifneq (,$(findstring $(DISTRIBUTION),"sid stretch jessie"))
	CMAKE_OPTS += -DSPATIALINDEX_LIBRARY=/usr/lib/$(DEB_BUILD_MULTIARCH)/libspatialindex.so
endif

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CMAKE_OPTS += -DCMAKE_BUILD_TYPE=Debug
else
ifneq (,$(findstring $(DISTRIBUTION),"trusty"))
	CMAKE_OPTS += -DKEEP_GLOBE_CXX_FLAGS=TRUE
endif
endif

ifneq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	CMAKE_OPTS += -DENABLE_TESTS=FALSE
else
	CMAKE_OPTS += -DENABLE_TESTS=TRUE
endif

ifneq (,$(findstring $(DISTRIBUTION),"wheezy jessie stretch trusty sid"))
CPPFLAGS := $(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS   := $(shell dpkg-buildflags --get CFLAGS) $(CPPFLAGS)
CXXFLAGS := $(shell dpkg-buildflags --get CXXFLAGS) $(CPPFLAGS)
LDFLAGS  := $(shell dpkg-buildflags --get LDFLAGS)
endif

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
	CXXFLAGS += -O0
else
	CFLAGS += -O2
	CXXFLAGS += -O2
endif

ifneq (,$(findstring profile,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -pg
	CXXFLAGS += -pg
	LDFLAGS += -pg
endif


# multi distribution support:
# - remove lines with applicable excludes
# - remove prefixes with applicable includes
# - remove prefixes with not applicable excludes
# - remove remaining comments

CONTROL_EXPRESSIONS = $(DISTRIBUTION) grass$(GRASSVER)

ifneq (,$(WITH_GLOBE))
	CONTROL_EXPRESSIONS += globe
endif

ifneq (,$(WITH_ORACLE))
	CONTROL_EXPRESSIONS += oracle
endif

define gentemplate
$(2): $(1)
	sed -r \
		-e '/#(.+ |)!($(subst $(eval) ,|,$(CONTROL_EXPRESSIONS)))( .+|)#/d' \
		-e 's/#([^#]+ |)($(subst $(eval) ,|,$(CONTROL_EXPRESSIONS)))( [^#]+|)#//g' \
		-e 's/#([^#]+ |)![^#]+( [^#]*|)#//g' \
		-e '/^#/d' \
		-e "s/\{DEB_BUILD_GNU_TYPE\}/$(DEB_BUILD_GNU_TYPE)/g" \
		-e "s#\{QT_PLUGIN_DIR\}#$(QT_PLUGIN_DIR)#g" \
		-e "s/\{QGIS_ABI\}/$(QGIS_ABI)/g" \
		-e "s/\{GRASS\}/$(GRASS)/g" \
		-e "s/\{GRASSVER\}/$(GRASSVER)/g" \
		-e "s/\{GRASSVER_QGISABI\}/$(GRASSVER)-$(QGIS_ABI)/g" \
		$$^ >$$@

templates:: $(2)

templateclean::
	rm -f $(2)
endef

$(foreach t,$(wildcard debian/*.in),$(eval $(call gentemplate,$(t),$(basename $(t)))))
$(foreach t,$(wildcard debian/*{GRASSVER_QGIS_ABI}*),$(eval $(call gentemplate,$(t),$(subst {GRASSVER_QGIS_ABI},$(GRASSVER)-$(QGIS_ABI),$(t)))))
$(foreach t,$(wildcard debian/*{QGIS_ABI}*),$(eval $(call gentemplate,$(t),$(subst {QGIS_ABI},$(QGIS_ABI),$(t)))))

cleantemplates:
	$(MAKE) -f debian/rules templateclean
	$(MAKE) -f debian/rules debian/control debian/compat

binary binary-arch binary-indep build build-arch build-indep clean install install-arch install-indep: templates
	dh $@ --with python2 --parallel --builddirectory=$(QGIS_BUILDDIR)

override_dh_clean: cleantemplates
	dh_clean qgis.bin.1 qbrowser.bin.1

	-$(RM) -r $(CURDIR)/$(QGIS_BUILDDIR)/

override_dh_auto_configure:
	dh_auto_configure -- $(CMAKE_OPTS)

override_dh_auto_test: test-stamp

test-stamp:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Code to run the package test suite - and ignore the outcome for now
	mkdir -p debian/tmp/locale/
	localedef -f UTF-8 -i en_US ./debian/tmp/locale/en_US.UTF-8/
	-LOCPATH=$(CURDIR)/debian/tmp/locale/ \
	LC_ALL=en_US.UTF-8 \
	LD_LIBRARY_PATH=$(CURDIR)/$(QGIS_BUILDDIR)/output/lib:$(LD_LIBRARY_PATH) \
	PATH=/usr/sbin:$(PATH) \
	$(TESTMAKE) -C $(QGIS_BUILDDIR) $(DEB_TEST_TARGET)
else
	@echo Skipping tests.
endif
	touch test-stamp

override_dh_auto_install:
	dh_auto_install

	# remove unwanted files
	$(RM) $(CURDIR)/debian/tmp/usr/share/qgis/doc/api/installdox
	$(RM) $(CURDIR)/debian/tmp/usr/share/qgis/doc/api/html/jquery.js
	$(RM) $(CURDIR)/debian/tmp/usr/share/qgis/doc/api/jquery.js

	# replace leaflet and jquery urls
	perl -i -p \
		-e 's#http://.*/leaflet.css#leaflet/leaflet.css#;s#http://.*/leaflet.js#leaflet/leaflet.js#;s#http://.*/jquery-.*.min.js#jquery-min.js#' \
		$(CURDIR)/debian/tmp/usr/share/qgis/doc/developersmap.html

	# Use /usr/bin/python2.7 explicitly for Python Policy compliance
	perl -i -pe 's=#!/usr/bin/env python=#!/usr/bin/python2.7=;' $$(find debian/tmp -name "*.py")

	# Don't include a copy of the world.tif also included in osgearth-data
	$(RM) $(CURDIR)/debian/tmp/usr/share/qgis/globe/world.tif

	# remove extra license files
	-find $(CURDIR)/debian/tmp/usr/share/qgis/resources/cpt-city-qgis-min/ -name COPYING.xml -delete
	$(RM) $(CURDIR)/debian/tmp/usr/share/qgis/doc/LICENSE
	$(RM) $(CURDIR)/debian/tmp/usr/share/qgis/python/plugins/db_manager/LICENSE
	$(RM) $(CURDIR)/debian/tmp/usr/share/qgis/python/plugins/MetaSearch/LICENSE.txt

	# Man pages are installed by dh_installman
	$(RM) $(CURDIR)/debian/tmp/usr/man/man1/qgis.1
	$(RM) $(CURDIR)/debian/tmp/usr/man/man1/qbrowser.1

	# Don't ship srs.db, automatically updated in postinst with crssync
	mv $(CURDIR)/debian/tmp/usr/share/qgis/resources/srs.db $(CURDIR)/debian/tmp/usr/share/qgis/resources/srs-template.db

	# Install menu pixmap
	install -o root -g root -d $(CURDIR)/debian/tmp/usr/share/pixmaps
	install -o root -g root -m 644 $(CURDIR)/images/icons/qgis_icon.svg $(CURDIR)/debian/tmp/usr/share/pixmaps/qgis.svg
	install -o root -g root -m 644 $(CURDIR)/images/icons/qbrowser_icon.svg $(CURDIR)/debian/tmp/usr/share/pixmaps/qbrowser.svg
	install -o root -g root -m 644 $(CURDIR)/images/icons/qgis-icon.png $(CURDIR)/debian/tmp/usr/share/pixmaps/qgis.png
	install -o root -g root -m 644 $(CURDIR)/images/icons/qbrowser-icon.png $(CURDIR)/debian/tmp/usr/share/pixmaps/qbrowser.png
	install -o root -g root -m 644 $(CURDIR)/images/icons/qgis-mime-icon.png $(CURDIR)/debian/tmp/usr/share/pixmaps/qgis-mime.png

	# Install MIME type icon
	for size in 8x8 16x16 22x22 24x24 32x32 36x36 42x42 48x48 64x64 72x72 80x80 96x96 128x128; do \
		install -o root -g root -d $(CURDIR)/debian/tmp/usr/share/icons/hicolor/$${size}/mimetypes ; \
		install -o root -g root -m 644 $(CURDIR)/debian/qgis-mime-icon$${size}.png $(CURDIR)/debian/tmp/usr/share/icons/hicolor/$${size}/mimetypes/qgis-mime.png ; \
	done

	# Install QGIS file formats icons
	for file_type in qgs qlr qml qpt; do \
		for size in 8x8 16x16 22x22 24x24 32x32 36x36 42x42 48x48 64x64 72x72 80x80 96x96 128x128 192x192 256x256 512x512; do \
			install -o root -g root -d $(CURDIR)/debian/tmp/usr/share/icons/hicolor/$${size}/mimetypes ; \
			install -o root -g root -m 644 \
				$(CURDIR)/debian/qgis-$${file_type}$${size}.png \
				$(CURDIR)/debian/tmp/usr/share/icons/hicolor/$${size}/mimetypes/qgis-$${file_type}.png ; \
		done ; \
	done

	# Install application icon
	for size in 8x8 16x16 22x22 24x24 32x32 36x36 42x42 48x48 64x64 72x72 80x80 96x96 128x128 192x192 256x256 512x512; do \
		install -o root -g root -d $(CURDIR)/debian/tmp/usr/share/icons/hicolor/$${size}/apps ; \
		install -o root -g root -m 644 $(CURDIR)/debian/qgis-icon$${size}.png $(CURDIR)/debian/tmp/usr/share/icons/hicolor/$${size}/apps/qgis.png ; \
		install -o root -g root -m 644 $(CURDIR)/debian/qbrowser-icon$${size}.png $(CURDIR)/debian/tmp/usr/share/icons/hicolor/$${size}/apps/qbrowser.png ; \
	done
	
	install -o root -g root -d $(CURDIR)/debian/tmp/usr/share/icons/scalable/apps
	install -o root -g root -m 644 $(CURDIR)/images/icons/qgis_icon.svg $(CURDIR)/debian/tmp/usr/share/icons/scalable/apps/qgis.svg
	install -o root -g root -m 644 $(CURDIR)/images/icons/qbrowser_icon.svg $(CURDIR)/debian/tmp/usr/share/icons/scalable/apps/qbrowser.svg

	# Install desktop files
	install -o root -g root -d $(CURDIR)/debian/tmp/usr/share/applications
	install -o root -g root -m 644 $(CURDIR)/debian/qgis.desktop $(CURDIR)/debian/tmp/usr/share/applications
	install -o root -g root -m 644 $(CURDIR)/debian/qbrowser.desktop $(CURDIR)/debian/tmp/usr/share/applications

	# Mime info
	install -o root -g root -d $(CURDIR)/debian/tmp/usr/share/mime/packages
	install -o root -g root -m 644 $(CURDIR)/debian/qgis.xml $(CURDIR)/debian/tmp/usr/share/mime/packages

	install -o root -g root -d $(CURDIR)/debian/tmp/usr/share/mimelnk/application
	install -o root -g root -m 644 $(CURDIR)/debian/mime/application/* $(CURDIR)/debian/tmp/usr/share/mimelnk/application

	# qgis binaries
	install -o root -g root -m 755 -d $(CURDIR)/debian/qgis/usr/bin
	install -o root -g root -m 755 $(CURDIR)/debian/tmp/usr/bin/qgis $(CURDIR)/debian/qgis/usr/bin/qgis.bin
	install -o root -g root -m 755 $(CURDIR)/debian/tmp/usr/bin/qbrowser $(CURDIR)/debian/qgis/usr/bin/qbrowser.bin

	$(RM) $(CURDIR)/debian/tmp/usr/bin/qgis
	$(RM) $(CURDIR)/debian/tmp/usr/bin/qbrowser

	# qgis binary wrappers
	sed -r \
		-e "s/\{GRASS\}/$(GRASS)/g" \
		-e "s#\{ORACLE_LIBDIR\}#$(ORACLE_LIBDIR)#g" \
		$(CURDIR)/debian/qgis.sh.in >$(CURDIR)/debian/qgis.sh

	install -o root -g root -m 755 $(CURDIR)/debian/qgis.sh $(CURDIR)/debian/qgis/usr/bin/qgis
	install -o root -g root -m 755 $(CURDIR)/debian/qgis.sh $(CURDIR)/debian/qgis/usr/bin/qbrowser

override_dh_install:
	dh_install --autodest --list-missing

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog

override_dh_installman:
	cp qgis.1 qgis.bin.1
	cp qbrowser.1 qbrowser.bin.1

	dh_installman -pqgis qgis.1 qbrowser.1 qgis.bin.1 qbrowser.bin.1

override_dh_installmime:
	dh_installmime -pqgis

override_dh_python2:
	dh_python2 --no-guessing-versions
	dh_python2 --no-guessing-versions usr/share/qgis/grass/scripts
	dh_sip -ppython-qgis

override_dh_compress:
	dh_compress --exclude=pdf

override_dh_makeshlibs:
ifneq (,$(WITH_ORACLE))
	dh_makeshlibs -Xqgis-plugin-grass -Xlibqgis-customwidgets -Xqgis-provider-oracle -- -c0 -v$(QGIS_VERSION)
else
	dh_makeshlibs -Xqgis-plugin-grass -Xlibqgis-customwidgets -- -c0 -v$(QGIS_VERSION)
endif

override_dh_shlibdeps:
ifneq (,$(WITH_ORACLE))
	dh_shlibdeps -l/usr/lib/$(GRASS)/lib -l$(ORACLE_LIBDIR)
else
	dh_shlibdeps -l/usr/lib/$(GRASS)/lib
endif

override_dh_strip:
	dh_strip --dbg-package=qgis-dbg

back to top