#!/bin/sh -e
## make_bytecode.dpatch by Sylvain Le Gall <gildor@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.

if [ $# -lt 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi

[ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
patch_opts="${patch_opts:--f --no-backup-if-mismatch}"

case "$1" in
       -patch) patch $patch_opts -p1 < $0;;
       -unpatch) patch $patch_opts -p1 -R < $0;;
        *)
                echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
                exit 1;;
esac

exit 0

@DPATCH@
diff -urNad ocamlgsl~/Makefile ocamlgsl/Makefile
--- ocamlgsl~/Makefile	2010-04-20 21:56:43.000000000 +0200
+++ ocamlgsl/Makefile	2010-04-20 21:57:44.297632550 +0200
@@ -119,8 +119,10 @@
            $(wildcard test/*.ml) $(wildcard ocamlgsl.info*)
 VERSION := 0.6.0
 
-all : stubs gsl.cma gsl.cmxa $(CMI)
-
+all : all-opt
+all-byte : stubs gsl.cma $(CMI)
+all-opt : all-byte gsl.cmxa
+ 
 STUBS = libmlgsl.$(A)
 ifdef DYNAMIC_LINKING
 STUBS += dllmlgsl.$(D)
@@ -147,20 +149,27 @@
 top : libmlgsl.$(A) gsl.cma
 	ocamlmktop -I . -o ocamlgsl$(EXE) bigarray.cma gsl.cma
 
-install : all
+install : install-opt
+install-opt : all-opt
+	$(MAKE) install-byte
+install-byte : all-byte
 	mkdir -p $(DESTDIR)$(INSTALLDIR)
-	cp $(STUBS) gsl.cma gsl.cmxa gsl.$(A) \
-          $(CMI) $(MLOPTOBJ) $(DESTDIR)$(INSTALLDIR)
+	cp $(STUBS) gsl.cma $(wildcard gsl.cmxa) $(wildcard gsl.$(A)) \
+          $(CMI) $(wildcard $(MLOPTOBJ)) $(DESTDIR)$(INSTALLDIR)
 	mkdir -p $(DESTDIR)$(OCAMLDIR)/stublibs
 	if test -w $(DESTDIR)$(OCAMLDIR)/stublibs ; then \
           ln -sf $(INSTALLDIR)/dllmlgsl.$(D) $(DESTDIR)$(OCAMLDIR)/stublibs ; fi
 
-install-findlib : all
+install-findlib: install-findlib-opt
+install-findlib-opt : all-opt
+	$(MAKE) install-findlib-byte
+install-findlib-byte : all-byte
 	export FINDLIBDIR=$$($(OCAMLFIND) printconf destdir) ; \
 	test -d "$${FINDLIBDIR}/stublibs" && mkdir -p $(DESTDIR)$${FINDLIBDIR}/stublibs ; \
 	OCAMLFIND_DESTDIR=$(DESTDIR)$${FINDLIBDIR} \
         $(OCAMLFIND) install gsl META \
-          libmlgsl.$(A) dllmlgsl.$(D) gsl.cma gsl.cmxa gsl.$(A) $(CMI) $(MLOPTOBJ) 
+          libmlgsl.$(A) dllmlgsl.$(D) gsl.cma $(wildcard gsl.cmxa) $(wildcard gsl.$(A)) \
+	  $(CMI) $(wildcard $(MLOPTOBJ))
 
 ocamlgsl.odoc : $(MLOBJ) $(CMI)
 	$(OCAMLDOC) -v -dump $@ $(filter-out gsl_misc.%, $(filter %.mli, $(SRC)))
