summaryrefslogtreecommitdiffstats
path: root/tools/ghc-rpm-macros/ghc-rpm-macros.ghc
blob: 3fee4c19bcdcc866be98ca4a6051943a73c22abe (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
# RPM Macros for packaging Haskell cabalized packages  -*-rpm-spec-*-
# see https://fedoraproject.org/wiki/Packaging:Haskell for more details

# "cabal"
%cabal [ -x Setup ] || ghc --make %{!?ghc_user_conf:-no-user-package-conf} %{!?ghc_without_dynamic:-dynamic} Setup\
./Setup

# check ghc version was rebuilt against self
%ghc_check_bootstrap\
if [ ! "$(ghc --info | grep \\"Booter\\ version\\",\\"%{ghc_version}\\")" ]; then\
  echo "Warning: this ghc build is not self-bootstrapped."\
%if %{undefined ghc_bootstrapping}\
  echo "The ghc package should be rebuilt against its current version before\
proceeding, to avoid dependency ABI breakage from a future ghc rebuild."\
  echo "To override set ghc_bootstrapping."\
  echo "Aborting."\
  exit 1\
%endif\
fi

# configure
%cabal_configure\
%ghc_check_bootstrap\
%cabal configure --prefix=%{_prefix} --libdir=%{_libdir} --docdir=%{_docdir}/%{name}-%{version} %{?pkg_name:--htmldir=%{ghclibdocdir}/%{pkg_name}-%{version}} --libsubdir='$compiler/$pkgid' --ghc %{!?ghc_without_dynamic:--enable-executable-dynamic} %{?cabal_configure_options} $cabal_configure_extra_options

# install
%cabal_install %cabal copy --destdir=%{buildroot} -v

# root dir for ghc docs
%ghcdocbasedir %{_docdir}/ghc/html
# libraries doc dir
%ghclibdocdir %{ghcdocbasedir}/libraries
# pkg doc dir
%ghcpkgdocdir %{ghcdocbasedir}/libraries/%{pkg_name}-%{version}
# top library dir
%ghclibdir %{_libdir}/ghc-%{ghc_version}

# 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-%{pkgname}\
%define pkgdir %{ghclibdir}/%{pkgnamever}\
%define docdir %{ghclibdocdir}/%{pkgnamever}\
rm -f %{basepkg}.files %{basepkg}-devel.files\
if [ -d "%{buildroot}%{pkgdir}" ]; then\
echo "%dir %{pkgdir}" >> %{basepkg}.files\
%if %{undefined ghc_without_shared}\
echo "%attr(755,root,root) %{pkgdir}/libHS%{pkgnamever}-ghc%{ghc_version}.so" >> %{basepkg}.files\
%endif\
fi\
%if %{undefined ghc_exclude_docdir}\
if [ -d "%{buildroot}%{_docdir}/%{name}-%{version}" ]; then\
  echo "%{_docdir}/%{name}-%{version}" >> %{basepkg}.files\
elif [ -d "%{buildroot}%{_docdir}/ghc-%{pkgnamever}" ]; then\
  echo "%{_docdir}/ghc-%{pkgnamever}" >> %{basepkg}.files\
fi\
%endif\
echo "%{ghclibdir}/package.conf.d/%{pkgnamever}*.conf" >> %{basepkg}-devel.files\
if [ -d "%{buildroot}%{pkgdir}" ]; then\
find %{buildroot}%{pkgdir} -mindepth 1 -type d | sed "s/^/%dir /" >> %{basepkg}-devel.files\
find %{buildroot}%{pkgdir} ! \\( -type d -o -name "libHS*.so" \\) >> %{basepkg}-devel.files\
fi\
if [ -d "%{buildroot}%{docdir}" ]; then\
echo "%{docdir}" >> %{basepkg}-devel.files\
fi\
for i in %{basepkg}.files %{basepkg}-devel.files; do\
if [ -f "$i" ]; then\
sed -i -e "s!%{buildroot}!!g" $i\
fi\
done\
%{nil}

%ghc_add_basepkg_file()\
%define basepkg ghc-%{pkg_name}\
echo "%*" >> %{basepkg}.files

# compiler version
%ghc_version %{!?ghc_version_override:%(ghc --numeric-version)}%{?ghc_version_override}

# 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\
mkdir -p %{buildroot}%{ghclibdir}/package.conf.d\
install --mode=0644 %{pkgnamever}.conf %{buildroot}%{ghclibdir}/package.conf.d\
%{nil}

# devel pkg basic requires
%ghc_devel_requires Requires:       ghc-compiler = %{ghc_version}\
Requires(post): ghc-compiler = %{ghc_version}\
Requires(postun): ghc-compiler = %{ghc_version}\
%if 0%{!?-m:1}\
Requires:       ghc-%{?pkg_name}%{!?pkg_name:%{pkgname}} = %{?pkgver}%{!?pkgver:%{version}}-%{release}\
%endif

%ghc_shared_files\
%files -n %{basepkg} -f %{basepkg}.files\
%defattr(-,root,root,-)\
%{?base_doc_files:%doc %base_doc_files}\
%{nil}

# ghc_lib_package [-c cdepslist] [-h pkgdepslist]
%ghc_lib_package(c:h:)\
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define basepkg ghc-%{pkgname}\
%ghc_shared_files\
\
%ghc_package_devel\
%{nil}

# ghc_package [-l licensetag] [name] [version]
%ghc_package(l:)\
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define pkgver %{?2}%{!?2:%{version}}\
%define basepkg ghc-%{pkgname}\
%package -n %{basepkg}\
Summary:        %{?common_summary}%{!?common_summary:Haskell %{pkgname} library}\
Group:          System Environment/Libraries\
%{?1:Version:        %{pkgver}}\
%{-l:License:        %{-l*}}\
%{?ghc_pkg_obsoletes:Obsoletes:      %(echo "%{ghc_pkg_obsoletes}" | sed -e "s/\\(ghc-[^, ]*\\)-devel/\\1/g")}

# ghc_description [name] [version]
%ghc_description()\
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define basepkg ghc-%{pkgname}\
%description -n %{basepkg}\
%{?common_description}%{!?common_description:Haskell %{pkgname} library.}\
%if %{defined ghc_version} && %{undefined ghc_without_shared}\
This package provides the shared library.\
%endif

# ghc_lib_subpackage [-c cdepslist] [-h pkgdepslist] [-l licensetag] [-x] [name] [version]
%ghc_lib_subpackage(c:h:l:x)\
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define pkgver %{?2}%{!?2:%{version}}\
%define pkgnamever %{pkgname}-%{pkgver}\
%{!-x:%{?1:%global ghc_packages_list %{?ghc_packages_list} %{pkgnamever}}}\
%define basepkg ghc-%{pkgname}\
%ghc_package\
\
%ghc_description\
\
%ghc_lib_package\
%{nil}

# (deprecated) for docs post and postun
%ghc_reindex_haddock :

%ghc_devel_files\
%files -n %{basepkg}-devel -f %{basepkg}-devel.files\
%defattr(-,root,root,-)\
%{?devel_doc_files:%doc %devel_doc_files}\
%{nil}

%ghc_files()\
%{?1:%define base_doc_files %*}\
%define basepkg ghc-%{pkg_name}\
%ghc_shared_files\
\
%ghc_devel_files\
%{nil}

# ghc_devel_package [-c cdepslist] [-h pkgdepslist] [-l licensetag] [-m] [name] [version]
#  -m : meta-package
%ghc_devel_package(c:h:l:m)\
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define pkgver %{?2}%{!?2:%{version}}\
%define basepkg ghc-%{pkgname}\
%package -n %{basepkg}-devel\
Summary:        %{?common_summary}%{!?common_summary:Haskell %{pkgname} library} development files\
Group:          Development/Libraries\
%{?1:Version:        %{pkgver}}\
%{-l:License:        %{-l*}}\
%{?ghc_devel_requires}\
%{-h:Requires:       %{-h*}}\
%{?ghc_pkg_c_deps:Requires:       %{ghc_pkg_c_deps}}\
%{-c:Requires:       %{-c*}}\
%{?ghc_pkg_obsoletes:Obsoletes:      %{ghc_pkg_obsoletes}}\
%{?ghc_pkg_obsoletes:Obsoletes:      %(echo "%{ghc_pkg_obsoletes}" | sed -e "s/\\(ghc-[^, ]*\\)-devel/\\1-doc/g")}\
Obsoletes:      %{basepkg}-doc < %{pkgver}-%{release}\
Provides:       %{basepkg}-doc = %{pkgver}-%{release}\
Obsoletes:      %{basepkg}-prof < %{pkgver}-%{release}\
%if %{undefined without_prof}\
Provides:       %{basepkg}-prof = %{pkgver}-%{release}\
%endif

# ghc_devel_description
%ghc_devel_description()\
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define basepkg ghc-%{pkgname}\
%description -n %{basepkg}-devel\
%{?common_description}%{!?common_description:Haskell %{pkgname} library.}\
\
This package contains the development files.

# ghc_devel_post_postun
%ghc_devel_post_postun()\
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define basepkg ghc-%{pkgname}\
%post -n %{basepkg}-devel\
%ghc_pkg_recache\
\
%postun -n %{basepkg}-devel\
%ghc_pkg_recache

# ghc_package_devel [-c cdepslist] [-h pkgdepslist] [-l licensetag] [name] [version]
%ghc_package_devel(c:h:l:)\
%define pkgname %{?1}%{!?1:%{pkg_name}}\
%define basepkg ghc-%{pkgname}\
%ghc_devel_package\
\
%ghc_devel_description\
\
%ghc_devel_post_postun\
\
%ghc_devel_files\
%{nil}

# ghc_bin_build
%ghc_bin_build\
%global debug_package %{nil}\
%cabal_configure\
%cabal build

# ghc_lib_build_without_haddock [name] [version]
%ghc_lib_build_without_haddock()\
%global debug_package %{nil}\
%cabal_configure %{!?without_prof:-p} %{!?ghc_without_shared:--enable-shared} %{?1:--docdir=%{_docdir}/ghc-%1-%2 --htmldir=%{ghclibdocdir}/%1-%2} %{!?ghc_with_lib_for_ghci:--disable-library-for-ghci}\
%cabal build\
%{nil}

# ghc_lib_build [name] [version]
%ghc_lib_build()\
%ghc_lib_build_without_haddock\
%if %{undefined without_haddock}\
%cabal haddock --html %{!?without_hscolour:%(if [ -x %{_bindir}/HsColour ]; then echo --hyperlink-source; fi)} --hoogle\
%endif\
%{nil}

# ghc_strip_dynlinked
%ghc_strip_dynlinked\
%if %{undefined __debug_package}\
find %{buildroot} -type f -exec sh -c "file {} | grep -q 'dynamically linked'" \\; -exec strip "{}" \\;\
%endif

# install bin package
%ghc_bin_install()\
%global _use_internal_dependency_generator 0\
%global __find_requires %{_prefix}/lib/rpm/ghc-deps.sh --requires %{buildroot}%{ghclibdir}\
%cabal_install\
%{!?1:%ghc_strip_dynlinked}\
%{nil}

# ghc_lib_install [name] [version]
%ghc_lib_install()\
%global _use_internal_dependency_generator 0\
%global __find_provides %{_prefix}/lib/rpm/ghc-deps.sh --provides %{buildroot}%{ghclibdir}\
%global __find_requires %{_prefix}/lib/rpm/ghc-deps.sh --requires %{buildroot}%{ghclibdir}\
%cabal_install\
%cabal_pkg_conf\
%ghc_gen_filelists\
%{!?1:%ghc_strip_dynlinked}\
%{nil}

# ghc_fix_dynamic_rpath prog ...
%ghc_fix_dynamic_rpath()\
%if %{undefined ghc_without_dynamic}\
PDIR=$(cd ..; pwd)\
for i in %*; do\
  PROG=%{buildroot}%{_bindir}/$i\
  RPATH=$(chrpath $PROG| sed -e "s@^$PROG: RPATH=@@")\
  case $RPATH in\
    *$PDIR*)\
      NEWRPATH=$(echo $RPATH | sed -e "s@$PDIR@%{ghclibdir}@g" -e "s@/dist/build@@g")\
      chrpath -r $NEWRPATH $PROG\
      ;;\
  esac\
done\
%endif\
%{nil}

%ghc_pkg_recache %{_bindir}/ghc-pkg recache --no-user-package-conf || :

# - without_hscolour, without_testsuite, and ghc_bootstrapping
#   need to be set locally in the spec file

# skip prof libs, and documentation
%ghc_test\
%global without_prof 1\
%global without_haddock 1\
%global without_manual 1

# skip shared and prof libs, documentation, and testsuite
%ghc_bootstrap\
%global ghc_without_shared 1\
%global ghc_without_dynamic 1\
%ghc_test