1cf78745466033cb9811921305d29535ab124301
[fedora-mingw.git] / ocaml / mingw32-ocaml.spec
1 # Built-in strip corrupts binaries, so use the mingw32 strip instead:
2 %define __strip %{_mingw32_strip}
3 %define __objdump %{_mingw32_objdump}
4
5 %define debug_package %{nil}
6
7 %define otherlibraries win32unix str num dynlink bigarray systhreads win32graph
8
9 Name:           mingw32-ocaml
10 Version:        3.11.0+beta1
11 Release:        14%{?dist}
12 Summary:        Objective Caml MinGW cross-compiler and programming environment
13
14 License:        QPL and (LGPLv2+ with exceptions)
15 Group:          Development/Libraries
16
17 URL:            http://caml.inria.fr/
18 Source0:        http://caml.inria.fr/pub/distrib/ocaml-3.11/ocaml-%{version}.tar.bz2
19
20 # This is installed as config/Makefile when we cross-compile.
21 Source1000:     Makefile-fedora-mingw.in
22 Source1001:     README.Fedora
23
24 # XXX We should apply any Fedora native patches here.
25
26 # For patch description, see the top of each patch file.
27 # Start numbering at 1000 since these are MinGW-specific patches.
28 Patch1000:      mingw32-ocaml-3.11.0+beta1-combined-Makefile.patch
29 Patch1001:      mingw32-ocaml-3.11.0+beta1-disable-cmxs.patch
30 Patch1002:      mingw32-ocaml-3.11.0+beta1-filename-win32-dirsep.patch
31 Patch1003:      mingw32-ocaml-3.11.0+beta1-i386-profiling.patch
32 Patch1004:      mingw32-ocaml-3.11.0+beta1-no-stdlib-dir.patch
33 Patch1005:      mingw32-ocaml-3.11.0+beta1-win32-fixes.patch
34 Patch1006:      mingw32-ocaml-3.11.0+beta1-win32unix-path.patch
35
36 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
37 # Is it noarch? (XXX)
38 # Answer: yes and no.  In theory it should be, but because we install
39 # Windows binaries in %{_libdir}, the path is different if built on
40 # 32 and 64 bit platforms.  We should probably install the binaries
41 # in /usr/share.
42 BuildArch:      noarch
43
44 BuildRequires:  mingw32-filesystem >= 30
45 BuildRequires:  mingw32-gcc
46 BuildRequires:  mingw32-binutils
47 BuildRequires:  mingw32-flexdll
48
49 # These are required so we can use gcc -m32 and link to 32 bit X11:
50 BuildRequires:  /lib/libgcc_s.so.1
51 BuildRequires:  /usr/lib/crt1.o
52 BuildRequires:  /usr/lib/libX11.so
53
54 # While we still ship bytecode, this requires a /usr/bin/ocamlrun from
55 # the _identical_ native package.  We don't have that at the moment,
56 # which is why this is commented out.
57 #Requires:       ocaml-runtime = %{version}
58
59 # The built program will try to run the cross-compiler and flexdll, so
60 # these must be runtime requires.
61 Requires:       mingw32-gcc
62 Requires:       mingw32-binutils
63 Requires:       mingw32-flexdll
64
65 # i686-pc-mingw32-ocamlmklib tries to run ocamlopt which is probably a
66 # bug, but requires this (XXX).
67 Requires:       ocaml
68
69
70 %description
71 Objective Caml is a high-level, strongly-typed, functional and
72 object-oriented programming language from the ML family of languages.
73
74 This package is an OCaml cross-compiler which runs natively on Fedora
75 and produces Windows native executables.
76
77
78 %prep
79 %setup -q -n ocaml-%{version}
80
81 %patch1000 -p1
82 %patch1001 -p1
83 %patch1002 -p1
84 %patch1003 -p1
85 %patch1004 -p1
86 %patch1005 -p1
87 %patch1006 -p0
88
89
90 %build
91 # Don't run out of memory.
92 ulimit -s unlimited
93
94 # Build native ocamlrun and ocamlc which contain the
95 # filename-win32-dirsep patch.
96 #
97 # Note that we must build a 32 bit compiler, even on 64 bit build
98 # architectures, because this compiler will try to do strength
99 # reduction optimizations using its internal int type, and that must
100 # match Windows' int type.  (That's what -cc and -host are for).
101 ./configure \
102   -no-tk \
103   -bindir %{_bindir} \
104   -libdir %{_libdir}/ocaml \
105   -mandir %{_mandir}/man1 \
106   -cc "gcc -m32" -host i386-pc-linux -x11lib /usr/lib -verbose
107 make world
108
109 # Now move the working ocamlrun, ocamlc into the boot/ directory,
110 # overwriting the binary versions which ship with the compiler with
111 # ones that contain the above filename-win32-dirsep patch.
112 make coreboot
113
114 # Now replace the compiler configuration (config/{s.h,m.h,Makefile})
115 # with ones as they would be on a 32 bit Windows system.
116 pushd config
117
118 # config/m.h can just be copied from config/m-nt.h which ships.
119 rm -f m.h
120 cp m-nt.h m.h
121
122 # config/s.h can just be copied from config/s-nt.h which ships.
123 rm -f s.h
124 cp s-nt.h s.h
125
126 # config/Makefile is a custom one which we supply.
127 rm -f Makefile
128 sed \
129   -e 's,@prefix@,%{_prefix},g' \
130   -e 's,@bindir@,%{_bindir},g' \
131   -e 's,@libdir@,%{_libdir},g' \
132   -e 's,@target@,%{_mingw32_target},g' \
133   -e 's,@otherlibraries@,%{otherlibraries},g' \
134   < %{SOURCE1000} > Makefile
135
136 popd
137
138 # We're going to build in otherlibs/win32unix and otherlibs/win32graph
139 # directories, but since they would normally only be built under
140 # Windows, they only have the Makefile.nt files.  Just symlink
141 # Makefile -> Makefile.nt for these cases.
142 for d in otherlibs/win32unix otherlibs/win32graph; do
143   ln -s Makefile.nt $d/Makefile
144 done
145
146 # Now clean the temporary files from the previous build.  This
147 # will also cause asmcomp/arch.ml (etc) to be linked to the 32 bit
148 # i386 versions, essentially causing ocamlopt to use the Win/i386 code
149 # generator.
150 make partialclean
151
152 # Just rebuild some small bits that we need for the following
153 # 'make opt' to work.  Note that 'make all' fails here.
154 make -C byterun libcamlrun.a
155 make ocaml ocamlc
156 make -C stdlib
157 make -C tools ocamlmklib
158
159 # Build ocamlopt
160 make opt
161
162 cp %{SOURCE1001} .
163
164
165 %install
166 rm -rf $RPM_BUILD_ROOT
167
168 mkdir -p $RPM_BUILD_ROOT%{_bindir}
169 mkdir -p $RPM_BUILD_ROOT%{_libdir}/%{_mingw32_target}-ocaml
170 mkdir -p $RPM_BUILD_ROOT%{_libdir}/%{_mingw32_target}-ocaml/threads
171 mkdir -p $RPM_BUILD_ROOT%{_libdir}/%{_mingw32_target}-ocaml/stublibs
172
173 # This is the equivalent of 'make install installopt', but
174 # we only want to install the parts which are really necessary
175 # for the cross-compiler.  eg. We don't need any of the native
176 # tools like ocamllex or ocamldoc.
177 %define makevars BINDIR=$RPM_BUILD_ROOT%{_bindir} LIBDIR=$RPM_BUILD_ROOT%{_libdir}/%{_mingw32_target}-ocaml
178 make %{makevars} -C byterun install
179 make %{makevars} -C stdlib install
180 for i in %{otherlibraries}; do
181   make %{makevars} -C otherlibs/$i install
182 done
183 make %{makevars} -C tools install
184 make %{makevars} installopt
185
186 install -m 0755 ocamlc $RPM_BUILD_ROOT%{_bindir}
187
188 cp config/Makefile \
189    $RPM_BUILD_ROOT%{_libdir}/%{_mingw32_target}-ocaml/Makefile.config
190
191 # For bytecode binaries, change the bang-path to point to the locally
192 # installed ocamlrun.
193 pushd $RPM_BUILD_ROOT%{_bindir}
194 for f in ocamlc ocamlcp ocamldep ocamlmklib ocamlopt ocamlprof; do
195   mv $f $f.old
196   echo '#!%{_bindir}/%{_mingw32_target}-ocamlrun' > $f
197   tail -n +2 $f.old >> $f
198   chmod +x $f
199   rm $f.old
200 done
201 popd
202
203 # Rename all the binaries to target-binary.
204 pushd $RPM_BUILD_ROOT%{_bindir}
205 for f in ocamlc ocamlcp ocamldep ocamlmklib ocamlmktop ocamlopt ocamlprof ocamlrun; do
206   mv $f %{_mingw32_target}-$f
207 done
208 popd
209
210
211 %clean
212 rm -rf $RPM_BUILD_ROOT
213
214
215 %files
216 %defattr(-,root,root)
217 %doc README.Fedora
218 %{_bindir}/%{_mingw32_target}-ocamlc
219 %{_bindir}/%{_mingw32_target}-ocamlcp
220 %{_bindir}/%{_mingw32_target}-ocamldep
221 %{_bindir}/%{_mingw32_target}-ocamlmklib
222 %{_bindir}/%{_mingw32_target}-ocamlmktop
223 %{_bindir}/%{_mingw32_target}-ocamlprof
224 %{_bindir}/%{_mingw32_target}-ocamlopt
225 %{_bindir}/%{_mingw32_target}-ocamlrun
226 %{_libdir}/%{_mingw32_target}-ocaml/
227
228
229 %changelog
230 * Mon Nov 17 2008 Richard W.M. Jones <rjones@redhat.com> - 3.11.0+beta1-14
231 - Added README.Fedora.
232
233 * Sun Nov 16 2008 Richard W.M. Jones <rjones@redhat.com> - 3.11.0+beta1-13
234 - Build the native compiler as 32 bits even on a 64 bit build
235   architecture (because the target, Windows, is 32 bit).  The
236   compiler does strength reduction and other optimizations
237   internally so we must ensure it uses the same int type.
238 - Requires libX11-devel.i386 and libgcc.i386.
239 - Allow the normal dependency generators to run because this
240   is a native package.
241 - Use mingw32 strip to avoid corrupting binaries.
242
243 * Sun Nov 16 2008 Richard W.M. Jones <rjones@redhat.com> - 3.11.0+beta1-8
244 - Install ocamlc.
245
246 * Sat Nov 15 2008 Richard W.M. Jones <rjones@redhat.com> - 3.11.0+beta1-7
247 - Further requirements.
248
249 * Sat Nov 15 2008 Richard W.M. Jones <rjones@redhat.com> - 3.11.0+beta1-6
250 - Install tools, particularly ocamlmklib.
251
252 * Sat Nov 15 2008 Richard W.M. Jones <rjones@redhat.com> - 3.11.0+beta1-5
253 - +Requires mingw32-flexdll and the cross-compiler.
254
255 * Sat Nov 15 2008 Richard W.M. Jones <rjones@redhat.com> - 3.11.0+beta1-4
256 - Initial RPM release.