summaryrefslogtreecommitdiff
path: root/ghc.spec
blob: 9ea0c0a65a4ab196062cea6888ffbac1e16beef8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
%define full_version 9.4.5

# Keep in sync with ghc-bootstrap.spec
%global llvm_major 14

# disable prof, docs, perf build
# for production builds: disable quick build
%bcond_with quickbuild

# for production builds: use hadrian buildsystem
%bcond_without hadrian

# for production builds: build hadrian
%bcond_without build_hadrian

# for production builds: enable debuginfo
%bcond_without ghc_debuginfo

%if %{without ghc_debuginfo}
%undefine _enable_debug_packages
%endif

# build profiling libraries
# build help document (haddock & manual)
# perf production build (disable for quick build)
%if %{with quickbuild}
%undefine with_ghc_prof
%undefine with_help
%undefine with_haddock
%bcond_with perf_build
%else
%bcond_without ghc_prof
%bcond_without help
%bcond_without haddock
%bcond_without perf_build
%endif

%global ghc_llvm_archs riscv64
%global ghc_unregisterized_arches noarch 

%global base_ver 4.17.1.0
%global ghc_compact_ver 0.1.0.0
%global hpc_ver 0.6.1.0
%global hsc2hs_ver 0.68.8

# Workaround for copr build
%global ghclibdir %{_libdir}/ghc-%{full_version}
%global ghcliblib %{ghclibdir}%{?with_hadrian:/lib}

Name:           ghc
Version:        %{full_version}
Release:        1
Summary:        The Glorious Glasgow Haskell Compiler
License:        BSD-3-Clause
URL:            https://www.haskell.org/ghc/
Source0:        https://downloads.haskell.org/~ghc/%{full_version}/ghc-%{version}-src.tar.xz
Source1:        ghc-rpmlintrc
Source2:        9_2_3-bootstrap-sources.tar.gz
Source3:        ghc-pkg.man
Source4:        haddock.man
Source5:        runghc.man

# Use absolute PATH in gen_contents_index
Patch1:         ghc-gen_contents_index-haddock-path.patch
# Add stack marker to StgCRunAsm.S
Patch2:         execstack.patch
# Set Linux as default PIE platform
Patch3:        ghc-pie.patch
# Fix sphinx7 issues
Patch4:        sphinx7.patch
# Fix sphinx extlinks
Patch5:        fix-sphinx-extlinks.patch

BuildRequires:  binutils-devel
BuildRequires:  gcc-c++
BuildRequires:  ghc-bootstrap >= 9.0
BuildRequires:  ghc-bootstrap-tools >= 1.0
BuildRequires:  ghc-rpm-macros-extra
BuildRequires:  glibc-devel
BuildRequires:  gmp-devel
BuildRequires:  elfutils-devel
BuildRequires:  elfutils-libelf-devel
BuildRequires:  libffi-devel
BuildRequires:  libtool
%ifarch riscv64
BuildRequires:  clang%{llvm_major}
BuildRequires:  llvm%{llvm_major}
BuildRequires:  llvm%{llvm_major}-devel
%endif
BuildRequires:  ncurses-devel
BuildRequires:  pkgconfig
BuildRequires:  python3
BuildRequires:  xz
%if %{with help}
BuildRequires:  python3-sphinx
%endif
BuildRequires:  numactl-devel

Requires:       %{name}-compiler = %{version}-%{release}
Requires:       %{name}-devel = %{version}-%{release}
Requires:       %{name}-ghc-boot-devel = %{version}-%{release}
Requires:       %{name}-ghc-compact-devel = %{ghc_compact_ver}-%{release}
Requires:       %{name}-ghc-devel = %{version}-%{release}
Requires:       %{name}-ghc-heap-devel = %{version}-%{release}
Requires:       %{name}-ghci-devel = %{version}-%{release}
Requires:       %{name}-hpc-devel = %{hpc_ver}-%{release}
Requires:       %{name}-libiserv-devel = %{version}-%{release}
Recommends:     %{name}-compiler-default = %{version}-%{release}
%if %{with help}
Suggests:       %{name}-help = %{version}-%{release}
%endif
%if %{with ghc_prof}
Suggests:       %{name}-prof = %{version}-%{release}
%endif

%description
Haskell is the standard purely functional programming language; the
current language version is Haskell 98, agreed in December 1998.

