2c0b10d
# RPM Macros for packaging Haskell cabalized packages  -*-rpm-spec-*-
73b0bd1
# see https://fedoraproject.org/wiki/Packaging:Haskell for more details
1f4312a
a0e7ada
# "cabal"
237337a
%cabal [ -x Setup ] || ghc --make %{!?ghc_user_conf:-no-user-package-db} %{!?ghc_without_dynamic:-dynamic} Setup\
c5902ba
LANG=en_US.utf8\
a1abcaa
./Setup
Yaakov Meir Nemoy b640c1a
5517c1f
# compiler version
5517c1f
%ghc_version %{!?ghc_version_override:%(ghc --numeric-version)}%{?ghc_version_override}
5517c1f
ed9a00f
# check ghc version was rebuilt against self
ed9a00f
%ghc_check_bootstrap\
78a6eab
if [ ! "$(ghc --info | grep \\"Booter\\ version\\",\\"%{ghc_version}\\")" ]; then\
e6a0b6c
  echo "Warning: this ghc build is not self-bootstrapped."\
e6a0b6c
%if %{undefined ghc_bootstrapping}\
e6a0b6c
  echo "The ghc package should be rebuilt against its current version before\
e6a0b6c
proceeding, to avoid dependency ABI breakage from a future ghc rebuild."\
5d0da9c
  echo "To override set ghc_bootstrapping."\
ed9a00f
  echo "Aborting."\
cd30bb3
  exit 1\
