2c0b10d
# RPM Macros for packaging Haskell cabalized packages  -*-rpm-spec-*-
73b0bd1
# see https://fedoraproject.org/wiki/Packaging:Haskell for more details
1f4312a
a0e7ada
# "cabal"
3e574ed
%cabal [ -x Setup ] || ghc --make -package Cabal -no-user-package-db %{!?ghc_static_setup:-dynamic} Setup\
c1326d8
LANG=C.utf8\
a1abcaa
./Setup
Yaakov Meir Nemoy b640c1a
5517c1f
# compiler version
5517c1f
%ghc_version %{!?ghc_version_override:%(ghc --numeric-version)}%{?ghc_version_override}
5517c1f
d190fa9
153f500
%ghc_set_gcc_flags\
9a341be
%global _lto_cflags %{nil}\
57481f9
%global __brp_strip_lto %{nil}\
5b2544a
# -Wunused-label is extremely noisy\
5b2544a
%ifarch s390x\
b47d44f
CFLAGS="$(echo ${CFLAGS:-%optflags} | sed -e 's/-Wall //' -e 's/-Werror=format-security //')"\
5b2544a
%else\
5b2544a
CFLAGS="${CFLAGS:-%optflags}"\
5b2544a
%endif\
5b2544a
export CFLAGS\
22d34de
%undefine _package_note_flags\
975f21c
%global _hardened_ldflags %{nil}\
d190fa9
export LDFLAGS="${LDFLAGS:-%{?__global_ldflags}}"\
32c4fa6
%{nil}
32c4fa6
32c4fa6
# configure
32c4fa6
%cabal_configure\
55f6227
%ghc_set_gcc_flags\
8bce457
if ! [ -f Setup.hs -o -f Setup.lhs ]; then\
8bce457
cp %{_datadir}/ghc-rpm-macros/Setup.hs .\
8bce457
fi\
c17dd21
%cabal --version\
16df5d8
%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')} -fhide-source-paths" %{?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
051b51f
# library package prefix
051b51f
%ghc_prefix %{?ghc_name}%{!?ghc_name:ghc}
051b51f
e780fd0
# top ghcdocdir
e780fd0
%_ghc_doc_dir %{_docdir}/%{ghc_prefix}
e780fd0
856d813
# root dir for ghc docs (used by ghc.spec)
e780fd0
%ghc_html_dir %{_ghc_doc_dir}/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
430af17
%ghcliblib %{ghclibdir}%{?with_hadrian:/lib}
430af17
e780fd0
%_ghclicensedir %{?_defaultlicensedir}%{!?_defaultlicensedir:%_docdir}
e780fd0
ad76ca4
# Cabal has specific arch names
400c117
%ghclibplatform %{ghcliblib}%{?with_hadrian:/%(echo %{_arch} | sed -e "s/ppc64le/ppc64/")-linux-ghc-%{ghc_version}}
430af17
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}\
051b51f
%define basepkg %{ghc_prefix}-%{pkgname}\
3f7e410
if [ -z "$(ls %{buildroot}%{ghcliblib}/package.conf.d/%{pkgnamever}*.conf)" ]; then\
3f7e410
echo '%{buildroot}%{ghcliblib}/package.conf.d/%{pkgnamever}*.conf not found'\
5d5eac1
exit 1\
5d5eac1
fi\
a848de7
rm -f %{basepkg}.files %{basepkg}-doc.files\
a848de7
touch %{basepkg}.files %{basepkg}-doc.files\
8e03288
%if 0%{?1:1}\
8e03288
for i in $(ls %{buildroot}%{_ghclicensedir}/%{basepkg}); do\
8e03288
echo "%%license %{pkgnamever}/$i" >> %{basepkg}.files\
8e03288
done\
8e03288
%endif\
3f7e410
for i in %{buildroot}%{?_ghcdynlibdir}%{!?_ghcdynlibdir:%{ghclibplatform}}/libHS%{pkgnamever}-*ghc%{ghc_version}.so; do\
bc06ab7
if [ -x "$i" ]; then\
75b5406
echo $i >> %{basepkg}.files\
bc06ab7
else\
3f7e410
echo 'Warning: %{buildroot}%{?_ghcdynlibdir}%{!?_ghcdynlibdir:%{ghclibplatform}}/libHS%{pkgnamever}-*ghc%{ghc_version}.so not found'\
bc06ab7
fi\
75b5406
done\
3f7e410
pkgdir="%{ghclibplatform}/%{pkgnamever}"\
7e15be0
if [ -d "%{buildroot}${pkgdir}" ]; then\
7c7ff55
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\
7c7ff55
else\
7c7ff55
rm -f %{basepkg}-devel.files %{basepkg}-prof.files\
7c7ff55
touch %{basepkg}-devel.files %{basepkg}-prof.files\
086f1bc
fi\
3f7e410
ls %{buildroot}%{ghcliblib}/package.conf.d/%{pkgnamever}*.conf >> %{basepkg}-devel.files\
4288e26
%if %{with haddock}\
f8ff148
haddock_dir=%{ghc_html_libraries_dir}/%{?with_hadrian:%pkgname}%{!?with_hadrian:%pkgnamever}\
f8ff148
if [ -d %{buildroot}$haddock_dir ]; then\
f8ff148
echo $haddock_dir >> %{basepkg}-doc.files\
a11ad68
fi\
4288e26
%endif\
a848de7
for i in %{basepkg}.files %{basepkg}-devel.files %{basepkg}-doc.files %{basepkg}-prof.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\
37fe2b4
if [ -d %{pkgnamever}.conf ]; then\
37fe2b4
for i in $(ls "%{pkgnamever}.conf/"); do\
37fe2b4
sub=$(echo $i | sed -e "s/^[0-9]\\+-//")\
ac98514
install -D --mode=0644 %{pkgnamever}.conf/${i} %{buildroot}%{ghcliblib}/package.conf.d/${sub}.conf\
37fe2b4
done\
37fe2b4
else\
ac98514
install -D --mode=0644 %{pkgnamever}.conf %{buildroot}%{ghcliblib}/package.conf.d/%{pkgnamever}.conf\
37fe2b4
fi\
c6c20a5
%{nil}
d9a9b5f
8ed58df
# workaround Cabal bug causing executable extra-source-files
8ed58df
%ghc_fix_doc_perms\
63e6e93
for f in $(ls | grep -i -e '^\\(ANNOUNCE\\|AUTHORS\\|CHANGELOG\\|CHANGES\\|CONTRIBUTORS\\|README\\|TODO\\)'); do\
db0d821
if [ -f $f -a -x $f ]; then chmod a-x $f; fi\
8ed58df
done\
8ed58df
%{nil}
8ed58df
28ead10
# ghc_bin_build
28ead10
%ghc_bin_build\
8ed58df
%ghc_fix_doc_perms\
e35da2e
%undefine _enable_debug_packages\
c6c20a5
%cabal_configure\
5969f32
%cabal build %{?ghc_smp_mflags} %{?cabal_build_options}
28ead10
5abcaac
# ghc_lib_build_without_haddock [name] [version]
5abcaac
%ghc_lib_build_without_haddock()\
8ed58df
%ghc_fix_doc_perms\
e35da2e
%undefine _enable_debug_packages\
97922d4
%if 0%{?rhel} && 0%{?rhel} < 8\
7faec45
licensedirversion=%{?2:-%2}\
97922d4
%endif\
35cd9d0
%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}\
5969f32
%cabal build %{?ghc_smp_mflags} %{?cabal_build_options}\
5abcaac
%{nil}
5abcaac
5abcaac
# ghc_lib_build [name] [version]
5abcaac
%ghc_lib_build()\
430e328
%ghc_lib_build_without_haddock %{?1} %{?2}\
35cd9d0
%if %{with haddock}\
c13aaea
%define pkgname %{?1}%{!?1:%{pkg_name}}\
c13aaea
%define pkgver %{?2}%{!?2:%{version}}\
78b7c8e
if [ -n dist/build/libHS%{pkgname}-%{pkgver}*.so ]; then\
b82b101
%cabal haddock --html --hyperlink-source --hoogle %{?cabal_haddock_options}\
c13aaea
fi\
d32b457
%endif\
c6c20a5
%{nil}
28ead10
c6c20a5
# install bin package
dae8fa2
%ghc_bin_install()\
28ead10
%cabal_install\
cc8736d
%ghc_delete_rpaths\
dae8fa2
%{nil}
28ead10
086f1bc
# ghc_lib_install [name] [version]
c6c20a5
%ghc_lib_install()\
28ead10
%cabal_install\
430e328
%cabal_pkg_conf %{?1} %{?2}\
430e328
%ghc_gen_filelists %{?1} %{?2}\
cc8736d
%ghc_delete_rpaths\
c6c20a5
%{nil}
e6a0b6c
cc8736d
# ghc_delete_rpaths
cc8736d
%ghc_delete_rpaths\
cc8736d
%if %{undefined disable_ghc_delete_rpaths}\
cc8736d
echo "running ghc_delete_rpaths:"\
411d61d
if ! type chrpath > /dev/null; then exit 1; fi\
7c7ff55
for i in $(find %{buildroot} -type f -executable -exec sh -c "file {} | grep -q 'dynamically linked'" \\; -print); do\
411d61d
  if [ -x "$i" ]; then\