GHC is a state-of-the-art programming suite for Haskell.  Included is
an optimising compiler generating good code for a variety of
platforms, together with an interactive system for convenient, quick
development.  The distribution includes space and time profiling
facilities, a large collection of libraries, and support for various
language extensions, including concurrency, exceptions, and foreign
language interfaces (C, C++, etc).

A wide variety of Haskell related resources (tutorials, libraries,
specifications, documentation, compilers, interprbeters, references,
contact information, links to research groups) are available from the
Haskell home page at <http://www.haskell.org/>.

%package compiler
Summary:        GHC compiler and utilities
License:        BSD-3-Clause
Requires:       gcc
Requires:       ghc-base-devel = %{base_ver}-%{release}
Provides:       hsc2hs-%{hsc2hs_ver}-%{release}
%ifarch riscv64 
Requires:       clang%{llvm_major}
Requires:       llvm%{llvm_major}
%endif

%description compiler
This package contains the GHC compiler, tools and utilities.

The GHC libraries are provided by ghc-devel.
To install all of GHC install package ghc.


%if %{with help}
%package help
Summary:        GHC manual and documentation
License:        BSD-3-Clause
Requires:       %{name}-compiler = %{version}-%{release}
BuildArch:      noarch

%description help
This package provides the GHC User Guide, Haddock manual and
GHC Haskell libraries documentation.
%endif

# These are libraries included with GHC compiler.
%global ghc_version_override %{version}
%global ghc_pkg_c_deps ghc-compiler = %{ghc_version_override}-%{release}
#!ForceMultiversion
%ghc_lib_subpackage -d Cabal-3.8.1.0
%ghc_lib_subpackage -d Cabal-syntax-3.8.1.0
%ghc_lib_subpackage -d array-0.5.4.0
%ghc_lib_subpackage -d -c gmp-devel,libffi-devel,elfutils-devel,elfutils-libelf-devel,numactl-devel base-%{base_ver}
%ghc_lib_subpackage -d binary-0.8.9.1
%ghc_lib_subpackage -d bytestring-0.11.4.0
%ghc_lib_subpackage -d containers-0.6.7
%ghc_lib_subpackage -d deepseq-1.4.8.0
%ghc_lib_subpackage -d directory-1.3.7.1
%ghc_lib_subpackage -d exceptions-0.10.5
%ghc_lib_subpackage -d filepath-1.4.2.2
%ghc_lib_subpackage -d -x ghc-%{ghc_version_override}
%ghc_lib_subpackage -d -x ghc-boot-%{ghc_version_override}
%ghc_lib_subpackage -d ghc-boot-th-%{ghc_version_override}
%ghc_lib_subpackage -d -x ghc-compact-0.1.0.0
%ghc_lib_subpackage -d -x ghc-heap-%{ghc_version_override}
%ghc_lib_subpackage -d -x ghci-%{ghc_version_override}
%ghc_lib_subpackage -d haskeline-0.8.2
%ghc_lib_subpackage -d -x hpc-0.6.1.0
%ghc_lib_subpackage -d -x libiserv-%{ghc_version_override}
%ghc_lib_subpackage -d mtl-2.2.2
%ghc_lib_subpackage -d parsec-3.1.16.1
%ghc_lib_subpackage -d pretty-1.1.3.6
%ghc_lib_subpackage -d process-1.6.16.0
%ghc_lib_subpackage -d stm-2.5.1.0
%ghc_lib_subpackage -d template-haskell-2.19.0.0
%ghc_lib_subpackage -d -c ncurses-devel terminfo-0.4.1.5
%ghc_lib_subpackage -d text-2.0.2
%ghc_lib_subpackage -d time-1.12.2
%ghc_lib_subpackage -d transformers-0.5.6.2
%ghc_lib_subpackage -d unix-2.7.3
%ghc_lib_subpackage -d xhtml-3000.2.2.1

%global version %{ghc_version_override}

%package devel
%{?ghc_packages_list:Requires: %(echo %{ghc_packages_list} | sed -e "s/\([^ ]*\)-\([^ ]*\)/%{name}-\1-devel = \2-%{release},/g")}
Summary:        GHC development libraries meta package
Requires:       ghc-compiler = %{version}-%{release}
Obsoletes:      ghc-libraries < %{version}-%{release}
Provides:       ghc-libraries = %{version}-%{release}