cd30bb3
%endif\
ed9a00f
fi
ed9a00f
ed9a00f
# configure
ed9a00f
%cabal_configure\
ed9a00f
%ghc_check_bootstrap\
c2213a0
%global _hardened_ldflags %{nil}\
9c211a6
# -Wunused-label is extremely noisy: remove for ghc-8.0\
df54044
%ifnarch aarch64 ppc64 ppc64le\
83e7a4f
CFLAGS="${CFLAGS:-%optflags}"; export CFLAGS\
46a6bfd
%endif\
55f359c
LDFLAGS="${LDFLAGS:-%{?__global_ldflags}}"; export LDFLAGS\
5517c1f
%cabal configure --prefix=%{_prefix} --libdir=%{_libdir} --docdir=%{_ghcdocdir} --libsubdir='$compiler/$pkgkey' --datasubdir='$pkgid' --ghc %{!?ghc_without_dynamic:--enable-executable-dynamic} %{?with_tests:--enable-tests} --ghc-options="${CFLAGS:+$(echo ' '$CFLAGS | sed -e 's/ / -optc/g')} ${LDFLAGS:+$(echo ' '$LDFLAGS | sed -e 's/ / -optl/g')}" %{?cabal_configure_options} $cabal_configure_extra_options
dffc2c5
a0e7ada
# install
5517c1f
%cabal_install %cabal copy --destdir=%{buildroot} %{?cabal_install_options}
Yaakov Meir Nemoy b640c1a
d609014
# tests
efcc8cc
%cabal_test\
efcc8cc
%if %{with tests}\
5517c1f
%cabal test %{?cabal_test_options}\
efcc8cc
%endif
efcc8cc
cfbdfc6
# no _pkgdocdir in EPEL <= 7
cfbdfc6
%ghc_pkgdocdir %{?_pkgdocdir}%{!?_pkgdocdir:%{_docdir}/%{name}-%{version}}
cfbdfc6
856d813
# root dir for ghc docs (used by ghc.spec)
7e15be0
%ghc_html_dir %{_docdir}/ghc/html
856d813
# deprecates
124ef72
%ghcdocbasedir %ghc_html_dir
856d813
856d813
# libraries doc dir (internal)
856d813
%ghc_html_libraries_dir %{ghc_html_dir}/libraries
856d813
# deprecates
124ef72
%ghclibdocdir %ghc_html_libraries_dir
856d813
4d2eb25
# pkg doc dir
856d813
%ghc_html_pkg_dir %{ghc_html_libraries_dir}/%{pkg_name}-%{version}
856d813
# deprecates
124ef72
%ghcpkgdocdir %ghc_html_pkg_dir
856d813
a0e7ada
# top library dir
086f1bc
%ghclibdir %{_libdir}/ghc-%{ghc_version}
c6c20a5
086f1bc
# ghc_gen_filelists [name] [version]
c6c20a5
%ghc_gen_filelists()\
086f1bc
%define pkgname %{?1}%{!?1:%{pkg_name}}\
086f1bc
%define pkgver %{?2}%{!?2:%{version}}\
086f1bc
%define pkgnamever %{pkgname}-%{pkgver}\
f0f6b55
%define basepkg %{?ghc_name}%{!?ghc_name:ghc}-%{pkgname}\
4b3c243
%define docdir %{ghclibdocdir}/%{pkgnamever}\
5517c1f
keyname=$(%{_rpmconfigdir}/ghc-pkg-wrapper %{buildroot}%{ghclibdir} field %{pkgnamever} key)\
7e15be0
pkgdir="%{ghclibdir}/${keyname}"\
1bc67af
rm -f %{basepkg}.files %{basepkg}-devel.files\
9460154
touch %{basepkg}.files %{basepkg}-devel.files\
7e15be0
echo "%{ghclibdir}/package.conf.d/%{pkgnamever}*.conf" >> %{basepkg}-devel.files\
7e15be0
if [ -d "%{buildroot}${pkgdir}" ]; then\
3a48002
echo "%%dir ${pkgdir}" >> %{basepkg}.files\
2c0b10d
%if %{undefined ghc_without_shared}\
3a48002
echo "%%attr(755,root,root) ${pkgdir}/libHS*-ghc%{ghc_version}.so" >> %{basepkg}.files\
086f1bc
%endif\
7e15be0
find %{buildroot}${pkgdir} -mindepth 1 -type d | sed "s/^/%dir /" >> %{basepkg}-devel.files\
7e15be0
find %{buildroot}${pkgdir} ! \\( -type d -o -name "libHS*.so" \\) >> %{basepkg}-devel.files\
086f1bc
fi\
086f1bc
if [ -d "%{buildroot}%{docdir}" ]; then\
086f1bc
echo "%{docdir}" >> %{basepkg}-devel.files\
086f1bc
fi\
5517c1f
%if 0%{?1:1}\
3a48002
for i in $(ls %{buildroot}%{?_defaultlicensedir}%{!?_defaultlicensedir:%_docdir}/%{!?1:%{name}}%{?1:%{basepkg}}); do\
ae0985a
echo "%%license %{?1:%{pkgnamever}/}$i" >> %{basepkg}.files\
c43600a
done\
5517c1f
%endif\
73b0bd1
for i in %{basepkg}.files %{basepkg}-devel.files; do\
8f4190a
if [ -f "$i" ]; then\
6b6cf52
sed -i -e "s!%{buildroot}!!g" $i\
6b6cf52
fi\
6b6cf52
done\
Yaakov Meir Nemoy b640c1a
%{nil}
Yaakov Meir Nemoy b640c1a
a0e7ada
# create and install package.conf file
086f1bc
# cabal_pkg_conf [name] [version]
c6c20a5
%cabal_pkg_conf()\
086f1bc
%define pkgname %{?1}%{!?1:%{pkg_name}}\
086f1bc
%define pkgver %{?2}%{!?2:%{version}}\
086f1bc
%define pkgnamever %{pkgname}-%{pkgver}\
086f1bc
%cabal register --gen-pkg-config\
4d2eb25
install -D --mode=0644 %{pkgnamever}.conf %{buildroot}%{ghclibdir}/package.conf.d/%{pkgnamever}.conf\
c6c20a5
%{nil}
d9a9b5f
28ead10
# ghc_bin_build
28ead10
%ghc_bin_build\
d364972
%global debug_package %{nil}\
c6c20a5
%cabal_configure\
5517c1f
%cabal build %{?cabal_build_options}
28ead10
5abcaac
# ghc_lib_build_without_haddock [name] [version]
5abcaac
%ghc_lib_build_without_haddock()\
d364972
%global debug_package %{nil}\
f1517cd
%cabal_configure %{!?without_prof:-p} %{!?ghc_without_shared:--enable-shared} %{?ghc_without_shared:--disable-shared} %{?pkg_name:--htmldir=%{ghclibdocdir}/%{pkg_name}-%{version}} %{?1:--docdir=%{?_defaultlicensedir}%{!?_defaultlicensedir:%_docdir}/ghc-%1%{!?fedora:-%2} --htmldir=%{ghclibdocdir}/%1-%2} %{?ghc_subpackaging:--user}%{!?ghc_subpackaging:--global} %{?ghc_with_lib_for_ghci:--enable-library-for-ghci}\
5517c1f
%cabal build  %{?cabal_build_options}\
5abcaac
%{nil}
5abcaac
5abcaac
# ghc_lib_build [name] [version]
5abcaac
%ghc_lib_build()\
88a603f
%ghc_lib_build_without_haddock\
d32b457
%if %{undefined without_haddock}\
c13aaea
%define pkgname %{?1}%{!?1:%{pkg_name}}\
c13aaea
%define pkgver %{?2}%{!?2:%{version}}\
c13aaea
if [ -f dist/build/libHS%{pkgname}-%{pkgver}.a ]; then\
5517c1f
%cabal haddock --html %{!?without_hscolour:%(if [ -x %{_bindir}/HsColour ]; then echo --hyperlink-source; fi)} --hoogle %{?cabal_haddock_options}\
c13aaea
fi\
d32b457
%endif\
c6c20a5
%{nil}
28ead10
49912b0
# ghc_strip_dynlinked
49912b0
%ghc_strip_dynlinked\
49912b0
%if %{undefined __debug_package}\
49912b0
find %{buildroot} -type f -exec sh -c "file {} | grep -q 'dynamically linked'" \\; -exec strip "{}" \\;\
49912b0
%endif
49912b0
c6c20a5
# install bin package
dae8fa2
%ghc_bin_install()\
7e15be0
%{!?_fileattrsdir:%global _use_internal_dependency_generator 0}\
7e15be0
%{!?_fileattrsdir:%global __find_requires %{_rpmconfigdir}/ghc-deps.sh %{buildroot}%{ghclibdir}}\
28ead10
%cabal_install\
dae8fa2
%{!?1:%ghc_strip_dynlinked}\
dae8fa2
%{nil}
28ead10
086f1bc
# ghc_lib_install [name] [version]
c6c20a5
%ghc_lib_install()\
7e15be0
%{!?_fileattrsdir:%global _use_internal_dependency_generator 0}\
7e15be0
%{!?_fileattrsdir:%global __find_provides %{_rpmconfigdir}/rpmdeps --provides}\
7e15be0
%{!?_fileattrsdir:%global __find_requires %{_rpmconfigdir}/ghc-deps.sh %{buildroot}%{ghclibdir}}\
28ead10
%cabal_install\
28ead10
%cabal_pkg_conf\
28ead10
%ghc_gen_filelists\
c6c20a5
%{!?1:%ghc_strip_dynlinked}\
c6c20a5
%{nil}
e6a0b6c
411d61d
# ghc_fix_rpath lib-ver ...
411d61d
%ghc_fix_rpath()\
411d61d
%if %{undefined ghc_without_dynamic}\
411d61d
if ! type chrpath > /dev/null; then exit 1; fi\
5517c1f
pdir=$(pwd)\
411d61d
for lib in %*; do\
411d61d
for i in $(find %{buildroot} -type f -exec sh -c "file {} | grep -q 'dynamically linked'" \\; -print); do\
411d61d
  if [ -x "$i" ]; then\
