ocaml/Makefile.best_binaries

54 lines
2.4 KiB
Makefile
Raw Normal View History

#**************************************************************************
#* *
#* OCaml *
#* *
#* Gabriel Scherer, projet Parsifal, INRIA Saclay *
#* *
#* Copyright 2019 Institut National de Recherche en Informatique et *
#* en Automatique. *
#* *
#* All rights reserved. This file is distributed under the terms of *
#* the GNU Lesser General Public License version 2.1, with the *
#* special exception on linking described in the file LICENSE. *
#* *
#**************************************************************************
# This Makefile should be included.
# It expects:
# - Makefile.common to be included as well
# - a ROOTDIR variable pointing to the repository root
# relative to the including Makefile
# It exports definitions of BEST_OCAML{C,OPT,LEX,DEP} commands that
# run to either the bytecode binary built in the repository or the
# native binary, if available. Note that they never use the boot/
# versions: we assume that ocamlc, ocamlopt, etc. have been run first.
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