From: Mike Furr <mfurr@debian.org>
Date: Wed, 4 May 2005 02:28:31 +0000
Subject: [PATCH] Fix Makefile to detect ocamlopt

Signed-off-by: Mike Furr <mfurr@debian.org>
Signed-off-by: Stephane Glondu <steph@glondu.net>
---
 Makefile |   29 ++++++++++++++++++++++++++---
 1 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 4827101..f79b054 100644
--- a/Makefile
+++ b/Makefile
@@ -20,6 +20,10 @@
 
 include Makefile.config
 
+ifeq (YES, $(shell if [ -x /usr/bin/ocamlopt ]; then echo YES; fi))
+HASOCAMLOPT := yes
+endif
+
 OCAMLC := ocamlc
 OCAMLOPT := ocamlopt
 OCAMLMKLIB := ocamlmklib
@@ -71,7 +75,11 @@ WRAPPERS := \
 	wrappers/pl_Template.cmo \
 	wrappers/pl_WWW_Mechanize.cmo
 
+ifdef HASOCAMLOPT
 all:	perl4caml.cma perl4caml.cmxa META all-examples html
+else
+all:	perl4caml.cma META all-examples html
+endif
 
 perl4caml.cma: perl.cmo perl_c.o $(WRAPPERS)
 	$(OCAMLMKLIB) -o perl4caml $(LIBPERL) $^
@@ -79,12 +87,20 @@ perl4caml.cma: perl.cmo perl_c.o $(WRAPPERS)
 perl4caml.cmxa: perl.cmx perl_c.o $(WRAPPERS:.cmo=.cmx)
 	$(OCAMLMKLIB) -o perl4caml $(LIBPERL) $^
 
+ifdef HASOCAMLOPT
 all-examples: examples/test.bc examples/loadpage.bc examples/google.bc \
 	examples/test.opt examples/loadpage.opt examples/google.opt \
 	examples/parsedate.bc examples/parsedate.opt
+else
+all-examples: examples/test.bc examples/loadpage.bc examples/google.bc \
+	examples/parsedate.bc
+endif
 
-TEST_PROGRAMS := $(patsubst %.ml,%.bc,$(wildcard test/*.ml)) \
-	$(patsubst %.ml,%.opt,$(wildcard test/*.ml))
+TEST_PROGRAMS := $(patsubst %.ml,%.bc,$(wildcard test/*.ml))
+
+ifdef HASOCAMLOPT
+TEST_PROGRAMS += $(patsubst %.ml,%.opt,$(wildcard test/*.ml))
+endif
 
 test: $(TEST_PROGRAMS) run-tests
 
@@ -161,10 +177,17 @@ install:
 	rm -rf $(DESTDIR)$(OCAMLLIBDIR)/perl
 	install -c -m 0755 -d $(DESTDIR)$(OCAMLLIBDIR)/perl
 	install -c -m 0755 -d $(DESTDIR)$(OCAMLLIBDIR)/stublibs
+ifdef HASOCAMLOPT
 	install -c -m 0644 perl.cmi perl.mli perl4caml.cma perl4caml.cmxa \
 	  perl4caml.a libperl4caml.a META \
 	  $(WRAPPERS:.cmo=.ml) $(WRAPPERS:.cmo=.cmi) \
 	  $(DESTDIR)$(OCAMLLIBDIR)/perl
+else
+	install -c -m 0644 perl.cmi perl.mli perl4caml.cma \
+	  META \
+	  $(WRAPPERS:.cmo=.ml) $(WRAPPERS:.cmo=.cmi) \
+	  $(DESTDIR)$(OCAMLLIBDIR)/perl
+endif
 	install -c -m 0644 dllperl4caml.so $(DESTDIR)$(OCAMLLIBDIR)/stublibs
 
 # Distribution.
@@ -220,4 +243,4 @@ html/index.html: $(wildcard *.ml) $(wildcard *.mli) $(wildcard wrappers/*.ml)
 	mkdir html
 	-$(OCAMLDOC) $(OCAMLDOCFLAGS) -d html $^
 
-.PHONY: depend dist check-manifest html dpkg test run-tests
\ No newline at end of file
+.PHONY: depend dist check-manifest html dpkg test run-tests
-- 