9e31d7d
     chrpath -d $i\
411d61d
  else\
cc8736d
    echo "%%ghc_delete_rpath: no $i executable"\
411d61d
    exit 1\
411d61d
  fi\
411d61d
done\
1862405
%endif
411d61d
192fd2f
# deprecated by ghc_delete_rpaths in F35
192fd2f
%ghc_fix_rpath()\
192fd2f
%if %{undefined disable_ghc_fix_rpath}\
192fd2f
if ! type chrpath > /dev/null; then exit 1; fi\
192fd2f
echo "ghc_fix_rpath %*"\
192fd2f
for i in $(find %{buildroot} -type f -executable -exec sh -c "file {} | grep -q 'dynamically linked'" \\; -print); do\
192fd2f
for lib in %*; do\
192fd2f
  if [ -x "$i" ]; then\
192fd2f
    rpath=$(chrpath $i | sed -e "s@^$i: R.*PATH=@@")\
192fd2f
    case $rpath in\
192fd2f
         *$PWD/$lib/dist/build*)\
192fd2f
         case %{ghc_version} in\
192fd2f
              7.10.*)\
ac98514
                pkgid=$(cd %{buildroot}%{ghcliblib}/package.conf.d; ls ${lib}* | sed -e "s/.conf$//")\
ac98514
                syspath=$(%{_rpmconfigdir}/ghc-pkg-wrapper %{buildroot}%{ghcliblib} --global --package-db=%{buildroot}%{ghcliblib}/package.conf.d field $pkgid library-dirs) ;;\
