-mkdir -p $RPM_BUILD_ROOT%{_libdir}/i686-pc-mingw32-ocaml
-mkdir -p $RPM_BUILD_ROOT%{_libdir}/i686-pc-mingw32-ocaml/threads
-
-make installopt \
- BINDIR=$RPM_BUILD_ROOT%{_bindir} \
- LIBDIR=$RPM_BUILD_ROOT%{_libdir}/i686-pc-mingw32-ocaml
+mkdir -p $RPM_BUILD_ROOT%{_libdir}/%{_mingw32_target}-ocaml
+mkdir -p $RPM_BUILD_ROOT%{_libdir}/%{_mingw32_target}-ocaml/threads
+mkdir -p $RPM_BUILD_ROOT%{_libdir}/%{_mingw32_target}-ocaml/stublibs
+
+# This is the equivalent of 'make install installopt', but
+# we only want to install the parts which are really necessary
+# for the cross-compiler. eg. We don't need any of the native
+# tools like ocamllex or ocamldoc.
+%define makevars BINDIR=$RPM_BUILD_ROOT%{_bindir} LIBDIR=$RPM_BUILD_ROOT%{_libdir}/%{_mingw32_target}-ocaml
+make %{makevars} -C byterun install
+make %{makevars} -C stdlib install
+for i in %{otherlibraries}; do
+ make %{makevars} -C otherlibs/$i install
+done
+make %{makevars} -C tools install
+make %{makevars} installopt
+
+cp config/Makefile \
+ $RPM_BUILD_ROOT%{_libdir}/%{_mingw32_target}-ocaml/Makefile.config
+
+# For bytecode binaries, change the bang-path to point to the locally
+# installed ocamlrun.
+pushd $RPM_BUILD_ROOT%{_bindir}
+for f in ocamlcp ocamldep ocamlmklib ocamlopt ocamlprof; do
+ mv $f $f.old
+ echo '#!%{_bindir}/%{_mingw32_target}-ocamlrun' > $f
+ tail -n +2 $f.old >> $f
+ chmod +x $f
+ rm $f.old
+done
+popd