2011-02-12 15:07:05 +00:00
# RPM Macros for packaging Haskell cabalized packages -*-rpm-spec-*-
2013-04-23 09:12:25 +00:00
# see https://fedoraproject.org/wiki/Packaging:Haskell for more details
2011-02-10 12:11:02 +00:00
2010-06-20 12:10:25 +00:00
# "cabal"
2020-04-27 13:11:59 +00:00
%cabal [ -x Setup ] || ghc --make -package Cabal -no-user-package-db %{!?ghc_static_setup:-dynamic} Setup\
2019-02-01 17:21:29 +00:00
LANG=C.utf8\
2011-01-23 05:05:38 +00:00
./Setup
2009-05-13 07:37:39 +00:00
2017-02-08 06:26:07 +00:00
# compiler version
2023-01-09 04:41:21 +00:00
%ghc_version %{?ghc_version_override}%{!?ghc_version_override:%(rpm -q --qf %%{version} %{?ghc_name}%{!?ghc_name:ghc}-compiler)}
2018-10-05 08:53:41 +00:00
2018-10-05 16:47:11 +00:00
%ghc_set_gcc_flags\
2022-02-08 05:27:43 +00:00
%global _lto_cflags %{nil}\
2022-03-10 05:13:54 +00:00
%global __brp_strip_lto %{nil}\
2018-10-24 15:12:12 +00:00
# -Wunused-label is extremely noisy\
%ifarch s390x\
2022-02-12 06:13:10 +00:00
CFLAGS="$(echo ${CFLAGS:-%optflags} | sed -e 's/-Wall //' -e 's/-Werror=format-security //')"\
2018-10-24 15:12:12 +00:00
%else\
CFLAGS="${CFLAGS:-%optflags}"\
%endif\
export CFLAGS\
2022-01-21 14:10:52 +00:00
%undefine _package_note_flags\
2018-10-05 16:13:16 +00:00
%global _hardened_ldflags %{nil}\
2018-10-05 08:53:41 +00:00
export LDFLAGS="${LDFLAGS:-%{?__global_ldflags}}"\
2017-12-04 12:24:21 +00:00
%{nil}
# configure
%cabal_configure\
2018-10-05 10:02:12 +00:00
%ghc_set_gcc_flags\
2018-07-30 16:30:50 +00:00
if ! [ -f Setup.hs -o -f Setup.lhs ]; then\
cp %{_datadir}/ghc-rpm-macros/Setup.hs .\
fi\
2023-01-21 05:30:48 +00:00
if [ -d "%{ghclibdir}/lib" ]; then\
subsubdir=/lib\
fi\
2017-03-26 10:57:33 +00:00
%cabal --version\
2023-01-21 05:30:48 +00:00
%cabal configure %{!-W:%{?ghc_name:--with-compiler=%{_bindir}/ghc-%{ghc_version}}} --prefix=%{_prefix} --libdir=%{_libdir} --docdir=%{_ghcdocdir} --libsubdir='$compiler'${subsubdir}/'$pkgid' --datasubdir='$pkgid' --libexecsubdir='$pkgid' --ghc --dynlibdir=%{?_ghcdynlibdir}%{?!_ghcdynlibdir:%{_libdir}/ghc-%{ghc_version}${subsubdir}/'$pkgid'} %{!?ghc_without_dynamic:--enable-executable-dynamic} %{?with_tests:--enable-tests} %{?ghc_subpackaging:--user}%{!?ghc_subpackaging:--global} --ghc-options="${CFLAGS:+$(echo ' '$CFLAGS | sed -e 's/ / -optc/g')} ${LDFLAGS:+$(echo ' '$LDFLAGS | sed -e 's/ / -optl/g')} -fhide-source-paths" %{?cabal_configure_options} $cabal_configure_extra_options
2009-12-23 14:42:16 +00:00
2010-06-20 12:10:25 +00:00
# install
2017-02-08 06:26:07 +00:00
%cabal_install %cabal copy --destdir=%{buildroot} %{?cabal_install_options}
2009-05-13 07:37:39 +00:00
2015-10-08 10:20:20 +00:00
# tests
2015-01-31 20:22:21 +00:00
%cabal_test\
%if %{with tests}\
2017-02-08 06:26:07 +00:00
%cabal test %{?cabal_test_options}\
2015-01-31 20:22:21 +00:00
%endif
2015-03-20 08:39:03 +00:00
# no _pkgdocdir in EPEL <= 7
%ghc_pkgdocdir %{?_pkgdocdir}%{!?_pkgdocdir:%{_docdir}/%{name}-%{version}}
2022-05-16 10:28:41 +00:00
# library package prefix
%ghc_prefix %{?ghc_name}%{!?ghc_name:ghc}
2022-06-08 10:14:29 +00:00
# top ghcdocdir
%_ghc_doc_dir %{_docdir}/%{ghc_prefix}
2015-01-22 04:46:10 +00:00
# root dir for ghc docs (used by ghc.spec)
2022-06-08 10:14:29 +00:00
%ghc_html_dir %{_ghc_doc_dir}/html
2015-01-22 04:46:10 +00:00
# deprecates
2015-05-09 02:55:12 +00:00
%ghcdocbasedir %ghc_html_dir
2015-01-22 04:46:10 +00:00
# libraries doc dir (internal)
%ghc_html_libraries_dir %{ghc_html_dir}/libraries
# deprecates
2015-05-09 02:55:12 +00:00
%ghclibdocdir %ghc_html_libraries_dir
2015-01-22 04:46:10 +00:00
2013-10-15 09:08:08 +00:00
# pkg doc dir
2015-01-22 04:46:10 +00:00
%ghc_html_pkg_dir %{ghc_html_libraries_dir}/%{pkg_name}-%{version}
# deprecates
2015-05-09 02:55:12 +00:00
%ghcpkgdocdir %ghc_html_pkg_dir
2015-01-22 04:46:10 +00:00
2010-06-20 12:10:25 +00:00
# top library dir
2011-01-03 11:37:32 +00:00
%ghclibdir %{_libdir}/ghc-%{ghc_version}
2010-12-30 12:19:29 +00:00
2023-01-13 00:23:03 +00:00
%ghcliblib %{ghclibdir}%{?with_hadrian:/lib}
2021-12-18 17:28:18 +00:00
2022-06-08 10:14:29 +00:00
%_ghclicensedir %{?_defaultlicensedir}%{!?_defaultlicensedir:%_docdir}
2023-01-21 05:30:48 +00:00
# deprecated
%ghclibplatform %{ghcliblib}%{?with_hadrian:/%{ghcplatform}}
2021-12-19 19:05:20 +00:00
# Cabal has specific arch names
2023-01-21 05:30:48 +00:00
%ghcplatform %(echo %{_arch} | sed -e "s/ppc64le/ppc64/")-linux-ghc-%{ghc_version}
2021-12-18 17:28:18 +00:00
2023-01-10 04:45:17 +00:00
# ghc_gen_filelists [-m] [name] [version]
%ghc_gen_filelists(m)\
2011-01-03 11:37:32 +00:00
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define pkgver %{?2}%{!?2:%{version}}\
%define pkgnamever %{pkgname}-%{pkgver}\
2023-01-21 05:30:48 +00:00
%if %{without hadrian}\
if [ -d "%{ghclibdir}/lib" ]; then\
subsubdir=/lib\
fi\
%endif\
if [ -z "$(ls %{buildroot}%{ghcliblib}${subsubdir}/package.conf.d/%{pkgnamever}*.conf)" ]; then\
echo "%{buildroot}%{ghcliblib}${subsubdir}/package.conf.d/%{pkgnamever}*.conf not found"\
2017-08-02 10:00:01 +00:00
exit 1\
fi\
2023-01-10 04:47:48 +00:00
%define basepkg %{ghc_prefix}-%{pkgname}\
2019-07-16 16:05:34 +00:00
rm -f %{basepkg}.files %{basepkg}-doc.files\
touch %{basepkg}.files %{basepkg}-doc.files\
2019-07-17 06:27:12 +00:00
%if 0%{?1:1}\
2022-07-26 10:33:57 +00:00
if [ -d "%{buildroot}%{_ghclicensedir}/%{basepkg}" ]; then\
2019-07-17 06:27:12 +00:00
for i in $(ls %{buildroot}%{_ghclicensedir}/%{basepkg}); do\
echo "%%license %{pkgnamever}/$i" >> %{basepkg}.files\
done\
2022-07-26 10:33:57 +00:00
fi\
2019-07-17 06:27:12 +00:00
%endif\
2023-01-21 05:30:48 +00:00
for i in %{buildroot}%{?_ghcdynlibdir}%{!?_ghcdynlibdir:%{ghcliblib}${subsubdir}%{?with_hadrian:/%{ghcplatform}}%{!?with_hadrian:/%{pkgnamever}}}/libHS%{pkgnamever}-*ghc%{ghc_version}.so; do\
2020-06-24 10:42:00 +00:00
if [ -x "$i" ]; then\
2019-07-31 08:03:09 +00:00
echo $i >> %{basepkg}.files\
2020-06-24 10:42:00 +00:00
else\
2023-01-21 05:30:48 +00:00
echo $i: not found\
2023-01-10 04:45:17 +00:00
%if 0%{!-m:1}\
exit 1\
%endif\
2020-06-24 10:42:00 +00:00
fi\
2019-07-31 08:03:09 +00:00
done\
2023-01-21 05:30:48 +00:00
pkgdir="%{ghcliblib}${subsubdir}%{?with_hadrian:/%{ghcplatform}}/%{pkgnamever}"\
2016-06-03 04:16:35 +00:00
if [ -d "%{buildroot}${pkgdir}" ]; then\
2019-07-15 08:40:09 +00:00
find %{buildroot}${pkgdir} -type d -fprintf %{basepkg}-devel.files '%%%%dir %p\\n' -o \\( -name '*.p_hi' -o -name 'libHS*_p.a' \\) -fprint %{basepkg}-prof.files -o -fprint %{basepkg}-devel.files\
else\
rm -f %{basepkg}-devel.files %{basepkg}-prof.files\
touch %{basepkg}-devel.files %{basepkg}-prof.files\
2011-01-03 11:37:32 +00:00
fi\
2023-01-21 05:30:48 +00:00
ls %{buildroot}%{ghcliblib}${subsubdir}/package.conf.d/%{pkgnamever}*.conf >> %{basepkg}-devel.files\
2019-07-31 08:04:12 +00:00
%if %{with haddock}\
2022-07-26 08:03:46 +00:00
haddock_dir=%{ghc_html_libraries_dir}/%{pkgnamever}\
2021-12-19 07:01:25 +00:00
if [ -d %{buildroot}$haddock_dir ]; then\
echo $haddock_dir >> %{basepkg}-doc.files\
2022-07-26 08:03:46 +00:00
%if %{with hadrian}\
# for < 9.4.1-rc1\
else\
haddock_dir=%{ghc_html_libraries_dir}/%{pkgname}\
if [ -d %{buildroot}$haddock_dir ]; then\
echo $haddock_dir >> %{basepkg}-doc.files\
fi\
%endif\
2019-08-07 12:07:56 +00:00
fi\
2019-07-31 08:04:12 +00:00
%endif\
2019-07-16 16:05:34 +00:00
for i in %{basepkg}.files %{basepkg}-devel.files %{basepkg}-doc.files %{basepkg}-prof.files; do\
2012-05-25 14:52:09 +00:00
if [ -f "$i" ]; then\
2012-05-25 13:10:06 +00:00
sed -i -e "s!%{buildroot}!!g" $i\
fi\
done\
2009-05-13 07:37:39 +00:00
%{nil}
2010-06-20 12:10:25 +00:00
# create and install package.conf file
2011-01-03 11:37:32 +00:00
# cabal_pkg_conf [name] [version]
2010-12-30 12:19:29 +00:00
%cabal_pkg_conf()\
2011-01-03 11:37:32 +00:00
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define pkgver %{?2}%{!?2:%{version}}\
%define pkgnamever %{pkgname}-%{pkgver}\
%cabal register --gen-pkg-config\
2023-01-21 05:30:48 +00:00
if [ -d "%{ghclibdir}/lib" ]; then\
subsubdir=/lib\
fi\
2018-05-25 09:03:11 +00:00
if [ -d %{pkgnamever}.conf ]; then\
for i in $(ls "%{pkgnamever}.conf/"); do\
sub=$(echo $i | sed -e "s/^[0-9]\\+-//")\
2023-01-21 05:30:48 +00:00
install -D --mode=0644 %{pkgnamever}.conf/${i} %{buildroot}%{ghcliblib}${subsubdir}/package.conf.d/${sub}.conf\
2018-05-25 09:03:11 +00:00
done\
else\
2023-01-21 05:30:48 +00:00
install -D --mode=0644 %{pkgnamever}.conf %{buildroot}%{ghcliblib}${subsubdir}/package.conf.d/%{pkgnamever}.conf\
2018-05-25 09:03:11 +00:00
fi\
2010-12-30 12:19:29 +00:00
%{nil}
2010-04-12 14:52:34 +00:00
2021-01-29 16:27:39 +00:00
# workaround Cabal bug causing executable extra-source-files
%ghc_fix_doc_perms\
2021-04-08 04:22:24 +00:00
for f in $(ls | grep -i -e '^\\(ANNOUNCE\\|AUTHORS\\|CHANGELOG\\|CHANGES\\|CONTRIBUTORS\\|README\\|TODO\\)'); do\
2021-07-09 17:37:03 +00:00
if [ -f $f -a -x $f ]; then chmod a-x $f; fi\
2021-01-29 16:27:39 +00:00
done\
%{nil}
2023-01-13 15:15:20 +00:00
# ghc_bin_build: -W: use default ghc (ie ignore ghc_name)
%ghc_bin_build(W)\
2021-01-29 16:27:39 +00:00
%ghc_fix_doc_perms\
2022-07-19 05:57:00 +00:00
%{?!ghc_debuginfo:%undefine _enable_debug_packages}\
2010-12-30 12:19:29 +00:00
%cabal_configure\
2017-07-30 20:05:03 +00:00
%cabal build %{?ghc_smp_mflags} %{?cabal_build_options}
2010-06-26 08:53:39 +00:00
2012-06-05 02:40:54 +00:00
# ghc_lib_build_without_haddock [name] [version]
%ghc_lib_build_without_haddock()\
2021-01-29 16:27:39 +00:00
%ghc_fix_doc_perms\
2022-07-19 05:57:00 +00:00
%{?!ghc_debuginfo:%undefine _enable_debug_packages}\
2017-11-14 10:22:31 +00:00
%if 0%{?rhel} && 0%{?rhel} < 8\
2017-11-15 02:25:18 +00:00
licensedirversion=%{?2:-%2}\
2017-11-14 10:22:31 +00:00
%endif\
2019-07-16 16:09:25 +00:00
%cabal_configure %{?with_ghc_prof:-p} %{!?ghc_without_shared:--enable-shared} %{?ghc_without_shared:--disable-shared} %{?pkg_name:--htmldir=%{ghclibdocdir}/%{pkg_name}-%{version}} %{?1:--docdir=%{_ghclicensedir}/ghc-%1${licensedirversion} --htmldir=%{ghclibdocdir}/%1-%2} %{?ghc_subpackaging:--user}%{!?ghc_subpackaging:--global} %{?ghc_with_lib_for_ghci:--enable-library-for-ghci}\
2017-07-30 20:05:03 +00:00
%cabal build %{?ghc_smp_mflags} %{?cabal_build_options}\
2012-06-05 02:40:54 +00:00
%{nil}
# ghc_lib_build [name] [version]
%ghc_lib_build()\
2017-09-13 09:36:31 +00:00
%ghc_lib_build_without_haddock %{?1} %{?2}\
2019-07-16 16:09:25 +00:00
%if %{with haddock}\
2015-01-31 18:03:52 +00:00
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define pkgver %{?2}%{!?2:%{version}}\
2017-03-24 09:17:14 +00:00
if [ -n dist/build/libHS%{pkgname}-%{pkgver}*.so ]; then\
2019-02-01 17:15:55 +00:00
%cabal haddock --html --hyperlink-source --hoogle %{?cabal_haddock_options}\
2015-01-31 18:03:52 +00:00
fi\
2011-11-17 05:36:50 +00:00
%endif\
2010-12-30 12:19:29 +00:00
%{nil}
2010-06-26 08:53:39 +00:00
2010-12-30 12:19:29 +00:00
# install bin package
2012-06-07 11:14:06 +00:00
%ghc_bin_install()\
2010-06-26 08:53:39 +00:00
%cabal_install\
2021-06-07 15:34:23 +00:00
%ghc_delete_rpaths\
2012-06-07 11:14:06 +00:00
%{nil}
2010-06-26 08:53:39 +00:00
2011-01-03 11:37:32 +00:00
# ghc_lib_install [name] [version]
2023-01-10 04:45:17 +00:00
%ghc_lib_install(m)\
2010-06-26 08:53:39 +00:00
%cabal_install\
2017-09-13 09:36:31 +00:00
%cabal_pkg_conf %{?1} %{?2}\
2023-01-10 04:45:17 +00:00
%ghc_gen_filelists %{-m} %{?1} %{?2}\
2021-06-07 15:34:23 +00:00
%ghc_delete_rpaths\
2010-12-30 12:19:29 +00:00
%{nil}
2011-06-17 08:00:17 +00:00
2021-06-07 15:34:23 +00:00
# ghc_delete_rpaths
%ghc_delete_rpaths\
2023-01-21 05:35:14 +00:00
%if %{defined _ghcdynlibdir}\
2021-06-07 15:34:23 +00:00
%if %{undefined disable_ghc_delete_rpaths}\
echo "running ghc_delete_rpaths:"\
2016-09-27 05:30:59 +00:00
if ! type chrpath > /dev/null; then exit 1; fi\
2019-07-15 08:40:09 +00:00
for i in $(find %{buildroot} -type f -executable -exec sh -c "file {} | grep -q 'dynamically linked'" \\; -print); do\
2016-09-27 05:30:59 +00:00
if [ -x "$i" ]; then\
2021-06-07 15:24:42 +00:00
chrpath -d $i\
2016-09-27 05:30:59 +00:00
else\
2021-06-07 15:34:23 +00:00
echo "%%ghc_delete_rpath: no $i executable"\
2016-09-27 05:30:59 +00:00
exit 1\
fi\
done\
2023-01-21 05:35:14 +00:00
%endif\
2019-07-15 16:33:38 +00:00
%endif
2016-09-27 05:30:59 +00:00
2021-06-08 13:20:51 +00:00
# deprecated by ghc_delete_rpaths in F35
%ghc_fix_rpath()\
%if %{undefined disable_ghc_fix_rpath}\
if ! type chrpath > /dev/null; then exit 1; fi\
echo "ghc_fix_rpath %*"\
for i in $(find %{buildroot} -type f -executable -exec sh -c "file {} | grep -q 'dynamically linked'" \\; -print); do\
for lib in %*; do\
if [ -x "$i" ]; then\
rpath=$(chrpath $i | sed -e "s@^$i: R.*PATH=@@")\
case $rpath in\
*$PWD/$lib/dist/build*)\
case %{ghc_version} in\
7.10.*)\
2021-12-18 15:29:58 +00:00
pkgid=$(cd %{buildroot}%{ghcliblib}/package.conf.d; ls ${lib}* | sed -e "s/.conf$//")\
syspath=$(%{_rpmconfigdir}/ghc-pkg-wrapper %{buildroot}%{ghcliblib} --global --package-db=%{buildroot}%{ghcliblib}/package.conf.d field $pkgid library-dirs) ;;\
2021-06-08 13:20:51 +00:00
8.0)\
pkgid=$(cd %{buildroot}%{ghclibdir}; echo ${lib}*)\
2021-12-18 15:29:58 +00:00
syspath=$(%{_rpmconfigdir}/ghc-pkg-wrapper %{buildroot}%{ghcliblib} --global --package-db=%{buildroot}%{ghcliblib}/package.conf.d field $lib library-dirs | grep $pkgid) ;;\
2021-06-08 13:20:51 +00:00
*)\
syspath="" ;;\
esac\
newrpath=$(echo $rpath | sed -e "s@$PWD/$lib/dist/build@${syspath}@g" -e "s/::/:/" -e "s/^://" -e "s/:$//")\
if [ "$newrpath" = "%{_libdir}" ]; then\
chrpath -d $i\
else\
chrpath -r $newrpath $i\
fi\
;;\
%{_libdir})\
chrpath -d $i\
;;\
esac\
else\
echo "%%ghc_fix_rpath: no $i executable"\
exit 1\
fi\
done\
done\
%endif
2015-03-08 05:41:30 +00:00
%ghc_pkg_recache %{_bindir}/ghc-pkg-%{ghc_version} recache --no-user-package-db || :
2013-05-04 14:34:41 +00:00
2018-05-23 01:34:08 +00:00
# skip prof libs and documentation
%ghc_quick_build\
2019-07-16 16:09:25 +00:00
%undefine with_ghc_prof\
%undefine with_haddock