192fd2f
              8.0)\
192fd2f
                pkgid=$(cd %{buildroot}%{ghclibdir}; echo ${lib}*)\
ac98514
                syspath=$(%{_rpmconfigdir}/ghc-pkg-wrapper %{buildroot}%{ghcliblib} --global --package-db=%{buildroot}%{ghcliblib}/package.conf.d field $lib library-dirs | grep $pkgid) ;;\
192fd2f
              *)\
192fd2f
                syspath="" ;;\
192fd2f
         esac\
192fd2f
         newrpath=$(echo $rpath | sed -e "s@$PWD/$lib/dist/build@${syspath}@g" -e "s/::/:/" -e "s/^://" -e "s/:$//")\
192fd2f
         if [ "$newrpath" = "%{_libdir}" ]; then\
192fd2f
            chrpath -d $i\
192fd2f
         else\
192fd2f
            chrpath -r $newrpath $i\
192fd2f
         fi\
192fd2f
         ;;\
192fd2f
         %{_libdir})\
192fd2f
         chrpath -d $i\
192fd2f
         ;;\
192fd2f
    esac\
192fd2f
  else\
192fd2f
    echo "%%ghc_fix_rpath: no $i executable"\
192fd2f
    exit 1\
192fd2f
  fi\
192fd2f
done\
192fd2f
done\
192fd2f
%endif
192fd2f
d125111
%ghc_pkg_recache %{_bindir}/ghc-pkg-%{ghc_version} recache --no-user-package-db || :
1b2339d
3124474
# skip prof libs and documentation
3124474
%ghc_quick_build\
35cd9d0
%undefine with_ghc_prof\
35cd9d0
%undefine with_haddock