#!/usr/bin/make -f

# Ubuntu/Debian build rules file for OOlite

# Copyright (c) 2007-2009 Chris Crowther <hikari@hikari.org.uk>
# Copyright (c) 2009      Darren Salt <linux@youmustbejoking.demon.co.uk>
# Copyright (c) 2009      Michael Werle <micha@michaelwerle.com>
# Copyright (c) 2010-2012 Nicolas Boulenguez <nicolas.boulenguez@free.fr>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

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

%:
	dh $@

GSMAKE := gs_make
GSMAKE += messages=yes # Display compilation flags to log checkers.

# Usually, "debug=yes strip=no" would be enough, but upstream uses
# "debug" to toggle mozjs features absent from the packaged
# libmozjs185-dev. So we failback to an Ugly Work-Around.
ifneq (,$(filter nostrip,$(DEB_BUILD_OPTIONS)))
  GSMAKE += STRIP=true
endif

# Oolite configuration. Non-default settings may require libpng12-dev
# libffi-dev, or even libmozjs recompilation.
GSMAKE += ESPEAK=no # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=591717
GSMAKE += OO_JAVASCRIPT_TRACE=no # Forced by libmozjs185 settings
GSMAKE += DEPLOYMENT_RELEASE_CONFIGURATION=yes

# Use Debian default build options.
include /usr/share/dpkg/buildflags.mk
GSMAKE += CFLAGS="$(CFLAGS)"
GSMAKE += CPPFLAGS="$(CPPFLAGS)"
GSMAKE += LDFLAGS="-Wl,--as-needed $(LDFLAGS)"
GSMAKE += OBJCFLAGS="$(CFLAGS)"

# Ignore GNUSTEP optimization setting, noopt is handled by CFLAGS.
GSMAKE += OPTFLAG=""

# Use all processors unless parallel is set in DEB_BUILD_OPTIONS.
# http://www.debian.org/doc/debian-policy/ch-source.html#s-debianrules-options
NUMJOBS := $(filter parallel=%,$(DEB_BUILD_OPTIONS))
ifneq (,$(NUMJOBS))
  GSMAKE += --jobs=$(subst parallel=,,$(NUMJOBS))
else
  GSMAKE += --jobs=$(shell getconf _NPROCESSORS_ONLN)
endif

override_dh_auto_build:
	$(GSMAKE)

override_dh_auto_clean:
	$(GSMAKE) distclean clean
	rm -rf oolite.app

override_dh_installchangelogs:
	dh_installchangelogs --all Doc/CHANGELOG.TXT
