/usr/share/haskell-devscripts/Dh_Haskell.sh is in haskell-devscripts-minimal 0.13.3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | run () {
echo -n "Running" >&2
printf " %q" "$@" >&2
echo >&2
"$@"
}
cpu(){
ghc -e 'putStr System.Info.arch'
}
os(){
ghc -e 'putStr System.Info.os'
}
ghcjs_version(){
ghcjs --numeric-ghcjs-version
}
ghcjs_ghc_version(){
ghcjs --numeric-ghc-version
}
package_prefix(){
echo $1 | sed -n -e 's|^\([^-]*\)-.*-[^-]*$|\1|p'
}
package_hc(){
case $1 in
ghc|ghc-prof) echo "ghc";;
*) echo $1 | sed -n -e 's|^lib\([^-]*\)-.*-[^-]*$|\1|p';;
esac
}
package_ext(){
case $1 in
# I'm told the ghc build uses these scripts, hence these special cases
ghc) echo "dev";;
ghc-prof) echo "prof";;
*) echo $1 | sed -n -e 's|^[^-]*-.*-\([^-]*\)$|\1|p';;
esac
}
packages_hc(){
hcs=`{ for i in ${DEB_PACKAGES}; do package_hc $i; done; } | LC_ALL=C sort -u`
if [ `echo ${hcs} | wc -w` = 0 ]; then hcs=${DEB_DEFAULT_COMPILER}; fi
if [ `echo ${hcs} | wc -w` != 1 ]; then echo "Multiple compilers not supported: ${hc}"; exit 1; fi
echo ${hcs}
}
hc_libdir(){
case $1 in
ghc) echo "usr/lib/haskell-packages/ghc/lib";;
ghcjs) echo "usr/lib/ghcjs/.cabal/lib";;
*) echo "Don't know package_libdir for $1" >&2; exit 1;;
esac
}
package_libdir(){
hc_libdir `package_hc $1`
}
hc_pkgdir(){
case $1 in
ghc) echo "var/lib/ghc/package.conf.d";;
ghcjs) echo "usr/lib/ghcjs/.ghcjs/`cpu`-`os`-`ghcjs_version`-`ghcjs_ghc_version`/ghcjs/package.conf.d";;
*) echo "Don't know pkgdir for $1" >&2; exit 1;;
esac
}
package_pkgdir(){
hc_pkgdir `package_hc $1`
}
hc_prefix(){
case $1 in
ghc) echo "usr";;
ghcjs) echo "usr/lib/ghcjs";;
*) echo "Don't know prefix for compiler $1" >&2; exit 1;;
esac
}
hc_haddock(){
case $1 in
ghc) echo "haddock";;
ghcjs) echo "haddock-ghcjs";;
*) echo "Don't know pkgdir for $1" >&2; exit 1;;
esac
}
hc_docdir(){
hc=$1
pkgid=$2
echo "usr/lib/${hc}-doc/haddock/${pkgid}/"
}
hc_htmldir(){
hc=$1
CABAL_PACKAGE=$2
echo "usr/share/doc/lib${hc}-${CABAL_PACKAGE}-doc/html/"
}
hc_hoogle(){
local hc
hc=$1
echo "/usr/lib/${hc}-doc/hoogle/"
}
strip_hash(){
echo "$1" | sed 's/-................................$//'
}
sort_uniq(){
{
for i in "$@" ; do
echo $i
done
} | LC_ALL=C sort -u | tr "\n" " "
}
dependency(){
local package
local version
local next_upstream_version
package=$1
version=`dpkg-query --showformat='${Version}' -W $package`
next_upstream_version=`echo $version | sed -e 's/-[^-]*$//' -e 's/$/+/'`
echo "$package (>= $version), $package (<< $next_upstream_version)"
}
ghc_pkg_field(){
hc=$1
pkg=$2
field=$3
${hc}-pkg --global field ${pkg} ${field} | head -n1
}
providing_package_for_ghc(){
local package
local dep
local dir
local dirs
local lib
local hc
local ghcversion=`dpkg-query --showformat '${Version}' --show ghc`
hc=$1
if dpkg --compare-versions "${ghcversion}" '>=' 8
then
dep=$2
else
dep=`strip-hash $2`
fi
dirs=`ghc_pkg_field $hc $dep library-dirs | grep -i ^library-dirs | cut -d':' -f 2`
lib=`ghc_pkg_field $hc $dep hs-libraries | grep -i ^hs-libraries | sed -e 's|hs-libraries: *\([^ ]*\).*|\1|' `
for dir in $dirs ; do
if [ -e "${dir}/lib${lib}.a" ] ; then
package=`dpkg-query -S ${dir}/lib${lib}.a | cut -d':' -f 1` || exit $?
continue
fi
done
echo $package
}
providing_package_for_ghc_prof(){
local package
local dep
local dir
local dirs
local lib
local hc
local ghcversion=`dpkg-query --showformat '${Version}' --show ghc`
hc=$1
if dpkg --compare-versions "${ghcversion}" '>=' 8
then
dep=$2
else
dep=`strip-hash $2`
fi
dirs=`ghc_pkg_field $hc $dep library-dirs | grep -i ^library-dirs | cut -d':' -f 2`
lib=`ghc_pkg_field $hc $dep hs-libraries | grep -i ^hs-libraries | sed -e 's|hs-libraries: *\([^ ]*\).*|\1|' `
for dir in $dirs ; do
if [ -e "${dir}/lib${lib}_p.a" ] ; then
package=`dpkg-query -S ${dir}/lib${lib}_p.a | cut -d':' -f 1` || exit $?
continue
fi
done
echo $package
}
cabal_package_ids(){
local config
local package_ids
until [ -z "$1" ]
do
config=$1
package_ids="$package_ids `grep-dctrl -n -i -s Id "" $config`"
shift
done
echo $package_ids
}
cabal_depends(){
local config
local dep
local depends
local final_depends
until [ -z "$1" ]
do
config=$1
depends="$depends `grep-dctrl -n -i -s Depends "" $config | tr "," " "`"
shift
done
for dep in `sort_uniq $depends` ; do
# The package is not mentioned in the ignored package list with the same version
# or mentioned without any version in the ignored package list?
if echo " $ignores " | grep -qv " $dep " &&
echo " $ignores " | grep -qv " `echo $dep | sed s%-[0-9][.0-9a-zA-Z]*$%%` " ;
then
final_depends="$final_depends $dep"
fi
done
echo $final_depends
}
hashed_dependency(){
local hc
local type
local pkgid
local virpkg
local ghcpkg
hc=$1
type=$2
pkgid=$3
ghcpkg="`usable_ghc_pkg`"
virtual_pkg=`package_id_to_virtual_package "${hc}" "$type" $pkgid "${ghcpkg}"`
# As a transition measure, check if dpkg knows about this virtual package
if dpkg-query -W $virtual_pkg >/dev/null 2>/dev/null;
then
echo $virtual_pkg
fi
}
depends_for_ghc(){
local dep
local packages
local pkgid
local hc
hc=$1
shift
for pkgid in `cabal_depends $@` ; do
dep=`hashed_dependency ${hc} dev $pkgid`
if [ -z "$dep" ]
then
pkg=`providing_package_for_ghc $hc $pkgid`
if [ -n "$pkg" ]
then
dep=`dependency $pkg`
packages="$packages, $dep"
else
echo "WARNING: No Debian package provides haskell package $pkgid." >&2
fi
else
packages="$packages, $dep"
fi
done
echo $packages | sed -e 's/^,[ ]*//'
}
depends_for_ghc_prof(){
local dep
local packages
local pkgid
local hc
hc=$1
shift
for pkgid in `cabal_depends $@` ; do
dep=`hashed_dependency ${hc} prof $pkgid`
if [ -z "$dep" ]
then
pkg=`providing_package_for_ghc_prof $hc $pkgid`
if [ -n "$pkg" ]
then
dep=`dependency $pkg`
packages="$packages, $dep"
else
echo "WARNING: No Debian package provides haskell package $pkgid." >&2
fi
else
packages="$packages, $dep"
fi
done
echo $packages | sed -e 's/^,[ ]*//'
}
usable_ghc_pkg() {
local ghcpkg
local version
if [ -x inplace/bin/ghc-pkg ]
then
# We are building ghc and need to use the new ghc-pkg
ghcpkg="inplace/bin/ghc-pkg"
version="`dpkg-parsechangelog -S Version`"
else
ghcpkg="ghc-pkg"
version="`dpkg-query --showformat '${Version}' --show ghc`"
fi
# ghc-pkg prior to version 8 is unusable for our purposes.
if dpkg --compare-versions "$version" '>=' 8
then
echo "${ghcpkg}"
fi
}
tmp_package_db() {
local ghcpkg
ghcpkg="`usable_ghc_pkg`"
if [ -n "${ghcpkg}" ]
then
if [ ! -f debian/tmp-db/package.cache ]
then
mkdir debian/tmp-db
cp $@ debian/tmp-db/
$ghcpkg --package-db debian/tmp-db/ recache
fi
echo "${ghcpkg} --package-db debian/tmp-db"
fi
}
provides_for_ghc(){
local hc
local dep
local packages
hc=$1
shift
ghcpkg="`tmp_package_db $@`"
for package_id in `cabal_package_ids $@` ; do
packages="$packages, `package_id_to_virtual_package "${hc}" dev $package_id "${ghcpkg}"`"
done
echo $packages | sed -e 's/^,[ ]*//'
}
provides_for_ghc_prof(){
local hc
local dep
local packages
hc=$1
shift
ghcpkg="`tmp_package_db $@`"
for package_id in `cabal_package_ids $@` ; do
packages="$packages, `package_id_to_virtual_package "${hc}" prof $package_id "${ghcpkg}"`"
done
echo $packages | sed -e 's/^,[ ]*//'
}
package_id_to_virtual_package(){
local hc
local type
local pkgid
local ghcpkg
hc="$1"
type="$2"
pkgid="$3"
ghcpkg="$4"
if [ -n "$ghcpkg" ]
then
name=`${ghcpkg} --simple-output field "${pkgid}" name`
version=`${ghcpkg} --simple-output field "${pkgid}" version`
abi=`${ghcpkg} --simple-output field "${pkgid}" abi | cut -c1-5`
echo "lib${hc}-${name}-${type}-${version}-${abi}" | tr A-Z a-z
else
# We don't have a usable ghc-pkg, so we fall back to parsing the package id.
echo ${pkgid} | tr A-Z a-z | \
grep '[a-z0-9]\+-[0-9\.]\+-................................' | \
perl -pe 's/([a-z0-9-]+)-([0-9\.]+)-(.....).........................../lib'${hc}'-\1-'$type'-\2-\3/'
fi
}
depends_for_hugs(){
local version
local upstream_version
version=`dpkg-query --showformat='${Version}' -W hugs`
upstream_version=`echo $version | sed -e 's/-[^-]*$//'`
echo "hugs (>= $upstream_version)"
}
find_config_for_ghc(){
local f
local pkg
pkg=$1
pkgdir=`package_pkgdir ${pkg}`
case "$pkg" in
ghc-prof)
pkg=ghc
;;
*-prof)
pkg=`echo $pkg | sed -e 's/-prof$/-dev/'`
;;
*)
;;
esac
for f in debian/$pkg/${pkgdir}/*.conf ; do
if [ -f "$f" ] ; then
echo $f
echo " "
fi
done
}
clean_recipe(){
# local PS5=$PS4; PS4=" + clean_recipe> "; set -x
[ ! -x "${DEB_SETUP_BIN_NAME}" ] || run ${DEB_SETUP_BIN_NAME} clean
run rm -rf dist dist-ghc dist-ghcjs dist-hugs ${DEB_SETUP_BIN_NAME} Setup.hi Setup.ho Setup.o .*config*
run rm -f configure-ghc-stamp configure-ghcjs-stamp build-ghc-stamp build-ghcjs-stamp build-hugs-stamp build-haddock-stamp
run rm -rf debian/tmp-inst-ghc debian/tmp-inst-ghcjs
run rm -f debian/extra-depends-ghc debian/extra-depends-ghcjs
if [ -f ${DEB_LINTIAN_OVERRIDES_FILE} ] ; then
run sed -i '/binary-or-shlib-defines-rpath/ d' ${DEB_LINTIAN_OVERRIDES_FILE}
run find ${DEB_LINTIAN_OVERRIDES_FILE} -empty -delete;
fi
run rm -f ${MAKEFILE}
run rm -rf debian/dh_haskell_shlibdeps
run rm -rf debian/tmp-db
# PS4=$PS5
}
make_setup_recipe(){
# local PS5=$PS4; PS4=" + make_setup_recipe> "; set -x
for setup in Setup.lhs Setup.hs
do
if test -e $setup
then
run ghc --make $setup -o ${DEB_SETUP_BIN_NAME}
exit 0
fi
done
# PS4=$PS5
}
configure_recipe(){
# local PS5=$PS4; PS4=" + configure_recipe> "; set -x
hc=`packages_hc`
ENABLE_PROFILING=`{ for i in ${DEB_PACKAGES}; do package_ext $i | grep prof; done; } | LC_ALL=C sort -u | sed 's/prof/--enable-library-profiling/'`
local GHC_OPTIONS
for i in `dpkg-buildflags --get LDFLAGS`
do
GHC_OPTIONS="$GHC_OPTIONS --ghc-option=-optl$i"
done
# DEB_SETUP_GHC_CONFIGURE_ARGS can contain multiple arguments with their own quoting,
# so run this through eval
eval run ${DEB_SETUP_BIN_NAME} \
configure "--${hc}" \
-v2 \
--package-db=/`hc_pkgdir ${hc}` \
--prefix=/`hc_prefix ${hc}` \
--libdir=/`hc_libdir ${hc}` \
--libexecdir=/usr/lib \
--builddir=dist-${hc} \
${GHC_OPTIONS} \
--haddockdir=/`hc_docdir ${hc} ${CABAL_PACKAGE}-${CABAL_VERSION}` \
--datasubdir=${CABAL_PACKAGE}\
--htmldir=/`hc_htmldir ${hc} ${CABAL_PACKAGE}` \
${ENABLE_PROFILING} \
${NO_GHCI_FLAG} \
${DEB_SETUP_GHC6_CONFIGURE_ARGS} \
${DEB_SETUP_GHC_CONFIGURE_ARGS} \
${OPTIMIZATION} \
${TESTS}
# PS4=$PS5
}
build_recipe(){
# local PS5=$PS4; PS4=" + build_recipe> "; set -x
hc=`packages_hc`
run ${DEB_SETUP_BIN_NAME} build --builddir=dist-${hc}
# PS4=$PS5
}
check_recipe(){
# local PS5=$PS4; PS4=" + check_recipe> "; set -x
hc=`packages_hc`
run ${DEB_SETUP_BIN_NAME} test --builddir=dist-${hc} --show-details=direct
# PS4=$PS5
}
haddock_recipe(){
# local PS5=$PS4; PS4=" + haddock_recipe> "; set -x
hc=`packages_hc`
haddock=`hc_haddock ${hc}`
if [ -x /usr/bin/${haddock} ] && \
! run ${DEB_SETUP_BIN_NAME} haddock --builddir=dist-${hc} --with-haddock=/usr/bin/${haddock} --with-ghc=${hc} --verbose=2 ${DEB_HADDOCK_OPTS} ; then
echo "Haddock failed (no modules?), refusing to create empty documentation package."
exit 1
fi
# PS4=$PS5
}
extra_depends_recipe(){
# local PS5=$PS4; PS4=" + extra_depends_recipe> "; set -x
hc=$1
pkg_config=`${DEB_SETUP_BIN_NAME} register --builddir=dist-${hc} --gen-pkg-config | tr -d ' \n' | sed -r 's,^.*:,,'`
run dh_haskell_extra_depends ${hc} $pkg_config
rm $pkg_config
# PS4=$PS5
}
install_dev_recipe(){
# local PS5=$PS4; PS4=" + install_dev_recipe> "; set -x
PKG=$1
hc=`package_hc ${PKG}`
libdir=`package_libdir ${PKG}`
pkgdir=`package_pkgdir ${PKG}`
( run cd debian/tmp-inst-${hc} ; run mkdir -p ${libdir} ; run find ${libdir}/ \
\( ! -name "*_p.a" ! -name "*.p_hi" ! -type d \) \
-exec install -Dm 644 '{}' ../${PKG}/'{}' ';' )
pkg_config=`${DEB_SETUP_BIN_NAME} register --builddir=dist-${hc} --gen-pkg-config | tr -d ' \n' | sed -r 's,^.*:,,'`
if [ "${HASKELL_HIDE_PACKAGES}" ]; then sed -i 's/^exposed: True$/exposed: False/' $pkg_config; fi
run install -Dm 644 $pkg_config debian/${PKG}/${pkgdir}/$pkg_config
run rm -f $pkg_config
if [ "z${DEB_GHC_EXTRA_PACKAGES}" != "z" ] ; then
EP_DIR=debian/${PKG}/usr/lib/haskell-packages/extra-packages
run mkdir -p $EP_DIR
echo "${DEB_GHC_EXTRA_PACKAGES}" > ${EP_DIR}/${CABAL_PACKAGE}-${CABAL_VERSION}
fi
grep -s binary-or-shlib-defines-rpath ${DEB_LINTIAN_OVERRIDES_FILE} \
|| echo binary-or-shlib-defines-rpath >> ${DEB_LINTIAN_OVERRIDES_FILE}
run dh_haskell_provides -p${PKG}
run dh_haskell_depends -p${PKG}
run dh_haskell_shlibdeps -p${PKG}
# PS4=$PS5
}
install_prof_recipe(){
# local PS5=$PS4; PS4=" + install_prof_recipe> "; set -x
PKG=$1
libdir=`package_libdir ${PKG}`
( run cd debian/tmp-inst-`package_hc ${PKG}`
run mkdir -p ${libdir}
run find ${libdir}/ \
! \( ! -name "*_p.a" ! -name "*.p_hi" \) \
-exec install -Dm 644 '{}' ../${PKG}/'{}' ';' )
run dh_haskell_provides -p${PKG}
run dh_haskell_depends -p${PKG}
# PS4=$PS5
}
install_doc_recipe(){
# local PS5=$PS4; PS4=" + install_doc_recipe> "; set -x
PKG=$1
hc=`package_hc ${PKG}`
pkgid=${CABAL_PACKAGE}-${CABAL_VERSION}
docdir=`hc_docdir ${hc} ${pkgid}`
htmldir=`hc_htmldir ${hc} ${CABAL_PACKAGE}`
hoogle=`hc_hoogle ${hc}`
run mkdir -p debian/${PKG}/${htmldir}
( run cd debian/tmp-inst-${hc}/ ;
run find ./${htmldir} \
! -name "*.haddock" ! -type d -exec install -Dm 644 '{}' \
../${PKG}/'{}' ';' )
run mkdir -p debian/${PKG}/${docdir}
[ 0 = `ls debian/tmp-inst-${hc}/${docdir}/ 2>/dev/null | wc -l` ] ||
run cp -r debian/tmp-inst-${hc}/${docdir}/*.haddock debian/${PKG}/${docdir}
if [ "${DEB_ENABLE_HOOGLE}" = "yes" ]
then
# We cannot just invoke dh_link here because that acts on
# either libghc-*-dev or all the binary packages, neither of
# which is desirable (see dh_link (1)). So we just create a
# (policy-compliant) symlink ourselves
source=`find debian/${PKG}/${htmldir} -name "*.txt"`
dest=debian/${PKG}${hoogle}${PKG}.txt
run mkdir -p `dirname $dest`
run ln -rs -T $source $dest
fi
run dh_haskell_depends -p${PKG}
# PS4=$PS5
}
if ! [ `which grep-dctrl` > /dev/null ] ; then
echo "grep-dctrl is missing" >&2
exit 1
fi
args=
ignores=
files=
until [ -z "$1" ]
do
case "$1" in
-X*)
pkg=${1##-X}
ignores="$ignores $pkg"
;;
--exclude=*)
pkg=${1##--exclude=}
ignores="$ignores $pkg"
;;
-*)
args="$args $1"
;;
*)
if [ -f $1 ] ; then
files="$files $1"
else
echo "Installed package description file $1 can not be found" >&2
exit 1
fi
;;
esac
shift
done
|