Makefile.best_binaries: only use the native tool when it is newer (not stale)

master
Gabriel Scherer 2019-07-30 09:29:58 +02:00
parent 879ddff59a
commit 23e2c6e610
1 changed files with 24 additions and 17 deletions

View File

@ -25,22 +25,29 @@
# native binary, if available. Note that they never use the boot/
# versions: we assume that ocamlc, ocamlopt, etc. have been run first.
ifeq "$(wildcard $(ROOTDIR)/ocamlc.opt)" ""
BEST_OCAMLC = $(CAMLRUN) $(ROOTDIR)/ocamlc
else
BEST_OCAMLC = $(ROOTDIR)/ocamlc.opt
endif
define define_best
ifeq "$(wildcard $(ROOTDIR)/$(3))" ""
$(1)=$(CAMLRUN) $(ROOTDIR)/$(2)
else
ifeq "$(shell \
if test $(ROOTDIR)/$(2) -nt $(ROOTDIR)/$(3); \
then echo 'stale'; else echo 'good'; fi)" "stale"
# the double-dollars ensure that the warning is displayed
# only if the conditional fires (by the `eval` call below)
# instead of always being shown as `define_best` is expanded.
$$(info Warning: we are not using the native binary $(3) \
because it is older than the bytecode binary $(2); \
you should silence this warning by either removing $(3) \
or rebuilding it (or `touch`-ing it) if you want it used.)
$(1)=$(CAMLRUN) $(ROOTDIR)/$(2)
else
$(1)=$(ROOTDIR)/$(3)
endif
endif
endef
$(eval $(call define_best,BEST_OCAMLC,ocamlc,ocamlc.opt))
$(eval $(call define_best,BEST_OCAMLOPT,ocamlopt,ocamlopt.opt))
$(eval $(call define_best,BEST_OCAMLLEX,lex/ocamllex,lex/ocamllex.opt))
BEST_OCAMLDEP = $(BEST_OCAMLC) -depend
ifeq "$(wildcard $(ROOTDIR)/ocamlopt.opt)" ""
BEST_OCAMLOPT = $(CAMLRUN) $(ROOTDIR)/ocamlopt
else
BEST_OCAMLOPT = $(ROOTDIR)/ocamlopt.opt
endif
ifeq "$(wildcard $(ROOTDIR)/lex/ocamllex.opt)" ""
BEST_OCAMLLEX = $(CAMLRUN) $(ROOTDIR)/lex/ocamllex
else
BEST_OCAMLLEX = $(ROOTDIR)/lex/ocamllex.opt
endif