ghc-rpm-macros/macros.ghc

225 lines
8.1 KiB
Plaintext
Raw Normal View History

# RPM Macros for packaging Haskell cabalized packages -*-rpm-spec-*-
# see https://fedoraproject.org/wiki/Packaging:Haskell for more details
# "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\
LANG=C.utf8\
./Setup
2009-05-13 07:37:39 +00:00
# compiler version
%ghc_version %{!?ghc_version_override:%(ghc --numeric-version)}%{?ghc_version_override}
2018-10-05 16:47:11 +00:00
%ghc_set_gcc_flags\
# -Wunused-label is extremely noisy\
%ifarch s390x\
%define _lto_cflags %{nil}\
CFLAGS="${CFLAGS:-$(echo %optflags | sed -e 's/-Wall //' -e 's/-Werror=format-security //')}"\
%else\
CFLAGS="${CFLAGS:-%optflags}"\
%endif\
export CFLAGS\
%global _hardened_ldflags %{nil}\
export LDFLAGS="${LDFLAGS:-%{?__global_ldflags}}"\
2017-12-04 12:24:21 +00:00
%{nil}
# configure
%cabal_configure\
%ghc_set_gcc_flags\
if ! [ -f Setup.hs -o -f Setup.lhs ]; then\
cp %{_datadir}/ghc-rpm-macros/Setup.hs .\
fi\
%cabal --version\
%cabal configure --prefix=%{_prefix} --libdir=%{_libdir} --docdir=%{_ghcdocdir} --libsubdir='$compiler/$pkgid' --datasubdir='$pkgid' --libexecsubdir='$pkgid' --ghc %{?_ghcdynlibdir:--dynlibdir=%{_ghcdynlibdir}} %{!?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')}" %{?cabal_configure_options} $cabal_configure_extra_options
# install
%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
%cabal_test\
%if %{with tests}\
%cabal test %{?cabal_test_options}\
%endif
# no _pkgdocdir in EPEL <= 7
%ghc_pkgdocdir %{?_pkgdocdir}%{!?_pkgdocdir:%{_docdir}/%{name}-%{version}}
# root dir for ghc docs (used by ghc.spec)
%ghc_html_dir %{_docdir}/ghc/html
# deprecates
2015-05-09 02:55:12 +00:00
%ghcdocbasedir %ghc_html_dir
# 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
# pkg doc dir
%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
# top library dir
%ghclibdir %{_libdir}/ghc-%{ghc_version}
%_ghclicensedir %{?_defaultlicensedir}%{!?_defaultlicensedir:%_docdir}
# ghc_gen_filelists [name] [version]
%ghc_gen_filelists()\
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define pkgver %{?2}%{!?2:%{version}}\
%define pkgnamever %{pkgname}-%{pkgver}\
%define basepkg %{?ghc_name}%{!?ghc_name:ghc}-%{pkgname}\
2019-07-15 08:40:09 +00:00
if [ -z "$(ls %{buildroot}%{ghclibdir}/package.conf.d/%{pkgnamever}*.conf)" ]; then\
echo '%{buildroot}%{ghclibdir}/package.conf.d/%{pkgnamever}*.conf not found'\
exit 1\
fi\
rm -f %{basepkg}.files %{basepkg}-doc.files\
touch %{basepkg}.files %{basepkg}-doc.files\
%if 0%{?1:1}\
for i in $(ls %{buildroot}%{_ghclicensedir}/%{basepkg}); do\
echo "%%license %{pkgnamever}/$i" >> %{basepkg}.files\
done\
%endif\
for i in %{buildroot}%{_ghcdynlibdir}/libHS%{pkgnamever}-*ghc%{ghc_version}.so; do\
if [ -x "$i" ]; then\
echo $i >> %{basepkg}.files\
else\
echo 'Warning: %{buildroot}%{_ghcdynlibdir}/libHS%{pkgnamever}-*ghc%{ghc_version}.so not found'\
fi\
done\
pkgdir="%{ghclibdir}/%{pkgnamever}"\
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\
fi\
2019-07-15 08:40:09 +00:00
ls %{buildroot}%{ghclibdir}/package.conf.d/%{pkgnamever}*.conf >> %{basepkg}-devel.files\
2019-07-31 08:04:12 +00:00
%if %{with haddock}\
2019-08-07 12:07:56 +00:00
if [ -d %{buildroot}%{ghc_html_libraries_dir}/%{pkgnamever} ]; then\
echo %dir %{_docdir}/ghc >> %{basepkg}-doc.files\
echo %dir %{ghc_html_dir} >> %{basepkg}-doc.files\
echo %dir %{ghc_html_libraries_dir} >> %{basepkg}-doc.files\
echo %{ghc_html_libraries_dir}/%{pkgnamever} >> %{basepkg}-doc.files\
2019-08-07 12:07:56 +00:00
fi\
2019-07-31 08:04:12 +00:00
%endif\
for i in %{basepkg}.files %{basepkg}-devel.files %{basepkg}-doc.files %{basepkg}-prof.files; do\
if [ -f "$i" ]; then\
sed -i -e "s!%{buildroot}!!g" $i\
fi\
done\
2009-05-13 07:37:39 +00:00
%{nil}
# create and install package.conf file
# cabal_pkg_conf [name] [version]
%cabal_pkg_conf()\
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define pkgver %{?2}%{!?2:%{version}}\
%define pkgnamever %{pkgname}-%{pkgver}\
%cabal register --gen-pkg-config\
if [ -d %{pkgnamever}.conf ]; then\
for i in $(ls "%{pkgnamever}.conf/"); do\
sub=$(echo $i | sed -e "s/^[0-9]\\+-//")\
install -D --mode=0644 %{pkgnamever}.conf/${i} %{buildroot}%{ghclibdir}/package.conf.d/${sub}.conf\
done\
else\
install -D --mode=0644 %{pkgnamever}.conf %{buildroot}%{ghclibdir}/package.conf.d/%{pkgnamever}.conf\
fi\
%{nil}
# ghc_bin_build
%ghc_bin_build\
%undefine _enable_debug_packages\
%cabal_configure\
%cabal build %{?ghc_smp_mflags} %{?cabal_build_options}
# ghc_lib_build_without_haddock [name] [version]
%ghc_lib_build_without_haddock()\
%undefine _enable_debug_packages\
%if 0%{?rhel} && 0%{?rhel} < 8\
licensedirversion=%{?2:-%2}\
%endif\
%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}\
%cabal build %{?ghc_smp_mflags} %{?cabal_build_options}\
%{nil}
# ghc_lib_build [name] [version]
%ghc_lib_build()\
%ghc_lib_build_without_haddock %{?1} %{?2}\
%if %{with haddock}\
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define pkgver %{?2}%{!?2:%{version}}\
if [ -n dist/build/libHS%{pkgname}-%{pkgver}*.so ]; then\
%cabal haddock --html --hyperlink-source --hoogle %{?cabal_haddock_options}\
fi\
%endif\
%{nil}
# install bin package
%ghc_bin_install()\
%{!?_fileattrsdir:%global _use_internal_dependency_generator 0}\
%{!?_fileattrsdir:%global __find_requires %{_rpmconfigdir}/ghc-deps.sh %{buildroot}%{ghclibdir}}\
%cabal_install\
%{?ghc_subpackaging:%ghc_fix_rpath %{subpkgs}}\
%{nil}
# ghc_lib_install [name] [version]
%ghc_lib_install()\
%{!?_fileattrsdir:%global _use_internal_dependency_generator 0}\
%{!?_fileattrsdir:%global __find_provides %{_rpmconfigdir}/rpmdeps --provides}\
%{!?_fileattrsdir:%global __find_requires %{_rpmconfigdir}/ghc-deps.sh %{buildroot}%{ghclibdir}}\
%cabal_install\
%cabal_pkg_conf %{?1} %{?2}\
%ghc_gen_filelists %{?1} %{?2}\
%{?ghc_subpackaging:%ghc_fix_rpath %{subpkgs}}\
%{nil}
# ghc_fix_rpath lib-ver ...
%ghc_fix_rpath()\
2019-07-15 16:33:38 +00:00
%if %{undefined disable_ghc_fix_rpath}\
if ! type chrpath > /dev/null; then exit 1; fi\
2019-07-31 08:04:40 +00:00
echo "ghc_fix_rpath %*"\
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\
2017-02-22 05:28:31 +00:00
for lib in %*; do\
if [ -x "$i" ]; then\
rpath=$(chrpath $i | sed -e "s@^$i: R.*PATH=@@")\
case $rpath in\
2017-02-22 05:28:31 +00:00
*$PWD/$lib/dist/build*)\
2017-04-07 10:09:23 +00:00
case %{ghc_version} in\
7.10.*)\
pkgid=$(cd %{buildroot}%{ghclibdir}/package.conf.d; ls ${lib}* | sed -e "s/.conf$//")\
syspath=$(%{_rpmconfigdir}/ghc-pkg-wrapper %{buildroot}%{ghclibdir} --global --package-db=%{buildroot}%{ghclibdir}/package.conf.d field $pkgid library-dirs) ;;\
8.0)\
2017-04-07 10:09:23 +00:00
pkgid=$(cd %{buildroot}%{ghclibdir}; echo ${lib}*)\
syspath=$(%{_rpmconfigdir}/ghc-pkg-wrapper %{buildroot}%{ghclibdir} --global --package-db=%{buildroot}%{ghclibdir}/package.conf.d field $lib library-dirs | grep $pkgid) ;;\
*)\
syspath="" ;;\
2017-04-07 10:09:23 +00:00
esac\
newrpath=$(echo $rpath | sed -e "s@$PWD/$lib/dist/build@${syspath}@g" -e "s/::/:/" -e "s/^://" -e "s/:$//")\
2019-07-15 16:33:38 +00:00
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\
2019-07-15 16:33:38 +00:00
%endif
2019-07-15 08:40:09 +00:00
# deprecated for f31
%ghc_pkg_recache %{_bindir}/ghc-pkg-%{ghc_version} recache --no-user-package-db || :
# skip prof libs and documentation
%ghc_quick_build\
%undefine with_ghc_prof\
%undefine with_haddock