diff options
author | David Allsopp <david.allsopp@metastack.com> | 2021-05-12 16:43:12 +0100 |
---|---|---|
committer | David Allsopp <david.allsopp@metastack.com> | 2022-05-11 16:45:35 +0100 |
commit | f4e120417651d8ca21fa0cdbe802dee57aa5e1b1 (patch) | |
tree | 13d0d4d7e75ec8dd7818af7f65ec23250778c4d1 /utils | |
parent | b9bf5ffd8ef780a77cc8ecb836a52297284dd4dc (diff) | |
download | ocaml-f4e120417651d8ca21fa0cdbe802dee57aa5e1b1.tar.gz |
Refactor MKEXE and introduce MKEXE_VIA_CC
Tidies up the flexlink aspects. Previously, it was viewed as MKEXE and a
special case needed in flexlink bootstrap to build the runtime without
using flexlink.
This commit moves the flags decisions into configure where they belong
and now exposes two versions of a command which links executables. MKEXE
_may_ link using a C compiler but may be a direct call to a wrapper for
a linker (i.e. flexlink). MKEXE_VIA_CC _always_ creates an executable by
calling the C compiler.
Rather than deriving the entire mkexe command line, configure now
determines what the _command_ will be (i.e. `$(CC)` or
`$(FLEXLINK_CMD)`) and the flags which get passed to that (and their
`-link` prefixes, if necessary) are computed _at the end of the
process_ which hopefully simplifies the number of special cases which
have to be considered during configuration.
Diffstat (limited to 'utils')
-rw-r--r-- | utils/Makefile | 7 | ||||
-rw-r--r-- | utils/config.mlp | 26 |
2 files changed, 18 insertions, 15 deletions
diff --git a/utils/Makefile b/utils/Makefile index 9c26fddba1..3afb6468ce 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -34,8 +34,10 @@ SUBST_QUOTE2=\ -e 's!%%$1%%!$(if $2,$(call SED_ESCAPE,"$(call OCAML_ESCAPE,$2)"))!' SUBST_QUOTE=$(call SUBST_QUOTE2,$1,$($1)) -FLEXLINK_LDFLAGS=$(if $(OC_LDFLAGS), -link "$(OC_LDFLAGS)") -FLEXLINK_DLL_LDFLAGS=$(if $(OC_DLL_LDFLAGS), -link "$(OC_DLL_LDFLAGS)") +prefix_and_quote = $(if $(1), $(2)$(if $(word 2,$(1)),"$(1)",$(1))) + +FLEXLINK_LDFLAGS = $(call prefix_and_quote,$(OC_LDFLAGS),-link $(EMPTY)) +FLEXLINK_DLL_LDFLAGS = $(call prefix_and_quote,$(OC_DLL_LDFLAGS),-link $(EMPTY)) config_main.ml: config.mlp $(ROOTDIR)/Makefile.config Makefile config.common.ml sed $(call SUBST,AFL_INSTRUMENT) \ @@ -57,6 +59,7 @@ config_main.ml: config.mlp $(ROOTDIR)/Makefile.config Makefile config.common.ml $(call SUBST,WITH_CMM_INVARIANTS) \ $(call SUBST_STRING,FLEXLINK_FLAGS) \ $(call SUBST_QUOTE,FLEXDLL_DIR) \ + $(call SUBST_STRING,FLEXDLL_CHAIN) \ $(call SUBST,HOST) \ $(call SUBST_STRING,BINDIR) \ $(call SUBST_STRING,LIBDIR) \ diff --git a/utils/config.mlp b/utils/config.mlp index 021d28579b..4b6343a9d9 100644 --- a/utils/config.mlp +++ b/utils/config.mlp @@ -47,21 +47,21 @@ let mksharedlibrpath = "%%MKSHAREDLIBRPATH%%" let ar = "%%ARCMD%%" let supports_shared_libraries = %%SUPPORTS_SHARED_LIBRARIES%% let mkdll, mkexe, mkmaindll = - (* @@DRA Cygwin - but only if shared libraries are enabled, which we - should be able to detect? *) if Sys.win32 || Sys.cygwin && supports_shared_libraries then - try + let flexlink = let flexlink = - let flexlink = Sys.getenv "OCAML_FLEXLINK" in - let f i = - let c = flexlink.[i] in - if c = '/' && Sys.win32 then '\\' else c in - (String.init (String.length flexlink) f) ^ " %%FLEXLINK_FLAGS%%" in - flexlink ^ "%%FLEXLINK_DLL_LDFLAGS%%", - flexlink ^ " -exe%%FLEXLINK_LDFLAGS%%", - flexlink ^ " -maindll%%FLEXLINK_DLL_LDFLAGS%%" - with Not_found -> - "%%MKDLL%%", "%%MKEXE%%", "%%MKMAINDLL%%" + Option.value ~default:"flexlink" (Sys.getenv_opt "OCAML_FLEXLINK") + in + let f i = + let c = flexlink.[i] in + if c = '/' && Sys.win32 then '\\' else c + in + String.init (String.length flexlink) f + in + let flags = " -chain %%FLEXDLL_CHAIN%% %%FLEXLINK_FLAGS%%" in + flexlink ^ flags ^ "%%FLEXLINK_DLL_LDFLAGS%%", + flexlink ^ " -exe" ^ flags ^ "%%FLEXLINK_LDFLAGS%%", + flexlink ^ " -maindll" ^ flags ^ "%%FLEXLINK_DLL_LDFLAGS%%" else "%%MKDLL%%", "%%MKEXE%%", "%%MKMAINDLL%%" |