# -*- mode: makefile -*- # Copyright 2008 Kari Pahula # Description: A class for Haskell library packages # # 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 2, 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, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # 02111-1307 USA. HC ?= ghc ifeq ($(HC),ghcjs) CPU ?= $(shell ghc -e 'putStr System.Info.arch') OS ?= $(shell ghc -e 'putStr System.Info.os') GHCJS_VERSION ?= $(shell ghcjs --numeric-ghcjs-version) GHC_VERSION ?= $(shell ghcjs --numeric-ghc-version) PREFIX ?= usr/lib/ghcjs LIBDIR ?= $(PREFIX)/.cabal/lib PKGDIR ?= $(PREFIX)/.ghcjs/$(CPU)-$(OS)-$(GHCJS_VERSION)-$(GHC_VERSION)/ghcjs/package.conf.d HADDOCK ?= haddock-ghcjs else PREFIX ?= usr LIBDIR ?= $(PREFIX)/lib/haskell-packages/ghc/lib PKGDIR ?= var/lib/ghc/package.conf.d HADDOCK ?= haddock endif export GREP_OPTIONS := # Set a dummy HOME variable upon build. Some build daemons do not set HOME, but # cabal expects it to be available. export HOME = /homedoesnotexistatbuildtime DEB_CABAL_PACKAGE ?= $(shell cat *.cabal |\ perl -ne \ 'if (/^name\s*:\s*(.*?)\s*$$/i) {$$_ = $$1; tr/A-Z/a-z/; print; exit 0;}') CABAL_PACKAGE=$(DEB_CABAL_PACKAGE) CABAL_VERSION=$(shell cat *.cabal | egrep -i '^\s*version:' | head -n1 | sed -r 's,^\s*version:\s*,,i'| sed -r 's,\s*$$,,i') DEB_ENABLE_TESTS ?= no DEB_ENABLE_HOOGLE ?= yes DEB_DH_GENCONTROL_ARGS_lib$(HC)-$(CABAL_PACKAGE)-dev += -- '-DGHC-Package=$${haskell:ghc-package}' ifneq (,$(filter lib$(HC)-$(CABAL_PACKAGE)-prof,$(DEB_PACKAGES))) ENABLE_PROFILING = --enable-library-profiling endif NO_GHCI_FLAG = $(shell test -e /usr/bin/ghci || echo --ghc-option=-DDEBIAN_NO_GHCI; exit 0) DEB_COMPRESS_EXCLUDE += .haddock .hs .txt # We do not want to take dependency information # from libHS*.so files, because # * dh_haskell_shlibs takes care of that and # * it would introduced unwanted dependencies on libgmp # If the latter can be avoided, this could be changed to # DEB_DH_SHLIBDEPS_ARGS_ALL += -- --ignore-missing-info # (because we do not (yet) have shlibs files for libHS libraries) DEB_DH_SHLIBDEPS_ARGS_ALL += -XlibHS # TODO: # - some of this would probably be useful for generic Haskell programs, # not just libraries # - provide more hooks # - get this included in the cdbs package once this gets mature enough (maybe?) DEB_SETUP_BIN_NAME ?= debian/hlibrary.setup DEB_HADDOCK_HTML_DIR ?= /usr/share/doc/lib$(HC)-$(CABAL_PACKAGE)-doc/html/ # most likely you don't need to touch this one GHC6_VERSION = $(shell ghc --numeric-version) GHC_VERSION = $(shell ghc --numeric-version) DEB_HADDOCK_DIR ?= /usr/lib/${HC}-doc/haddock/$(CABAL_PACKAGE)-$(CABAL_VERSION)/ DEB_HADDOCK_OPTS += --html --hoogle ifndef DEB_NO_IMPLICIT_HADDOCK_HYPERLINK DEB_HADDOCK_OPTS += --hyperlink-source endif DEB_HOOGLE_TXT_DIR = /usr/lib/ghc-doc/hoogle/ MAKEFILE := debian/hlibrary.Makefile #ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS))) # NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS))) # MAKEFLAGS := -j$(NUMJOBS) # BUILD_GHC := $(DEB_SETUP_BIN_NAME) makefile -f $(MAKEFILE) && $(MAKE) $(MAKEFLAGS) -f $(MAKEFILE) && $(BUILD_GHC) #endif ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) OPTIMIZATION = --disable-optimization endif ifeq ($(DEB_ENABLE_TESTS),yes) ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) TESTS = --enable-tests endif endif DEB_BUILD_DEPENDENCIES = build-arch clean:: [ ! -x "$(DEB_SETUP_BIN_NAME)" ] || $(DEB_SETUP_BIN_NAME) clean rm -rf dist dist-$(HC) dist-hugs $(DEB_SETUP_BIN_NAME) Setup.hi Setup.ho Setup.o .*config* rm -f configure-$(HC)-stamp build-$(HC)-stamp build-hugs-stamp build-haddock-stamp rm -rf debian/tmp-inst-$(HC) rm -f debian/extra-depends rm -f debian/lib$(HC)-$(CABAL_PACKAGE)-doc.links rm -f $(MAKEFILE) rm -rf debian/dh_haskell_shlibdeps $(DEB_SETUP_BIN_NAME): if test ! -e Setup.lhs -a ! -e Setup.hs; then echo "No setup script found!"; exit 1; fi for setup in Setup.lhs Setup.hs; do if test -e $$setup; then ghc --make $$setup -o $(DEB_SETUP_BIN_NAME); exit 0; fi; done configure-$(HC)-stamp: $(DEB_SETUP_BIN_NAME) $(DEB_SETUP_BIN_NAME) configure --$(HC) -v2 --package-db=/$(PKGDIR) \ --prefix=/$(PREFIX) --libdir=/$(LIBDIR) \ --builddir=dist-$(HC) \ --haddockdir=$(DEB_HADDOCK_DIR) --datasubdir=$(CABAL_PACKAGE)\ --htmldir=$(DEB_HADDOCK_HTML_DIR) $(ENABLE_PROFILING) $(NO_GHCI_FLAG) \ $(DEB_SETUP_GHC6_CONFIGURE_ARGS) $(DEB_SETUP_GHC_CONFIGURE_ARGS) $(OPTIMIZATION) $(TESTS) touch $@ build-$(HC)-stamp: configure-$(HC)-stamp $(DEB_SETUP_BIN_NAME) build --builddir=dist-$(HC) touch $@ ifeq ($(DEB_ENABLE_TESTS),yes) ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) check-$(HC)-stamp: build-$(HC)-stamp $(DEB_SETUP_BIN_NAME) test --builddir=dist-$(HC) --show-details=always touch $@ else check-$(HC)-stamp: build-$(HC)-stamp @echo DEB_BUILD_OPTIONS contains nocheck, not running checks touch $@ endif else check-$(HC)-stamp: build-$(HC)-stamp @echo DEB_ENABLE_TESTS not set to yes, not running any tests. touch $@ endif build/lib$(HC)-$(CABAL_PACKAGE)-prof build/lib$(HC)-$(CABAL_PACKAGE)-dev:: build-$(HC)-stamp check-$(HC)-stamp build-haddock-stamp: [ ! -x /usr/bin/$(HADDOCK) ] || $(DEB_SETUP_BIN_NAME) haddock --builddir=dist-$(HC) $(DEB_HADDOCK_OPTS) || \ echo "Haddock failed (no modules?), creating empty documentation package." touch build-haddock-stamp build/haskell-$(CABAL_PACKAGE)-doc build/lib$(HC)-$(CABAL_PACKAGE)-doc:: configure-$(HC)-stamp build-haddock-stamp dist-hugs: $(DEB_SETUP_BIN_NAME) $(DEB_SETUP_BIN_NAME) configure --hugs --prefix=/usr -v2 --builddir=dist-hugs $(DEB_SETUP_HUGS_CONFIGURE_ARGS) build/libhugs-$(CABAL_PACKAGE):: dist-hugs $(DEB_SETUP_BIN_NAME) build --builddir=dist-hugs debian/tmp-inst-$(HC): $(DEB_SETUP_BIN_NAME) build-$(HC)-stamp $(DEB_SETUP_BIN_NAME) copy --builddir=dist-$(HC) --destdir=debian/tmp-inst-$(HC) debian/extra-depends: debian/tmp-inst-$(HC) pkg_config=`$(DEB_SETUP_BIN_NAME) register --builddir=dist-$(HC) --gen-pkg-config | tr -d ' \n' | sed -r 's,^.*:,,'` ; \ HC=$(HC) dh_haskell_extra_depends $$pkg_config ; \ rm $$pkg_config install/lib$(HC)-$(CABAL_PACKAGE)-dev:: debian/tmp-inst-$(HC) debian/extra-depends cd debian/tmp-inst-$(HC) ; mkdir -p $(LIBDIR); find $(LIBDIR)/ \ \( ! -name "*_p.a" ! -name "*.p_hi" \) \ -exec install -Dm 644 '{}' ../$(notdir $@)/'{}' ';' pkg_config=`$(DEB_SETUP_BIN_NAME) register --builddir=dist-$(HC) --gen-pkg-config | tr -d ' \n' | sed -r 's,^.*:,,'`; \ $(if $(HASKELL_HIDE_PACKAGES),sed -i 's/^exposed: True$$/exposed: False/' $$pkg_config;) \ install -Dm 644 $$pkg_config debian/$(notdir $@)/$(PKGDIR)/$$pkg_config; \ rm -f $$pkg_config if [ 'z$(DEB_GHC_EXTRA_PACKAGES)' != 'z' ] ; then \ echo '$(DEB_GHC_EXTRA_PACKAGES)' > debian/$(notdir $@)/$(LIBDIR)/$(CABAL_PACKAGE)-$(CABAL_VERSION)/extra-packages ; \ fi HC=$(HC) dh_haskell_provides -p$(notdir $@) HC=$(HC) dh_haskell_depends -p$(notdir $@) HC=$(HC) dh_haskell_shlibdeps -p$(notdir $@) install/lib$(HC)-$(CABAL_PACKAGE)-prof:: debian/tmp-inst-$(HC) install/lib$(HC)-$(CABAL_PACKAGE)-dev debian/extra-depends cd debian/tmp-inst-$(HC) ; mkdir -p $(LIBDIR) ; find $(LIBDIR)/ \ ! \( ! -name "*_p.a" ! -name "*.p_hi" \) \ -exec install -Dm 644 '{}' ../$(notdir $@)/'{}' ';' HC=$(HC) dh_haskell_provides -p$(notdir $@) HC=$(HC) dh_haskell_depends -p$(notdir $@) install/haskell-$(CABAL_PACKAGE)-doc install/lib$(HC)-$(CABAL_PACKAGE)-doc:: debian/tmp-inst-$(HC) build-haddock-stamp debian/extra-depends mkdir -p debian/$(notdir $@)/$(DEB_HADDOCK_HTML_DIR) cd debian/tmp-inst-$(HC)/ ; find ./$(DEB_HADDOCK_HTML_DIR)/ \ ! -name "*.haddock" -exec install -Dm 644 '{}' \ ../$(notdir $@)/'{}' ';' mkdir -p debian/$(notdir $@)/$(DEB_HADDOCK_DIR) [ 0 = `ls debian/tmp-inst-$(HC)/$(DEB_HADDOCK_DIR)/ 2>/dev/null | wc -l` ] || \ cp -r debian/tmp-inst-$(HC)/$(DEB_HADDOCK_DIR)/*.haddock \ debian/$(notdir $@)/$(DEB_HADDOCK_DIR) ifeq ($(DEB_ENABLE_HOOGLE),yes) find debian/$(notdir $@)/$(DEB_HADDOCK_HTML_DIR) -name "*.txt" \ -printf "%p $(DEB_HOOGLE_TXT_DIR)/$(notdir $@).txt\n" >> debian/lib$(HC)-$(CABAL_PACKAGE)-doc.links sed -i s,^debian/lib$(HC)-$(CABAL_PACKAGE)-doc,, debian/lib$(HC)-$(CABAL_PACKAGE)-doc.links endif HC=$(HC) dh_haskell_depends -p$(notdir $@) install/libhugs-$(CABAL_PACKAGE):: $(DEB_SETUP_BIN_NAME) dist-hugs debian/extra-depends $(DEB_SETUP_BIN_NAME) copy --destdir=debian/libhugs-$(CABAL_PACKAGE) --builddir=dist-hugs rm -rf debian/libhugs-$(CABAL_PACKAGE)/usr/share/doc/* HC=$(HC) dh_haskell_depends -p$(notdir $@) # Run dh_haskell_blurbs on all packags, useful e.g. for binary packages $(patsubst %,install/%,$(DEB_PACKAGES)) :: install/%: HC=$(HC) dh_haskell_blurbs -p$(cdbs_curpkg) # Support for installing executables define newline endef $(patsubst debian/%.haskell-binaries,build/%,$(wildcard debian/*.haskell-binaries)):: build-$(HC)-stamp $(patsubst debian/%.haskell-binaries,install/%,$(wildcard debian/*.haskell-binaries)):: debian/tmp-inst-$(HC) $(foreach binary,$(shell cat debian/$(cdbs_curpkg).haskell-binaries),dh_install -p$(cdbs_curpkg) dist-$(HC)/build/$(binary)/$(binary) usr/bin $(newline))