dev-lang/GHC: initial import

This commit is contained in:
Julian Ospald 2018-09-21 01:50:55 +08:00
parent 6fa0b20a53
commit 0d8361b925
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
2 changed files with 394 additions and 0 deletions

View File

@ -0,0 +1,176 @@
# Copyright 2008 Santiago M. Mola
# Copyright 2008, 2009, 2010, 2011 Ingmar Vanhassel
# Copyright 2011 Markus Rothe
# Distributed under the terms of the GNU General Public License v2
# Based in part upon 'ghc-6.8.2.ebuild' from Gentoo, which is:
# Copyright 1999-2008 Gentoo Foundation
# Copyright 2018 Julian Ospald <hasufell@posteo.de>
MY_PN="ghc"
MY_PNV="${MY_PN}-${PV}"
MY_PNVR="${MY_PN}-${PVR}"
require bash-completion flag-o-matic alternatives
require autotools [ supported_autoconf=[ 2.5 ] supported_automake=[ 1.15 ] ]
SUMMARY="The Glorious Glasgow Haskell Compilation System (non-haskell packages version)"
DESCRIPTION="
GHC is a state-of-the-art, open source, compiler and interactive environment for the functional
language Haskell.
"
HOMEPAGE="https://www.haskell.org/ghc/"
DOWNLOADS="
https://downloads.haskell.org/~ghc/${PV}/${MY_PNV}-src.tar.xz
https://downloads.haskell.org/~ghc/${PV}/${MY_PNV}-testsuite.tar.xz
https://downloads.haskell.org/~ghc/${PV}/ghc-${PV}-x86_64-fedora27-linux.tar.xz
"
PLATFORMS="-* ~amd64"
BUGS_TO=""
REMOTE_IDS="freecode:${MY_PN}"
UPSTREAM_RELEASE_NOTES="http://www.haskell.org/${MY_PN}/docs/${PV}/html/users_guide/release-${PV//./-}.html"
LICENCES="BSD-3"
SLOT="${PV}"
MYOPTIONS="
doc
llvm [[ description = [ Code generation using LLVM ] ]]
"
# `make test` takes really long, so disable it. It also succeeds (i.e. returned value is zero) in
# case of unexpected failures. There are always unexpected failures.
# If you really want to run the tests, then enable expensive tests in order to run `make fulltest`,
# which runs the same tests as `make test`, but includes more test cases per test.
RESTRICT="test"
DEPENDENCIES="
build:
dev-libs/libxslt[>=1.1.2]
dev-python/Sphinx
build+run:
dev-lang/perl:*[>=5.6.1]
dev-libs/gmp:=[>=5]
dev-libs/libedit
dev-libs/libffi
llvm? ( dev-lang/llvm[>=2.7] )
!dev-lang/ghc [[ resolution = uninstall-blocked-before ]]
!dev-lang/ghc-bin [[ resolution = uninstall-blocked-before ]]
"
WORK=${WORKBASE}/${MY_PNV}
src_unpack() {
unpack ghc-${PV}-x86_64-fedora27-linux.tar.xz
edo mv "${WORK}" "${WORK}-pre"
unpack ${MY_PNV}-src.tar.xz
unpack ${MY_PNV}-testsuite.tar.xz
}
src_prepare() {
# prepare pre-built ghc
edo pushd "${WORK}-pre"
edo ./configure \
--prefix="${TEMP}/ghc-pre" \
--target=$(exhost --target)
emake install
edo popd
autotools_src_prepare
}
src_configure() {
# Initialize build.mk
echo '# Exherbo changes' > mk/build.mk
cat <<EOF >> mk/build.mk
# Put docs into the right place
docdir = /usr/share/doc/${MY_PNVR}
htmldir = /usr/share/doc/${MY_PNVR}/html
EOF
if option doc; then
echo "BUILD_SPHINX_HTML=YES" >> mk/build.mk
echo "BUILD_SPHINX_PDF=NO" >> mk/build.mk
echo "HADDOCK_DOCS=YES" >> mk/build.mk
else
echo "BUILD_SPHINX_HTML=NO" >> mk/build.mk
echo "BUILD_SPHINX_PDF=NO" >> mk/build.mk
echo "HADDOCK_DOCS=NO" >> mk/build.mk
fi
GHC_SRC_CONFIGURE_OPTIONS+=( --with-ghc=${TEMP}/ghc-pre/bin/ghc )
export PATH="${WORKBASE}/usr/bin:${PATH}"
if option llvm; then
echo "GhcWithLlvmCodeGen=YES" >> mk/build.mk
else
echo "GhcWithLlvmCodeGen=NO" >> mk/build.mk
fi
GHC_SRC_CONFIGURE_OPTIONS+=(
--with-system-libffi
--with-ffi-includes=$(${PKG_CONFIG} --variable includedir libffi)
)
# host and build cause compilation (at least for 7.6.1) to fail, as they're intended for
# cross-compilation.
econf \
AR=${AR} \
CC=${CC} \
--target=$(exhost --target) \
"${GHC_SRC_CONFIGURE_OPTIONS[@]}"
# don't strip anything. Very useful when stage2 SIGSEGVs on you
echo "STRIP_CMD = :" >> mk/build.mk
}
src_install() {
default
# libraries/ is a partial dupe of the html/ dir hierarchy, but
# containing only LICENSE files
edo rm -rf "${IMAGE}"/usr/share/doc/${MY_PNVR}/{LICENSE,libraries}
dobashcompletion "${FILES}/ghc-bash-completion"
alternatives_for ghc ${SLOT} ${SLOT} \
/usr/share/bash-completion/completions/ghc-bin{,-${SLOT}}
# some scripts are not versioned, move
edo mv "${IMAGE}"/usr/$(exhost --target)/bin/{hp2ps,hp2ps-${SLOT}}
edo mv "${IMAGE}"/usr/$(exhost --target)/bin/{hpc,hpc-${SLOT}}
edo mv "${IMAGE}"/usr/$(exhost --target)/bin/{hsc2hs,hsc2hs-${SLOT}}
# remove unversioned symlinks, we create alternatives later
local ghc_bin
for ghc_bin in ghc ghci ghc-pkg $(optionq doc && echo "haddock") runghc runhaskell ; do
edo rm "${IMAGE}"/usr/$(exhost --target)/bin/${ghc_bin}
done
unset ghc_bin
# create alternatives for scripts/binaries
alternatives_for ghc ${SLOT} ${SLOT} \
/usr/$(exhost --target)/bin/ghc{,-${SLOT}} \
/usr/$(exhost --target)/bin/ghci{,-${SLOT}} \
/usr/$(exhost --target)/bin/ghc-pkg{,-${SLOT}} \
$(optionq doc && echo "/usr/$(exhost --target)/bin/haddock{,-ghc-${SLOT}}") \
/usr/$(exhost --target)/bin/hp2ps{,-${SLOT}} \
/usr/$(exhost --target)/bin/hpc{,-${SLOT}} \
/usr/$(exhost --target)/bin/hsc2hs{,-${SLOT}} \
/usr/$(exhost --target)/bin/runghc{,-${SLOT}} \
/usr/$(exhost --target)/bin/runhaskell /usr/$(exhost --target)/bin/runghc-${SLOT}
# alternatives for manpages
local file alternatives=()
for file in "${IMAGE}"/usr/share/man/*/*; do
alternatives+=(
${file#${IMAGE}}
${file#${IMAGE}}-${SLOT}
)
done
}
src_test_expensive() {
emake fulltest
}

View File

@ -0,0 +1,218 @@
# ghc-pkg command line completion for bash
#
# Copyright 2006-2007 Lennart Kolmodin <kolmodin@dtek.chalmers.se>
_ghc-pkg-get-ghc-pkg()
{
echo ghc-pkg
}
_ghc-pkg-pkg-fields()
{
# usage: _ghc-pkg-pkg-fields pkg-id
#
# list all fields of the pkg-id
# same fields for all packages but different in different versions of
# ghc-pkg? this can probably be done better/faster
if [[ -z "$1" ]]; then
echo "usage: _ghc-pkg-pkg-fields pkg-id"
return 1
fi
local fields
fields="$( $(_ghc-pkg-get-ghc-pkg) describe $1 )"
#if [[ fields != *"cannot find package"* ]]; then
echo "$fields" | grep ".*:.*" | sed "s/^\(.*\):.*\$/\1/"
#fi
}
_ghc-pkg-pkg-ids()
{
# usage: _ghc-pkg-pkg-ids
#
# simply lists all package ids known by ghc-pkg.
$(_ghc-pkg-get-ghc-pkg) list --simple-output
}
_ghc-pkg-pkgs()
{
# usage: _ghc-pkg-pkgs [include-pkgs] [include-ids]
#
# with optional parameter include-pkgs it will list all packages known
# to ghc-pkg.
# with optional parameter include-ids it will list all package-ids known
# to ghc-pkg.
local pkgs
local result
pkgs=( $( _ghc-pkg-pkg-ids ) )
result=( )
local withPkgs="no" withIds="no"
while [[ -n "$1" ]]; do
case "$1" in
include-pkgs)
withPkgs="yes" ;;
include-ids)
withIds="yes" ;;
*)
echo "unknown parameter '$1' to _ghc-pkg-pkgs"
return 1 ;;
esac
shift
done
# user must supply either include-pkgs, include-ids or both
if [[ $withPkgs != "yes" && $withIds != "yes" ]]; then
echo "usage: _ghc-pkg-pkgs [include-pkgs] [include-ids]"
return 1
fi
# find all packages if the user requested them
if [[ $withPkgs == "yes" ]]; then
# O(n^2) algorithm to exclude duplicates
for p in ${pkgs[*]}; do
p="${p//-[0-9.]*/}"
for existing in ${result[*]}; do
if [[ "$existing" == "$p" ]]; then
continue 2
fi
done
result=( "${result[@]}" "${p}" )
done
fi
# include all pkg-ids if requested
if [[ $withIds == "yes" ]]; then
result=( "${result[@]}" "${pkgs[@]}" )
fi
# we are finished, echo the result
echo "${result[*]}"
# happy ending
return 0
}
_ghc-pkg()
{
local cur
cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=()
local actions flags
actions='register update unregister expose hide list latest describe field'
dbflags="--user \
--global \
-f --package-conf= \
--global-conf="
registerflags="--force \
-g --auto-ghci-libs \
-D --define-name="
listflags="--simple-output"
flags="$dbflags \
$registerflags \
$listflags \
-? --help \
-V --version"
# if it's the users first word; complete it and return
if (($COMP_CWORD == 1)); then
COMPREPLY=( $( compgen -W "$actions $flags" -- $cur ) )
return 0
fi
# now we know we have at least one word written
local action="unknown" \
prev numwords \
cword act
prev=${COMP_WORDS[COMP_CWORD-1]}
numwords=${#COMP_WORDS[@]}
# find the action with O(n*m) algorithm
# where n = ${#COMP_WORDS[*]}
# m = number of actions
for cword in ${COMP_WORDS[*]}; do
for act in $actions; do
if [[ "$cword" == "$act" ]]; then
action=$cword
fi
done
done
case $action in
register|update)
# we want to complete both flags and paths, how?
# we do it by checking if the user has started to write a flag
# or a path, and then decide what to complete.
# that is, to complete a flag, the user must start to write a '-'
if [[ "$cur" == -* ]]; then
# (we assume) it's the start of a flag
# set COMPREPLY to flags relevant to these actions
COMPREPLY=( $( compgen -W "$dbflags $registerflags" -- $cur ) )
fi
;;
unregister|expose|hide|list|describe)
# all these actions can be completed with exactly one argument,
# a pkg-id.
COMPREPLY=( $( compgen -W "$dbflags" -- $cur ) )
# add special flags for some actions
if [[ "$action" == "list" ]]; then
COMPREPLY+=( $( compgen -W "$listflags" -- $cur ) )
fi
COMPREPLY+=( $( compgen -W "$( _ghc-pkg-pkgs include-ids )" -- $cur ) )
;;
latest)
# complete only packages, not package ids
COMPREPLY=( $( compgen -W "$( _ghc-pkg-pkgs include-pkgs )" -- $cur ) )
;;
field)
# we should always complete on the flags...
COMPREPLY=( $( compgen -W "$dbflags" -- $cur ) )
# then, we should either complete the package name or the field
# lets find out which one
# find the number of words in COMP_WORDS before COMP_CWORD that
# isn't flags. it should be 2 or 3 for us to complete it,
# exactly 2 if we should complete the package name
# exactly 3 if we should complete the field name
# otherwise, don't do any additional completion except the
# flags
# count the number of non flags up till the current word
local numnonflags=0 lastword i
for (( i=0 ; $i < $COMP_CWORD ; i++ )); do
if [[ ${COMP_WORDS[$i]} != -* ]]; then
lastword=${COMP_WORDS[$i]}
numnonflags=$(( ++numnonflags ))
fi
done
case $numnonflags in
2)
# complete on pkg-ids
COMPREPLY+=( $( compgen -W "$( _ghc-pkg-pkgs include-ids )" -- $cur ) ) ;;
3)
# complete on fields
COMPREPLY+=( $( compgen -W "$( _ghc-pkg-pkg-fields $lastword )" -- $cur ) ) ;;
esac
;;
*)
# unknown action, not yet given by the user
# return all possible completions
COMPREPLY=( $( compgen -W "$actions $flags" -- $cur ) )
;;
esac
}
complete -F _ghc-pkg -o default ghc-pkg
# vim: set ft=sh tw=80 sw=4 et :