From 252aa149a8c1e8df04c02d1b8be1501f122526ad Mon Sep 17 00:00:00 2001 From: letouzey Date: Thu, 4 Mar 2010 16:18:23 +0000 Subject: Makefile: try to avoid rare make failures related with make -j + ocamlopt + .cmi As said now in a comment of Makefile.build: NB: for the moment ocamlopt erases and recreates .cmi if there's no .mli around. This can lead to nasty things with make -j (e.g. another process accessing a partial .cmi). To avoid that: 1) We make .cmx always depend on .cmi 2) This .cmi will be created from the .mli, or trigger the compilation of the .cmo if there's no .mli (see rule below about MLWITHOUTMLI) 3) We tell ocamlopt to output to temporary names, remove the temp .cmi (since the actual .cmi should already be there and up-to-date) and move the temp .cmx and .o back in place Ok, this is quite a hack. I'll make a proper bug report to ocaml asap... git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@12837 85f007b7-540e-0410-9357-904b9bb8a0f7 --- Makefile.build | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile.build b/Makefile.build index 130435f77..eb1ab45be 100644 --- a/Makefile.build +++ b/Makefile.build @@ -748,9 +748,23 @@ COND_OPTFLAGS= \ $(SHOW)'OCAMLC $<' $(HIDE)$(OCAMLC) $(COND_BYTEFLAGS) -c $< +## NB: for the moment ocamlopt erases and recreates .cmi if there's no .mli around. +## This can lead to nasty things with make -j. To avoid that: +## 1) We make .cmx always depend on .cmi +## 2) This .cmi will be created from the .mli, or trigger the compilation of the +## .cmo if there's no .mli (see rule below about MLWITHOUTMLI) +## 3) We tell ocamlopt to output to temporary names, remove the temp .cmi +## (since the actual .cmi should already be there and up-to-date) and move +## the temp .cmx and .o back in place + +$(MLFILES:.ml=.cmx): %.cmx: %.cmi + +$(MLWITHOUTMLI:.ml=.cmi): %.cmi: %.cmo + %.cmx: %.ml | %.ml.d $(SHOW)'OCAMLOPT $<' - $(HIDE)$(OCAMLOPT) $(COND_OPTFLAGS) -c $< + $(HIDE)$(OCAMLOPT) $(COND_OPTFLAGS) -c -o $*.tmp.cmx $< && \ + rm -f $*.tmp.cmi && mv -f $*.tmp.o $*.o && mv -f $*.tmp.cmx $*.cmx %.cmxs: %.cmxa $(SHOW)'OCAMLOPT -shared -o $@' -- cgit v1.2.3