# Conditional build:
%bcond_without emacs # without emacs subpackage
%bcond_without x # without X11 support
+%bcond_without opt # don't build native, optimized compiler
+
+%ifarch x32
+%undefine with_opt
+%endif
%define sver 4.02
# Source5-md5: 77fa1da7375dea1393cc0b6cd802d7e1
Patch1: %{name}-CFLAGS.patch
Patch2: %{name}-as_needed.patch
+Patch3: x32.patch
URL: http://caml.inria.fr/
%{?with_x:BuildRequires: xorg-lib-libX11-devel}
%if %{with emacs}
cp %{SOURCE2} docs/ocaml.ps.gz
%patch1 -p1
%patch2 -p1
+%patch3 -p1
%build
cp -f /usr/share/automake/config.sub config/gnu
./configure \
+ -host %{_target_platform} \
-cc "%{__cc}" \
-bindir %{_bindir} \
-libdir %{_libdir}/%{name} \
-mandir %{_mandir}/man1 \
- -host %{_host} \
-with-pthread \
-x11lib %{_libdir}
-%{__make} -j1 world bootstrap opt.opt CFLAGS="%{rpmcflags} -Wall -DUSE_INTERP_RESULT"
-%{__make} -C tools objinfo CFLAGS="%{rpmcflags} -Wall -DUSE_INTERP_RESULT" -j1
+%{__make} -j1 world bootstrap %{?with_opt:opt.opt} \
+ CFLAGS="%{rpmcflags} -Wall -DUSE_INTERP_RESULT"
+
+%{__make} -C tools objinfo \
+ CFLAGS="%{rpmcflags} -Wall -DUSE_INTERP_RESULT" -j1
%install
rm -rf $RPM_BUILD_ROOT
# compiled sources of compiler, needed by some programs
for f in {asm,byte}comp parsing typing utils ; do
install -d $RPM_BUILD_ROOT%{_libdir}/%{name}/compiler/$f
- cp $f/*.{cmi,cmo,cmx,o} $RPM_BUILD_ROOT%{_libdir}/%{name}/compiler/$f
+ cp $f/*.{cmi,cmo} $RPM_BUILD_ROOT%{_libdir}/%{name}/compiler/$f
+ %{?with_opt:cp $f/*.{cmx,o} $RPM_BUILD_ROOT%{_libdir}/%{name}/compiler/$f}
done
# this isn't installed by default, but is useful
%attr(755,root,root) %{_bindir}/ocaml
%attr(755,root,root) %{_bindir}/ocamlbuild*
%attr(755,root,root) %{_bindir}/ocamlc
-%attr(755,root,root) %{_bindir}/ocamlc.*
+%{?with_opt:%attr(755,root,root) %{_bindir}/ocamlc.*}
%attr(755,root,root) %{_bindir}/ocamlcp
%attr(755,root,root) %{_bindir}/ocamldebug
%attr(755,root,root) %{_bindir}/ocamldep*
%attr(755,root,root) %{_bindir}/ocamlmklib
%attr(755,root,root) %{_bindir}/ocamlmktop
%attr(755,root,root) %{_bindir}/ocamlobjinfo
-%attr(755,root,root) %{_bindir}/ocamlopt
-%attr(755,root,root) %{_bindir}/ocamlopt.*
+%{?with_opt:%attr(755,root,root) %{_bindir}/ocamlopt}
+%{?with_opt:%attr(755,root,root) %{_bindir}/ocamlopt.*}
%attr(755,root,root) %{_bindir}/ocamloptp
%attr(755,root,root) %{_bindir}/ocamlprof
%attr(755,root,root) %{_bindir}/ocamlyacc
%dir %{_libdir}/%{name}/vmthreads/*.cm*
%dir %{_libdir}/%{name}/vmthreads/*.a
%{_libdir}/%{name}/*.a
-%{_libdir}/%{name}/*.o
+%{?with_opt:%{_libdir}/%{name}/*.o}
%{_libdir}/%{name}/*.cm*
%exclude %{_libdir}/%{name}/*graphics*
%{_libdir}/%{name}/Makefile.config
%files x11graphics-devel
%defattr(644,root,root,755)
%{_libdir}/%{name}/graphics*.cm*
-%{_libdir}/%{name}/graphics.a
+%{?with_opt:%{_libdir}/%{name}/graphics.a}
%{_libdir}/%{name}/libgraphics.a
%endif
%files ocamldoc-devel
%defattr(644,root,root,755)
%{_libdir}/%{name}/ocamldoc/*.cm*
-%{_libdir}/%{name}/ocamldoc/*.a
+%{?with_opt:%{_libdir}/%{name}/ocamldoc/*.a}
%files examples
%defattr(644,root,root,755)
--- /dev/null
+Package: src:ocaml
+Version: 4.02.1-2
+Severity: wishlist
+Tags: patch
+User: debian-x32@lists.debian.org
+Usertags: port-x32
+
+
+Please apply the attached patch, it adds support for x32 (as non-native).
+It's made against 4.02.1-2 (in experimental) as I guess you're not going
+to ever upload 4.01 again other than for eventual RC bug fixes.
+
+As you can see, the main problem is the current code confusing x32 for
+sometimes amd64 sometimes i386. I guess adding native optimized support
+wouldn't be hard (copying parts of i386 and parts of amd64...), but, not
+knowing anything about ocaml or the compiler, I preferred to keep it safe.
+</pre><pre>--- ocaml-4.02.1.orig/byterun/signals_machdep.h
++++ ocaml-4.02.1/byterun/signals_machdep.h
+@@ -25,10 +25,19 @@
+
+ #elif defined(__GNUC__) && defined(__x86_64__)
+
++#ifdef __ILP32__
++/* x32 */
++#define Read_and_clear(dst,src) \
++ asm("xorl %0, %0; xchgl %0, %1" \
++ : "=r" (dst), "=m" (src) \
++ : "m" (src))
++#else
++/* amd64 */
+ #define Read_and_clear(dst,src) \
+ asm("xorq %0, %0; xchgq %0, %1" \
+ : "=r" (dst), "=m" (src) \
+ : "m" (src))
++#endif
+
+ #elif defined(__GNUC__) && defined(__ppc__)
+
+--- ocaml-4.02.1.orig/configure
++++ ocaml-4.02.1/configure
+@@ -832,6 +832,7 @@ case "$target" in
+ arm*-*-linux-gnueabi) arch=arm; system=linux_eabi;;
+ arm*-*-openbsd*) arch=arm; system=bsd;;
+ zaurus*-*-openbsd*) arch=arm; system=bsd;;
++ x86_64-*-linux-gnux32) arch=x32; system=linux;;
+ x86_64-*-linux*) arch=amd64; system=linux;;
+ x86_64-*-gnu*) arch=amd64; system=gnu;;
+ x86_64-*-freebsd*) arch=amd64; system=freebsd;;
+--- ocaml-4.02.1.orig/otherlibs/num/bng.c
++++ ocaml-4.02.1/otherlibs/num/bng.c
+@@ -17,7 +17,7 @@
+ #include "config.h"
+
+ #if defined(__GNUC__) && BNG_ASM_LEVEL > 0
+-#if defined(BNG_ARCH_ia32)
++#if defined(BNG_ARCH_ia32) || defined(BNG_ARCH_x32)
+ #include "bng_ia32.c"
+ #elif defined(BNG_ARCH_amd64)
+ #include "bng_amd64.c"
+--- ocaml-4.02.1.orig/otherlibs/num/bng_ia32.c
++++ ocaml-4.02.1/otherlibs/num/bng_ia32.c
+@@ -187,7 +187,7 @@ static bngdigit bng_ia32_mult_sub_digit
+ This is faster than the plain IA32 code above on the Pentium 4.
+ (Arithmetic operations with carry are slow on the Pentium 4). */
+
+-#if BNG_ASM_LEVEL >= 2
++#if BNG_ASM_LEVEL >= 2 || defined(__x86_64__)
+
+ static bngcarry bng_ia32sse2_add
+ (bng a/*[alen]*/, bngsize alen,
+@@ -393,6 +393,13 @@ static int bng_ia32_sse2_supported(void)
+
+ static void bng_ia32_setup_ops(void)
+ {
++#ifdef __x86_64__
++ /* x32 -- SSE2 always supported */
++ bng_ops.add = bng_ia32sse2_add;
++ bng_ops.sub = bng_ia32sse2_sub;
++ bng_ops.mult_add_digit = bng_ia32sse2_mult_add_digit;
++ bng_ops.mult_sub_digit = bng_ia32sse2_mult_sub_digit;
++#else
+ #if BNG_ASM_LEVEL >= 2
+ if (bng_ia32_sse2_supported()) {
+ bng_ops.add = bng_ia32sse2_add;
+@@ -406,6 +413,7 @@ static void bng_ia32_setup_ops(void)
+ bng_ops.sub = bng_ia32_sub;
+ bng_ops.mult_add_digit = bng_ia32_mult_add_digit;
+ bng_ops.mult_sub_digit = bng_ia32_mult_sub_digit;
++#endif
+ }
+
+ #define BNG_SETUP_OPS bng_ia32_setup_ops()
+--- ocaml-4.02.1.orig/testsuite/makefiles/Makefile.common
++++ ocaml-4.02.1/testsuite/makefiles/Makefile.common
+@@ -68,7 +68,7 @@ OCAMLMKLIB=$(OCAMLRUN) $(OTOPDIR)/tools/
+ OCAMLYACC=$(TOPDIR)/yacc/ocamlyacc$(EXE)
+ OCAMLBUILD=$(TOPDIR)/_build/ocamlbuild/ocamlbuild.native
+ DUMPOBJ=$(OCAMLRUN) $(OTOPDIR)/tool/dumpobj
+-BYTECODE_ONLY=[ "$(ARCH)" = "none" -o "$(ASM)" = "none" ]
++BYTECODE_ONLY=[ "$(ARCH)" = "none" -o "$(ARCH)" = "x32" -o "$(ASM)" = "none" ]
+
+ #FORTRAN_COMPILER=
+ #FORTRAN_LIBRARY=