5517c1f
    rpath=$(chrpath $i | sed -e "s@^$i: R.*PATH=@@")\
5517c1f
    case $rpath in\
5517c1f
         *$pdir/$lib/*)\
5517c1f
         syspath=$(%{_rpmconfigdir}/ghc-pkg-wrapper %{buildroot}%{ghclibdir} --package-db=%{buildroot}%{ghclibdir}/package.conf.d field $lib library-dirs)\
5517c1f
         NEWRPATH=$(echo $rpath | sed -e "s@$pdir/$lib/dist/build@${syspath}@g")\
5517c1f
         chrpath -r $newrpath $i\
411d61d
         ;;\
411d61d
    esac\
411d61d
  else\
411d61d
    echo "%%ghc_fix_rpath: no $i executable"\
411d61d
    exit 1\
411d61d
  fi\
411d61d
done\
411d61d
done\
411d61d
%endif\
411d61d
%{nil}
411d61d
411d61d
# Deprecated by ghc_fix_rpath:
436bfaf
# ghc_fix_dynamic_rpath prog ...
436bfaf
%ghc_fix_dynamic_rpath()\
436bfaf
%if %{undefined ghc_without_dynamic}\
671df91
if ! type chrpath > /dev/null; then exit 1; fi\
5517c1f
pdir=$(pwd)\
436bfaf
for i in %*; do\
07399a8
  case $i in\
5517c1f
    /*) prog=%{buildroot}$i ;;\
5517c1f
    *) prog=%{buildroot}%{_bindir}/$i ;;\
07399a8
  esac\
5517c1f
  if [ -x "$prog" ]; then\
5517c1f
    RPATH=$(chrpath $prog | sed -e "s@^$prog: R.*PATH=@@")\
5517c1f
    case $rpath in\
5517c1f
         *$pdir*)\
5517c1f
         newrpath=$(echo $rpath | sed -e "s@$pdir/dist/build@%{ghclibdir}/%{pkg_name}-%{version}@g")\
5517c1f
         chrpath -r $newrpath $prog\
87a97e8
         ;;\
87a97e8
    esac\
87a97e8
  else\
5517c1f
    echo "%%ghc_fix_dynamic_rpath: no such file $prog"\
87a97e8
    exit 1\
87a97e8
  fi\
436bfaf
done\
436bfaf
%endif\
436bfaf
%{nil}
436bfaf
d125111
%ghc_pkg_recache %{_bindir}/ghc-pkg-%{ghc_version} recache --no-user-package-db || :
1b2339d
8cf968c
# - without_hscolour, without_testsuite, and ghc_bootstrapping
8cf968c
#   need to be set locally in the spec file
5995766
8598900
# skip prof libs and documentation
8598900
%ghc_bootstrap\
5995766
%global without_prof 1\
5995766
%global without_haddock 1\
5995766
%global without_manual 1