2018-03-29 05:38:33 -07:00
|
|
|
#**************************************************************************
|
|
|
|
#* *
|
|
|
|
#* OCaml *
|
|
|
|
#* *
|
|
|
|
#* Gabriel Scherer, projet Parsifal, INRIA Saclay *
|
|
|
|
#* *
|
|
|
|
#* Copyright 2018 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. *
|
|
|
|
#* *
|
|
|
|
#**************************************************************************
|
|
|
|
|
2019-09-11 00:16:15 -07:00
|
|
|
# This makefile contains common definitions and rules shared by
|
|
|
|
# other Makefiles
|
2020-05-03 01:42:13 -07:00
|
|
|
|
2020-05-04 23:37:59 -07:00
|
|
|
include $(ROOTDIR)/Makefile.config_if_required
|
2018-03-29 05:38:33 -07:00
|
|
|
|
2020-04-17 06:11:22 -07:00
|
|
|
# %(DEPDIR) must be kept in sync with entries in .gitignore
|
|
|
|
DEPDIR=.dep
|
|
|
|
D=d
|
|
|
|
MKDIR=mkdir -p
|
|
|
|
|
2019-05-02 10:36:40 -07:00
|
|
|
DESTDIR ?=
|
2020-06-17 10:34:27 -07:00
|
|
|
INSTALL_BINDIR := $(DESTDIR)$(BINDIR)
|
|
|
|
INSTALL_LIBDIR := $(DESTDIR)$(LIBDIR)
|
|
|
|
INSTALL_STUBLIBDIR := $(DESTDIR)$(STUBLIBDIR)
|
|
|
|
INSTALL_MANDIR := $(DESTDIR)$(MANDIR)
|
2018-07-26 08:28:17 -07:00
|
|
|
|
|
|
|
ifeq "$(UNIX_OR_WIN32)" "win32"
|
|
|
|
FLEXDLL_SUBMODULE_PRESENT := $(wildcard $(ROOTDIR)/flexdll/Makefile)
|
2018-09-06 07:12:42 -07:00
|
|
|
else
|
|
|
|
FLEXDLL_SUBMODULE_PRESENT =
|
|
|
|
endif
|
|
|
|
|
2019-03-18 03:45:43 -07:00
|
|
|
# Use boot/ocamlc.opt if available
|
2020-06-17 00:29:56 -07:00
|
|
|
CAMLRUN ?= $(ROOTDIR)/boot/ocamlrun$(EXE)
|
2019-03-18 03:45:43 -07:00
|
|
|
ifeq (0,$(shell \
|
|
|
|
test $(ROOTDIR)/boot/ocamlc.opt -nt $(ROOTDIR)/boot/ocamlc; \
|
|
|
|
echo $$?))
|
|
|
|
BOOT_OCAMLC = $(ROOTDIR)/boot/ocamlc.opt
|
|
|
|
else
|
|
|
|
BOOT_OCAMLC = $(CAMLRUN) $(ROOTDIR)/boot/ocamlc
|
|
|
|
endif
|
|
|
|
|
2018-07-26 08:28:17 -07:00
|
|
|
ifeq "$(FLEXDLL_SUBMODULE_PRESENT)" ""
|
|
|
|
FLEXLINK_ENV =
|
2018-09-06 07:12:42 -07:00
|
|
|
CAMLOPT_CMD = $(CAMLOPT)
|
|
|
|
OCAMLOPT_CMD = $(OCAMLOPT)
|
|
|
|
MKLIB_CMD = $(MKLIB)
|
|
|
|
ocamlc_cmd = $(ocamlc)
|
|
|
|
ocamlopt_cmd = $(ocamlopt)
|
2018-07-26 08:28:17 -07:00
|
|
|
else
|
|
|
|
FLEXLINK_ENV = \
|
2018-09-06 07:12:42 -07:00
|
|
|
OCAML_FLEXLINK="$(ROOTDIR)/boot/ocamlrun $(ROOTDIR)/flexdll/flexlink.exe"
|
|
|
|
CAMLOPT_CMD = $(FLEXLINK_ENV) $(CAMLOPT)
|
|
|
|
OCAMLOPT_CMD = $(FLEXLINK_ENV) $(OCAMLOPT)
|
|
|
|
MKLIB_CMD = $(FLEXLINK_ENV) $(MKLIB)
|
|
|
|
ocamlc_cmd = $(FLEXLINK_ENV) $(ocamlc)
|
|
|
|
ocamlopt_cmd = $(FLEXLINK_ENV) $(ocamlopt)
|
2018-07-26 08:28:17 -07:00
|
|
|
endif
|
2019-05-07 02:32:05 -07:00
|
|
|
|
2020-04-06 07:40:27 -07:00
|
|
|
OPTCOMPFLAGS=
|
2020-04-06 07:45:50 -07:00
|
|
|
ifeq "$(FUNCTION_SECTIONS)" "true"
|
|
|
|
OPTCOMPFLAGS += -function-sections
|
|
|
|
endif
|
2019-05-07 02:32:05 -07:00
|
|
|
# By default, request ocamllex to be quiet
|
|
|
|
OCAMLLEX_FLAGS ?= -q
|
2019-09-11 00:16:15 -07:00
|
|
|
|
2020-02-05 09:29:43 -08:00
|
|
|
# Escape special characters in the argument string.
|
|
|
|
# There are four characters that need escaping:
|
|
|
|
# - backslash and ampersand, which are special in the replacement text
|
|
|
|
# of sed's "s" command
|
|
|
|
# - exclamation mark, which is the delimiter we use for sed's "s" command
|
|
|
|
# - single quote, which interferes with shell quoting. We are inside
|
|
|
|
# single quotes already, so the proper escape is '\''
|
|
|
|
# (close single quotation, insert single quote character,
|
|
|
|
# reopen single quotation).
|
|
|
|
SED_ESCAPE=$(subst ','\'',$(subst !,\!,$(subst &,\&,$(subst \,\\,$1))))
|
|
|
|
|
|
|
|
# Escape special characters in an OCaml string literal "..."
|
|
|
|
# There are two: backslash and double quote.
|
|
|
|
OCAML_ESCAPE=$(subst ",\",$(subst \,\\,$1))
|
|
|
|
|
|
|
|
# SUBST generates the sed substitution for the variable *named* in $1
|
|
|
|
SUBST=-e 's!%%$1%%!$(call SED_ESCAPE,$($1))!'
|
|
|
|
|
|
|
|
# SUBST_STRING does the same, for a variable that occurs between "..."
|
|
|
|
# in config.mlp. Thus, backslashes and double quotes must be escaped.
|
|
|
|
SUBST_STRING=-e 's!%%$1%%!$(call SED_ESCAPE,$(call OCAML_ESCAPE,$($1)))!'
|
|
|
|
|
2019-09-11 00:16:15 -07:00
|
|
|
# The rule to compile C files
|
|
|
|
|
|
|
|
# This rule is similar to GNU make's implicit rule, except that it is more
|
|
|
|
# general (it supports both .o and .obj)
|
|
|
|
|
2020-04-17 06:11:22 -07:00
|
|
|
ifneq "$(COMPUTE_DEPS)" "false"
|
2020-05-03 07:26:53 -07:00
|
|
|
RUNTIME_HEADERS :=
|
2020-04-17 06:11:22 -07:00
|
|
|
REQUIRED_HEADERS :=
|
|
|
|
else
|
|
|
|
RUNTIME_HEADERS := $(wildcard $(ROOTDIR)/runtime/caml/*.tbl) \
|
|
|
|
$(wildcard $(ROOTDIR)/runtime/caml/*.h)
|
|
|
|
REQUIRED_HEADERS := $(RUNTIME_HEADERS) $(wildcard *.h)
|
|
|
|
endif
|
|
|
|
|
2020-05-03 07:27:14 -07:00
|
|
|
%.$(O): %.c $(REQUIRED_HEADERS)
|
2020-07-28 08:44:59 -07:00
|
|
|
$(CC) -c $(OC_CFLAGS) $(CFLAGS) $(OC_CPPFLAGS) $(CPPFLAGS) \
|
|
|
|
$(OUTPUTOBJ)$@ $<
|
2020-04-17 06:11:22 -07:00
|
|
|
|
|
|
|
$(DEPDIR):
|
|
|
|
$(MKDIR) $@
|
2020-06-17 00:29:56 -07:00
|
|
|
|
|
|
|
# When executable files have an extension (e.g. ".exe"),
|
|
|
|
# provide phony synonyms
|
|
|
|
define PROGRAM_SYNONYM
|
|
|
|
ifneq ($(EXE),)
|
|
|
|
.PHONY: $(1)
|
|
|
|
$(1): $(1)$(EXE)
|
|
|
|
endif
|
|
|
|
endef # PROGRAM_SYNONYM
|