From 4ab2e100f97da1a4251137dfaf473af705f0274f Mon Sep 17 00:00:00 2001 From: Samuel Hym Date: Fri, 23 Feb 2024 16:56:07 +0100 Subject: [PATCH 12/14] WIP Add a Makefile.cross for recipes to build a cross-compiler Define cross.opt and cross-install targets FIXME: Problems of inconsistencies between compilation options (only about zstd?) between the native toolchain and the cross toolchain may break the build? --- Makefile | 2 ++ Makefile.cross | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Makefile.cross diff --git a/Makefile b/Makefile index df191af79c..cb6b3f4484 100644 --- a/Makefile +++ b/Makefile @@ -2732,6 +2732,8 @@ endif include .depend +include Makefile.cross + Makefile.config Makefile.build_config: config.status config.status: @echo "Please refer to the installation instructions:" diff --git a/Makefile.cross b/Makefile.cross new file mode 100644 index 0000000000..b993783d2f --- /dev/null +++ b/Makefile.cross @@ -0,0 +1,83 @@ +#************************************************************************** +#* * +#* OCaml * +#* * +#* Samuel Hym, Tarides * +#* * +#* Copyright 2024 Tarides * +#* * +#* 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. * +#* * +#************************************************************************** + +# Recipes to build a cross-compiler (_not_ cross-compiling the compiler), aka +# generating code that will run on `target`, assuming that a non-cross OCaml +# compiler (so targetting our build machine) of the same version is available in +# $PATH + +# We assume no zstd for the cross-compiler (ie no requirement on zstd for the +# target) +# Still the cross-compiler will run on host, not target. And as a consequence of +# the rules linking it, the cross-compilers will be linked with the _build_ +# version of libcomprmarsh, so we still must discover the flags to link with +# libzstd if it was set up in the non-cross compiler, so we rely on the +# pkg-config command to get the linking flags for zstd +PKG_CONFIG := pkg-config +# This is used only once, so it doesn't have to be much lazier +NATIVE_ZSTD_LIBS=ZSTD_LIBS="$(shell $(PKG_CONFIG) --libs libzstd)" +# As the libcomprmarsh built by the C cross compiler will not be linked in, we +# can build an empty one +NO_ZSTD=libcomprmarsh_OBJECTS= + +CROSS_OVERRIDES=OCAMLRUN=ocamlrun NEW_OCAMLRUN=ocamlrun \ + BOOT_OCAMLLEX=ocamllex OCAMLYACC=ocamlyacc +CROSS_COMPILER_OVERRIDES=$(CROSS_OVERRIDES) CAMLC=ocamlc CAMLOPT=ocamlopt \ + BEST_OCAMLC=ocamlc BEST_OCAMLOPT=ocamlopt BEST_OCAMLLEX=ocamllex + +INSTALL_OVERRIDES=build_ocamldoc=false WITH_DEBUGGER= + +# Freestanding target custom options +ifeq "$(SYSTEM)" "none" +RUNTIME_BUILD_OVERRIDES=runtime_PROGRAMS= +INSTALL_OVERRIDES += runtime_PROGRAMS=`which ocamlrun` \ + runtime_BYTECODE_STATIC_LIBRARIES=runtime/ld.conf +else +RUNTIME_BUILD_OVERRIDES= +endif + +cross.opt: + $(MAKE) runtime-all $(NO_ZSTD) $(RUNTIME_BUILD_OVERRIDES) + $(MAKE) ocamlc ocamlopt $(TOOLS_BYTECODE_TARGETS) expunge \ + $(CROSS_COMPILER_OVERRIDES) + $(MAKE) library $(CROSS_OVERRIDES) +ifneq "$(SYSTEM)" "none" + $(MAKE) ocamlyacc $(CROSS_OVERRIDES) + $(MAKE) ocamllex $(CROSS_COMPILER_OVERRIDES) +endif + $(MAKE) ocaml $(CROSS_COMPILER_OVERRIDES) + $(MAKE) -C otherlibs all $(CROSS_OVERRIDES) + # Opt + $(MAKE) runtimeopt $(NO_ZSTD) + $(MAKE) ocamlc.opt ocamlopt.opt $(TOOLS_NATIVE_TARGETS) \ + $(NO_ZSTD) $(CROSS_COMPILER_OVERRIDES) $(NATIVE_ZSTD_LIBS) + $(MAKE) libraryopt $(NO_ZSTD) $(CROSS_OVERRIDES) + $(MAKE) otherlibrariesopt ocamltoolsopt $(NO_ZSTD) $(CROSS_OVERRIDES) + $(MAKE) tools-allopt.opt $(NO_ZSTD) $(CROSS_COMPILER_OVERRIDES) + +.PHONY: cross-install +cross-install: + # dummy files + touch \ + $(addprefix toplevel/, \ + $(foreach ext,cmi cmt cmti cmx, native/nat__dummy__.$(ext)) \ + all__dummy__.cmx topstart.o native/tophooks.cmi) + $(LN) `which ocamlyacc` yacc/ocamlyacc.opt$(EXE) + $(LN) `which ocamllex` lex/ocamllex.opt$(EXE) +ifeq "$(SYSTEM)" "none" + $(LN) `which ocamlyacc` yacc/ocamlyacc$(EXE) + $(LN) `which ocamllex` lex/ocamllex$(EXE) +endif + # Real installation + $(MAKE) install $(INSTALL_OVERRIDES) OCAMLRUN=ocamlrun -- 2.45.2