%description devel
This is a meta-package for all the development library packages in GHC
except the ghc library, which is installed by the toplevel ghc metapackage.

%if %{with ghc_prof}
%package prof
Summary:        GHC profiling libraries meta package
License:        BSD-3-Clause
Requires:       %{name}-compiler = %{version}-%{release}

%description prof
Installing this package causes %{name}-*-prof packages corresponding to
%{name}-*-devel packages to be automatically installed too.
%endif

%prep
%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1

rm libffi-tarballs/libffi-*.tar.gz

%build
# for ghc-bootstrap
export PATH=/opt/bin:$PATH
cp %{SOURCE2} ./
hadrian/bootstrap/bootstrap.py --bootstrap-sources 9_2_3-bootstrap-sources.tar.gz
%global hadrian _build/bin/hadrian

%ghc_set_gcc_flags

export CC=%{_bindir}/gcc
export LD=%{_bindir}/ld
export LANG=C.utf8

autoupdate

python3 boot.source --hadrian

./configure --prefix=%{_prefix} --exec-prefix=%{_exec_prefix} \
  --bindir=%{_bindir} --sbindir=%{_sbindir} --sysconfdir=%{_sysconfdir} \
  --datadir=%{_datadir} --includedir=%{_includedir} --libdir=%{_libdir} \
  --libexecdir=%{_libexecdir} --localstatedir=%{_localstatedir} \
  --sharedstatedir=%{_sharedstatedir} --mandir=%{_mandir} \
  --docdir=%{_docdir}/%{name}-%{version} \
  --with-system-libffi \
%ifarch %{ghc_unregisterized_arches}
  --enable-unregisterised \
%endif

%undefine _ghcdynlibdir

%ifarch %{ghc_llvm_archs}
%global hadrian_llvm +llvm
%endif
%define hadrian_docs %{!?with_help:--docs=no-haddocks} %{!?with_help:--docs=no-sphinx}%{?with_help:--docs=no-sphinx-pdfs --docs=no-sphinx-man}

%{hadrian} %{?_smp_mflags} --flavour=%{?with_quickbuild:quick+no_profiled_libs}%{!?with_quickbuild:perf%{!?with_ghc_prof:+no_profiled_libs}}%{?hadrian_llvm} %{hadrian_docs} binary-dist-dir

%install

(
cd _build/bindist/ghc-%{version}-*
./configure --prefix=%{buildroot}%{ghclibdir} --bindir=%{buildroot}%{_bindir} --libdir=%{buildroot}%{_libdir} --mandir=%{buildroot}%{_mandir} --docdir=%{buildroot}%{_docdir}/%{name}-%{version}
make install
)
mkdir -p %{buildroot}%{_sysconfdir}/ld.so.conf.d
echo "%{ghclibplatform}" > %{buildroot}%{_sysconfdir}/ld.so.conf.d/%{name}.conf
# avoid 'E: binary-or-shlib-defines-rpath'
for i in $(find %{buildroot} -type f -executable -exec sh -c "file {} | grep -q 'dynamically linked'" \; -print); do
  chrpath -d $i
done

# containers src moved to a subdir
cp -p libraries/containers/containers/LICENSE libraries/containers/LICENSE
# hack for Cabal-syntax/LICENSE
mkdir -p libraries/Cabal-syntax
cp -p libraries/Cabal/Cabal-syntax/LICENSE libraries/Cabal-syntax

rm -f %{name}-*.files

for i in %{ghc_packages_list}; do
name=$(echo $i | sed -e "s/\(.*\)-.*/\1/")
ver=$(echo $i | sed -e "s/.*-\(.*\)/\1/")
%ghc_gen_filelists $name $ver
echo "%%license libraries/$name/LICENSE" >> %{name}-$name.files
done

echo "%%dir %{ghclibdir}" >> %{name}-base%{?_ghcdynlibdir:-devel}.files

%ghc_gen_filelists ghc %{ghc_version_override}
%ghc_gen_filelists ghc-boot %{ghc_version_override}
%ghc_gen_filelists ghc-compact %{ghc_compact_ver}
%ghc_gen_filelists ghc-heap %{ghc_version_override}
%ghc_gen_filelists ghci %{ghc_version_override}
%ghc_gen_filelists hpc %{hpc_ver}
%ghc_gen_filelists libiserv %{ghc_version_override}

