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