-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
-
-# ocamlopt is a cross-compiler, so rename the binary.
-# XXX This should probably use %{_mingw32_target} macro.
-mv $RPM_BUILD_ROOT%{_bindir}/ocamlopt \
- $RPM_BUILD_ROOT%{_bindir}/i686-pc-mingw32-ocamlopt
+mkdir -p $RPM_BUILD_ROOT%{_libdir}/%{_mingw32_target}-ocaml
+mkdir -p $RPM_BUILD_ROOT%{_libdir}/%{_mingw32_target}-ocaml/threads
+
+# 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
+make %{makevars} installopt
+
+cp config/Makefile \
+ $RPM_BUILD_ROOT%{_libdir}/%{_mingw32_target}-ocaml/Makefile.config
+
+# Rename the binaries so they don't clash with base OCaml package.
+mv $RPM_BUILD_ROOT%{_bindir}/ocamlrun \
+ $RPM_BUILD_ROOT%{_bindir}/%{_mingw32_target}-ocamlrun
+echo '#!%{_bindir}/%{_mingw32_target}-ocamlrun' \
+ > $RPM_BUILD_ROOT%{_bindir}/%{_mingw32_target}-ocamlopt
+tail -n +2 $RPM_BUILD_ROOT%{_bindir}/ocamlopt \
+ >> $RPM_BUILD_ROOT%{_bindir}/%{_mingw32_target}-ocamlopt
+chmod 0755 $RPM_BUILD_ROOT%{_bindir}/%{_mingw32_target}-ocamlopt
+rm $RPM_BUILD_ROOT%{_bindir}/ocamlopt