%ghc_gen_filelists ghc-bignum 1.3
%ghc_gen_filelists ghc-prim 0.9.0
%ghc_gen_filelists integer-gmp 1.1
%ghc_gen_filelists rts 1.0.2

%ghc_merge_filelist ghc-bignum base
%ghc_merge_filelist ghc-prim base
%ghc_merge_filelist integer-gmp base
%ghc_merge_filelist rts base

for i in %{buildroot}%{ghclibplatform}/libHSrts*ghc%{ghc_version}.so; do
  echo $i >> %{name}-base.files
done
echo "%{_sysconfdir}/ld.so.conf.d/%{name}.conf" >> %{name}-base.files

if [ -f %{buildroot}%{ghcliblib}/package.conf.d/system-cxx-std-lib-1.0.conf ]; then
ls -d %{buildroot}%{ghcliblib}/package.conf.d/system-cxx-std-lib-1.0.conf >> %{name}-base-devel.files
fi

%if %{with ghc_prof}
ls %{buildroot}%{ghclibdir}/bin/ghc-iserv-prof* >> %{name}-base-prof.files
ls %{buildroot}%{ghclibdir}/lib/bin/ghc-iserv-prof >> %{name}-base-prof.files
echo "%%dir %{ghcliblib}/bin"
%endif

