#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2012-2013, 2015-2016 Jonas Smedegaard <dr@jones.dk>
# Description: Main Debian packaging script for FaCT++
#
# 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, 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/>.

# DEB_BUILDDIR unused but required by CDBS sanity check
DEB_BUILDDIR = build
DEB_MAKE_FLAVORS = lisp kernel

include /usr/share/cdbs/1/rules/utils.mk
include /usr/share/cdbs/1/class/makefile.mk
include /usr/share/cdbs/1/rules/debhelper.mk

pkg = $(DEB_SOURCE_PACKAGE)

# Build-depend unversioned on debhelper
#  TODO: Drop when adopted in cdbs
CDBS_BUILD_DEPENDS_rules_debhelper_v9 = debhelper

# subdirs contain chars unusable as flavor labels so are added manually
DEB_MAKE_BUILDDIRSKEL = $(cdbs_curbuilddir)

CDBS_BUILD_DEPENDS += , cloog-ppl
DEB_BUILDDIR_kernel = Kernel

DEB_BUILDDIR_lisp = FaCT++
ifneq (,$(filter lisp,$(DEB_MAKE_FLAVORS)))
binaries += FaCT++/obj/FaCT++
endif
debian/stamp-makefile-build/lisp: debian/stamp-makefile-build/kernel

DEB_BUILDDIR_jni = FaCT++.JNI
ifneq (,$(filter jni,$(DEB_MAKE_FLAVORS)))
include /usr/share/javahelper/java-vars.mk
export JAVA_HOME
CDBS_BUILD_DEPENDS += , default-jdk
DEB_INSTALL_EXAMPLES_$(pkg) += FaCT++.JNI/obj/libFaCTPlusPlusJNI.so
endif
debian/stamp-makefile-build/jni: debian/stamp-makefile-build/kernel

# Anything POSIX is "LINUX" to upstream build logic, apparently
DEB_MAKE_EXTRA_ARGS += OS=LINUX

# Include CPPFLAGS - e.g. for security hardening
DEB_MAKE_EXTRA_ARGS += DEFINES="$(CPPFLAGS)"

# Support non-optimized builds
ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
DEB_MAKE_EXTRA_ARGS += GENERAL_DEFINES=
endif

# TODO: make testsuite work
#PATH=$PWD/FaCT++:$PATH make -C Models.lisp/DataTypeTest

DEB_DH_INSTALL_ARGS_$(pkg) = $(binaries) $(if $(binaries), usr/bin)
