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

include /usr/share/cdbs/1/rules/debhelper.mk
-include /usr/share/cdbs/1/class/hlibrary.mk

# helper macros for GHC dependencies
# example use: foo bar,dev,prof doc,>=,1.2,<<,1.3 baz
expand-or-strip-ghc-dep = $(foreach expandsuffix,$1,\
 $(comma) libghc-$3-$(expandsuffix) $(if $4,($4 $5))\
 $(if $6,\
  $(comma) libghc-$3-$(expandsuffix) ($6 $7)))\
 $(foreach stripsuffix,$2,\
  $(comma) libghc-$3-$(stripsuffix))
expand-ghc-deps = $(foreach dep,$(sort $3),$(call expand-or-strip-ghc-dep,\
 $1,\
 $2,$(strip \
 $(word 1,$(subst $(comma),$(space),$(dep)))),$(strip \
 $(word 2,$(subst $(comma),$(space),$(dep)))),$(strip \
 $(word 3,$(subst $(comma),$(space),$(dep)))),$(strip \
 $(word 4,$(subst $(comma),$(space),$(dep)))),$(strip \
 $(word 5,$(subst $(comma),$(space),$(dep))))))

# Needed by upstream build
ghc-deps += text,<<,1.3
ghc-deps += hashable,<<,1.3
ghc-deps += unordered-containers,<<,0.3
bdeps = ghc, ghc-prof
bdeps +=, $(call expand-ghc-deps,dev,prof,$(ghc-deps))

# Needed by upstream documentation build
bdeps-indep = ghc-doc
bdeps-indep +=, $(call expand-ghc-deps,,doc,$(ghc-deps))

# Needed for our packaging
bdeps +=, haskell-devscripts

# TODO: actually use CDBS_BUILD_DEPENDS_INDEP, instead of hardcoding
CDBS_BUILD_DEPENDS +=, $(bdeps)
CDBS_BUILD_DEPENDS_INDEP +=, $(bdeps-indep)

DEB_INSTALL_EXAMPLES_libghc-intern-dev = examples/*
