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