sed -i -e "s|^%{buildroot}||g" %{name}-base*.files
sed -i -e "s|%{buildroot}||g" %{buildroot}%{_bindir}/*


%if %{with help}
rm %{buildroot}%{_docdir}/ghc-%{version}/archives/libraries.html.tar.xz
rm %{buildroot}%{_docdir}/ghc-%{version}/archives/Haddock.html.tar.xz
rm %{buildroot}%{_docdir}/ghc-%{version}/archives/users_guide.html.tar.xz
%endif


mkdir -p %{buildroot}%{_mandir}/man1
install -p -m 0644 %{SOURCE3} %{buildroot}%{_mandir}/man1/ghc-pkg.1
install -p -m 0644 %{SOURCE4} %{buildroot}%{_mandir}/man1/haddock.1
install -p -m 0644 %{SOURCE5} %{buildroot}%{_mandir}/man1/runghc.1


rm %{buildroot}%{ghclibdir}/lib/package.conf.d/.stamp
rm %{buildroot}%{ghclibdir}/lib/package.conf.d/*.conf.copy

(
cd %{buildroot}%{ghclibdir}/lib/bin
for i in *; do
if [ -f %{buildroot}%{ghclibdir}/bin/$i ]; then
ln -sf ../../bin/$i
fi
done
)

%check
# Simple tests to check the compiler whether actually works
# This comes from the Debian Haskell package.
export LANG=C.utf8
%if %{with hadrian}
export LD_LIBRARY_PATH=%{buildroot}%{ghclibplatform}:
GHC=%{buildroot}%{ghclibdir}/bin/ghc
%else
GHC=inplace/bin/ghc-stage2
%endif
rm -rf testghc
mkdir testghc
echo 'main = putStrLn "Foo"' > testghc/foo.hs
$GHC testghc/foo.hs -o testghc/foo
[ "$(testghc/foo)" = "Foo" ]
rm testghc/*
echo 'main = putStrLn "Foo"' > testghc/foo.hs
$GHC testghc/foo.hs -o testghc/foo -O2
[ "$(testghc/foo)" = "Foo" ]
rm testghc/*
echo 'main = putStrLn "Foo"' > testghc/foo.hs
$GHC testghc/foo.hs -o testghc/foo -dynamic
[ "$(testghc/foo)" = "Foo" ]
rm testghc/*

$GHC --info

%ldconfig_scriptlets

%transfiletriggerin compiler -- %{ghcliblib}/package.conf.d
%ghc_pkg_recache
%end

%transfiletriggerpostun compiler -- %{ghcliblib}/package.conf.d
%ghc_pkg_recache
%end

%files
%license LICENSE
%dir %{ghcliblib}
%dir %{ghclibdir}
%dir %{ghcliblib}/%{ghcplatform}

%files compiler
%license LICENSE
%doc README.md
%{_bindir}/ghc-%{version}
%{_bindir}/ghc-pkg-%{version}
%{_bindir}/ghci-%{version}
%{_bindir}/hp2ps-%{?with_hadrian:ghc-}%{version}
%{_bindir}/hpc-%{?with_hadrian:ghc-}%{version}
%{_bindir}/hsc2hs-%{?with_hadrian:ghc-}%{version}
%{_bindir}/runghc-%{version}
%{_bindir}/runhaskell-%{version}
%{_bindir}/ghc
%{_bindir}/ghc-pkg
%{_bindir}/ghci
%{_bindir}/haddock
%{_bindir}/hp2ps
%{_bindir}/hpc
%{_bindir}/hsc2hs
%{_bindir}/runghc
%{_bindir}/runhaskell
%dir %{ghclibdir}/bin
%dir %{ghcliblib}/bin
%{ghclibdir}/bin/ghc
%{ghclibdir}/bin/ghc-iserv
%{ghclibdir}/bin/ghc-iserv-dyn
%{ghclibdir}/bin/ghc-pkg
%{ghclibdir}/bin/hpc
%{ghclibdir}/bin/hsc2hs
%{ghclibdir}/bin/runghc
%{ghclibdir}/bin/hp2ps
%{ghclibdir}/bin/unlit
%{ghclibdir}/bin/ghc-%{version}
%{ghclibdir}/bin/ghc-iserv-ghc-%{version}
%{ghclibdir}/bin/ghc-iserv-dyn-ghc-%{version}
%{ghclibdir}/bin/ghc-pkg-%{version}
%{ghclibdir}/bin/haddock
%{ghclibdir}/bin/haddock-ghc-%{version}
%{ghclibdir}/bin/hp2ps-ghc-%{version}
%{ghclibdir}/bin/hpc-ghc-%{version}
%{ghclibdir}/bin/hsc2hs-ghc-%{version}
%{ghclibdir}/bin/runghc-%{version}
%{ghclibdir}/bin/runhaskell
%{ghclibdir}/bin/runhaskell-%{version}
%{ghclibdir}/bin/unlit-ghc-%{version}
%{ghclibdir}/lib/bin/ghc-iserv
%{ghclibdir}/lib/bin/ghc-iserv-dyn
%{ghclibdir}/lib/bin/unlit
%{ghcliblib}/ghc-usage.txt
%{ghcliblib}/ghci-usage.txt
%{ghcliblib}/llvm-passes
%{ghcliblib}/llvm-targets
%dir %{ghcliblib}/package.conf.d
%ghost %{ghcliblib}/package.conf.d/package.cache
%{ghcliblib}/package.conf.d/package.cache.lock
%{ghcliblib}/settings
%{ghcliblib}/template-hsc.h
%{_mandir}/man1/ghc-pkg.1*
%{_mandir}/man1/haddock.1*
%{_mandir}/man1/runghc.1*
%{_bindir}/haddock-ghc-%{version}
%{ghcliblib}/html
%{ghcliblib}/latex
%if %{with help}
%{ghc_html_libraries_dir}/prologue.txt
%verify(not size mtime) %{ghc_html_libraries_dir}/haddock-bundle.min.js
%verify(not size mtime) %{ghc_html_libraries_dir}/linuwial.css
%verify(not size mtime) %{ghc_html_libraries_dir}/quick-jump.css
%verify(not size mtime) %{ghc_html_libraries_dir}/synopsis.png
%if %{without hadrian}
%{_mandir}/man1/ghc.1*
%endif
%endif


%files devel

%if %{with help}
%files help
%{ghc_html_dir}/index.html
%{ghc_html_libraries_dir}/gen_contents_index
%verify(not size mtime) %{ghc_html_libraries_dir}/doc-index*.html
%verify(not size mtime) %{ghc_html_libraries_dir}/index*.html
%dir %_ghc_doc_dir
%dir %ghc_html_dir
%dir %ghc_html_libraries_dir
%{ghc_html_dir}/users_guide
%{ghc_html_dir}/Haddock
%endif

%if %{with ghc_prof}
%files prof
%endif

%changelog
* Fri Oct 27 2023 Lin Runze <lrzlin@163.com> 9.4.5-1
- Fix newer version of sphinx related bugs.
* Tue Jul 25 2023 Lin Runze <lrzlin@163.com> 9.4.5-1
- Initial packaging (Version 9.4.5)