diff --git a/.ci/Manifest.toml b/.ci/Manifest.toml index 1a916252483..e3046488ec7 100644 --- a/.ci/Manifest.toml +++ b/.ci/Manifest.toml @@ -37,19 +37,19 @@ uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" [[deps.BinaryBuilder]] deps = ["ArgParse", "BinaryBuilderBase", "Binutils_jll", "Dates", "Downloads", "GitHub", "HTTP", "JLD2", "JSON", "LibGit2", "Libdl", "Logging", "LoggingExtras", "ObjectFile", "OutputCollectors", "Patchelf_jll", "Pkg", "PkgLicenses", "REPL", "Random", "Registrator", "RegistryTools", "SHA", "Scratch", "Sockets", "TOML", "UUIDs", "ghr_jll"] -git-tree-sha1 = "32a89265ffd77083daf729618d4279242ee44020" +git-tree-sha1 = "b29c38af4f7f438c22f5be49f87fef3adf402d3b" repo-rev = "master" -repo-url = "https://github.com/JuliaPackaging/BinaryBuilder.jl" +repo-url = "https://github.com/JuliaPackaging/BinaryBuilder.jl.git" uuid = "12aac903-9f7c-5d81-afc2-d9565ea332ae" version = "0.6.4" [[deps.BinaryBuilderBase]] deps = ["Bzip2_jll", "CodecZlib", "Downloads", "Gzip_jll", "HistoricalStdlibVersions", "InteractiveUtils", "JLLWrappers", "JSON", "LibGit2", "LibGit2_jll", "Libdl", "Logging", "OrderedCollections", "OutputCollectors", "Pkg", "Printf", "ProgressMeter", "REPL", "Random", "SHA", "Scratch", "SimpleBufferStream", "TOML", "Tar", "Tar_jll", "UUIDs", "XZ_jll", "Zstd_jll", "p7zip_jll", "pigz_jll", "unzip_jll"] -git-tree-sha1 = "85259632e317f61245d8240d3ee9b08112f52903" +git-tree-sha1 = "a4afdd2de689d496613b80ad609b4bf05dc5c283" repo-rev = "master" repo-url = "https://github.com/JuliaPackaging/BinaryBuilderBase.jl.git" uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e" -version = "1.37.0" +version = "1.38.0" [[deps.Binutils_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl"] diff --git a/0_RootFS/OCaml@5.3/build_tarballs.jl b/0_RootFS/OCaml@5.3/build_tarballs.jl new file mode 100644 index 00000000000..2735ba6d929 --- /dev/null +++ b/0_RootFS/OCaml@5.3/build_tarballs.jl @@ -0,0 +1,30 @@ +### Instructions for adding a new version of the OCaml toolchain +# +# * update the `version` variable and `sources` +# * To deploy the shard and automatically update your BinaryBuilderBase's +# `Artifacts.toml`, use the `--deploy` flag to the `build_tarballs.jl` script. +# You can build & deploy by running: +# +# julia build_tarballs.jl --debug --verbose --deploy TARGET +# + +using BinaryBuilderBase, BinaryBuilder, Pkg.Artifacts + +include("../common.jl") + +name = "OCamlBase" +version = v"5.3.0" + +sources = [ + GitSource("https://github.com/ocaml/ocaml", + "1ccb919e35f8378834060c503ae953897fe0fb7f"), # 5.3.0 + GitSource("https://github.com/ocaml/dune", + "76c0c3941798f81dcc13a305d7abb120c191f5fa"), # 3.19.1 + GitSource("https://github.com/ocaml/ocamlbuild", + "131ba63a1b96d00f3986c8187677c8af61d20a08"), # 0.16.1 + GitSource("https://github.com/ocaml/ocamlfind", + "bd9aad183f0d1c2caf3ec29e4f52bc69361f266d"), # 1.9.8 + DirectorySource("./bundled"), +] + +include("../ocaml_common.jl") diff --git a/0_RootFS/OCaml@5.3/bundled/patches/0001-Backport-support-for-building-cross-compilers.patch b/0_RootFS/OCaml@5.3/bundled/patches/0001-Backport-support-for-building-cross-compilers.patch new file mode 100644 index 00000000000..e3ec706861d --- /dev/null +++ b/0_RootFS/OCaml@5.3/bundled/patches/0001-Backport-support-for-building-cross-compilers.patch @@ -0,0 +1,5143 @@ +From 1515ed9f7c8e2e7feb9864115b12040532a07230 Mon Sep 17 00:00:00 2001 +From: Samuel Hym +Date: Tue, 1 Oct 2024 18:18:41 +0200 +Subject: [PATCH] Backport support for building cross compilers + +This is the squashed combination of the following commits: + +- Add the missing `$(EXE)` for `stripdebug` invocations +- Use `target` instead of `host` to detect the C toolchain +- Use `target` instead of `host` when relevant in configuration +- Detect a _build_ C toolchain to build `sak` +- Check that the OCaml versions are compatible for a cross compiler +- Use a `TARGET_BINDIR` configure variable instead of `--with-target-bindir` +- Add a configurable library directory on target +- Detect `flexlink` only on relevant targets +- Add a `Config` entry for the target OS type +- Add a Makefile.cross with rules to build a cross compiler +- Enable bootstrapping flexdll in the cross-compiler setting +- Add cross-compilation cases to `sak` +- Add a CI workflow to test cross compilers +- Fix static builds of the compiler +--- + .depend | 4 + + .gitattributes | 1 + + .github/workflows/build-cross.yml | 269 +++ + Makefile | 21 +- + Makefile.build_config.in | 8 + + Makefile.common | 2 +- + Makefile.config.in | 5 +- + Makefile.cross | 116 ++ + aclocal.m4 | 13 +- + build-aux/ax_prog_cc_for_build.m4 | 155 ++ + configure | 2074 +++++++++++++++++++--- + configure.ac | 223 ++- + middle_end/closure/closure.ml | 6 +- + middle_end/flambda/closure_conversion.ml | 9 +- + runtime/sak.c | 164 +- + utils/config.common.ml.in | 4 +- + utils/config.fixed.ml | 2 + + utils/config.generated.ml.in | 1 + + utils/config.mli | 6 + + 19 files changed, 2705 insertions(+), 378 deletions(-) + create mode 100644 .github/workflows/build-cross.yml + create mode 100644 Makefile.cross + create mode 100644 build-aux/ax_prog_cc_for_build.m4 + +diff --git a/.depend b/.depend +index ad3238204db2..4ad235142e1a 100644 +--- a/.depend ++++ b/.depend +@@ -4951,6 +4951,7 @@ middle_end/closure/closure.cmo : \ + typing/env.cmi \ + lambda/debuginfo.cmi \ + middle_end/convert_primitives.cmi \ ++ utils/config.cmi \ + middle_end/compilenv.cmi \ + utils/clflags.cmi \ + middle_end/clambda_primitives.cmi \ +@@ -4973,6 +4974,7 @@ middle_end/closure/closure.cmx : \ + typing/env.cmx \ + lambda/debuginfo.cmx \ + middle_end/convert_primitives.cmx \ ++ utils/config.cmx \ + middle_end/compilenv.cmx \ + utils/clflags.cmx \ + middle_end/clambda_primitives.cmx \ +@@ -5162,6 +5164,7 @@ middle_end/flambda/closure_conversion.cmo : \ + middle_end/flambda/flambda.cmi \ + lambda/debuginfo.cmi \ + middle_end/convert_primitives.cmi \ ++ utils/config.cmi \ + middle_end/compilation_unit.cmi \ + middle_end/flambda/base_types/closure_origin.cmi \ + middle_end/flambda/base_types/closure_id.cmi \ +@@ -5190,6 +5193,7 @@ middle_end/flambda/closure_conversion.cmx : \ + middle_end/flambda/flambda.cmx \ + lambda/debuginfo.cmx \ + middle_end/convert_primitives.cmx \ ++ utils/config.cmx \ + middle_end/compilation_unit.cmx \ + middle_end/flambda/base_types/closure_origin.cmx \ + middle_end/flambda/base_types/closure_id.cmx \ +diff --git a/.gitattributes b/.gitattributes +index b17969703130..db48325e8e98 100644 +--- a/.gitattributes ++++ b/.gitattributes +@@ -57,6 +57,7 @@ META.in typo.missing-header + + # Github templates and scripts lack headers, have long lines + /.github/** typo.missing-header typo.long-line=may typo.very-long-line=may ++/.github/workflows/build-cross.yml typo.non-ascii + + /.mailmap typo.long-line typo.missing-header typo.non-ascii + /CONTRIBUTING.md typo.non-ascii=may +diff --git a/.github/workflows/build-cross.yml b/.github/workflows/build-cross.yml +new file mode 100644 +index 000000000000..041d029b6b55 +--- /dev/null ++++ b/.github/workflows/build-cross.yml +@@ -0,0 +1,269 @@ ++name: Cross compilers ++ ++on: ++ pull_request: ++ types: [opened, synchronize, reopened, labeled, unlabeled] ++ workflow_dispatch: ++ ++# Restrict the GITHUB_TOKEN ++permissions: {} ++ ++# See build.yml ++concurrency: ++ group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'pull_request' || github.sha }} ++ cancel-in-progress: true ++ ++env: ++ res: 0 ++ TESTDIR: >- ++ C:\Бактріан🐫 ++ STR_UTF8: >- ++ "C:\\Бактріан🐫" ++ STR_UTF16: >- ++ L"C:\\\x0411\x0430\x043a\x0442\x0440\x0456\x0430\x043d\xd83d\xdc2b" ++ EXAMPLE_PROGRAM: | ++ let _ = ++ Printf.printf "Version: %s\nOS: %s\nUnix: %b\nWin: %b\nCygwin: %b\n" ++ Sys.ocaml_version Sys.os_type Sys.unix Sys.win32 Sys.cygwin ++ COMPLIBS_PROG_X86_64: | ++ let _ = ++ Printf.printf "allow_unaligned_access = %b\n" Arch.allow_unaligned_access; ++ Printf.printf "win64 = %b\n" Arch.win64 ++ COMPLIBS_PROG_AARCH64: | ++ let _ = ++ Printf.printf "allow_unaligned_access = %b\n" Arch.allow_unaligned_access; ++ Printf.printf "macosx = %b\n" Arch.macosx ++ ++jobs: ++ non-cross: ++ if: contains(github.event.pull_request.labels.*.name, 'run-crosscompiler-tests') ++ runs-on: ubuntu-latest ++ steps: ++ - name: Checkout OCaml ++ uses: actions/checkout@v4 ++ with: ++ persist-credentials: false ++ - name: Configure, build and install OCaml ++ run: | ++ PREFIX="$HOME/.local" ++ echo "$PREFIX/bin" >> "$GITHUB_PATH" ++ set -x ++ ./configure --disable-warn-error --disable-ocamldoc \ ++ --disable-ocamltest --disable-stdlib-manpages \ ++ --disable-dependency-generation --prefix="$PREFIX" || res=$? ++ if ! [ "$res" = 0 ]; then cat config.log; exit "$res"; fi ++ make -j ++ make install ++ cd "$HOME" ++ tar caf /tmp/ocaml.tar.zst .local ++ - name: Upload Artifact ++ uses: actions/upload-artifact@v4 ++ with: ++ name: non-cross-ocaml ++ path: /tmp/ocaml.tar.zst ++ retention-days: 1 ++ ++ cross-windows: ++ runs-on: ubuntu-latest ++ needs: non-cross ++ steps: ++ - name: Download Artifact ++ uses: actions/download-artifact@v4 ++ with: ++ name: non-cross-ocaml ++ - name: Install non-cross OCaml and set up environment ++ run: | ++ set -x ++ tar xaf ocaml.tar.zst -C "$HOME" ++ rm -f ocaml.tar.zst ++ echo "$HOME/.local/bin" >> "$GITHUB_PATH" ++ sudo apt-get install -y gcc-mingw-w64-x86-64 ++ - name: Checkout OCaml ++ uses: actions/checkout@v4 ++ with: ++ submodules: true ++ persist-credentials: false ++ - name: Configure, build and install Linux-to-Windows OCaml ++ run: | ++ set -x ++ ./configure --prefix="$HOME/cross" --target=x86_64-w64-mingw32 \ ++ TARGET_LIBDIR="$TESTDIR" || res=$? ++ if ! [ "$res" = 0 ]; then cat config.log; exit "$res"; fi ++ make crossopt -j$(nproc) ++ make installcross ++ ln -sr "$HOME/cross/bin/flexlink.opt.exe" "$HOME/.local/bin/flexlink" ++ - name: Show opt.opt configuration ++ run: | ++ set -x ++ $HOME/cross/bin/ocamlopt.opt.exe -config ++ cat runtime/build_config.h ++ - name: Cross compile a small program ++ run: | ++ printf %s "$EXAMPLE_PROGRAM$COMPLIBS_PROG_X86_64" > example.ml ++ set -x ++ cat example.ml ++ $HOME/cross/bin/ocamlopt.opt.exe -I $HOME/cross/lib/ocaml/compiler-libs/ ocamlcommon.cmxa ocamloptcomp.cmxa example.ml -o example.exe -verbose ++ - name: Upload Artifact ++ uses: actions/upload-artifact@v4 ++ with: ++ name: windows-executable ++ path: example.exe ++ retention-days: 1 ++ - name: Test cross sak ++ run: | ++ printf %s "$STR_UTF16" > utf16.ref ++ printf %s "$STR_UTF8" > utf8.ref ++ set -x ++ runtime/sak.exe encode-C-utf16-literal "$TESTDIR" > utf16 ++ git diff --no-index utf16.ref utf16 ++ runtime/sak.exe encode-C-utf8-literal "$TESTDIR" > utf8 ++ git diff --no-index utf8.ref utf8 ++ ++ run-windows: ++ runs-on: windows-latest ++ needs: cross-windows ++ steps: ++ - name: Download Artifact ++ uses: actions/download-artifact@v4 ++ with: ++ name: windows-executable ++ - name: Run example program ++ run: | ++ .\example.exe ++ ++ cross-arm-linux: ++ runs-on: ubuntu-latest ++ needs: non-cross ++ steps: ++ - name: Download Artifact ++ uses: actions/download-artifact@v4 ++ with: ++ name: non-cross-ocaml ++ - name: Install non-cross OCaml and set up environment ++ run: | ++ set -x ++ tar xaf ocaml.tar.zst -C "$HOME" ++ rm -f ocaml.tar.zst ++ echo "$HOME/.local/bin" >> "$GITHUB_PATH" ++ sudo apt-get install -y gcc-aarch64-linux-gnu qemu-user ++ - name: Checkout OCaml ++ uses: actions/checkout@v4 ++ with: ++ submodules: true ++ persist-credentials: false ++ - name: Configure, build and install Linux-to-Windows OCaml ++ run: | ++ set -x ++ ./configure --prefix="$HOME/cross" --target=aarch64-linux-gnu \ ++ || res=$? ++ if ! [ "$res" = 0 ]; then cat config.log; exit "$res"; fi ++ make crossopt -j ++ make installcross ++ - name: Show opt.opt configuration ++ run: | ++ set -x ++ $HOME/cross/bin/ocamlopt.opt -config ++ cat runtime/build_config.h ++ - name: Cross compile a small program ++ run: | ++ printf %s "$EXAMPLE_PROGRAM$COMPLIBS_PROG_AARCH64" > example.ml ++ set -x ++ cat example.ml ++ $HOME/cross/bin/ocamlopt.opt -I $HOME/cross/lib/ocaml/compiler-libs/ ocamlcommon.cmxa ocamloptcomp.cmxa example.ml -o example -verbose ++ - name: Run the small example program ++ run: | ++ set -x ++ qemu-aarch64 -L /usr/aarch64-linux-gnu example ++ - name: Test cross sak ++ run: | ++ printf %s "$STR_UTF16" > utf16.ref ++ printf %s "$STR_UTF8" > utf8.ref ++ set -x ++ runtime/sak encode-C-utf16-literal "$TESTDIR" > utf16 ++ git diff --no-index utf16.ref utf16 ++ runtime/sak encode-C-utf8-literal "$TESTDIR" > utf8 ++ git diff --no-index utf8.ref utf8 ++ ++ cross-android: ++ runs-on: ubuntu-latest ++ needs: non-cross ++ steps: ++ - name: Download Artifact ++ uses: actions/download-artifact@v4 ++ with: ++ name: non-cross-ocaml ++ - name: Install non-cross OCaml ++ run: | ++ set -x ++ tar xaf ocaml.tar.zst -C "$HOME" ++ rm -f ocaml.tar.zst ++ echo "$HOME/.local/bin" >> "$GITHUB_PATH" ++ - name: Restore the Android NDK from cache ++ uses: actions/cache/restore@v4 ++ id: cache ++ with: ++ path: | ++ /home/runner/android ++ key: android-ndk ++ - name: Download the Android NDK ++ run: | ++ set -x ++ mkdir -p "$HOME/android" ++ cd "$HOME/android" ++ wget --no-verbose https://dl.google.com/android/repository/android-ndk-r27b-linux.zip ++ unzip android-ndk-r27b-linux.zip ++ rm android-ndk-r27b-linux.zip ++ if: steps.cache.outputs.cache-hit != 'true' ++ - name: Save the Android NDK to cache ++ uses: actions/cache/save@v4 ++ with: ++ path: | ++ /home/runner/android ++ key: android-ndk ++ if: steps.cache.outputs.cache-hit != 'true' ++ - name: Checkout OCaml ++ uses: actions/checkout@v4 ++ with: ++ persist-credentials: false ++ - name: Configure, build and install Linux-to-Android OCaml ++ env: ++ TARGET: x86_64-linux-android21 ++ TOOLDIR: android-ndk-r27b/toolchains/llvm/prebuilt/linux-x86_64/bin ++ run: | ++ DIR="$HOME/android/$TOOLDIR" ++ set -x ++ # Hack around the fact that pthread_cancel isn't available on Android ++ # So the result program should _not_ be run with cleanup on exit ++ # (so no `c=1` in `OCAMLRUNPARAM`) ++ ./configure --prefix="$HOME/cross" --target=$TARGET \ ++ TARGET_LIBDIR="/dummy/directory" \ ++ CC="$DIR/clang --target=$TARGET" \ ++ CPPFLAGS='-Dpthread_cancel=assert' \ ++ AR="$DIR/llvm-ar" \ ++ PARTIALLD="$DIR/ld -r" \ ++ RANLIB="$DIR/llvm-ranlib" \ ++ STRIP="$DIR/llvm-strip" || res=$? ++ if ! [ "$res" = 0 ]; then cat config.log; exit "$res"; fi ++ make crossopt -j ++ make installcross ++ - name: Show opt.opt configuration ++ run: | ++ set -x ++ $HOME/cross/bin/ocamlopt.opt -config ++ cat runtime/build_config.h ++ - name: Cross compile a small program ++ run: | ++ printf %s "$EXAMPLE_PROGRAM" > example.ml ++ set -x ++ cat example.ml ++ $HOME/cross/bin/ocamlopt.opt example.ml -o example -verbose ++ file example ++ - name: Run example ++ uses: reactivecircus/android-emulator-runner@v2 ++ with: ++ api-level: 21 ++ arch: x86_64 ++ disable-animations: true ++ script: | ++ adb push example /data/local/tmp/example ++ adb shell /data/local/tmp/example +diff --git a/Makefile b/Makefile +index f7fffdce4db9..778dbb11782b 100644 +--- a/Makefile ++++ b/Makefile +@@ -715,9 +715,9 @@ compare: + # The core system has to be rebuilt after bootstrap anyway, so strip ocamlc + # and ocamllex, which means the artefacts should be identical. + mv ocamlc$(EXE) ocamlc.tmp +- $(OCAMLRUN) tools/stripdebug -all ocamlc.tmp ocamlc$(EXE) ++ $(OCAMLRUN) tools/stripdebug$(EXE) -all ocamlc.tmp ocamlc$(EXE) + mv lex/ocamllex$(EXE) ocamllex.tmp +- $(OCAMLRUN) tools/stripdebug -all ocamllex.tmp lex/ocamllex$(EXE) ++ $(OCAMLRUN) tools/stripdebug$(EXE) -all ocamllex.tmp lex/ocamllex$(EXE) + rm -f ocamllex.tmp ocamlc.tmp + @if $(CMPCMD) boot/ocamlc ocamlc$(EXE) \ + && $(CMPCMD) boot/ocamllex lex/ocamllex$(EXE); \ +@@ -745,7 +745,7 @@ promote-cross: promote-common + # Promote the newly compiled system to the rank of bootstrap compiler + # (Runs on the new runtime, produces code for the new runtime) + .PHONY: promote +-promote: PROMOTE = $(OCAMLRUN) tools/stripdebug -all ++promote: PROMOTE = $(OCAMLRUN) tools/stripdebug$(EXE) -all + promote: promote-common + rm -f boot/ocamlrun$(EXE) + cp runtime/ocamlrun$(EXE) boot/ocamlrun$(EXE) +@@ -1383,23 +1383,17 @@ runtime/caml/jumptbl.h : runtime/caml/instruct.h + sed -n -e '/^ /s/ \([A-Z]\)/ \&\&lbl_\1/gp' \ + -e '/^}/q' > $@ + +-# These are provided as a temporary shim to allow cross-compilation systems +-# to supply a host C compiler and different flags and a linking macro. +-SAK_CC ?= $(CC) +-SAK_CFLAGS ?= $(OC_CFLAGS) $(CFLAGS) $(OC_CPPFLAGS) $(CPPFLAGS) +-SAK_LINK ?= $(MKEXE_VIA_CC) +- + $(SAK): runtime/sak.$(O) + $(V_MKEXE)$(call SAK_LINK,$@,$^) + + runtime/sak.$(O): runtime/sak.c runtime/caml/misc.h runtime/caml/config.h + $(V_CC)$(SAK_CC) $(SAK_CFLAGS) $(OUTPUTOBJ)$@ -c $< + +-C_LITERAL = $(shell $(SAK) encode-C-literal '$(1)') ++C_LITERAL = $(shell $(SAK) $(ENCODE_C_LITERAL) '$(1)') + + runtime/build_config.h: $(ROOTDIR)/Makefile.config $(SAK) + $(V_GEN)echo '/* This file is generated from $(ROOTDIR)/Makefile.config */' > $@ && \ +- echo '#define OCAML_STDLIB_DIR $(call C_LITERAL,$(LIBDIR))' >> $@ && \ ++ echo '#define OCAML_STDLIB_DIR $(call C_LITERAL,$(TARGET_LIBDIR))' >> $@ && \ + echo '#define HOST "$(HOST)"' >> $@ + + ## Runtime libraries and programs +@@ -2968,6 +2962,11 @@ endif + + include .depend + ++# Include the cross-compiler recipes only when relevant ++ifneq "$(HOST)" "$(TARGET)" ++include Makefile.cross ++endif ++ + Makefile.config Makefile.build_config: config.status + config.status: + @echo "Please refer to the installation instructions:" +diff --git a/Makefile.build_config.in b/Makefile.build_config.in +index ae649dcebaa2..852469ef1bac 100644 +--- a/Makefile.build_config.in ++++ b/Makefile.build_config.in +@@ -99,6 +99,14 @@ OC_DLL_LDFLAGS=@oc_dll_ldflags@ + + MKEXE_VIA_CC=$(CC) @mkexe_via_cc_ldflags@ @mkexe_via_cc_extra_cmd@ + ++# How to build sak ++SAK_CC=@SAK_CC@ ++SAK_CFLAGS=@SAK_CFLAGS@ ++SAK_LINK=@SAK_LINK@ ++ ++# sak command to encode C literals ++ENCODE_C_LITERAL=@encode_C_literal@ ++ + # Which tool to use to display differences between files + DIFF=@DIFF@ + # Which flags to pass to the diff tool +diff --git a/Makefile.common b/Makefile.common +index 1e6a7eff8903..253356d68fbb 100644 +--- a/Makefile.common ++++ b/Makefile.common +@@ -455,7 +455,7 @@ endef # OCAML_LIBRARY + + # Installing a bytecode executable, with debug information removed + define INSTALL_STRIPPED_BYTE_PROG +-$(OCAMLRUN) $(ROOTDIR)/tools/stripdebug $(1) $(1).tmp \ ++$(OCAMLRUN) $(ROOTDIR)/tools/stripdebug$(EXE) $(1) $(1).tmp \ + && $(INSTALL_PROG) $(1).tmp $(2) \ + && rm $(1).tmp + endef # INSTALL_STRIPPED_BYTE_PROG +diff --git a/Makefile.config.in b/Makefile.config.in +index e432851cdea5..522c0f63381b 100644 +--- a/Makefile.config.in ++++ b/Makefile.config.in +@@ -46,9 +46,12 @@ BINDIR=@bindir@ + + datarootdir=@datarootdir@ + +-### Where to install the standard library ++### Where to install the standard library on host + LIBDIR=@libdir@ + ++### Where to look for the standard library on target ++TARGET_LIBDIR=@TARGET_LIBDIR@ ++ + ### Where to install the stub code for the standard library + STUBLIBDIR=@libdir@/stublibs + +diff --git a/Makefile.cross b/Makefile.cross +new file mode 100644 +index 000000000000..0d2cf8f32349 +--- /dev/null ++++ b/Makefile.cross +@@ -0,0 +1,116 @@ ++#************************************************************************** ++#* * ++#* 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 ++ ++# As the cross compiler will be linked with the _build_ version of ++# libcomprmarsh, we cannot rely on the detection of zstd done during `configure` ++# (as it would have detected the _target_ version). So we recover the flags to ++# link with zstd of the non-cross compiler. ++# Note that the shell call is a variable that is used only once, so it doesn't ++# have to be lazier. ++HOST_ZSTD_LIBS=$(shell grep ^ZSTD_LIBS= "$$(ocamlopt -where)/Makefile.config") ++ ++# The build system adds various include directories which pertain to the current ++# tree, including -I runtime, which is necessary for -custom executables. ++# ocamltest is always a -custom executable, but some others (ocamldoc; the ++# debugger, etc.) are only -custom in specific circumstances. It is therefore ++# fiddly to change this in the main build system, so we perform a slightly ++# different trick by ensuring that "+" is the first entry in VPATH. This will ++# put the host compiler's standard library (and consequently its runtime ++# objects) well above the .a files found with -I runtime. For now, this seems ++# the least nefarious way of ensuring that the bytecode compiler has the C ++# headers in runtime/caml available without breaking builds with an external ++# ocamlopt. ++VPATH := + $(VPATH) ++ ++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 ++CROSS_COMPILERLIBS_OVERRIDES=$(CROSS_OVERRIDES) CAMLC=ocamlc \ ++ CAMLOPT="$(ROOTDIR)/ocamlopt.opt$(EXE) $(STDLIBFLAGS)" ++ ++ifeq "$(BOOTSTRAPPING_FLEXDLL)" "true" ++# Declare flexlink to be an 'old' file, so that make doesn't try to rebuild it ++# with the build rules in `Makefile`; its build is driven by the `cross-flexdll` ++# recipe provided here instead ++OLDS := -o $(BYTE_BINDIR)/flexlink$(EXE) ++else ++OLDS := ++endif ++ ++# The compiler libs that should be rebuilt for target (they are first built for ++# host as part of the .opt compilers) ++CROSSCOMPILERLIBS := $(addprefix compilerlibs/,$(addsuffix .cmxa,\ ++ ocamlcommon ocamlmiddleend ocamlbytecomp ocamloptcomp ocamltoplevel)) ++ ++.PHONY: crossopt ++ifeq "$(BOOTSTRAPPING_FLEXDLL)" "true" ++crossopt: cross-flexdll ++ $(MAKE) runtime-all $(OLDS) ++else ++# In that case, $(OLDS) is empty, we can depend directly on runtime-all ++crossopt: runtime-all ++endif ++ $(MAKE) ocamlc $(TOOLS_BYTECODE_TARGETS) expunge$(EXE) \ ++ $(CROSS_COMPILER_OVERRIDES) $(OLDS) ++ $(MAKE) library $(CROSS_OVERRIDES) $(OLDS) ++ $(MAKE) ocamlyacc $(CROSS_OVERRIDES) $(OLDS) ++ $(MAKE) ocamllex $(CROSS_COMPILER_OVERRIDES) $(OLDS) ++ $(MAKE) ocaml $(CROSS_COMPILER_OVERRIDES) $(OLDS) ++ $(MAKE) dynlink-all $(CROSS_OVERRIDES) $(OLDS) ++ $(MAKE) -C otherlibs all $(CROSS_OVERRIDES) $(OLDS) ++ $(MAKE) runtimeopt $(OLDS) ++ $(MAKE) ocamlc.opt ocamlopt.opt $(TOOLS_NATIVE_TARGETS) \ ++ $(CROSS_COMPILER_OVERRIDES) "$(HOST_ZSTD_LIBS)" $(OLDS) ++ $(MAKE) libraryopt $(CROSS_OVERRIDES) $(OLDS) ++ $(MAKE) otherlibrariesopt ocamltoolsopt $(CROSS_OVERRIDES) $(OLDS) ++ $(MAKE) tools-allopt.opt $(CROSS_COMPILER_OVERRIDES) $(OLDS) ++ # We now build the compiler libs again, but for target this time ++ rm -f $(ocamlcommon_NCOBJS) $(ocamlmiddleend_NCOBJS) \ ++ $(ocamlbytecomp_NCOBJS) $(ocamloptcomp_NCOBJS) \ ++ $(ocamltoplevel_NCOBJS) $(CROSSCOMPILERLIBS) ++ $(MAKE) $(CROSSCOMPILERLIBS) $(CROSS_COMPILERLIBS_OVERRIDES) $(OLDS) ++ ++.PHONY: cross-flexdll ++cross-flexdll: | $(BYTE_BINDIR) $(OPT_BINDIR) ++ rm -f $(FLEXDLL_SOURCE_DIR)/flexlink.exe ++ $(MAKE) -C $(FLEXDLL_SOURCE_DIR) $(FLEXLINK_BUILD_ENV) \ ++ NATDYNLINK=false LINKFLAGS= flexlink.exe support ++ $(LN) $(FLEXDLL_SOURCE_DIR)/flexlink.exe flexlink.opt.exe ++ $(LN) flexlink.opt.exe flexlink.byte.exe ++ cp flexlink.byte.exe $(BYTE_BINDIR)/flexlink ++ cd $(BYTE_BINDIR) && $(LN) flexlink flexlink.exe ++ cp $(addprefix $(FLEXDLL_SOURCE_DIR)/, $(FLEXDLL_OBJECTS)) $(BYTE_BINDIR) ++ cp flexlink.opt.exe $(OPT_BINDIR)/flexlink ++ cd $(OPT_BINDIR) && $(LN) flexlink flexlink.exe ++ cp $(addprefix $(FLEXDLL_SOURCE_DIR)/, $(FLEXDLL_OBJECTS)) $(OPT_BINDIR) ++ ++INSTALL_OVERRIDES=build_ocamldoc=false WITH_DEBUGGER= OCAMLRUN=ocamlrun ++ ++.PHONY: installcross ++installcross: ++ # Create dummy files to keep `install` happy ++ touch \ ++ $(addprefix toplevel/, \ ++ $(foreach ext,cmi cmt cmti cmx, native/nat__dummy__.$(ext)) \ ++ all__dummy__.cmx topstart.o native/tophooks.cmi) ++ $(LN) `command -v ocamllex` lex/ocamllex.opt$(EXE) ++ $(LN) `command -v ocamlyacc` yacc/ocamlyacc.opt$(EXE) ++ # Real installation ++ $(MAKE) install $(INSTALL_OVERRIDES) +diff --git a/aclocal.m4 b/aclocal.m4 +index 7353e09a96ef..b17e11d511aa 100644 +--- a/aclocal.m4 ++++ b/aclocal.m4 +@@ -30,6 +30,7 @@ m4_include([build-aux/lt~obsolete.m4]) + # Macros from the autoconf macro archive + m4_include([build-aux/ax_check_compile_flag.m4]) + m4_include([build-aux/ax_func_which_gethostbyname_r.m4]) ++m4_include([build-aux/ax_prog_cc_for_build.m4]) + m4_include([build-aux/ax_pthread.m4]) + + # OCaml version +@@ -369,27 +370,27 @@ AC_DEFUN([OCAML_TEST_WINPTHREADS_PTHREAD_H], [ + OCAML_CC_RESTORE_VARIABLES + ]) + +-AC_DEFUN([OCAML_HOST_IS_EXECUTABLE], [ +- AC_MSG_CHECKING([whether host executables can be run in the build]) ++AC_DEFUN([OCAML_TARGET_IS_EXECUTABLE], [ ++ AC_MSG_CHECKING([whether target executables can be run in the build]) + old_cross_compiling="$cross_compiling" + cross_compiling='no' + AC_RUN_IFELSE( + [AC_LANG_PROGRAM], + [AC_MSG_RESULT([yes]) +- host_runnable=true], ++ target_runnable=true], + [AC_MSG_RESULT([no]) +- host_runnable=false], ++ target_runnable=false], + # autoconf displays a warning if this parameter is missing, but + # cross-compilation mode was disabled above. + [assert=false]) + cross_compiling="$old_cross_compiling" + ]) + +-# This is AC_RUN_IFELSE but taking $host_runnable into account (i.e. if the ++# This is AC_RUN_IFELSE but taking $target_runnable into account (i.e. if the + # program can be run, then it is run) + AC_DEFUN([OCAML_RUN_IFELSE], [ + old_cross_compiling="$cross_compiling" +- AS_IF([test "x$host_runnable" = 'xtrue'], [cross_compiling='no']) ++ AS_IF([test "x$target_runnable" = 'xtrue'], [cross_compiling='no']) + AC_RUN_IFELSE([$1],[$2],[$3],[$4]) + cross_compiling="$old_cross_compiling" + ]) +diff --git a/build-aux/ax_prog_cc_for_build.m4 b/build-aux/ax_prog_cc_for_build.m4 +new file mode 100644 +index 000000000000..1db8d73f9667 +--- /dev/null ++++ b/build-aux/ax_prog_cc_for_build.m4 +@@ -0,0 +1,155 @@ ++# =========================================================================== ++# https://www.gnu.org/software/autoconf-archive/ax_prog_cc_for_build.html ++# =========================================================================== ++# ++# SYNOPSIS ++# ++# AX_PROG_CC_FOR_BUILD ++# ++# DESCRIPTION ++# ++# This macro searches for a C compiler that generates native executables, ++# that is a C compiler that surely is not a cross-compiler. This can be ++# useful if you have to generate source code at compile-time like for ++# example GCC does. ++# ++# The macro sets the CC_FOR_BUILD and CPP_FOR_BUILD macros to anything ++# needed to compile or link (CC_FOR_BUILD) and preprocess (CPP_FOR_BUILD). ++# The value of these variables can be overridden by the user by specifying ++# a compiler with an environment variable (like you do for standard CC). ++# ++# It also sets BUILD_EXEEXT and BUILD_OBJEXT to the executable and object ++# file extensions for the build platform, and GCC_FOR_BUILD to `yes' if ++# the compiler we found is GCC. All these variables but GCC_FOR_BUILD are ++# substituted in the Makefile. ++# ++# LICENSE ++# ++# Copyright (c) 2008 Paolo Bonzini ++# ++# Copying and distribution of this file, with or without modification, are ++# permitted in any medium without royalty provided the copyright notice ++# and this notice are preserved. This file is offered as-is, without any ++# warranty. ++ ++#serial 21 ++ ++AU_ALIAS([AC_PROG_CC_FOR_BUILD], [AX_PROG_CC_FOR_BUILD]) ++AC_DEFUN([AX_PROG_CC_FOR_BUILD], [dnl ++AC_REQUIRE([AC_PROG_CC])dnl ++AC_REQUIRE([AC_PROG_CPP])dnl ++AC_REQUIRE([AC_CANONICAL_BUILD])dnl ++ ++dnl Use the standard macros, but make them use other variable names ++dnl ++pushdef([ac_cv_prog_CPP], ac_cv_build_prog_CPP)dnl ++pushdef([ac_cv_prog_cc_c89], ac_cv_build_prog_cc_c89)dnl ++pushdef([ac_cv_prog_cc_c99], ac_cv_build_prog_cc_c99)dnl ++pushdef([ac_cv_prog_cc_c11], ac_cv_build_prog_cc_c11)dnl ++pushdef([ac_cv_prog_gcc], ac_cv_build_prog_gcc)dnl ++pushdef([ac_cv_prog_cc_works], ac_cv_build_prog_cc_works)dnl ++pushdef([ac_cv_prog_cc_cross], ac_cv_build_prog_cc_cross)dnl ++pushdef([ac_cv_prog_cc_g], ac_cv_build_prog_cc_g)dnl ++pushdef([ac_cv_c_compiler_gnu], ac_cv_build_c_compiler_gnu)dnl ++pushdef([ac_cv_exeext], ac_cv_build_exeext)dnl ++pushdef([ac_cv_objext], ac_cv_build_objext)dnl ++pushdef([ac_exeext], ac_build_exeext)dnl ++pushdef([ac_objext], ac_build_objext)dnl ++pushdef([CC], CC_FOR_BUILD)dnl ++pushdef([CPP], CPP_FOR_BUILD)dnl ++pushdef([GCC], GCC_FOR_BUILD)dnl ++pushdef([CFLAGS], CFLAGS_FOR_BUILD)dnl ++pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl ++pushdef([EXEEXT], BUILD_EXEEXT)dnl ++pushdef([LDFLAGS], LDFLAGS_FOR_BUILD)dnl ++pushdef([OBJEXT], BUILD_OBJEXT)dnl ++pushdef([host], build)dnl ++pushdef([host_alias], build_alias)dnl ++pushdef([host_cpu], build_cpu)dnl ++pushdef([host_vendor], build_vendor)dnl ++pushdef([host_os], build_os)dnl ++pushdef([ac_cv_host], ac_cv_build)dnl ++pushdef([ac_cv_host_alias], ac_cv_build_alias)dnl ++pushdef([ac_cv_host_cpu], ac_cv_build_cpu)dnl ++pushdef([ac_cv_host_vendor], ac_cv_build_vendor)dnl ++pushdef([ac_cv_host_os], ac_cv_build_os)dnl ++pushdef([ac_tool_prefix], ac_build_tool_prefix)dnl ++pushdef([am_cv_CC_dependencies_compiler_type], am_cv_build_CC_dependencies_compiler_type)dnl ++pushdef([am_cv_prog_cc_c_o], am_cv_build_prog_cc_c_o)dnl ++pushdef([cross_compiling], cross_compiling_build)dnl ++ ++cross_compiling_build=no ++ ++ac_build_tool_prefix= ++AS_IF([test -n "$build"], [ac_build_tool_prefix="$build-"], ++ [test -n "$build_alias"],[ac_build_tool_prefix="$build_alias-"]) ++ ++AC_LANG_PUSH([C]) ++ ++dnl The pushdef([ac_cv_c_compiler_gnu], ...) currently does not cover ++dnl the use of this variable in _AC_LANG_COMPILER_GNU called by ++dnl AC_PROG_CC. Unset this cache variable temporarily as a workaround. ++was_set_c_compiler_gnu=${[ac_cv_c_compiler_gnu]+y} ++AS_IF([test ${was_set_c_compiler_gnu}], ++ [saved_c_compiler_gnu=$[ac_cv_c_compiler_gnu] ++ AS_UNSET([[ac_cv_c_compiler_gnu]])]) ++ ++AC_PROG_CC ++ ++dnl Restore ac_cv_c_compiler_gnu ++AS_IF([test ${was_set_c_compiler_gnu}], ++ [[ac_cv_c_compiler_gnu]=$[saved_c_compiler_gnu]]) ++ ++_AC_COMPILER_EXEEXT ++_AC_COMPILER_OBJEXT ++AC_PROG_CPP ++ ++dnl Restore the old definitions ++dnl ++popdef([cross_compiling])dnl ++popdef([am_cv_prog_cc_c_o])dnl ++popdef([am_cv_CC_dependencies_compiler_type])dnl ++popdef([ac_tool_prefix])dnl ++popdef([ac_cv_host_os])dnl ++popdef([ac_cv_host_vendor])dnl ++popdef([ac_cv_host_cpu])dnl ++popdef([ac_cv_host_alias])dnl ++popdef([ac_cv_host])dnl ++popdef([host_os])dnl ++popdef([host_vendor])dnl ++popdef([host_cpu])dnl ++popdef([host_alias])dnl ++popdef([host])dnl ++popdef([OBJEXT])dnl ++popdef([LDFLAGS])dnl ++popdef([EXEEXT])dnl ++popdef([CPPFLAGS])dnl ++popdef([CFLAGS])dnl ++popdef([GCC])dnl ++popdef([CPP])dnl ++popdef([CC])dnl ++popdef([ac_objext])dnl ++popdef([ac_exeext])dnl ++popdef([ac_cv_objext])dnl ++popdef([ac_cv_exeext])dnl ++popdef([ac_cv_c_compiler_gnu])dnl ++popdef([ac_cv_prog_cc_g])dnl ++popdef([ac_cv_prog_cc_cross])dnl ++popdef([ac_cv_prog_cc_works])dnl ++popdef([ac_cv_prog_cc_c89])dnl ++popdef([ac_cv_prog_gcc])dnl ++popdef([ac_cv_prog_CPP])dnl ++ ++dnl restore global variables ac_ext, ac_cpp, ac_compile, ++dnl ac_link, ac_compiler_gnu (dependant on the current ++dnl language after popping): ++AC_LANG_POP([C]) ++ ++dnl Finally, set Makefile variables ++dnl ++AC_SUBST(BUILD_EXEEXT)dnl ++AC_SUBST(BUILD_OBJEXT)dnl ++AC_SUBST([CFLAGS_FOR_BUILD])dnl ++AC_SUBST([CPPFLAGS_FOR_BUILD])dnl ++AC_SUBST([LDFLAGS_FOR_BUILD])dnl ++]) +diff --git a/configure b/configure +index 401b94298e4f..983ef77202a5 100755 +--- a/configure ++++ b/configure +@@ -730,6 +730,14 @@ INSTALL_DATA + INSTALL_SCRIPT + INSTALL_PROGRAM + flexlink ++LDFLAGS_FOR_BUILD ++CPPFLAGS_FOR_BUILD ++CFLAGS_FOR_BUILD ++BUILD_OBJEXT ++BUILD_EXEEXT ++CPP_FOR_BUILD ++ac_ct_CC_FOR_BUILD ++CC_FOR_BUILD + CPP + ac_ct_DEP_CC + DEP_CC +@@ -764,6 +772,7 @@ ac_ct_LD + LD + DEFAULT_STRING + WINDOWS_UNICODE_MODE ++TARGET_BINDIR + LIBUNWIND_LDFLAGS + LIBUNWIND_CPPFLAGS + DLLIBS +@@ -787,6 +796,7 @@ build_cpu + build + ar_supports_response_files + QS ++TARGET_LIBDIR + ocaml_libdir + ocaml_bindir + compute_deps +@@ -898,6 +908,7 @@ native_cppflags + native_cflags + bytecode_cppflags + bytecode_cflags ++target_os_type + system + model + arch64 +@@ -913,6 +924,10 @@ ac_tool_prefix + CSCFLAGS + CSC + DIFF_FLAGS ++encode_C_literal ++SAK_LINK ++SAK_CFLAGS ++SAK_CC + CC + LINEAR_MAGIC_NUMBER + CMT_MAGIC_NUMBER +@@ -1008,7 +1023,6 @@ enable_native_compiler + enable_flambda + enable_flambda_invariants + enable_cmm_invariants +-with_target_bindir + with_target_sh + enable_reserved_header_bits + enable_stdlib_manpages +@@ -1043,6 +1057,8 @@ COMPILER_NATIVE_CPPFLAGS + DLLIBS + LIBUNWIND_CPPFLAGS + LIBUNWIND_LDFLAGS ++TARGET_BINDIR ++TARGET_LIBDIR + WINDOWS_UNICODE_MODE + DEFAULT_STRING + CC +@@ -1729,8 +1745,6 @@ Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --with-odoc build documentation with odoc +- --with-target-bindir location of the runtime binaries on the target +- system + --with-target-sh location of Posix sh on the target system + --with-afl use the AFL fuzzer + --with-flexdll bootstrap FlexDLL from the given sources +@@ -1766,6 +1780,11 @@ Some influential environment variables: + libunwind headers>) + LIBUNWIND_LDFLAGS + linker flags for libunwind (e.g. -L ++ TARGET_BINDIR ++ location of the runtime binaries on the target system ++ TARGET_LIBDIR ++ location of the libraries on the target system, to be used for ++ dynlink; defaults to the value of libdir + WINDOWS_UNICODE_MODE + how to handle Unicode under Windows: ansi, compatible + DEFAULT_STRING +@@ -3387,6 +3406,10 @@ LINEAR_MAGIC_NUMBER=Caml1999L035 + + + ++ ++ ++ ++ + # Note: This is present for the flexdll bootstrap where it exposed as the old + # TOOLPREF variable. It would be better if flexdll where updated to require + # WINDRES instead. +@@ -3469,6 +3492,7 @@ LINEAR_MAGIC_NUMBER=Caml1999L035 + + + ++ + + + # TODO: rename this variable +@@ -3516,6 +3540,7 @@ LINEAR_MAGIC_NUMBER=Caml1999L035 + + + ++ + + + ## Generated files +@@ -3693,6 +3718,26 @@ test -n "$target_alias" && + NONENONEs,x,x, && + program_prefix=${target_alias}- + ++# Override cross_compiling and ac_tool_prefix variables since the C toolchain is ++# used to generate target code when building a cross compiler ++cross_compiling=no ++if test x"$target_alias" != x ++then : ++ if test x"$build_alias" = x ++then : ++ cross_compiling=maybe ++else $as_nop ++ if test x"$build_alias" != x"$target_alias" ++then : ++ cross_compiling=yes ++fi ++fi ++fi ++if test -n "$target_alias" ++then : ++ ac_tool_prefix=$target_alias- ++fi ++ + # Ensure that AC_CONFIG_LINKS will either create symlinks which are compatible + # with native Windows (i.e. NTFS symlinks, not WSL or Cygwin-emulated ones) or + # use its fallback mechanisms. Native Windows versions of ocamlc/ocamlopt cannot +@@ -3707,7 +3752,7 @@ esac + + # Systems that are known not to work, even in bytecode only. + +-case $host in #( ++case $target in #( + i386-*-solaris*) : + as_fn_error $? "Building for 32 bits target is not supported. \ + If your host is 64 bits, you can try with './configure CC=\"gcc -m64\"' \ +@@ -3718,7 +3763,7 @@ esac + + # MSVC special case + +-case $host in #( ++case $target in #( + *-pc-windows) : + if test -z "$CC" + then : +@@ -4051,13 +4096,7 @@ fi + + + +-# Check whether --with-target-bindir was given. +-if test ${with_target_bindir+y} +-then : +- withval=$with_target_bindir; target_bindir=$withval +-else $as_nop +- target_bindir='' +-fi ++ + + + +@@ -4226,10 +4265,138 @@ else $as_nop + + fi + ++# Are we building a cross-compiler ++ ++if test x"$host" = x"$target" ++then : ++ cross_compiler=false ++else $as_nop ++ # We require a non-cross compiler of the same version ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the installed OCaml compiler can build the cross compiler" >&5 ++printf %s "checking if the installed OCaml compiler can build the cross compiler... " >&6; } ++ already_installed_version="$(ocamlc -vnum)" ++ if test x"5.3.0" = x"$already_installed_version" ++then : ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes (5.3.0)" >&5 ++printf "%s\n" "yes (5.3.0)" >&6; } ++else $as_nop ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no (5.3.0 vs $already_installed_version)" >&5 ++printf "%s\n" "no (5.3.0 vs $already_installed_version)" >&6; } ++ as_fn_error $? "exiting" "$LINENO" 5 ++fi ++ cross_compiler=true ++fi ++ + # Initialization of libtool + # Allow the MSVC linker to be found even if ld isn't installed. + # User-specified LD still takes precedence. +-if test -n "$ac_tool_prefix"; then ++if $cross_compiler ++then : ++ for ac_prog in ld link ++do ++ # Extract the first word of "$target_alias-$ac_prog", so it can be a program name with args. ++set dummy $target_alias-$ac_prog; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_prog_LD+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ if test -n "$LD"; then ++ ac_cv_prog_LD="$LD" # Let the user override the test. ++else ++as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ ac_cv_prog_LD="$target_alias-$ac_prog" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++fi ++fi ++LD=$ac_cv_prog_LD ++if test -n "$LD"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 ++printf "%s\n" "$LD" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ ++ test -n "$LD" && break ++done ++if test -z "$LD"; then ++ if test "$build" = "$target"; then ++ ac_ct_LD=$LD ++ for ac_prog in ld link ++do ++ # Extract the first word of "$ac_prog", so it can be a program name with args. ++set dummy $ac_prog; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_prog_ac_ct_LD+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ if test -n "$ac_ct_LD"; then ++ ac_cv_prog_ac_ct_LD="$ac_ct_LD" # Let the user override the test. ++else ++as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ ac_cv_prog_ac_ct_LD="$ac_prog" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++fi ++fi ++ac_ct_LD=$ac_cv_prog_ac_ct_LD ++if test -n "$ac_ct_LD"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LD" >&5 ++printf "%s\n" "$ac_ct_LD" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ ++ test -n "$ac_ct_LD" && break ++done ++test -n "$ac_ct_LD" || ac_ct_LD="false" ++ ++ LD=$ac_ct_LD ++ else ++ LD="false" ++ fi ++fi ++ ++else $as_nop ++ if test -n "$ac_tool_prefix"; then + for ac_prog in ld link + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +@@ -4339,14 +4506,20 @@ esac + fi + fi + ++fi ++# libtool will detect a build-to-host C toolchain but when building an OCaml ++# cross compiler we need the C toolchain to build the target runtime so we ++# temporarily define host* values as macros for target* values so that the ++# proper toolchain is configured. Note that host=target unless we are building a ++# cross compiler so this is transparent for the usual use case. + # libtool expects host_os=mingw for native Windows + # Also, it has been observed that, on some platforms (e.g. msvc) LT_INIT + # alters the CFLAGS variable, so we save its value before calling the macro + # and restore it after the call +-old_host_os=$host_os +-if test x"$host_os" = "xwindows" ++old_host_os=$target_os ++if test x"$target_os" = "xwindows" + then : +- host_os=mingw ++ target_os=mingw + fi + saved_CFLAGS="$CFLAGS" + +@@ -4551,8 +4724,8 @@ fi + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + CC=$ac_ct_CC +@@ -4771,8 +4944,8 @@ done + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + CC=$ac_ct_CC +@@ -4873,8 +5046,8 @@ fi + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + CC=$ac_ct_CC +@@ -5108,7 +5281,7 @@ printf "%s\n" "$ac_try_echo"; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 + printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} + as_fn_error 77 "cannot run C compiled programs. +-If you meant to cross compile, use \`--host'. ++If you meant to cross compile, use \`--target'. + See \`config.log' for more details" "$LINENO" 5; } + fi + fi +@@ -5776,7 +5949,7 @@ if test yes = "$GCC"; then + # Check if gcc -print-prog-name=ld gives a path. + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 + printf %s "checking for ld used by $CC... " >&6; } +- case $host in ++ case $target in + *-*-mingw*) + # gcc leaves a trailing carriage return, which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; +@@ -5888,7 +6061,7 @@ else $as_nop + lt_cv_path_NM=$NM + else + lt_nm_to_check=${ac_tool_prefix}nm +- if test -n "$ac_tool_prefix" && test "$build" = "$host"; then ++ if test -n "$ac_tool_prefix" && test "$build" = "$target"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do +@@ -6043,8 +6216,8 @@ done + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + DUMPBIN=$ac_ct_DUMPBIN +@@ -6288,13 +6461,13 @@ esac + + + +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5 +-printf %s "checking how to convert $build file names to $host format... " >&6; } ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $target format" >&5 ++printf %s "checking how to convert $build file names to $target format... " >&6; } + if test ${lt_cv_to_host_file_cmd+y} + then : + printf %s "(cached) " >&6 + else $as_nop +- case $host in ++ case $target in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys +@@ -6344,7 +6517,7 @@ then : + else $as_nop + #assume ordinary cross tools, or native build. + lt_cv_to_tool_file_cmd=func_convert_file_noop +-case $host in ++case $target in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys +@@ -6380,7 +6553,7 @@ case $reload_flag in + *) reload_flag=" $reload_flag" ;; + esac + reload_cmds='$LD$reload_flag -o $output$reload_objs' +-case $host_os in ++case $target_os in + cygwin* | mingw* | pw32* | cegcc*) + if test yes != "$GCC"; then + reload_cmds=false +@@ -6495,8 +6668,8 @@ fi + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + OBJDUMP=$ac_ct_OBJDUMP +@@ -6535,7 +6708,7 @@ lt_cv_deplibs_check_method='unknown' + # If you have 'file' or equivalent on your system and you're not sure + # whether 'pass_all' will *always* work, you probably want this one. + +-case $host_os in ++case $target_os in + aix[4-9]*) + lt_cv_deplibs_check_method=pass_all + ;; +@@ -6582,7 +6755,7 @@ darwin* | rhapsody*) + + freebsd* | dragonfly*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then +- case $host_cpu in ++ case $target_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. +@@ -6602,7 +6775,7 @@ haiku*) + + hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file +- case $host_cpu in ++ case $target_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so +@@ -6681,7 +6854,7 @@ sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + ;; + + sysv4 | sysv4.3*) +- case $host_vendor in ++ case $target_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` +@@ -6721,8 +6894,8 @@ printf "%s\n" "$lt_cv_deplibs_check_method" >&6; } + + file_magic_glob= + want_nocaseglob=no +-if test "$build" = "$host"; then +- case $host_os in ++if test "$build" = "$target"; then ++ case $target_os in + mingw* | pw32*) + if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then + want_nocaseglob=yes +@@ -6850,8 +7023,8 @@ fi + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + DLLTOOL=$ac_ct_DLLTOOL +@@ -6879,7 +7052,7 @@ then : + else $as_nop + lt_cv_sharedlib_from_linklib_cmd='unknown' + +-case $host_os in ++case $target_os in + cygwin* | mingw* | pw32* | cegcc*) + # two different shell functions defined in ltmain.sh; + # decide which one to use based on capabilities of $DLLTOOL +@@ -7013,8 +7186,8 @@ done + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + AR=$ac_ct_AR +@@ -7186,8 +7359,8 @@ fi + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + STRIP=$ac_ct_STRIP +@@ -7295,8 +7468,8 @@ fi + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + RANLIB=$ac_ct_RANLIB +@@ -7318,7 +7491,7 @@ old_postinstall_cmds='chmod 644 $oldlib' + old_postuninstall_cmds= + + if test -n "$RANLIB"; then +- case $host_os in ++ case $target_os in + bitrig* | openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib" + ;; +@@ -7329,7 +7502,7 @@ if test -n "$RANLIB"; then + old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib" + fi + +-case $host_os in ++case $target_os in + darwin*) + lock_old_archive_extraction=yes ;; + *) +@@ -7449,7 +7622,7 @@ symcode='[BCDEGRST]' + sympat='\([_A-Za-z][_A-Za-z0-9]*\)' + + # Define system-specific variables. +-case $host_os in ++case $target_os in + aix*) + symcode='[BCDT]' + ;; +@@ -7457,7 +7630,7 @@ cygwin* | mingw* | pw32* | cegcc*) + symcode='[ABCDGISTW]' + ;; + hpux*) +- if test ia64 = "$host_cpu"; then ++ if test ia64 = "$target_cpu"; then + symcode='[ABCDEGRST]' + fi + ;; +@@ -7872,7 +8045,7 @@ func_cc_basename () + *) break;; + esac + done +- func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` ++ func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$target_alias-%%"` + } + + # Check whether --enable-libtool-lock was given. +@@ -7885,7 +8058,7 @@ test no = "$enable_libtool_lock" || enable_libtool_lock=yes + + # Some flags need to be propagated to the compiler or linker for good + # libtool support. +-case $host in ++case $target in + ia64-*-hpux*) + # Find out what ABI is being produced by ac_compile, and set mode + # options accordingly. +@@ -7996,7 +8169,7 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + test $ac_status = 0; }; then + case `/usr/bin/file conftest.o` in + *32-bit*) +- case $host in ++ case $target in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_i386_fbsd" + ;; +@@ -8025,7 +8198,7 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + esac + ;; + *64-bit*) +- case $host in ++ case $target in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_x86_64_fbsd" + ;; +@@ -8113,7 +8286,7 @@ printf "%s\n" "$lt_cv_cc_needs_belf" >&6; } + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) +- case $host in ++ case $target in + i?86-*-solaris*|x86_64-*-solaris*) + LD="${LD-ld} -m elf_x86_64" + ;; +@@ -8233,8 +8406,8 @@ fi + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + MANIFEST_TOOL=$ac_ct_MANIFEST_TOOL +@@ -8270,7 +8443,7 @@ fi + + + +- case $host_os in ++ case $target_os in + rhapsody* | darwin*) + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args. +@@ -8364,8 +8537,8 @@ fi + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + DSYMUTIL=$ac_ct_DSYMUTIL +@@ -8466,8 +8639,8 @@ fi + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + NMEDIT=$ac_ct_NMEDIT +@@ -8568,8 +8741,8 @@ fi + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + LIPO=$ac_ct_LIPO +@@ -8670,8 +8843,8 @@ fi + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + OTOOL=$ac_ct_OTOOL +@@ -8772,8 +8945,8 @@ fi + else + case $cross_compiling:$ac_tool_warned in + yes:) +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +-printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with target triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with target triplet" >&2;} + ac_tool_warned=yes ;; + esac + OTOOL64=$ac_ct_OTOOL64 +@@ -8915,7 +9088,7 @@ _LT_EOF + fi + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 + printf "%s\n" "$lt_cv_ld_force_load" >&6; } +- case $host_os in ++ case $target_os in + rhapsody* | darwin1.[012]) + _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; + darwin1.*) +@@ -8924,7 +9097,7 @@ printf "%s\n" "$lt_cv_ld_force_load" >&6; } + # if running on 10.5 or later, the deployment target defaults + # to the OS version, if on x86, and 10.4, the deployment + # target defaults to 10.4. Don't you love it? +- case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in ++ case ${MACOSX_DEPLOYMENT_TARGET-10.0},$target in + 10.0,*86*-darwin8*|10.0,*-darwin[91]*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + 10.[012][,.]*) +@@ -9163,7 +9336,7 @@ fi + + + shared_archive_member_spec= +-case $host,$enable_shared in ++case $target,$enable_shared in + power*-*-aix[5-9]*,yes) + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking which variant of shared library versioning to provide" >&5 + printf %s "checking which variant of shared library versioning to provide... " >&6; } +@@ -9302,7 +9475,7 @@ printf "%s\n" "#define LT_OBJDIR \"$lt_cv_objdir/\"" >>confdefs.h + + + +-case $host_os in ++case $target_os in + aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems +@@ -9614,10 +9787,10 @@ lt_prog_compiler_static= + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_static='-static' + +- case $host_os in ++ case $target_os in + aix*) + # All AIX code is PIC. +- if test ia64 = "$host_cpu"; then ++ if test ia64 = "$target_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + fi +@@ -9625,7 +9798,7 @@ lt_prog_compiler_static= + ;; + + amigaos*) +- case $host_cpu in ++ case $target_cpu in + powerpc) + # see comment about AmigaOS4 .so support + lt_prog_compiler_pic='-fPIC' +@@ -9649,7 +9822,7 @@ lt_prog_compiler_static= + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + lt_prog_compiler_pic='-DDLL_EXPORT' +- case $host_os in ++ case $target_os in + os2*) + lt_prog_compiler_static='$wl-static' + ;; +@@ -9672,7 +9845,7 @@ lt_prog_compiler_static= + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. +- case $host_cpu in ++ case $target_cpu in + hppa*64*) + # +Z the default + ;; +@@ -9721,10 +9894,10 @@ lt_prog_compiler_static= + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. +- case $host_os in ++ case $target_os in + aix*) + lt_prog_compiler_wl='-Wl,' +- if test ia64 = "$host_cpu"; then ++ if test ia64 = "$target_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + else +@@ -9750,7 +9923,7 @@ lt_prog_compiler_static= + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic='-DDLL_EXPORT' +- case $host_os in ++ case $target_os in + os2*) + lt_prog_compiler_static='$wl-static' + ;; +@@ -9761,7 +9934,7 @@ lt_prog_compiler_static= + lt_prog_compiler_wl='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. +- case $host_cpu in ++ case $target_cpu in + hppa*64*|ia64*) + # +Z the default + ;; +@@ -9937,7 +10110,7 @@ lt_prog_compiler_static= + esac + fi + +-case $host_os in ++case $target_os in + # For platforms that do not support PIC, -DPIC is meaningless: + *djgpp*) + lt_prog_compiler_pic= +@@ -10252,7 +10425,7 @@ printf %s "checking whether the $compiler linker ($LD) supports shared libraries + # Exclude shared library initialization/finalization symbols. + extract_expsyms_cmds= + +- case $host_os in ++ case $target_os in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using +@@ -10279,7 +10452,7 @@ printf %s "checking whether the $compiler linker ($LD) supports shared libraries + # that we're better off using the native interface for both. + lt_use_gnu_ld_interface=no + if test yes = "$with_gnu_ld"; then +- case $host_os in ++ case $target_os in + aix*) + # The AIX port of GNU ld has always aspired to compatibility + # with the native linker. However, as the warning in the GNU ld +@@ -10327,10 +10500,10 @@ printf %s "checking whether the $compiler linker ($LD) supports shared libraries + esac + + # See if GNU ld supports shared libraries. +- case $host_os in ++ case $target_os in + aix[3-9]*) + # On AIX/PPC, the GNU linker is very broken +- if test ia64 != "$host_cpu"; then ++ if test ia64 != "$target_cpu"; then + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +@@ -10346,7 +10519,7 @@ _LT_EOF + ;; + + amigaos*) +- case $host_cpu in ++ case $target_cpu in + powerpc) + # see comment about AmigaOS4 .so support + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' +@@ -10448,7 +10621,7 @@ _LT_EOF + + gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) + tmp_diet=no +- if test linux-dietlibc = "$host_os"; then ++ if test linux-dietlibc = "$target_os"; then + case $cc_basename in + diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) + esac +@@ -10458,7 +10631,7 @@ _LT_EOF + then + tmp_addflag=' $pic_flag' + tmp_sharedflag='-shared' +- case $cc_basename,$host_cpu in ++ case $cc_basename,$target_cpu in + pgcc*) # Portland Group C compiler + whole_archive_flag_spec='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag' +@@ -10612,7 +10785,7 @@ _LT_EOF + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) +- case $host_os in ++ case $target_os in + aix3*) + allow_undefined_flag=unsupported + always_export_symbols=yes +@@ -10628,7 +10801,7 @@ _LT_EOF + ;; + + aix[4-9]*) +- if test ia64 = "$host_cpu"; then ++ if test ia64 = "$target_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no +@@ -10665,7 +10838,7 @@ _LT_EOF + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive +- case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) ++ case $target_os in aix4.[23]|aix4.[23].*|aix[5-9]*) + for ld_flag in $LDFLAGS; do + if (test x-brtl = "x$ld_flag" || test x-Wl,-brtl = "x$ld_flag"); then + aix_use_runtimelinking=yes +@@ -10708,7 +10881,7 @@ _LT_EOF + esac + + if test yes = "$GCC"; then +- case $host_os in aix4.[012]|aix4.[012].*) ++ case $target_os in aix4.[012]|aix4.[012].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` +@@ -10740,7 +10913,7 @@ _LT_EOF + shared_flag_svr4='-shared $wl-G' + else + # not using gcc +- if test ia64 = "$host_cpu"; then ++ if test ia64 = "$target_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' +@@ -10813,7 +10986,7 @@ fi + hardcode_libdir_flag_spec='$wl-blibpath:$libdir:'"$aix_libpath" + archive_expsym_cmds='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else +- if test ia64 = "$host_cpu"; then ++ if test ia64 = "$target_cpu"; then + hardcode_libdir_flag_spec='$wl-R $libdir:/usr/lib:/lib' + allow_undefined_flag="-z nodefs" + archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" +@@ -10897,7 +11070,7 @@ fi + ;; + + amigaos*) +- case $host_cpu in ++ case $target_cpu in + powerpc) + # see comment about AmigaOS4 .so support + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' +@@ -11082,7 +11255,7 @@ fi + + hpux11*) + if test yes,no = "$GCC,$with_gnu_ld"; then +- case $host_cpu in ++ case $target_cpu in + hppa*64*) + archive_cmds='$CC -shared $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; +@@ -11094,7 +11267,7 @@ fi + ;; + esac + else +- case $host_cpu in ++ case $target_cpu in + hppa*64*) + archive_cmds='$CC -b $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; +@@ -11150,7 +11323,7 @@ fi + hardcode_libdir_flag_spec='$wl+b $wl$libdir' + hardcode_libdir_separator=: + +- case $host_cpu in ++ case $target_cpu in + hppa*64*|ia64*) + hardcode_direct=no + hardcode_shlibpath_var=no +@@ -11175,8 +11348,8 @@ fi + # work, assume that -exports_file does not work either and + # implicitly export all symbols. + # This should be the same for all languages, so no per-tag cache variable. +- { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 +-printf %s "checking whether the $host_os linker accepts -exported_symbol... " >&6; } ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $target_os linker accepts -exported_symbol" >&5 ++printf %s "checking whether the $target_os linker accepts -exported_symbol... " >&6; } + if test ${lt_cv_irix_exported_symbol+y} + then : + printf %s "(cached) " >&6 +@@ -11349,7 +11522,7 @@ printf "%s\n" "$lt_cv_irix_exported_symbol" >&6; } + fi + hardcode_libdir_flag_spec='-R$libdir' + hardcode_shlibpath_var=no +- case $host_os in ++ case $target_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + # The compiler driver will combine and reorder linker options, +@@ -11367,7 +11540,7 @@ printf "%s\n" "$lt_cv_irix_exported_symbol" >&6; } + ;; + + sunos4*) +- if test sequent = "$host_vendor"; then ++ if test sequent = "$target_vendor"; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + archive_cmds='$CC -G $wl-h $soname -o $lib $libobjs $deplibs $compiler_flags' +@@ -11381,7 +11554,7 @@ printf "%s\n" "$lt_cv_irix_exported_symbol" >&6; } + ;; + + sysv4) +- case $host_vendor in ++ case $target_vendor in + sni) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes # is this really true??? +@@ -11470,8 +11643,8 @@ printf "%s\n" "$lt_cv_irix_exported_symbol" >&6; } + ;; + esac + +- if test sni = "$host_vendor"; then +- case $host in ++ if test sni = "$target_vendor"; then ++ case $target in + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + export_dynamic_flag_spec='$wl-Blargedynsym' + ;; +@@ -11724,11 +11897,11 @@ esac + printf %s "checking dynamic linker characteristics... " >&6; } + + if test yes = "$GCC"; then +- case $host_os in ++ case $target_os in + darwin*) lt_awk_arg='/^libraries:/,/LR/' ;; + *) lt_awk_arg='/^libraries:/' ;; + esac +- case $host_os in ++ case $target_os in + mingw* | cegcc*) lt_sed_strip_eq='s|=\([A-Za-z]:\)|\1|g' ;; + *) lt_sed_strip_eq='s|=/|/|g' ;; + esac +@@ -11786,7 +11959,7 @@ BEGIN {RS = " "; FS = "/|\n";} { + }'` + # AWK program above erroneously prepends '/' to C:/dos/paths + # for these hosts. +- case $host_os in ++ case $target_os in + mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ + $SED 's|/\([A-Za-z]:\)|\1|g'` ;; + esac +@@ -11805,7 +11978,7 @@ finish_eval= + shlibpath_var= + shlibpath_overrides_runpath=unknown + version_type=none +-dynamic_linker="$host_os ld.so" ++dynamic_linker="$target_os ld.so" + sys_lib_dlsearch_path_spec="/lib /usr/lib" + need_lib_prefix=unknown + hardcode_into_libs=no +@@ -11816,7 +11989,7 @@ need_version=unknown + + + +-case $host_os in ++case $target_os in + aix3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname.a' +@@ -11831,7 +12004,7 @@ aix[4-9]*) + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes +- if test ia64 = "$host_cpu"; then ++ if test ia64 = "$target_cpu"; then + # AIX 5 supports IA64 + library_names_spec='$libname$release$shared_ext$major $libname$release$shared_ext$versuffix $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH +@@ -11841,7 +12014,7 @@ aix[4-9]*) + # the line '#! .'. This would cause the generated library to + # depend on '.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. +- case $host_os in ++ case $target_os in + aix4 | aix4.[01] | aix4.[01].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' +@@ -11921,7 +12094,7 @@ aix[4-9]*) + ;; + + amigaos*) +- case $host_cpu in ++ case $target_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. +@@ -11937,7 +12110,7 @@ amigaos*) + + beos*) + library_names_spec='$libname$shared_ext' +- dynamic_linker="$host_os ld.so" ++ dynamic_linker="$target_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +@@ -11980,7 +12153,7 @@ cygwin* | mingw* | pw32* | cegcc*) + $RM \$dlpath' + shlibpath_overrides_runpath=yes + +- case $host_os in ++ case $target_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' +@@ -12066,7 +12239,7 @@ cygwin* | mingw* | pw32* | cegcc*) + ;; + + darwin* | rhapsody*) +- dynamic_linker="$host_os dyld" ++ dynamic_linker="$target_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no +@@ -12095,7 +12268,7 @@ freebsd* | dragonfly*) + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else +- case $host_os in ++ case $target_os in + freebsd[23].*) objformat=aout ;; + *) objformat=elf ;; + esac +@@ -12114,7 +12287,7 @@ freebsd* | dragonfly*) + ;; + esac + shlibpath_var=LD_LIBRARY_PATH +- case $host_os in ++ case $target_os in + freebsd2.*) + shlibpath_overrides_runpath=yes + ;; +@@ -12138,7 +12311,7 @@ haiku*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no +- dynamic_linker="$host_os runtime_loader" ++ dynamic_linker="$target_os runtime_loader" + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LIBRARY_PATH +@@ -12153,11 +12326,11 @@ hpux9* | hpux10* | hpux11*) + version_type=sunos + need_lib_prefix=no + need_version=no +- case $host_cpu in ++ case $target_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes +- dynamic_linker="$host_os dld.so" ++ dynamic_linker="$target_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' +@@ -12173,7 +12346,7 @@ hpux9* | hpux10* | hpux11*) + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes +- dynamic_linker="$host_os dld.sl" ++ dynamic_linker="$target_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' +@@ -12183,7 +12356,7 @@ hpux9* | hpux10* | hpux11*) + ;; + *) + shrext_cmds='.sl' +- dynamic_linker="$host_os dld.sl" ++ dynamic_linker="$target_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' +@@ -12209,7 +12382,7 @@ interix[3-9]*) + ;; + + irix5* | irix6* | nonstopux*) +- case $host_os in ++ case $target_os in + nonstopux*) version_type=nonstopux ;; + *) + if test yes = "$lt_cv_prog_gnu_ld"; then +@@ -12222,7 +12395,7 @@ irix5* | irix6* | nonstopux*) + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$release$shared_ext $libname$shared_ext' +- case $host_os in ++ case $target_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; +@@ -12482,7 +12655,7 @@ sysv4 | sysv4.3*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH +- case $host_vendor in ++ case $target_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no +@@ -12522,7 +12695,7 @@ sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' +- case $host_os in ++ case $target_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; +@@ -12726,7 +12899,7 @@ else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + +- case $host_os in ++ case $target_os in + beos*) + lt_cv_dlopen=load_add_on + lt_cv_dlopen_libs= +@@ -13261,7 +13434,7 @@ if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + printf "%s\n" "yes" >&6; } + else + # FIXME - insert some real tests, host_os isn't really good enough +- case $host_os in ++ case $target_os in + darwin*) + if test -n "$STRIP"; then + striplib="$STRIP -x" +@@ -13303,7 +13476,7 @@ printf %s "checking whether to build shared libraries... " >&6; } + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. +- case $host_os in ++ case $target_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then +@@ -13313,7 +13486,7 @@ printf %s "checking whether to build shared libraries... " >&6; } + ;; + + aix[4-9]*) +- if test ia64 != "$host_cpu"; then ++ if test ia64 != "$target_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only +@@ -13367,7 +13540,7 @@ CC=$lt_save_CC + + + CFLAGS="$saved_CFLAGS" +-host_os=$old_host_os ++target_os=$old_host_os + + case $host in #( + sparc-sun-solaris*) : +@@ -13511,7 +13684,7 @@ else $as_nop + fi ;; + esac + +-case $host in #( ++case $target in #( + # In config/Makefile.mingw*, we had: + # TARGET=i686-w64-mingw32 and x86_64-w64-mingw32 + # TOOLPREF=$(TARGET)- +@@ -13523,7 +13696,7 @@ case $host in #( + mkexe_via_cc_extra_cmd=' && $(call MERGEMANIFESTEXE,$(1))' + libext=lib + AR="" +- if test "$host_cpu" = "x86_64" ++ if test "$target_cpu" = "x86_64" + then : + machine="-machine:AMD64 " + else $as_nop +@@ -13734,8 +13907,8 @@ printf "%s\n" "$ocaml_cc_vendor" >&6; } + ## In cross-compilation mode, can we run executables produced? + # At the moment, it's required, but the fact is used in C99 function detection + +- { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether host executables can be run in the build" >&5 +-printf %s "checking whether host executables can be run in the build... " >&6; } ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether target executables can be run in the build" >&5 ++printf %s "checking whether target executables can be run in the build... " >&6; } + old_cross_compiling="$cross_compiling" + cross_compiling='no' + if test "$cross_compiling" = yes +@@ -13759,11 +13932,11 @@ if ac_fn_c_try_run "$LINENO" + then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 + printf "%s\n" "yes" >&6; } +- host_runnable=true ++ target_runnable=true + else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 + printf "%s\n" "no" >&6; } +- host_runnable=false ++ target_runnable=false + fi + rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +@@ -13813,6 +13986,14 @@ esac + ocamlsrcdir=$(unset CDPATH; cd -- "$srcdir" && printf %sX "$PWD") || fail + ocamlsrcdir=${ocamlsrcdir%X} + ++case $host in #( ++ *-*-mingw32*|*-pc-windows) : ++ ln='cp -pf' ++ ocamlsrcdir="$(LC_ALL=C.UTF-8 cygpath -w -- "$ocamlsrcdir")" ;; #( ++ *) : ++ ln='ln -sf' ;; ++esac ++ + # Whether ar supports @FILE arguments + + case $lt_cv_ar_at_file in #( +@@ -13822,23 +14003,20 @@ case $lt_cv_ar_at_file in #( + ar_supports_response_files=true ;; + esac + +-# Libraries to build depending on the host ++# Libraries to build depending on the target + +-case $host in #( ++case $target in #( + *-*-mingw32*|*-pc-windows) : + unix_or_win32="win32" +- ln='cp -pf' + ocamltest_libunix="Some false" +- ocamlsrcdir="$(LC_ALL=C.UTF-8 cygpath -w -- "$ocamlsrcdir")" + ocamlyacc_wstr_module="yacc/wstr" ;; #( + *) : + unix_or_win32="unix" +- ln='ln -sf' + ocamltest_libunix="Some true" + ocamlyacc_wstr_module="" ;; + esac + +-case $host in #( ++case $target in #( + *-*-cygwin*|*-*-mingw32*|*-pc-windows) : + exeext=".exe" ;; #( + *) : +@@ -13910,7 +14088,7 @@ shebangscripts=false + launch_method='exe' + if test "x$interpval" = "xyes" + then : +- case $host in #( ++ case $target in #( + *-cygwin) : + # Cygwin supports shebangs, which we use for the compiler itself, but + # partially for legacy, and partially so that executables can be easily +@@ -13938,65 +14116,1244 @@ fi + ac_config_commands="$ac_config_commands shebang" + + +-# Are we building a cross-compiler ++# How to build sak + +-if test x"$host" = x"$target" ++if test x"$build" = x"$target" -o x"$target_runnable" = xtrue + then : +- cross_compiler=false ++ SAK_CC='$(CC)' ++ SAK_CFLAGS='$(OC_CFLAGS) $(CFLAGS) $(OC_CPPFLAGS) $(CPPFLAGS)' ++ SAK_LINK='$(MKEXE_VIA_CC)' + else $as_nop +- cross_compiler=true +-fi ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: detecting the C toolchain for build" >&5 ++printf "%s\n" "$as_me: detecting the C toolchain for build" >&6;} + +-# Checks for programs + +-## Check for the C compiler: done by libtool +-## AC_PROG_CC ++cross_compiling_build=no + +-## Check for C99 support: done by libtool +-## AC_PROG_CC_C99 ++ac_build_tool_prefix= ++if test -n "$build" ++then : ++ ac_build_tool_prefix="$build-" ++elif test -n "$build_alias" ++then : ++ ac_build_tool_prefix="$build_alias-" ++fi + +-## Determine which flags to use for the C compiler ++ac_ext=c ++ac_cpp='$CPP_FOR_BUILD $CPPFLAGS_FOR_BUILD' ++ac_compile='$CC_FOR_BUILD -c $CFLAGS_FOR_BUILD $CPPFLAGS_FOR_BUILD conftest.$ac_ext >&5' ++ac_link='$CC_FOR_BUILD -o conftest$ac_build_exeext $CFLAGS_FOR_BUILD $CPPFLAGS_FOR_BUILD $LDFLAGS_FOR_BUILD conftest.$ac_ext $LIBS >&5' ++ac_compiler_gnu=$ac_cv_build_c_compiler_gnu + +-case $ocaml_cc_vendor in #( +- xlc-*) : +- outputobj='-o ' +- warn_error_flag='' +- cc_warnings='-qflag=i:i' ;; #( +- # all warnings enabled +- sunc-*) : +- outputobj='-o '; cc_warnings="" ;; #( +- msvc-*) : +- outputobj='-Fo' +- case $ocaml_cc_vendor in #( +- msvc-*-clang-*) : +- cc_warnings='-W4 -Wno-unused-parameter -Wno-sign-compare -Wundef' +- warn_error_flag='-WX' ;; #( +- *) : +- cc_warnings='-W2' +- warn_error_flag='-WX -options:strict' ;; +-esac ;; #( +- *) : +- outputobj='-o ' +- warn_error_flag='-Werror' +- cc_warnings="-Wall -Wint-conversion -Wstrict-prototypes \ +--Wold-style-definition -Wundef" ;; +-esac + +-# Use -Wold-style-declaration if supported +-as_CACHEVAR=`printf "%s\n" "ax_cv_check_cflags_$warn_error_flag_-Wold-style-declaration" | $as_tr_sh` +-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler accepts -Wold-style-declaration" >&5 +-printf %s "checking whether the C compiler accepts -Wold-style-declaration... " >&6; } +-if eval test \${$as_CACHEVAR+y} ++was_set_c_compiler_gnu=${ac_cv_c_compiler_gnu+y} ++if test ${was_set_c_compiler_gnu} ++then : ++ saved_c_compiler_gnu=$ac_cv_c_compiler_gnu ++ { ac_cv_c_compiler_gnu=; unset ac_cv_c_compiler_gnu;} ++fi ++ ++ac_ext=c ++ac_cpp='$CPP_FOR_BUILD $CPPFLAGS_FOR_BUILD' ++ac_compile='$CC_FOR_BUILD -c $CFLAGS_FOR_BUILD $CPPFLAGS_FOR_BUILD conftest.$ac_ext >&5' ++ac_link='$CC_FOR_BUILD -o conftest$ac_build_exeext $CFLAGS_FOR_BUILD $CPPFLAGS_FOR_BUILD $LDFLAGS_FOR_BUILD conftest.$ac_ext $LIBS >&5' ++ac_compiler_gnu=$ac_cv_build_c_compiler_gnu ++if test -n "$ac_build_tool_prefix"; then ++ # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. ++set dummy ${ac_build_tool_prefix}gcc; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_prog_CC_FOR_BUILD+y} + then : + printf %s "(cached) " >&6 + else $as_nop +- +- ax_check_save_flags=$CFLAGS +- CFLAGS="$CFLAGS $warn_error_flag -Wold-style-declaration" +- cat confdefs.h - <<_ACEOF >conftest.$ac_ext +-/* end confdefs.h. */ +- +-int ++ if test -n "$CC_FOR_BUILD"; then ++ ac_cv_prog_CC_FOR_BUILD="$CC_FOR_BUILD" # Let the user override the test. ++else ++as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ ac_cv_prog_CC_FOR_BUILD="${ac_build_tool_prefix}gcc" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++fi ++fi ++CC_FOR_BUILD=$ac_cv_prog_CC_FOR_BUILD ++if test -n "$CC_FOR_BUILD"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC_FOR_BUILD" >&5 ++printf "%s\n" "$CC_FOR_BUILD" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ ++fi ++if test -z "$ac_cv_prog_CC_FOR_BUILD"; then ++ ac_ct_CC_FOR_BUILD=$CC_FOR_BUILD ++ # Extract the first word of "gcc", so it can be a program name with args. ++set dummy gcc; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_prog_ac_ct_CC_FOR_BUILD+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ if test -n "$ac_ct_CC_FOR_BUILD"; then ++ ac_cv_prog_ac_ct_CC_FOR_BUILD="$ac_ct_CC_FOR_BUILD" # Let the user override the test. ++else ++as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ ac_cv_prog_ac_ct_CC_FOR_BUILD="gcc" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++fi ++fi ++ac_ct_CC_FOR_BUILD=$ac_cv_prog_ac_ct_CC_FOR_BUILD ++if test -n "$ac_ct_CC_FOR_BUILD"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC_FOR_BUILD" >&5 ++printf "%s\n" "$ac_ct_CC_FOR_BUILD" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ if test "x$ac_ct_CC_FOR_BUILD" = x; then ++ CC_FOR_BUILD="" ++ else ++ case $cross_compiling_build:$ac_tool_warned in ++yes:) ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with build triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with build triplet" >&2;} ++ac_tool_warned=yes ;; ++esac ++ CC_FOR_BUILD=$ac_ct_CC_FOR_BUILD ++ fi ++else ++ CC_FOR_BUILD="$ac_cv_prog_CC_FOR_BUILD" ++fi ++ ++if test -z "$CC_FOR_BUILD"; then ++ if test -n "$ac_build_tool_prefix"; then ++ # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. ++set dummy ${ac_build_tool_prefix}cc; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_prog_CC_FOR_BUILD+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ if test -n "$CC_FOR_BUILD"; then ++ ac_cv_prog_CC_FOR_BUILD="$CC_FOR_BUILD" # Let the user override the test. ++else ++as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ ac_cv_prog_CC_FOR_BUILD="${ac_build_tool_prefix}cc" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++fi ++fi ++CC_FOR_BUILD=$ac_cv_prog_CC_FOR_BUILD ++if test -n "$CC_FOR_BUILD"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC_FOR_BUILD" >&5 ++printf "%s\n" "$CC_FOR_BUILD" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ ++ fi ++fi ++if test -z "$CC_FOR_BUILD"; then ++ # Extract the first word of "cc", so it can be a program name with args. ++set dummy cc; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_prog_CC_FOR_BUILD+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ if test -n "$CC_FOR_BUILD"; then ++ ac_cv_prog_CC_FOR_BUILD="$CC_FOR_BUILD" # Let the user override the test. ++else ++ ac_prog_rejected=no ++as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ if test "$as_dir$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ++ ac_prog_rejected=yes ++ continue ++ fi ++ ac_cv_prog_CC_FOR_BUILD="cc" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++if test $ac_prog_rejected = yes; then ++ # We found a bogon in the path, so make sure we never use it. ++ set dummy $ac_cv_prog_CC_FOR_BUILD ++ shift ++ if test $# != 0; then ++ # We chose a different compiler from the bogus one. ++ # However, it has the same basename, so the bogon will be chosen ++ # first if we set CC_FOR_BUILD to just the basename; use the full file name. ++ shift ++ ac_cv_prog_CC_FOR_BUILD="$as_dir$ac_word${1+' '}$@" ++ fi ++fi ++fi ++fi ++CC_FOR_BUILD=$ac_cv_prog_CC_FOR_BUILD ++if test -n "$CC_FOR_BUILD"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC_FOR_BUILD" >&5 ++printf "%s\n" "$CC_FOR_BUILD" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ ++fi ++if test -z "$CC_FOR_BUILD"; then ++ if test -n "$ac_build_tool_prefix"; then ++ for ac_prog in cl.exe ++ do ++ # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. ++set dummy $ac_build_tool_prefix$ac_prog; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_prog_CC_FOR_BUILD+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ if test -n "$CC_FOR_BUILD"; then ++ ac_cv_prog_CC_FOR_BUILD="$CC_FOR_BUILD" # Let the user override the test. ++else ++as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ ac_cv_prog_CC_FOR_BUILD="$ac_build_tool_prefix$ac_prog" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++fi ++fi ++CC_FOR_BUILD=$ac_cv_prog_CC_FOR_BUILD ++if test -n "$CC_FOR_BUILD"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC_FOR_BUILD" >&5 ++printf "%s\n" "$CC_FOR_BUILD" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ ++ test -n "$CC_FOR_BUILD" && break ++ done ++fi ++if test -z "$CC_FOR_BUILD"; then ++ ac_ct_CC_FOR_BUILD=$CC_FOR_BUILD ++ for ac_prog in cl.exe ++do ++ # Extract the first word of "$ac_prog", so it can be a program name with args. ++set dummy $ac_prog; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_prog_ac_ct_CC_FOR_BUILD+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ if test -n "$ac_ct_CC_FOR_BUILD"; then ++ ac_cv_prog_ac_ct_CC_FOR_BUILD="$ac_ct_CC_FOR_BUILD" # Let the user override the test. ++else ++as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ ac_cv_prog_ac_ct_CC_FOR_BUILD="$ac_prog" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++fi ++fi ++ac_ct_CC_FOR_BUILD=$ac_cv_prog_ac_ct_CC_FOR_BUILD ++if test -n "$ac_ct_CC_FOR_BUILD"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC_FOR_BUILD" >&5 ++printf "%s\n" "$ac_ct_CC_FOR_BUILD" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ ++ test -n "$ac_ct_CC_FOR_BUILD" && break ++done ++ ++ if test "x$ac_ct_CC_FOR_BUILD" = x; then ++ CC_FOR_BUILD="" ++ else ++ case $cross_compiling_build:$ac_tool_warned in ++yes:) ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with build triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with build triplet" >&2;} ++ac_tool_warned=yes ;; ++esac ++ CC_FOR_BUILD=$ac_ct_CC_FOR_BUILD ++ fi ++fi ++ ++fi ++if test -z "$CC_FOR_BUILD"; then ++ if test -n "$ac_build_tool_prefix"; then ++ # Extract the first word of "${ac_tool_prefix}clang", so it can be a program name with args. ++set dummy ${ac_build_tool_prefix}clang; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_prog_CC_FOR_BUILD+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ if test -n "$CC_FOR_BUILD"; then ++ ac_cv_prog_CC_FOR_BUILD="$CC_FOR_BUILD" # Let the user override the test. ++else ++as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ ac_cv_prog_CC_FOR_BUILD="${ac_build_tool_prefix}clang" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++fi ++fi ++CC_FOR_BUILD=$ac_cv_prog_CC_FOR_BUILD ++if test -n "$CC_FOR_BUILD"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC_FOR_BUILD" >&5 ++printf "%s\n" "$CC_FOR_BUILD" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ ++fi ++if test -z "$ac_cv_prog_CC_FOR_BUILD"; then ++ ac_ct_CC_FOR_BUILD=$CC_FOR_BUILD ++ # Extract the first word of "clang", so it can be a program name with args. ++set dummy clang; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_prog_ac_ct_CC_FOR_BUILD+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ if test -n "$ac_ct_CC_FOR_BUILD"; then ++ ac_cv_prog_ac_ct_CC_FOR_BUILD="$ac_ct_CC_FOR_BUILD" # Let the user override the test. ++else ++as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ ac_cv_prog_ac_ct_CC_FOR_BUILD="clang" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++fi ++fi ++ac_ct_CC_FOR_BUILD=$ac_cv_prog_ac_ct_CC_FOR_BUILD ++if test -n "$ac_ct_CC_FOR_BUILD"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC_FOR_BUILD" >&5 ++printf "%s\n" "$ac_ct_CC_FOR_BUILD" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ if test "x$ac_ct_CC_FOR_BUILD" = x; then ++ CC_FOR_BUILD="" ++ else ++ case $cross_compiling_build:$ac_tool_warned in ++yes:) ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with build triplet" >&5 ++printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with build triplet" >&2;} ++ac_tool_warned=yes ;; ++esac ++ CC_FOR_BUILD=$ac_ct_CC_FOR_BUILD ++ fi ++else ++ CC_FOR_BUILD="$ac_cv_prog_CC_FOR_BUILD" ++fi ++ ++fi ++ ++ ++test -z "$CC_FOR_BUILD" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 ++printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} ++as_fn_error $? "no acceptable C compiler found in \$PATH ++See \`config.log' for more details" "$LINENO" 5; } ++ ++# Provide some information about the compiler. ++printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 ++set X $ac_compile ++ac_compiler=$2 ++for ac_option in --version -v -V -qversion -version; do ++ { { ac_try="$ac_compiler $ac_option >&5" ++case "(($ac_try" in ++ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; ++ *) ac_try_echo=$ac_try;; ++esac ++eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" ++printf "%s\n" "$ac_try_echo"; } >&5 ++ (eval "$ac_compiler $ac_option >&5") 2>conftest.err ++ ac_status=$? ++ if test -s conftest.err; then ++ sed '10a\ ++... rest of stderr output deleted ... ++ 10q' conftest.err >conftest.er1 ++ cat conftest.er1 >&5 ++ fi ++ rm -f conftest.er1 conftest.err ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 ++ test $ac_status = 0; } ++done ++ ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5 ++printf %s "checking whether the compiler supports GNU C... " >&6; } ++if test ${ac_cv_c_compiler_gnu+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++ ++int ++main (void) ++{ ++#ifndef __GNUC__ ++ choke me ++#endif ++ ++ ; ++ return 0; ++} ++_ACEOF ++if ac_fn_c_try_compile "$LINENO" ++then : ++ ac_compiler_gnu=yes ++else $as_nop ++ ac_compiler_gnu=no ++fi ++rm -f core conftest.err conftest.$ac_build_objext conftest.beam conftest.$ac_ext ++ac_cv_c_compiler_gnu=$ac_compiler_gnu ++ ++fi ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 ++printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; } ++ac_compiler_gnu=$ac_cv_c_compiler_gnu ++ ++if test $ac_compiler_gnu = yes; then ++ GCC_FOR_BUILD=yes ++else ++ GCC_FOR_BUILD= ++fi ++ac_test_CFLAGS=${CFLAGS_FOR_BUILD+y} ++ac_save_CFLAGS=$CFLAGS_FOR_BUILD ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC_FOR_BUILD accepts -g" >&5 ++printf %s "checking whether $CC_FOR_BUILD accepts -g... " >&6; } ++if test ${ac_cv_build_prog_cc_g+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ ac_save_c_werror_flag=$ac_c_werror_flag ++ ac_c_werror_flag=yes ++ ac_cv_build_prog_cc_g=no ++ CFLAGS_FOR_BUILD="-g" ++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++ ++int ++main (void) ++{ ++ ++ ; ++ return 0; ++} ++_ACEOF ++if ac_fn_c_try_compile "$LINENO" ++then : ++ ac_cv_build_prog_cc_g=yes ++else $as_nop ++ CFLAGS_FOR_BUILD="" ++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++ ++int ++main (void) ++{ ++ ++ ; ++ return 0; ++} ++_ACEOF ++if ac_fn_c_try_compile "$LINENO" ++then : ++ ++else $as_nop ++ ac_c_werror_flag=$ac_save_c_werror_flag ++ CFLAGS_FOR_BUILD="-g" ++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++ ++int ++main (void) ++{ ++ ++ ; ++ return 0; ++} ++_ACEOF ++if ac_fn_c_try_compile "$LINENO" ++then : ++ ac_cv_build_prog_cc_g=yes ++fi ++rm -f core conftest.err conftest.$ac_build_objext conftest.beam conftest.$ac_ext ++fi ++rm -f core conftest.err conftest.$ac_build_objext conftest.beam conftest.$ac_ext ++fi ++rm -f core conftest.err conftest.$ac_build_objext conftest.beam conftest.$ac_ext ++ ac_c_werror_flag=$ac_save_c_werror_flag ++fi ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build_prog_cc_g" >&5 ++printf "%s\n" "$ac_cv_build_prog_cc_g" >&6; } ++if test $ac_test_CFLAGS; then ++ CFLAGS_FOR_BUILD=$ac_save_CFLAGS ++elif test $ac_cv_build_prog_cc_g = yes; then ++ if test "$GCC_FOR_BUILD" = yes; then ++ CFLAGS_FOR_BUILD="-g -O2" ++ else ++ CFLAGS_FOR_BUILD="-g" ++ fi ++else ++ if test "$GCC_FOR_BUILD" = yes; then ++ CFLAGS_FOR_BUILD="-O2" ++ else ++ CFLAGS_FOR_BUILD= ++ fi ++fi ++ac_prog_cc_stdc=no ++if test x$ac_prog_cc_stdc = xno ++then : ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC_FOR_BUILD option to enable C11 features" >&5 ++printf %s "checking for $CC_FOR_BUILD option to enable C11 features... " >&6; } ++if test ${ac_cv_build_prog_cc_c11+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ ac_cv_build_prog_cc_c11=no ++ac_save_CC=$CC_FOR_BUILD ++cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++$ac_c_conftest_c11_program ++_ACEOF ++for ac_arg in '' -std=gnu11 ++do ++ CC_FOR_BUILD="$ac_save_CC $ac_arg" ++ if ac_fn_c_try_compile "$LINENO" ++then : ++ ac_cv_build_prog_cc_c11=$ac_arg ++fi ++rm -f core conftest.err conftest.$ac_build_objext conftest.beam ++ test "x$ac_cv_build_prog_cc_c11" != "xno" && break ++done ++rm -f conftest.$ac_ext ++CC_FOR_BUILD=$ac_save_CC ++fi ++ ++if test "x$ac_cv_build_prog_cc_c11" = xno ++then : ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 ++printf "%s\n" "unsupported" >&6; } ++else $as_nop ++ if test "x$ac_cv_build_prog_cc_c11" = x ++then : ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 ++printf "%s\n" "none needed" >&6; } ++else $as_nop ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build_prog_cc_c11" >&5 ++printf "%s\n" "$ac_cv_build_prog_cc_c11" >&6; } ++ CC_FOR_BUILD="$CC_FOR_BUILD $ac_cv_build_prog_cc_c11" ++fi ++ ac_cv_prog_cc_stdc=$ac_cv_build_prog_cc_c11 ++ ac_prog_cc_stdc=c11 ++fi ++fi ++if test x$ac_prog_cc_stdc = xno ++then : ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC_FOR_BUILD option to enable C99 features" >&5 ++printf %s "checking for $CC_FOR_BUILD option to enable C99 features... " >&6; } ++if test ${ac_cv_build_prog_cc_c99+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ ac_cv_build_prog_cc_c99=no ++ac_save_CC=$CC_FOR_BUILD ++cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++$ac_c_conftest_c99_program ++_ACEOF ++for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99= ++do ++ CC_FOR_BUILD="$ac_save_CC $ac_arg" ++ if ac_fn_c_try_compile "$LINENO" ++then : ++ ac_cv_build_prog_cc_c99=$ac_arg ++fi ++rm -f core conftest.err conftest.$ac_build_objext conftest.beam ++ test "x$ac_cv_build_prog_cc_c99" != "xno" && break ++done ++rm -f conftest.$ac_ext ++CC_FOR_BUILD=$ac_save_CC ++fi ++ ++if test "x$ac_cv_build_prog_cc_c99" = xno ++then : ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 ++printf "%s\n" "unsupported" >&6; } ++else $as_nop ++ if test "x$ac_cv_build_prog_cc_c99" = x ++then : ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 ++printf "%s\n" "none needed" >&6; } ++else $as_nop ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build_prog_cc_c99" >&5 ++printf "%s\n" "$ac_cv_build_prog_cc_c99" >&6; } ++ CC_FOR_BUILD="$CC_FOR_BUILD $ac_cv_build_prog_cc_c99" ++fi ++ ac_cv_prog_cc_stdc=$ac_cv_build_prog_cc_c99 ++ ac_prog_cc_stdc=c99 ++fi ++fi ++if test x$ac_prog_cc_stdc = xno ++then : ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC_FOR_BUILD option to enable C89 features" >&5 ++printf %s "checking for $CC_FOR_BUILD option to enable C89 features... " >&6; } ++if test ${ac_cv_build_prog_cc_c89+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ ac_cv_build_prog_cc_c89=no ++ac_save_CC=$CC_FOR_BUILD ++cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++$ac_c_conftest_c89_program ++_ACEOF ++for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" ++do ++ CC_FOR_BUILD="$ac_save_CC $ac_arg" ++ if ac_fn_c_try_compile "$LINENO" ++then : ++ ac_cv_build_prog_cc_c89=$ac_arg ++fi ++rm -f core conftest.err conftest.$ac_build_objext conftest.beam ++ test "x$ac_cv_build_prog_cc_c89" != "xno" && break ++done ++rm -f conftest.$ac_ext ++CC_FOR_BUILD=$ac_save_CC ++fi ++ ++if test "x$ac_cv_build_prog_cc_c89" = xno ++then : ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 ++printf "%s\n" "unsupported" >&6; } ++else $as_nop ++ if test "x$ac_cv_build_prog_cc_c89" = x ++then : ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 ++printf "%s\n" "none needed" >&6; } ++else $as_nop ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build_prog_cc_c89" >&5 ++printf "%s\n" "$ac_cv_build_prog_cc_c89" >&6; } ++ CC_FOR_BUILD="$CC_FOR_BUILD $ac_cv_build_prog_cc_c89" ++fi ++ ac_cv_prog_cc_stdc=$ac_cv_build_prog_cc_c89 ++ ac_prog_cc_stdc=c89 ++fi ++fi ++ ++ac_ext=c ++ac_cpp='$CPP_FOR_BUILD $CPPFLAGS_FOR_BUILD' ++ac_compile='$CC_FOR_BUILD -c $CFLAGS_FOR_BUILD $CPPFLAGS_FOR_BUILD conftest.$ac_ext >&5' ++ac_link='$CC_FOR_BUILD -o conftest$ac_build_exeext $CFLAGS_FOR_BUILD $CPPFLAGS_FOR_BUILD $LDFLAGS_FOR_BUILD conftest.$ac_ext $LIBS >&5' ++ac_compiler_gnu=$ac_cv_build_c_compiler_gnu ++ ++ ++if test ${was_set_c_compiler_gnu} ++then : ++ ac_cv_c_compiler_gnu=$saved_c_compiler_gnu ++fi ++ ++cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++ ++int ++main (void) ++{ ++ ++ ; ++ return 0; ++} ++_ACEOF ++ac_clean_files_save=$ac_clean_files ++ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" ++# Try to create an executable without -o first, disregard a.out. ++# It will help us diagnose broken compilers, and finding out an intuition ++# of exeext. ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 ++printf %s "checking whether the C compiler works... " >&6; } ++ac_link_default=`printf "%s\n" "$ac_link" | sed 's/ -o *conftest[^ ]*//'` ++ ++# The possible output files: ++ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ++ ++ac_rmfiles= ++for ac_file in $ac_files ++do ++ case $ac_file in ++ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; ++ * ) ac_rmfiles="$ac_rmfiles $ac_file";; ++ esac ++done ++rm -f $ac_rmfiles ++ ++if { { ac_try="$ac_link_default" ++case "(($ac_try" in ++ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; ++ *) ac_try_echo=$ac_try;; ++esac ++eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" ++printf "%s\n" "$ac_try_echo"; } >&5 ++ (eval "$ac_link_default") 2>&5 ++ ac_status=$? ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 ++ test $ac_status = 0; } ++then : ++ # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. ++# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' ++# in a Makefile. We should not override ac_cv_exeext if it was cached, ++# so that the user can short-circuit this test for compilers unknown to ++# Autoconf. ++for ac_file in $ac_files '' ++do ++ test -f "$ac_file" || continue ++ case $ac_file in ++ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ++ ;; ++ [ab].out ) ++ # We found the default executable, but exeext='' is most ++ # certainly right. ++ break;; ++ *.* ) ++ if test ${ac_cv_build_exeext+y} && test "$ac_cv_build_exeext" != no; ++ then :; else ++ ac_cv_build_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` ++ fi ++ # We set ac_cv_exeext here because the later test for it is not ++ # safe: cross compilers may not add the suffix if given an `-o' ++ # argument, so we may need to know it at that point already. ++ # Even if this section looks crufty: it has the advantage of ++ # actually working. ++ break;; ++ * ) ++ break;; ++ esac ++done ++test "$ac_cv_build_exeext" = no && ac_cv_build_exeext= ++ ++else $as_nop ++ ac_file='' ++fi ++if test -z "$ac_file" ++then : ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++printf "%s\n" "$as_me: failed program was:" >&5 ++sed 's/^/| /' conftest.$ac_ext >&5 ++ ++{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 ++printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} ++as_fn_error 77 "C compiler cannot create executables ++See \`config.log' for more details" "$LINENO" 5; } ++else $as_nop ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 ++printf "%s\n" "yes" >&6; } ++fi ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 ++printf %s "checking for C compiler default output file name... " >&6; } ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 ++printf "%s\n" "$ac_file" >&6; } ++ac_build_exeext=$ac_cv_build_exeext ++ ++rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_build_exeext b.out ++ac_clean_files=$ac_clean_files_save ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 ++printf %s "checking for suffix of executables... " >&6; } ++if { { ac_try="$ac_link" ++case "(($ac_try" in ++ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; ++ *) ac_try_echo=$ac_try;; ++esac ++eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" ++printf "%s\n" "$ac_try_echo"; } >&5 ++ (eval "$ac_link") 2>&5 ++ ac_status=$? ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 ++ test $ac_status = 0; } ++then : ++ # If both `conftest.exe' and `conftest' are `present' (well, observable) ++# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will ++# work properly (i.e., refer to `conftest.exe'), while it won't with ++# `rm'. ++for ac_file in conftest.exe conftest conftest.*; do ++ test -f "$ac_file" || continue ++ case $ac_file in ++ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; ++ *.* ) ac_cv_build_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` ++ break;; ++ * ) break;; ++ esac ++done ++else $as_nop ++ { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 ++printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} ++as_fn_error $? "cannot compute suffix of executables: cannot compile and link ++See \`config.log' for more details" "$LINENO" 5; } ++fi ++rm -f conftest conftest$ac_cv_build_exeext ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build_exeext" >&5 ++printf "%s\n" "$ac_cv_build_exeext" >&6; } ++ ++rm -f conftest.$ac_ext ++EXEEXT=$ac_cv_build_exeext ++ac_build_exeext=$BUILD_EXEEXT ++cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++#include ++int ++main (void) ++{ ++FILE *f = fopen ("conftest.out", "w"); ++ return ferror (f) || fclose (f) != 0; ++ ++ ; ++ return 0; ++} ++_ACEOF ++ac_clean_files="$ac_clean_files conftest.out" ++# Check that the compiler produces executables we can run. If not, either ++# the compiler is broken, or we cross compile. ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 ++printf %s "checking whether we are cross compiling... " >&6; } ++if test "$cross_compiling_build" != yes; then ++ { { ac_try="$ac_link" ++case "(($ac_try" in ++ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; ++ *) ac_try_echo=$ac_try;; ++esac ++eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" ++printf "%s\n" "$ac_try_echo"; } >&5 ++ (eval "$ac_link") 2>&5 ++ ac_status=$? ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 ++ test $ac_status = 0; } ++ if { ac_try='./conftest$ac_cv_build_exeext' ++ { { case "(($ac_try" in ++ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; ++ *) ac_try_echo=$ac_try;; ++esac ++eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" ++printf "%s\n" "$ac_try_echo"; } >&5 ++ (eval "$ac_try") 2>&5 ++ ac_status=$? ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 ++ test $ac_status = 0; }; }; then ++ cross_compiling_build=no ++ else ++ if test "$cross_compiling_build" = maybe; then ++ cross_compiling_build=yes ++ else ++ { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 ++printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} ++as_fn_error 77 "cannot run C compiled programs. ++If you meant to cross compile, use \`--build'. ++See \`config.log' for more details" "$LINENO" 5; } ++ fi ++ fi ++fi ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cross_compiling_build" >&5 ++printf "%s\n" "$cross_compiling_build" >&6; } ++ ++rm -f conftest.$ac_ext conftest$ac_cv_build_exeext conftest.out ++ac_clean_files=$ac_clean_files_save ++ ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 ++printf %s "checking for suffix of object files... " >&6; } ++if test ${ac_cv_build_objext+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++ ++int ++main (void) ++{ ++ ++ ; ++ return 0; ++} ++_ACEOF ++rm -f conftest.o conftest.obj ++if { { ac_try="$ac_compile" ++case "(($ac_try" in ++ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; ++ *) ac_try_echo=$ac_try;; ++esac ++eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" ++printf "%s\n" "$ac_try_echo"; } >&5 ++ (eval "$ac_compile") 2>&5 ++ ac_status=$? ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 ++ test $ac_status = 0; } ++then : ++ for ac_file in conftest.o conftest.obj conftest.*; do ++ test -f "$ac_file" || continue; ++ case $ac_file in ++ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; ++ *) ac_cv_build_objext=`expr "$ac_file" : '.*\.\(.*\)'` ++ break;; ++ esac ++done ++else $as_nop ++ printf "%s\n" "$as_me: failed program was:" >&5 ++sed 's/^/| /' conftest.$ac_ext >&5 ++ ++{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 ++printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} ++as_fn_error $? "cannot compute suffix of object files: cannot compile ++See \`config.log' for more details" "$LINENO" 5; } ++fi ++rm -f conftest.$ac_cv_build_objext conftest.$ac_ext ++fi ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build_objext" >&5 ++printf "%s\n" "$ac_cv_build_objext" >&6; } ++OBJEXT=$ac_cv_build_objext ++ac_build_objext=$BUILD_OBJEXT ++ ++ac_ext=c ++ac_cpp='$CPP_FOR_BUILD $CPPFLAGS_FOR_BUILD' ++ac_compile='$CC_FOR_BUILD -c $CFLAGS_FOR_BUILD $CPPFLAGS_FOR_BUILD conftest.$ac_ext >&5' ++ac_link='$CC_FOR_BUILD -o conftest$ac_build_exeext $CFLAGS_FOR_BUILD $CPPFLAGS_FOR_BUILD $LDFLAGS_FOR_BUILD conftest.$ac_ext $LIBS >&5' ++ac_compiler_gnu=$ac_cv_build_c_compiler_gnu ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 ++printf %s "checking how to run the C preprocessor... " >&6; } ++# On Suns, sometimes $CPP names a directory. ++if test -n "$CPP_FOR_BUILD" && test -d "$CPP_FOR_BUILD"; then ++ CPP_FOR_BUILD= ++fi ++if test -z "$CPP_FOR_BUILD"; then ++ if test ${ac_cv_build_prog_CPP+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ # Double quotes because $CC needs to be expanded ++ for CPP_FOR_BUILD in "$CC_FOR_BUILD -E" "$CC_FOR_BUILD -E -traditional-cpp" cpp /lib/cpp ++ do ++ ac_preproc_ok=false ++for ac_c_preproc_warn_flag in '' yes ++do ++ # Use a header file that comes with gcc, so configuring glibc ++ # with a fresh cross-compiler works. ++ # On the NeXT, cc -E runs the code through the compiler's parser, ++ # not just through cpp. "Syntax error" is here to catch this case. ++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++#include ++ Syntax error ++_ACEOF ++if ac_fn_c_try_cpp "$LINENO" ++then : ++ ++else $as_nop ++ # Broken: fails on valid input. ++continue ++fi ++rm -f conftest.err conftest.i conftest.$ac_ext ++ ++ # OK, works on sane cases. Now check whether nonexistent headers ++ # can be detected and how. ++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++#include ++_ACEOF ++if ac_fn_c_try_cpp "$LINENO" ++then : ++ # Broken: success on invalid input. ++continue ++else $as_nop ++ # Passes both tests. ++ac_preproc_ok=: ++break ++fi ++rm -f conftest.err conftest.i conftest.$ac_ext ++ ++done ++# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. ++rm -f conftest.i conftest.err conftest.$ac_ext ++if $ac_preproc_ok ++then : ++ break ++fi ++ ++ done ++ ac_cv_build_prog_CPP=$CPP_FOR_BUILD ++ ++fi ++ CPP_FOR_BUILD=$ac_cv_build_prog_CPP ++else ++ ac_cv_build_prog_CPP=$CPP_FOR_BUILD ++fi ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CPP_FOR_BUILD" >&5 ++printf "%s\n" "$CPP_FOR_BUILD" >&6; } ++ac_preproc_ok=false ++for ac_c_preproc_warn_flag in '' yes ++do ++ # Use a header file that comes with gcc, so configuring glibc ++ # with a fresh cross-compiler works. ++ # On the NeXT, cc -E runs the code through the compiler's parser, ++ # not just through cpp. "Syntax error" is here to catch this case. ++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++#include ++ Syntax error ++_ACEOF ++if ac_fn_c_try_cpp "$LINENO" ++then : ++ ++else $as_nop ++ # Broken: fails on valid input. ++continue ++fi ++rm -f conftest.err conftest.i conftest.$ac_ext ++ ++ # OK, works on sane cases. Now check whether nonexistent headers ++ # can be detected and how. ++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++#include ++_ACEOF ++if ac_fn_c_try_cpp "$LINENO" ++then : ++ # Broken: success on invalid input. ++continue ++else $as_nop ++ # Passes both tests. ++ac_preproc_ok=: ++break ++fi ++rm -f conftest.err conftest.i conftest.$ac_ext ++ ++done ++# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. ++rm -f conftest.i conftest.err conftest.$ac_ext ++if $ac_preproc_ok ++then : ++ ++else $as_nop ++ { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 ++printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} ++as_fn_error $? "C preprocessor \"$CPP_FOR_BUILD\" fails sanity check ++See \`config.log' for more details" "$LINENO" 5; } ++fi ++ ++ac_ext=c ++ac_cpp='$CPP_FOR_BUILD $CPPFLAGS_FOR_BUILD' ++ac_compile='$CC_FOR_BUILD -c $CFLAGS_FOR_BUILD $CPPFLAGS_FOR_BUILD conftest.$ac_ext >&5' ++ac_link='$CC_FOR_BUILD -o conftest$ac_build_exeext $CFLAGS_FOR_BUILD $CPPFLAGS_FOR_BUILD $LDFLAGS_FOR_BUILD conftest.$ac_ext $LIBS >&5' ++ac_compiler_gnu=$ac_cv_build_c_compiler_gnu ++ ++ ++ ++ac_ext=c ++ac_cpp='$CPP $CPPFLAGS' ++ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ++ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ++ac_compiler_gnu=$ac_cv_c_compiler_gnu ++ ++ ++ ++ SAK_CC="$CC_FOR_BUILD" ++ SAK_CFLAGS="$CFLAGS_FOR_BUILD $CPPFLAGS_FOR_BUILD" ++ # Note that *-pc-windows is not supported for _build_ so we can use '-o' ++ SAK_LINK='$(SAK_CC) $(SAK_CFLAGS) -o $(1) $(2)' ++fi ++ ++# sak command to use to encode C literal strings ++ ++case $target in #( ++ *-*-mingw32*|*-pc-windows) : ++ encode_C_literal="encode-C-utf16-literal" ;; #( ++ *) : ++ encode_C_literal="encode-C-utf8-literal" ;; ++esac ++ ++# Checks for programs ++ ++## Check for the C compiler: done by libtool ++## AC_PROG_CC ++ ++## Check for C99 support: done by libtool ++## AC_PROG_CC_C99 ++ ++## Determine which flags to use for the C compiler ++ ++case $ocaml_cc_vendor in #( ++ xlc-*) : ++ outputobj='-o ' ++ warn_error_flag='' ++ cc_warnings='-qflag=i:i' ;; #( ++ # all warnings enabled ++ sunc-*) : ++ outputobj='-o '; cc_warnings="" ;; #( ++ msvc-*) : ++ outputobj='-Fo' ++ case $ocaml_cc_vendor in #( ++ msvc-*-clang-*) : ++ cc_warnings='-W4 -Wno-unused-parameter -Wno-sign-compare -Wundef' ++ warn_error_flag='-WX' ;; #( ++ *) : ++ cc_warnings='-W2' ++ warn_error_flag='-WX -options:strict' ;; ++esac ;; #( ++ *) : ++ outputobj='-o ' ++ warn_error_flag='-Werror' ++ cc_warnings="-Wall -Wint-conversion -Wstrict-prototypes \ ++-Wold-style-definition -Wundef" ;; ++esac ++ ++# Use -Wold-style-declaration if supported ++as_CACHEVAR=`printf "%s\n" "ax_cv_check_cflags_$warn_error_flag_-Wold-style-declaration" | $as_tr_sh` ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler accepts -Wold-style-declaration" >&5 ++printf %s "checking whether the C compiler accepts -Wold-style-declaration... " >&6; } ++if eval test \${$as_CACHEVAR+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ ++ ax_check_save_flags=$CFLAGS ++ CFLAGS="$CFLAGS $warn_error_flag -Wold-style-declaration" ++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++ ++int + main (void) + { + +@@ -14075,7 +15432,7 @@ case $enable_warn_error,false in #( + ;; + esac + +-case $host in #( ++case $target in #( + *-*-mingw32*|*-pc-windows) : + case $WINDOWS_UNICODE_MODE in #( + ansi) : +@@ -14179,7 +15536,7 @@ fi + esac + + # Enable SSE2 on x86 mingw to avoid using 80-bit registers. +-case $host in #( ++case $target in #( + i686-*-mingw32*) : + internal_cflags="$internal_cflags -mfpmath=sse -msse2" ;; #( + *) : +@@ -14189,7 +15546,7 @@ esac + # Use 64-bit file offset if possible + # See also AC_SYS_LARGEFILE + # Problem: flags are added to CC rather than CPPFLAGS +-case $host in #( ++case $target in #( + *-*-mingw32*|*-pc-windows) : + ;; #( + *) : +@@ -14207,7 +15564,7 @@ esac + if test x"$enable_shared" = "xno" + then : + supports_shared_libraries=false +- case $host in #( ++ case $target in #( + *-pc-windows|*-w64-mingw32*) : + as_fn_error $? "Cannot build native Win32 with --disable-shared" "$LINENO" 5 ;; #( + *) : +@@ -14219,7 +15576,7 @@ fi + + # Define flexlink chain and flags correctly for the different Windows ports + flexlink_flags='' +-case $host in #( ++case $target in #( + i686-*-cygwin) : + flexdll_chain='cygwin' + flexlink_flags='-merge-manifest -stack 16777216' ;; #( +@@ -14305,7 +15662,9 @@ fi ;; + esac + fi + +- # Extract the first word of "flexlink", so it can be a program name with args. ++ case $target in #( ++ *-*-cygwin*|*-w64-mingw32*|*-pc-windows) : ++ # Extract the first word of "flexlink", so it can be a program name with args. + set dummy flexlink; ac_word=$2 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 + printf %s "checking for $ac_word... " >&6; } +@@ -14346,7 +15705,10 @@ else + printf "%s\n" "no" >&6; } + fi + +- ++ ;; #( ++ *) : ++ ;; ++esac + + if test -n "$flexlink" && test -z "$flexdll_source_dir" + then : +@@ -14563,7 +15925,7 @@ fi + + fi + +-case $have_flexdll_h,$supports_shared_libraries,$host in #( ++case $have_flexdll_h,$supports_shared_libraries,$target in #( + no,true,*-*-cygwin*) : + supports_shared_libraries=false + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: flexdll.h not found: shared library support disabled." >&5 +@@ -14574,7 +15936,7 @@ printf "%s\n" "$as_me: WARNING: flexdll.h not found: shared library support disa + ;; + esac + +-case $flexdll_source_dir,$supports_shared_libraries,$flexlink,$host in #( ++case $flexdll_source_dir,$supports_shared_libraries,$flexlink,$target in #( + ,true,,*-*-cygwin*) : + supports_shared_libraries=false + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: flexlink not found: shared library support disabled." >&5 +@@ -14587,7 +15949,7 @@ esac + + mkexe_cmd_exp="$CC" + +-case $ocaml_cc_vendor,$host in #( ++case $ocaml_cc_vendor,$target in #( + *,x86_64-*-darwin*) : + oc_ldflags='-Wl,-no_compact_unwind'; + printf "%s\n" "#define HAS_ARCH_CODE32 1" >>confdefs.h +@@ -14609,7 +15971,7 @@ else $as_nop + fi + ostype="Cygwin" ;; #( + *,*-*-mingw32*) : +- case $host in #( ++ case $target in #( + i686-*-*) : + oc_dll_ldflags="-static-libgcc" ;; #( + *) : +@@ -14974,7 +16336,7 @@ then : + fi + + +-case $host in #( ++case $target in #( + *-*-linux*) : + ac_fn_c_check_header_compile "$LINENO" "linux/futex.h" "ac_cv_header_linux_futex_h" "$ac_includes_default" + if test "x$ac_cv_header_linux_futex_h" = xyes +@@ -15833,7 +17195,7 @@ fi + # Full support for thread local storage + # macOS and MinGW-w64 have problems with thread local storage accessed from DLLs + +-case $host in #( ++case $target in #( + *-apple-darwin*|*-mingw32*|*-pc-windows) : + ;; #( + *) : +@@ -15854,7 +17216,7 @@ natdynlinkopts="" + if test x"$enable_shared" != "xno" + then : + mkdll='' +- case $host in #( ++ case $target in #( + x86_64-apple-darwin*) : + mkdll_flags=\ + '-shared -undefined dynamic_lookup -Wl,-no_compact_unwind -Wl,-w' +@@ -15885,7 +17247,7 @@ esac ;; #( + *-*-linux*|*-*-freebsd[3-9]*|*-*-freebsd[1-9][0-9]*\ + |*-*-openbsd*|*-*-netbsd*|*-*-dragonfly*|*-*-gnu*|*-*-haiku*) : + sharedlib_cflags="-fPIC" +- case $ocaml_cc_vendor,$host in #( ++ case $ocaml_cc_vendor,$target in #( + gcc-*,powerpc-*-linux*) : + mkdll_flags='-shared -mbss-plt' ;; #( + *,i[3456]86-*) : +@@ -15895,7 +17257,7 @@ esac ;; #( + *) : + mkdll_flags='-shared' ;; + esac +- case $host in #( ++ case $target in #( + *-*-openbsd7.[3-9]|*-*-openbsd[89].*) : + mkdll_flags="${mkdll_flags} -Wl,--no-execute-only" ;; #( + *) : +@@ -15925,7 +17287,7 @@ fi + # Make sure code sections in OCaml-generated executables are readable + # (required for marshaling of function closures) + +-case $host in #( ++case $target in #( + *-*-openbsd7.[3-9]|*-*-openbsd[89].*) : + oc_ldflags="$oc_ldflags -Wl,--no-execute-only" + natdynlinkopts="$natdynlinkopts -Wl,--no-execute-only" ;; #( +@@ -15935,7 +17297,7 @@ esac + + # Disable control flow integrity + +-case $host in #( ++case $target in #( + *-*-openbsd7.[4-9]|*-*-openbsd[89].*) : + oc_ldflags="$oc_ldflags -Wl,-z,nobtcfi" + natdynlinkopts="$natdynlinkopts -Wl,-z,nobtcfi" ;; #( +@@ -15950,7 +17312,7 @@ natdynlink=false + + if test x"$supports_shared_libraries" = 'xtrue' + then : +- case "$host" in #( ++ case "$target" in #( + *-*-cygwin*) : + natdynlink=true ;; #( + *-*-mingw32*) : +@@ -16028,7 +17390,7 @@ case $enable_native_toplevel,$natdynlink in #( + esac + + # Try to work around the Skylake/Kaby Lake processor bug. +-case "$ocaml_cc_vendor,$host" in #( ++case "$ocaml_cc_vendor,$target" in #( + *gcc*,x86_64-*|*gcc*,i686-*) : + as_CACHEVAR=`printf "%s\n" "ax_cv_check_cflags_$warn_error_flag_-fno-tree-vrp" | $as_tr_sh` + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler accepts -fno-tree-vrp" >&5 +@@ -16158,7 +17520,7 @@ system=unknown + # preserving $arch = 'none' <=> $system = 'unknown' + has_native_backend=no + native_ldflags="" +-case $host in #( ++case $target in #( + i[3456]86-*-linux*) : + arch=i386; system=linux ;; #( + i[3456]86-*-freebsd*) : +@@ -16324,8 +17686,107 @@ fi + + printf "%s\n" "#define OCAML_OS_TYPE \"$ostype\"" >>confdefs.h + ++target_os_type="$ostype" + +-if test -n "$ac_tool_prefix"; then ++if $cross_compiler ++then : ++ # Extract the first word of "$target_alias-ld", so it can be a program name with args. ++set dummy $target_alias-ld; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_prog_DIRECT_LD+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ if test -n "$DIRECT_LD"; then ++ ac_cv_prog_DIRECT_LD="$DIRECT_LD" # Let the user override the test. ++else ++as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ ac_cv_prog_DIRECT_LD="$target_alias-ld" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++fi ++fi ++DIRECT_LD=$ac_cv_prog_DIRECT_LD ++if test -n "$DIRECT_LD"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DIRECT_LD" >&5 ++printf "%s\n" "$DIRECT_LD" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ ++if test -z "$ac_cv_prog_DIRECT_LD"; then ++ if test "$build" = "$target"; then ++ ac_ct_DIRECT_LD=$DIRECT_LD ++ # Extract the first word of "ld", so it can be a program name with args. ++set dummy ld; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_prog_ac_ct_DIRECT_LD+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ if test -n "$ac_ct_DIRECT_LD"; then ++ ac_cv_prog_ac_ct_DIRECT_LD="$ac_ct_DIRECT_LD" # Let the user override the test. ++else ++as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ ac_cv_prog_ac_ct_DIRECT_LD="ld" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++ test -z "$ac_cv_prog_ac_ct_DIRECT_LD" && ac_cv_prog_ac_ct_DIRECT_LD="false" ++fi ++fi ++ac_ct_DIRECT_LD=$ac_cv_prog_ac_ct_DIRECT_LD ++if test -n "$ac_ct_DIRECT_LD"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DIRECT_LD" >&5 ++printf "%s\n" "$ac_ct_DIRECT_LD" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ DIRECT_LD=$ac_ct_DIRECT_LD ++ else ++ DIRECT_LD="false" ++ fi ++else ++ DIRECT_LD="$ac_cv_prog_DIRECT_LD" ++fi ++ ++else $as_nop ++ if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ld", so it can be a program name with args. + set dummy ${ac_tool_prefix}ld; ac_word=$2 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +@@ -16427,9 +17888,10 @@ else + DIRECT_LD="$ac_cv_prog_DIRECT_LD" + fi + ++fi + if test -z "$PARTIALLD" + then : +- case "$host,$ocaml_cc_vendor" in #( ++ case "$target,$ocaml_cc_vendor" in #( + x86_64-*-darwin*,gcc-*) : + PACKLD_FLAGS=' -arch x86_64' ;; #( + powerpc64le*-*-linux*,gcc-*) : +@@ -16476,7 +17938,7 @@ case $arch in #( + # ocamlopt generates PIC code or doesn't generate code at all + ;; #( + *) : +- case $host in #( ++ case $target in #( + # expected to match "*-linux-musl" as well as "*-linux-musleabi*" + *-linux-musl*) : + # Alpine and other musl-based Linux distributions +@@ -16679,7 +18141,7 @@ then : + printf %s "checking whether round works... " >&6; } + + old_cross_compiling="$cross_compiling" +- if test "x$host_runnable" = 'xtrue' ++ if test "x$target_runnable" = 'xtrue' + then : + cross_compiling='no' + fi +@@ -16751,7 +18213,7 @@ fi + printf %s "checking whether fma works... " >&6; } + + old_cross_compiling="$cross_compiling" +- if test "x$host_runnable" = 'xtrue' ++ if test "x$target_runnable" = 'xtrue' + then : + cross_compiling='no' + fi +@@ -16912,7 +18374,7 @@ fi + ## On Unix platforms, we check for the appropriate POSIX feature-test macros. + ## On MacOS clock_gettime's CLOCK_MONOTONIC flag is not actually monotonic. + +-case $host in #( ++case $target in #( + *-*-windows) : + has_monotonic_clock=true ;; #( + *-apple-darwin*) : +@@ -16975,7 +18437,7 @@ esac + if test "x$enable_instrumented_runtime" != "xno" + then : + +- case $host in #( ++ case $target in #( + sparc-sun-solaris*) : + instrumented_runtime=false ;; #( + *-*-windows) : +@@ -17361,7 +18823,7 @@ fi + + sockets=true + +-case $host in #( ++case $target in #( + *-*-mingw32*) : + cclibs="$cclibs -lws2_32" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for library containing socket" >&5 +@@ -17709,7 +19171,7 @@ fi + + ## socklen_t + +-case $host in #( ++case $target in #( + *-*-mingw32*|*-pc-windows) : + ac_fn_c_check_type "$LINENO" "socklen_t" "ac_cv_type_socklen_t" "#include + " +@@ -17740,7 +19202,7 @@ fi + + ## Unix domain sockets support on Windows + +-case $host in #( ++case $target in #( + *-*-mingw32*|*-pc-windows) : + for ac_header in afunix.h + do : +@@ -17762,7 +19224,7 @@ esac + + ipv6=true + +-case $host in #( ++case $target in #( + *-*-mingw32*|*-pc-windows) : + ac_fn_c_check_type "$LINENO" "struct sockaddr_in6" "ac_cv_type_struct_sockaddr_in6" "#include + " +@@ -17860,7 +19322,7 @@ fi + ## Note: this was defined in config/s-nt.h but the autoconf macros do not + # seem to detect it properly on Windows so we hardcode the definition + # of HAS_UTIME on Windows but this will probably need to be clarified +-case $host in #( ++case $target in #( + *-*-mingw32*|*-pc-windows) : + printf "%s\n" "#define HAS_UTIME 1" >>confdefs.h + ;; #( +@@ -18075,7 +19537,7 @@ fi + ## gethostname + # Note: detection fails on Windows so hardcoding the result + # (should be debugged later) +-case $host in #( ++case $target in #( + *-*-mingw32*|*-pc-windows) : + printf "%s\n" "#define HAS_GETHOSTNAME 1" >>confdefs.h + ;; #( +@@ -18131,7 +19593,7 @@ fi + + ## setsid + +-case $host in #( ++case $target in #( + *-cygwin|*-*-mingw32*|*-pc-windows) : + ;; #( + *) : +@@ -18172,7 +19634,7 @@ fi + ## newlocale() and + # Note: the detection fails on msvc so we hardcode the result + # (should be debugged later) +-case $host in #( ++case $target in #( + *-pc-windows) : + printf "%s\n" "#define HAS_LOCALE_H 1" >>confdefs.h + ;; #( +@@ -18227,7 +19689,7 @@ fi + ## strtod_l + # Note: not detected on MSVC so hardcoding the result + # (should be debugged later) +-case $host in #( ++case $target in #( + *-pc-windows) : + printf "%s\n" "#define HAS_STRTOD_L 1" >>confdefs.h + ;; #( +@@ -18244,7 +19706,7 @@ esac + ## shared library support + if $supports_shared_libraries + then : +- case $host in #( ++ case $target in #( + *-*-mingw32*|*-pc-windows|*-*-cygwin*) : + DLLIBS="" ;; #( + *) : +@@ -18344,7 +19806,7 @@ fi + + + ## -fdebug-prefix-map support by the C compiler +-case $ocaml_cc_vendor,$host in #( ++case $ocaml_cc_vendor,$target in #( + *,*-*-mingw32*) : + cc_has_debug_prefix_map=false ;; #( + *,*-pc-windows) : +@@ -18960,7 +20422,111 @@ fi + fi + + +-if test -n "$ac_tool_prefix"; then ++if $cross_compiler ++then : ++ # Extract the first word of "$target_alias-pkg-config", so it can be a program name with args. ++set dummy $target_alias-pkg-config; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_path_PKG_CONFIG+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ case $PKG_CONFIG in ++ [\\/]* | ?:[\\/]*) ++ ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path. ++ ;; ++ *) ++ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ ac_cv_path_PKG_CONFIG="$as_dir$ac_word$ac_exec_ext" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++ ;; ++esac ++fi ++PKG_CONFIG=$ac_cv_path_PKG_CONFIG ++if test -n "$PKG_CONFIG"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5 ++printf "%s\n" "$PKG_CONFIG" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ ++if test -z "$ac_cv_path_PKG_CONFIG"; then ++ if test "$build" = "$target"; then ++ ac_pt_PKG_CONFIG=$PKG_CONFIG ++ # Extract the first word of "pkg-config", so it can be a program name with args. ++set dummy pkg-config; ac_word=$2 ++{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 ++printf %s "checking for $ac_word... " >&6; } ++if test ${ac_cv_path_ac_pt_PKG_CONFIG+y} ++then : ++ printf %s "(cached) " >&6 ++else $as_nop ++ case $ac_pt_PKG_CONFIG in ++ [\\/]* | ?:[\\/]*) ++ ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path. ++ ;; ++ *) ++ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR ++for as_dir in $PATH ++do ++ IFS=$as_save_IFS ++ case $as_dir in #((( ++ '') as_dir=./ ;; ++ */) ;; ++ *) as_dir=$as_dir/ ;; ++ esac ++ for ac_exec_ext in '' $ac_executable_extensions; do ++ if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ++ ac_cv_path_ac_pt_PKG_CONFIG="$as_dir$ac_word$ac_exec_ext" ++ printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 ++ break 2 ++ fi ++done ++ done ++IFS=$as_save_IFS ++ ++ test -z "$ac_cv_path_ac_pt_PKG_CONFIG" && ac_cv_path_ac_pt_PKG_CONFIG="false" ++ ;; ++esac ++fi ++ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG ++if test -n "$ac_pt_PKG_CONFIG"; then ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5 ++printf "%s\n" "$ac_pt_PKG_CONFIG" >&6; } ++else ++ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 ++printf "%s\n" "no" >&6; } ++fi ++ ++ PKG_CONFIG=$ac_pt_PKG_CONFIG ++ else ++ PKG_CONFIG="false" ++ fi ++else ++ PKG_CONFIG="$ac_cv_path_PKG_CONFIG" ++fi ++ ++else $as_nop ++ if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args. + set dummy ${ac_tool_prefix}pkg-config; ac_word=$2 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +@@ -19068,6 +20634,7 @@ else + PKG_CONFIG="$ac_cv_path_PKG_CONFIG" + fi + ++fi + + ## ZSTD compression library + +@@ -19229,9 +20796,9 @@ fi + # library available, but not have the DLL in PATH. This then causes the build to + # fail as soon as ocamlrun is first executed. This check avoids automatically + # enabling zstd when the resulting executable doesn't actually work. +-case $host in #( ++case $target in #( + *-w64-mingw32*|*-pc-windows) : +- check_zstd_runs=$host_runnable ;; #( ++ check_zstd_runs=$target_runnable ;; #( + *) : + check_zstd_runs=false ;; + esac +@@ -19365,7 +20932,7 @@ esac + + ## Determine how to link with the POSIX threads library + +-case $host in #( ++case $target in #( + *-*-mingw32*) : + link_gcc_eh='' + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for printf in -lgcc_eh" >&5 +@@ -20275,7 +21842,7 @@ as_has_debug_prefix_map=false + asm_cfi_supported=false + if $native_compiler + then : +- case $host in #( ++ case $target in #( + *-*-mingw32*|*-pc-windows) : + ;; #( + *) : +@@ -20448,7 +22015,7 @@ fi + + if test x"$enable_frame_pointers" = "xyes" + then : +- case $host in #( ++ case $target in #( + x86_64-*-linux*|x86_64-*-darwin*) : + case $ocaml_cc_vendor in #( + clang-*|gcc-*) : +@@ -20893,7 +22460,7 @@ native_cflags="$native_cflags $PTHREAD_CFLAGS $COMPILER_NATIVE_CFLAGS" + bytecode_cppflags="$common_cppflags $COMPILER_BYTECODE_CPPFLAGS" + native_cppflags="$common_cppflags $COMPILER_NATIVE_CPPFLAGS" + +-case $host in #( ++case $target in #( + *-*-mingw32*) : + cclibs="$cclibs -lole32 -luuid -lversion -lshlwapi -lsynchronization" ;; #( + *-pc-windows) : +@@ -20912,6 +22479,11 @@ then : + libdir="$libdir"/ocaml + fi + ++if test x"$TARGET_LIBDIR" = x ++then : ++ TARGET_LIBDIR="$libdir" ++fi ++ + if test x"$mandir" = x'${datarootdir}/man' + then : + mandir='${prefix}/man' +@@ -20933,22 +22505,18 @@ then : + ;; + esac + else $as_nop +- if test x"$unix_or_win32" = "xwin32" \ +- && test "$host_vendor-$host_os" != "$build_vendor-$build_os" +-then : +- case $build in #( +- *-pc-cygwin) : ++ case $build,$host in #( ++ *-pc-cygwin,*-*-mingw32*|*-pc-cygwin,*-pc-windows) : + prefix="$(LC_ALL=C.UTF-8 cygpath -m "$prefix")" ;; #( + *) : + ;; + esac + fi +-fi + + # Define a few macros that were defined in config/m-nt.h + # but whose value is not guessed properly by configure + # (all this should be understood and fixed) +-case $host in #( ++case $target in #( + *-*-mingw32*) : + printf "%s\n" "#define HAS_BROKEN_PRINTF 1" >>confdefs.h + +@@ -21134,9 +22702,9 @@ fi + eval "exec_prefix=\"$exec_prefix\"" + eval "ocaml_bindir=\"$bindir\"" + eval "ocaml_libdir=\"$libdir\"" +- if test x"$target_bindir" = 'x' ++ if test x"$TARGET_BINDIR" = 'x' + then : +- target_bindir="$ocaml_bindir" ++ TARGET_BINDIR="$ocaml_bindir" + fi + if test x"$target_launch_method" = 'x' + then : +@@ -22099,7 +23667,7 @@ fi + target_launch_method=\ + '$(echo "$target_launch_method" | sed -e "s/'/'\"'\"'/g")' + ocaml_bindir='$(echo "$ocaml_bindir" | sed -e "s/'/'\"'\"'/g")' +- target_bindir='$(echo "$target_bindir" | sed -e "s/'/'\"'\"'/g")' ++ TARGET_BINDIR='$(echo "$TARGET_BINDIR" | sed -e "s/'/'\"'\"'/g")' + + _ACEOF + +@@ -23270,7 +24838,7 @@ ltmain=$ac_aux_dir/ltmain.sh + ;; + "shebang":C) printf '%s\n%s\000\n' "$launch_method" "$ocaml_bindir" \ + > stdlib/runtime.info +- printf '%s\n%s\000\n' "$target_launch_method" "$target_bindir" \ ++ printf '%s\n%s\000\n' "$target_launch_method" "$TARGET_BINDIR" \ + > stdlib/target_runtime.info ;; + + esac +diff --git a/configure.ac b/configure.ac +index 64e6d7e16006..6a955201014a 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -122,6 +122,10 @@ AC_SUBST([CMXS_MAGIC_NUMBER], [CMXS__MAGIC_NUMBER]) + AC_SUBST([CMT_MAGIC_NUMBER], [CMT__MAGIC_NUMBER]) + AC_SUBST([LINEAR_MAGIC_NUMBER], [LINEAR__MAGIC_NUMBER]) + AC_SUBST([CC]) ++AC_SUBST([SAK_CC]) ++AC_SUBST([SAK_CFLAGS]) ++AC_SUBST([SAK_LINK]) ++AC_SUBST([encode_C_literal]) + AC_SUBST([DIFF_FLAGS]) + AC_SUBST([CSC]) + AC_SUBST([CSCFLAGS]) +@@ -140,6 +144,7 @@ AC_SUBST([arch_specific_SOURCES]) + AC_SUBST([arch64]) + AC_SUBST([model]) + AC_SUBST([system]) ++AC_SUBST([target_os_type]) + AC_SUBST([bytecode_cflags]) + AC_SUBST([bytecode_cppflags]) + AC_SUBST([native_cflags]) +@@ -253,6 +258,7 @@ AC_SUBST([build_libraries_manpages]) + AC_SUBST([compute_deps]) + AC_SUBST([ocaml_bindir]) + AC_SUBST([ocaml_libdir]) ++AC_SUBST([TARGET_LIBDIR]) + AC_SUBST([QS]) + AC_SUBST([ar_supports_response_files]) + +@@ -295,6 +301,17 @@ AC_CANONICAL_BUILD + AC_CANONICAL_HOST + AC_CANONICAL_TARGET + ++# Override cross_compiling and ac_tool_prefix variables since the C toolchain is ++# used to generate target code when building a cross compiler ++cross_compiling=no ++AS_IF([test x"$target_alias" != x], ++ [AS_IF([test x"$build_alias" = x], ++ [cross_compiling=maybe], ++ [AS_IF([test x"$build_alias" != x"$target_alias"], ++ [cross_compiling=yes])])]) ++AS_IF([test -n "$target_alias"], ++ [ac_tool_prefix=$target_alias-]) ++ + # Ensure that AC_CONFIG_LINKS will either create symlinks which are compatible + # with native Windows (i.e. NTFS symlinks, not WSL or Cygwin-emulated ones) or + # use its fallback mechanisms. Native Windows versions of ocamlc/ocamlopt cannot +@@ -307,7 +324,7 @@ AS_CASE([$host], + + # Systems that are known not to work, even in bytecode only. + +-AS_CASE([$host], ++AS_CASE([$target], + [i386-*-solaris*], + [AC_MSG_ERROR([Building for 32 bits target is not supported. \ + If your host is 64 bits, you can try with './configure CC="gcc -m64"' \ +@@ -315,7 +332,7 @@ If your host is 64 bits, you can try with './configure CC="gcc -m64"' \ + + # MSVC special case + +-AS_CASE([$host], ++AS_CASE([$target], + [*-pc-windows], + [AS_IF([test -z "$CC"], [CC=cl]) + ccomptype=msvc +@@ -505,11 +522,12 @@ AC_ARG_ENABLE([cmm-invariants], + [AS_HELP_STRING([--enable-cmm-invariants], + [enable invariants checks in Cmm])]) + +-AC_ARG_WITH([target-bindir], +- [AS_HELP_STRING([--with-target-bindir], +- [location of the runtime binaries on the target system])], +- [target_bindir=$withval], +- [target_bindir='']) ++AC_ARG_VAR([TARGET_BINDIR], ++ [location of the runtime binaries on the target system]) ++ ++AC_ARG_VAR([TARGET_LIBDIR], ++ [location of the libraries on the target system, to be used for dynlink; ++ defaults to the value of libdir]) + + AC_ARG_WITH([target-sh], + [AS_HELP_STRING([--with-target-sh], +@@ -608,10 +626,38 @@ AS_IF([test x"$enable_ocamldoc" = "xno"], + optional_libraries="$optional_libraries ocamldoc/odoc_info" + AC_CONFIG_FILES([ocamldoc/META])]) + ++# Are we building a cross-compiler ++ ++AS_IF( ++ [test x"$host" = x"$target"], ++ [cross_compiler=false], ++ [# We require a non-cross compiler of the same version ++ AC_MSG_CHECKING(m4_normalize([if the installed OCaml compiler can build the ++ cross compiler])) ++ already_installed_version="$(ocamlc -vnum)" ++ AS_IF([test x"AC_PACKAGE_VERSION" = x"$already_installed_version"], ++ [AC_MSG_RESULT([yes (AC_PACKAGE_VERSION)])], ++ [AC_MSG_RESULT(m4_normalize([no (AC_PACKAGE_VERSION vs ++ $already_installed_version)])) ++ AC_MSG_ERROR([exiting])]) ++ cross_compiler=true]) ++ + # Initialization of libtool + # Allow the MSVC linker to be found even if ld isn't installed. + # User-specified LD still takes precedence. +-AC_CHECK_TOOLS([LD],[ld link]) ++AS_IF([$cross_compiler], ++ [AC_CHECK_TARGET_TOOLS([LD],[ld link],[false])], ++ [AC_CHECK_TOOLS([LD],[ld link])]) ++# libtool will detect a build-to-host C toolchain but when building an OCaml ++# cross compiler we need the C toolchain to build the target runtime so we ++# temporarily define host* values as macros for target* values so that the ++# proper toolchain is configured. Note that host=target unless we are building a ++# cross compiler so this is transparent for the usual use case. ++pushdef([host], target)dnl ++pushdef([host_alias], target_alias)dnl ++pushdef([host_cpu], target_cpu)dnl ++pushdef([host_vendor], target_vendor)dnl ++pushdef([host_os], target_os)dnl + # libtool expects host_os=mingw for native Windows + # Also, it has been observed that, on some platforms (e.g. msvc) LT_INIT + # alters the CFLAGS variable, so we save its value before calling the macro +@@ -622,6 +668,11 @@ saved_CFLAGS="$CFLAGS" + LT_INIT + CFLAGS="$saved_CFLAGS" + host_os=$old_host_os ++popdef([host_os])dnl ++popdef([host_vendor])dnl ++popdef([host_cpu])dnl ++popdef([host_alias])dnl ++popdef([host])dnl + + AS_CASE([$host], + [sparc-sun-solaris*], +@@ -646,7 +697,7 @@ AS_CASE([$enable_dependency_generation], + [compute_deps=true])], + [compute_deps=false])]) + +-AS_CASE([$host], ++AS_CASE([$target], + # In config/Makefile.mingw*, we had: + # TARGET=i686-w64-mingw32 and x86_64-w64-mingw32 + # TOOLPREF=$(TARGET)- +@@ -658,7 +709,7 @@ AS_CASE([$host], + mkexe_via_cc_extra_cmd=' && $(call MERGEMANIFESTEXE,$(1))' + libext=lib + AR="" +- AS_IF([test "$host_cpu" = "x86_64" ], ++ AS_IF([test "$target_cpu" = "x86_64" ], + [machine="-machine:AMD64 "], + [machine=""]) + mklib="link -lib -nologo $machine /out:\$(1) \$(2)" +@@ -672,7 +723,7 @@ OCAML_CC_VENDOR + + ## In cross-compilation mode, can we run executables produced? + # At the moment, it's required, but the fact is used in C99 function detection +-OCAML_HOST_IS_EXECUTABLE ++OCAML_TARGET_IS_EXECUTABLE + + # Determine how to call the C preprocessor directly. + # Most of the time, calling the C preprocessor through the C compiler is +@@ -713,27 +764,30 @@ AS_CASE([$ocaml_cc_vendor], + ocamlsrcdir=$(unset CDPATH; cd -- "$srcdir" && printf %sX "$PWD") || fail + ocamlsrcdir=${ocamlsrcdir%X} + ++AS_CASE([$host], ++ [*-*-mingw32*|*-pc-windows], ++ [ln='cp -pf' ++ ocamlsrcdir="$(LC_ALL=C.UTF-8 cygpath -w -- "$ocamlsrcdir")"], ++ [ln='ln -sf']) ++ + # Whether ar supports @FILE arguments + + AS_CASE([$lt_cv_ar_at_file], + [no], [ar_supports_response_files=false], + [ar_supports_response_files=true]) + +-# Libraries to build depending on the host ++# Libraries to build depending on the target + +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-mingw32*|*-pc-windows], + [unix_or_win32="win32" +- ln='cp -pf' + ocamltest_libunix="Some false" +- ocamlsrcdir="$(LC_ALL=C.UTF-8 cygpath -w -- "$ocamlsrcdir")" + ocamlyacc_wstr_module="yacc/wstr"], + [unix_or_win32="unix" +- ln='ln -sf' + ocamltest_libunix="Some true" + ocamlyacc_wstr_module=""]) + +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-cygwin*|*-*-mingw32*|*-pc-windows], + [exeext=".exe"], + [exeext='']) +@@ -778,7 +832,7 @@ AC_SYS_INTERPRETER + shebangscripts=false + launch_method='exe' + AS_IF([test "x$interpval" = "xyes"], +- [AS_CASE([$host], ++ [AS_CASE([$target], + [*-cygwin], + [# Cygwin supports shebangs, which we use for the compiler itself, but + # partially for legacy, and partially so that executables can be easily +@@ -800,7 +854,7 @@ AS_IF([test "x$interpval" = "xyes"], + AC_CONFIG_COMMANDS([shebang], + [printf '%s\n%s\000\n' "$launch_method" "$ocaml_bindir" \ + > stdlib/runtime.info +- printf '%s\n%s\000\n' "$target_launch_method" "$target_bindir" \ ++ printf '%s\n%s\000\n' "$target_launch_method" "$TARGET_BINDIR" \ + > stdlib/target_runtime.info], + dnl These declarations are put in a here-document in configure, so the command + dnl in '$(...)' _is_ evaluated as the content is written to config.status (by +@@ -810,14 +864,28 @@ dnl nefarious single quotes which may appear in any of the strings. + target_launch_method=\ + '$(echo "$target_launch_method" | sed -e "s/'/'\"'\"'/g")' + ocaml_bindir='$(echo "$ocaml_bindir" | sed -e "s/'/'\"'\"'/g")' +- target_bindir='$(echo "$target_bindir" | sed -e "s/'/'\"'\"'/g")']) ++ TARGET_BINDIR='$(echo "$TARGET_BINDIR" | sed -e "s/'/'\"'\"'/g")']) + +-# Are we building a cross-compiler ++# How to build sak + + AS_IF( +- [test x"$host" = x"$target"], +- [cross_compiler=false], +- [cross_compiler=true]) ++ [test x"$build" = x"$target" -o x"$target_runnable" = xtrue], ++ [SAK_CC='$(CC)' ++ SAK_CFLAGS='$(OC_CFLAGS) $(CFLAGS) $(OC_CPPFLAGS) $(CPPFLAGS)' ++ SAK_LINK='$(MKEXE_VIA_CC)'], ++ [AC_MSG_NOTICE([detecting the C toolchain for build]) ++ AX_PROG_CC_FOR_BUILD ++ SAK_CC="$CC_FOR_BUILD" ++ SAK_CFLAGS="$CFLAGS_FOR_BUILD $CPPFLAGS_FOR_BUILD" ++ # Note that *-pc-windows is not supported for _build_ so we can use '-o' ++ SAK_LINK='$(SAK_CC) $(SAK_CFLAGS) -o $(1) $(2)']) ++ ++# sak command to use to encode C literal strings ++ ++AS_CASE([$target], ++ [*-*-mingw32*|*-pc-windows], ++ [encode_C_literal="encode-C-utf16-literal"], ++ [encode_C_literal="encode-C-utf8-literal"]) + + # Checks for programs + +@@ -864,7 +932,7 @@ AS_CASE([$enable_warn_error,OCAML__DEVELOPMENT_VERSION], + [yes,*|,true], + [cc_warnings="$cc_warnings $warn_error_flag"]) + +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-mingw32*|*-pc-windows], + [AS_CASE([$WINDOWS_UNICODE_MODE], + [ansi], +@@ -926,14 +994,14 @@ AS_CASE([$ocaml_cc_vendor], + [common_cflags="-O"]) + + # Enable SSE2 on x86 mingw to avoid using 80-bit registers. +-AS_CASE([$host], ++AS_CASE([$target], + [i686-*-mingw32*], + [internal_cflags="$internal_cflags -mfpmath=sse -msse2"]) + + # Use 64-bit file offset if possible + # See also AC_SYS_LARGEFILE + # Problem: flags are added to CC rather than CPPFLAGS +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-mingw32*|*-pc-windows], [], + [common_cppflags="$common_cppflags -D_FILE_OFFSET_BITS=64"]) + +@@ -947,14 +1015,14 @@ AS_CASE([$host], + + AS_IF([test x"$enable_shared" = "xno"], + [supports_shared_libraries=false +- AS_CASE([$host], ++ AS_CASE([$target], + [*-pc-windows|*-w64-mingw32*], + [AC_MSG_ERROR([Cannot build native Win32 with --disable-shared])])], + [supports_shared_libraries=true]) + + # Define flexlink chain and flags correctly for the different Windows ports + flexlink_flags='' +-AS_CASE([$host], ++AS_CASE([$target], + [i686-*-cygwin], + [flexdll_chain='cygwin' + flexlink_flags='-merge-manifest -stack 16777216'], +@@ -1015,7 +1083,9 @@ AS_IF([test x"$supports_shared_libraries" != 'xfalse'], [ + [AC_MSG_RESULT([requested but not supported]) + AC_MSG_ERROR([exiting])])])]) + +- AC_CHECK_PROG([flexlink],[flexlink],[flexlink]) ++ AS_CASE([$target], ++ [*-*-cygwin*|*-w64-mingw32*|*-pc-windows], ++ [AC_CHECK_PROG([flexlink],[flexlink],[flexlink])]) + + AS_IF([test -n "$flexlink" && test -z "$flexdll_source_dir"],[ + OCAML_TEST_FLEXLINK([$flexlink], [$flexdll_chain], +@@ -1044,14 +1114,14 @@ AS_IF([test x"$supports_shared_libraries" != 'xfalse'], [ + ]) + ]) + +-AS_CASE([$have_flexdll_h,$supports_shared_libraries,$host], ++AS_CASE([$have_flexdll_h,$supports_shared_libraries,$target], + [no,true,*-*-cygwin*], + [supports_shared_libraries=false + AC_MSG_WARN([flexdll.h not found: shared library support disabled.])], + [no,*,*-w64-mingw32*|no,*,*-pc-windows], + [AC_MSG_ERROR([flexdll.h is required for native Win32])]) + +-AS_CASE([$flexdll_source_dir,$supports_shared_libraries,$flexlink,$host], ++AS_CASE([$flexdll_source_dir,$supports_shared_libraries,$flexlink,$target], + [,true,,*-*-cygwin*], + [supports_shared_libraries=false + AC_MSG_WARN([flexlink not found: shared library support disabled.])], +@@ -1060,7 +1130,7 @@ AS_CASE([$flexdll_source_dir,$supports_shared_libraries,$flexlink,$host], + + mkexe_cmd_exp="$CC" + +-AS_CASE([$ocaml_cc_vendor,$host], ++AS_CASE([$ocaml_cc_vendor,$target], + [*,x86_64-*-darwin*], + [oc_ldflags='-Wl,-no_compact_unwind'; + AC_DEFINE([HAS_ARCH_CODE32], [1])], +@@ -1077,7 +1147,7 @@ AS_CASE([$ocaml_cc_vendor,$host], + ) + ostype="Cygwin"], + [*,*-*-mingw32*], +- [AS_CASE([$host], ++ [AS_CASE([$target], + [i686-*-*], [oc_dll_ldflags="-static-libgcc"]) + ostype="Win32" + toolchain="mingw" +@@ -1172,7 +1242,7 @@ AC_CHECK_HEADER([sys/select.h], [AC_DEFINE([HAS_SYS_SELECT_H], [1])], [], + + AC_CHECK_HEADER([sys/mman.h], [AC_DEFINE([HAS_SYS_MMAN_H], [1])]) + +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-linux*], + [AC_CHECK_HEADER([linux/futex.h], [AC_DEFINE([HAS_LINUX_FUTEX_H])])]) + +@@ -1269,7 +1339,7 @@ AS_IF([! $cc_supports_atomic], + # Full support for thread local storage + # macOS and MinGW-w64 have problems with thread local storage accessed from DLLs + +-AS_CASE([$host], ++AS_CASE([$target], + [*-apple-darwin*|*-mingw32*|*-pc-windows], [], + [AC_DEFINE([HAS_FULL_THREAD_VARIABLES], [1])] + ) +@@ -1285,7 +1355,7 @@ natdynlinkopts="" + + AS_IF([test x"$enable_shared" != "xno"], + [mkdll='' +- AS_CASE([$host], ++ AS_CASE([$target], + [x86_64-apple-darwin*], + [mkdll_flags=\ + '-shared -undefined dynamic_lookup -Wl,-no_compact_unwind -Wl,-w' +@@ -1313,7 +1383,7 @@ AS_IF([test x"$enable_shared" != "xno"], + [[*-*-linux*|*-*-freebsd[3-9]*|*-*-freebsd[1-9][0-9]*\ + |*-*-openbsd*|*-*-netbsd*|*-*-dragonfly*|*-*-gnu*|*-*-haiku*]], + [sharedlib_cflags="-fPIC" +- AS_CASE([$ocaml_cc_vendor,$host], ++ AS_CASE([$ocaml_cc_vendor,$target], + [gcc-*,powerpc-*-linux*], + [mkdll_flags='-shared -mbss-plt'], + [[*,i[3456]86-*]], +@@ -1321,7 +1391,7 @@ AS_IF([test x"$enable_shared" != "xno"], + # See https://github.com/ocaml/ocaml/issues/9800 + [mkdll_flags='-shared -Wl,-z,notext'], + [mkdll_flags='-shared']) +- AS_CASE([$host], ++ AS_CASE([$target], + [[*-*-openbsd7.[3-9]|*-*-openbsd[89].*]], + [mkdll_flags="${mkdll_flags} -Wl,--no-execute-only"]) + oc_ldflags="$oc_ldflags -Wl,-E" +@@ -1341,14 +1411,14 @@ AS_IF([test -z "$mkmaindll"], + # Make sure code sections in OCaml-generated executables are readable + # (required for marshaling of function closures) + +-AS_CASE([$host], ++AS_CASE([$target], + [[*-*-openbsd7.[3-9]|*-*-openbsd[89].*]], + [oc_ldflags="$oc_ldflags -Wl,--no-execute-only" + natdynlinkopts="$natdynlinkopts -Wl,--no-execute-only"]) + + # Disable control flow integrity + +-AS_CASE([$host], ++AS_CASE([$target], + [[*-*-openbsd7.[4-9]|*-*-openbsd[89].*]], + [oc_ldflags="$oc_ldflags -Wl,-z,nobtcfi" + natdynlinkopts="$natdynlinkopts -Wl,-z,nobtcfi"]) +@@ -1359,7 +1429,7 @@ AS_CASE([$host], + natdynlink=false + + AS_IF([test x"$supports_shared_libraries" = 'xtrue'], +- [AS_CASE(["$host"], ++ [AS_CASE(["$target"], + [*-*-cygwin*], [natdynlink=true], + [*-*-mingw32*], [natdynlink=true], + [*-pc-windows], [natdynlink=true], +@@ -1401,7 +1471,7 @@ AS_CASE([$enable_native_toplevel,$natdynlink], + [install_ocamlnat=false]) + + # Try to work around the Skylake/Kaby Lake processor bug. +-AS_CASE(["$ocaml_cc_vendor,$host"], ++AS_CASE(["$ocaml_cc_vendor,$target"], + [*gcc*,x86_64-*|*gcc*,i686-*], + [AX_CHECK_COMPILE_FLAG([-fno-tree-vrp], + [internal_cflags="$internal_cflags -fno-tree-vrp"], [], +@@ -1423,7 +1493,7 @@ system=unknown + # preserving $arch = 'none' <=> $system = 'unknown' + has_native_backend=no + native_ldflags="" +-AS_CASE([$host], ++AS_CASE([$target], + [[i[3456]86-*-linux*]], + [arch=i386; system=linux], + [[i[3456]86-*-freebsd*]], +@@ -1560,10 +1630,13 @@ AS_IF([$natdynlink], + [natdynlink_archive=""]) + + AC_DEFINE_UNQUOTED([OCAML_OS_TYPE], ["$ostype"]) ++target_os_type="$ostype" + +-AC_CHECK_TOOL([DIRECT_LD],[ld]) ++AS_IF([$cross_compiler], ++ [AC_CHECK_TARGET_TOOL([DIRECT_LD],[ld],[false])], ++ [AC_CHECK_TOOL([DIRECT_LD],[ld])]) + AS_IF([test -z "$PARTIALLD"], +- [AS_CASE(["$host,$ocaml_cc_vendor"], ++ [AS_CASE(["$target,$ocaml_cc_vendor"], + [x86_64-*-darwin*,gcc-*], [PACKLD_FLAGS=' -arch x86_64'], + [powerpc64le*-*-linux*,gcc-*], [PACKLD_FLAGS=' -m elf64lppc'], + [powerpc*-*-linux*,gcc-*], +@@ -1598,7 +1671,7 @@ AS_CASE([$arch], + [amd64|arm64|s390x|none], + # ocamlopt generates PIC code or doesn't generate code at all + [], +- [AS_CASE([$host], ++ [AS_CASE([$target], + # expected to match "*-linux-musl" as well as "*-linux-musleabi*" + [*-linux-musl*], + # Alpine and other musl-based Linux distributions +@@ -1716,7 +1789,7 @@ AC_CHECK_FUNC([issetugid], [AC_DEFINE([HAS_ISSETUGID], [1])]) + ## On Unix platforms, we check for the appropriate POSIX feature-test macros. + ## On MacOS clock_gettime's CLOCK_MONOTONIC flag is not actually monotonic. + +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-windows], + [has_monotonic_clock=true], + [*-apple-darwin*], [ +@@ -1748,7 +1821,7 @@ AS_CASE([$host], + # clock source is missing. + AS_IF([test "x$enable_instrumented_runtime" != "xno" ], + [ +- AS_CASE([$host], ++ AS_CASE([$target], + [sparc-sun-solaris*], + [instrumented_runtime=false], + [*-*-windows], +@@ -1939,7 +2012,7 @@ AS_IF([$tsan], + + sockets=true + +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-mingw32*], + [cclibs="$cclibs -lws2_32" + AC_SEARCH_LIBS([socket], [ws2_32]) +@@ -1967,7 +2040,7 @@ AS_IF([$sockets], [AC_DEFINE([HAS_SOCKETS], [1])]) + + ## socklen_t + +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-mingw32*|*-pc-windows], + [AC_CHECK_TYPE([socklen_t], [AC_DEFINE([HAS_SOCKLEN_T], [1])], [], + [#include ])], +@@ -1978,7 +2051,7 @@ AC_CHECK_FUNC([inet_aton], [AC_DEFINE([HAS_INET_ATON], [1])]) + + ## Unix domain sockets support on Windows + +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-mingw32*|*-pc-windows], + [AC_CHECK_HEADERS([afunix.h], [AC_DEFINE([HAS_AFUNIX_H], [1])], [], + [#include ])]) +@@ -1987,7 +2060,7 @@ AS_CASE([$host], + + ipv6=true + +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-mingw32*|*-pc-windows], + [AC_CHECK_TYPE( + [struct sockaddr_in6], [], [ipv6=false], [#include ])], +@@ -2021,7 +2094,7 @@ AC_CHECK_FUNC([system], [AC_DEFINE([HAS_SYSTEM], [1])]) + ## Note: this was defined in config/s-nt.h but the autoconf macros do not + # seem to detect it properly on Windows so we hardcode the definition + # of HAS_UTIME on Windows but this will probably need to be clarified +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-mingw32*|*-pc-windows], [AC_DEFINE([HAS_UTIME], [1])], + [AC_CHECK_HEADER([sys/types.h], + [AC_CHECK_HEADER([utime.h], +@@ -2097,7 +2170,7 @@ AC_CHECK_FUNC([setitimer], + ## gethostname + # Note: detection fails on Windows so hardcoding the result + # (should be debugged later) +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-mingw32*|*-pc-windows], [AC_DEFINE([HAS_GETHOSTNAME], [1])], + [AC_CHECK_FUNC([gethostname], [AC_DEFINE([HAS_GETHOSTNAME], [1])])]) + +@@ -2121,7 +2194,7 @@ AC_CHECK_FUNC([mktime], [AC_DEFINE([HAS_MKTIME], [1])]) + + ## setsid + +-AS_CASE([$host], ++AS_CASE([$target], + [*-cygwin|*-*-mingw32*|*-pc-windows], [], + [AC_CHECK_FUNC([setsid], [AC_DEFINE([HAS_SETSID], [1])])]) + +@@ -2137,7 +2210,7 @@ AC_CHECK_FUNC([setenv], + ## newlocale() and + # Note: the detection fails on msvc so we hardcode the result + # (should be debugged later) +-AS_CASE([$host], ++AS_CASE([$target], + [*-pc-windows], [AC_DEFINE([HAS_LOCALE_H], [1])], + [AC_CHECK_HEADER([locale.h], + [AC_CHECK_FUNC([newlocale], +@@ -2152,13 +2225,13 @@ AC_CHECK_HEADER([xlocale.h], + ## strtod_l + # Note: not detected on MSVC so hardcoding the result + # (should be debugged later) +-AS_CASE([$host], ++AS_CASE([$target], + [*-pc-windows], [AC_DEFINE([HAS_STRTOD_L], [1])], + [AC_CHECK_FUNC([strtod_l], [AC_DEFINE([HAS_STRTOD_L], [1])])]) + + ## shared library support + AS_IF([$supports_shared_libraries], +- [AS_CASE([$host], ++ [AS_CASE([$target], + [*-*-mingw32*|*-pc-windows|*-*-cygwin*], + [DLLIBS=""], + [AC_CHECK_FUNC([dlopen], +@@ -2184,7 +2257,7 @@ AC_CHECK_HEADER([sys/mman.h], + AC_CHECK_FUNC([pwrite], [AC_DEFINE([HAS_PWRITE], [1])]) + + ## -fdebug-prefix-map support by the C compiler +-AS_CASE([$ocaml_cc_vendor,$host], ++AS_CASE([$ocaml_cc_vendor,$target], + [*,*-*-mingw32*], [cc_has_debug_prefix_map=false], + [*,*-pc-windows], [cc_has_debug_prefix_map=false], + [xlc*,powerpc-ibm-aix*], [cc_has_debug_prefix_map=false], +@@ -2263,7 +2336,9 @@ AC_CHECK_HEADER([spawn.h], + [AC_CHECK_FUNC([posix_spawn], + [AC_CHECK_FUNC([posix_spawnp], [AC_DEFINE([HAS_POSIX_SPAWN], [1])])])]) + +-AC_PATH_TOOL([PKG_CONFIG], [pkg-config], [false]) ++AS_IF([$cross_compiler], ++ [AC_PATH_TARGET_TOOL([PKG_CONFIG], [pkg-config], [false])], ++ [AC_PATH_TOOL([PKG_CONFIG], [pkg-config], [false])]) + + ## ZSTD compression library + +@@ -2294,9 +2369,9 @@ AS_IF([test x"$with_zstd" != "xno"], + # library available, but not have the DLL in PATH. This then causes the build to + # fail as soon as ocamlrun is first executed. This check avoids automatically + # enabling zstd when the resulting executable doesn't actually work. +-AS_CASE([$host], ++AS_CASE([$target], + [*-w64-mingw32*|*-pc-windows], +- [check_zstd_runs=$host_runnable], ++ [check_zstd_runs=$target_runnable], + [check_zstd_runs=false]) + + AS_IF([test x"$zstd_status" = "xok"],[ +@@ -2364,7 +2439,7 @@ AS_CASE([$enable_debug_runtime], + + ## Determine how to link with the POSIX threads library + +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-mingw32*], + [link_gcc_eh='' + AC_CHECK_LIB([gcc_eh], [printf], [link_gcc_eh="-lgcc_eh"]) +@@ -2432,7 +2507,7 @@ AS_CASE([$enable_systhreads,$enable_unix_lib], + as_has_debug_prefix_map=false + asm_cfi_supported=false + AS_IF([$native_compiler], +- [AS_CASE([$host], ++ [AS_CASE([$target], + [*-*-mingw32*|*-pc-windows], [], + [OCAML_AS_HAS_DEBUG_PREFIX_MAP + OCAML_AS_HAS_CFI_DIRECTIVES])]) +@@ -2440,7 +2515,7 @@ AS_IF([$native_compiler], + ## Frame pointers + + AS_IF([test x"$enable_frame_pointers" = "xyes"], +- [AS_CASE([$host], ++ [AS_CASE([$target], + [x86_64-*-linux*|x86_64-*-darwin*], + [AS_CASE([$ocaml_cc_vendor], + [clang-*|gcc-*], +@@ -2621,7 +2696,7 @@ native_cflags="$native_cflags $PTHREAD_CFLAGS $COMPILER_NATIVE_CFLAGS" + bytecode_cppflags="$common_cppflags $COMPILER_BYTECODE_CPPFLAGS" + native_cppflags="$common_cppflags $COMPILER_NATIVE_CPPFLAGS" + +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-mingw32*], + [cclibs="$cclibs -lole32 -luuid -lversion -lshlwapi -lsynchronization"], + [*-pc-windows], +@@ -2635,6 +2710,9 @@ AC_CONFIG_COMMANDS_PRE([cclibs="$cclibs $mathlib $DLLIBS $PTHREAD_LIBS"]) + AS_IF([test x"$libdir" = x'${exec_prefix}/lib'], + [libdir="$libdir"/ocaml]) + ++AS_IF([test x"$TARGET_LIBDIR" = x], ++ [TARGET_LIBDIR="$libdir"]) ++ + AS_IF([test x"$mandir" = x'${datarootdir}/man'], + [mandir='${prefix}/man']) + +@@ -2645,15 +2723,14 @@ AS_IF([test x"$prefix" = "xNONE"], + [x86_64-w64-mingw32*], [prefix='C:/ocamlmgw64'], + [i686-pc-windows], [prefix='C:/ocamlms'], + [x86_64-pc-windows], [prefix='C:/ocamlms64'])], +- [AS_IF([test x"$unix_or_win32" = "xwin32" \ +- && test "$host_vendor-$host_os" != "$build_vendor-$build_os" ], +- [AS_CASE([$build], +- [*-pc-cygwin], [prefix="$(LC_ALL=C.UTF-8 cygpath -m "$prefix")"])])]) ++ [AS_CASE([$build,$host], ++ [*-pc-cygwin,*-*-mingw32*|*-pc-cygwin,*-pc-windows], ++ [prefix="$(LC_ALL=C.UTF-8 cygpath -m "$prefix")"])]) + + # Define a few macros that were defined in config/m-nt.h + # but whose value is not guessed properly by configure + # (all this should be understood and fixed) +-AS_CASE([$host], ++AS_CASE([$target], + [*-*-mingw32*], + [AC_DEFINE([HAS_BROKEN_PRINTF], [1]) + AC_DEFINE([HAS_IPV6], [1]) +@@ -2680,7 +2757,7 @@ AC_CONFIG_COMMANDS_PRE([ + eval "exec_prefix=\"$exec_prefix\"" + eval "ocaml_bindir=\"$bindir\"" + eval "ocaml_libdir=\"$libdir\"" +- AS_IF([test x"$target_bindir" = 'x'],[target_bindir="$ocaml_bindir"]) ++ AS_IF([test x"$TARGET_BINDIR" = 'x'],[TARGET_BINDIR="$ocaml_bindir"]) + AS_IF([test x"$target_launch_method" = 'x'], + [target_launch_method="$launch_method"]) + prefix="$saved_prefix" +diff --git a/middle_end/closure/closure.ml b/middle_end/closure/closure.ml +index 880773fbac09..b78feab118c9 100644 +--- a/middle_end/closure/closure.ml ++++ b/middle_end/closure/closure.ml +@@ -1058,9 +1058,9 @@ let rec close ({ backend; fenv; cenv ; mutable_vars } as env) lam = + | Word_size -> make_const_int (8*B.size_int) + | Int_size -> make_const_int (8*B.size_int - 1) + | Max_wosize -> make_const_int ((1 lsl ((8*B.size_int) - 10)) - 1 ) +- | Ostype_unix -> make_const_bool (Sys.os_type = "Unix") +- | Ostype_win32 -> make_const_bool (Sys.os_type = "Win32") +- | Ostype_cygwin -> make_const_bool (Sys.os_type = "Cygwin") ++ | Ostype_unix -> make_const_bool (Config.target_os_type = "Unix") ++ | Ostype_win32 -> make_const_bool (Config.target_os_type = "Win32") ++ | Ostype_cygwin -> make_const_bool (Config.target_os_type = "Cygwin") + | Backend_type -> + make_const_int 0 (* tag 0 is the same as Native here *) + in +diff --git a/middle_end/flambda/closure_conversion.ml b/middle_end/flambda/closure_conversion.ml +index 6b9e8d967019..3e8d88bf52b9 100644 +--- a/middle_end/flambda/closure_conversion.ml ++++ b/middle_end/flambda/closure_conversion.ml +@@ -397,9 +397,12 @@ let rec close t env (lam : Lambda.lambda) : Flambda.t = + | Int_size -> lambda_const_int (8*Backend.size_int - 1) + | Max_wosize -> + lambda_const_int ((1 lsl ((8*Backend.size_int) - 10)) - 1) +- | Ostype_unix -> lambda_const_bool (String.equal Sys.os_type "Unix") +- | Ostype_win32 -> lambda_const_bool (String.equal Sys.os_type "Win32") +- | Ostype_cygwin -> lambda_const_bool (String.equal Sys.os_type "Cygwin") ++ | Ostype_unix -> ++ lambda_const_bool (String.equal Config.target_os_type "Unix") ++ | Ostype_win32 -> ++ lambda_const_bool (String.equal Config.target_os_type "Win32") ++ | Ostype_cygwin -> ++ lambda_const_bool (String.equal Config.target_os_type "Cygwin") + | Backend_type -> + Lambda.const_int 0 (* tag 0 is the same as Native *) + end +diff --git a/runtime/sak.c b/runtime/sak.c +index 029ca5258d8e..f975bb1f0d22 100644 +--- a/runtime/sak.c ++++ b/runtime/sak.c +@@ -24,19 +24,22 @@ + #define CAML_INTERNALS + #include "caml/misc.h" + ++#include + #include + #include + #include ++#include + + /* Operations +- - encode-C-literal. Used for the OCAML_STDLIB_DIR macro in +- runtime/build_config.h to ensure the LIBDIR make variable is correctly +- represented as a C string literal. ++ - encode-C-utf8-literal and encode-C-utf16-literal. Used for the ++ OCAML_STDLIB_DIR macro in runtime/build_config.h to ensure the LIBDIR make ++ variable is correctly represented as a C string literal. + +- On Unix, `sak encode-C-literal /usr/local/lib` returns `"/usr/local/lib"` ++ `sak encode-C-utf8-literal /usr/local/lib` returns `"/usr/local/lib"`, in a ++ format suitable for a Unix build. + +- On Windows, `sak encode-C-literal "C:\OCaml🐫\lib"` returns +- `L"C:\\OCaml\xd83d\xdc2b\\lib"` ++ `sak encode-C-utf16-literal "C:\OCaml🐫\lib"` returns ++ `L"C:\\OCaml\xd83d\xdc2b\\lib"`, a format suitable for a Windows build. + */ + + static void usage(void) +@@ -45,43 +48,152 @@ static void usage(void) + "OCaml Build System Swiss Army Knife\n" + "Usage: sak command\n" + "Commands:\n" +- " * encode-C-literal path - encodes path as a C string literal\n" ++ " * encode-C-utf8-literal path - encodes path as a C UTF-8 string literal\n" ++ " * encode-C-utf16-literal path - encodes path as a C UTF-16 string " ++ "literal\n" + ); + } + ++#define printable(c) ((c) >= 0x20 && (c) < 0x7f) ++ ++/* Some Unicode macros */ ++ ++/* Whether a byte is a UTF-8 continuation byte */ ++#define U8C(x) (((x) & 0xc0) == 0x80) ++/* Incorporate data from a continuation byte */ ++#define U8S(x,c) (((x) << 6) | ((c) & 0x3f)) ++/* Build a UTF-8 continuation byte (n = 0 for the least significant) */ ++#define U8B(uc,n) (0x80 | (((uc)>>(6*n)) & 0x3f)) ++ ++/* Format strings for escaped UTF-8 and UTF-16 characters */ ++/* For UTF-16, also use the older \x notation for increased compatibility, ++ rather than the newer \U */ ++#define F8 "\\x%02x" ++#define F16 "\\x%04x" ++ ++/* Prints the (possibly multibyte) Unicode character c as Windows UTF-16 ++ Returns the number of bytes that composed the decoded character */ ++unsigned print_utf8_as_utf16(const char *c) { ++ unsigned uc = 0, bytes = 0; ++ ++ /* Decode UTF8 */ ++ if ((c[0] & 0x80) == 0) { ++ bytes = 1; ++ uc = c[0]; ++ } else if ((c[0] & 0xe0) == 0xc0) { ++ bytes = 2; ++ assert(U8C(c[1])); ++ uc = U8S(c[0] & 0x1f, c[1]); ++ } else if ((c[0] & 0xf0) == 0xe0) { ++ bytes = 3; ++ assert(U8C(c[1]) && U8C(c[2])); ++ uc = U8S(U8S(c[0] & 0xf, c[1]), c[2]); ++ } else if ((c[0] & 0xf8) == 0xf0) { ++ bytes = 4; ++ assert(U8C(c[1]) && U8C(c[2]) && U8C(c[3])); ++ uc = U8S(U8S(U8S(c[0] & 0x7, c[1]), c[2]), c[3]); ++ } ++ ++ assert(bytes); ++ ++ /* Encode UTF16 */ ++ if (printable(uc)) { ++ printf("%c", uc); ++ } else { ++ if (uc <= 0xd7ff || (uc >= 0xe000 && uc <= 0xffff)) { ++ printf(F16, uc); ++ } else { ++ assert(uc >= 0x10000); /* otherwise we are in the prohibited range */ ++ uc -= 0x10000; ++ printf(F16 F16, 0xd800 | ((uc >> 10) & 0x3ff), 0xdc00 | (uc & 0x3ff)); ++ } ++ } ++ ++ return bytes; ++} ++ ++/* Prints the Unicode character c (possibly encoded as two wchar_t) as UTF-8 ++ Returns the number of wchar_t that composed the decoded character */ ++unsigned print_utf16_as_utf8(const wchar_t *c) { ++ unsigned uc = 0, wchars = 0; ++ ++ /* Decode UTF-16 */ ++ if ((c[0] >= 0 && c[0] <= 0xd7ff) || (c[0] >= 0xe000 && c[0] <= 0xffff)) { ++ wchars = 1; ++ uc = c[0]; ++ } else { ++ wchars = 2; ++ assert(c[0] >= 0xd800 && c[0] <= 0xdbff && c[1] >= 0xdc00 ++ && c[1] <= 0xdfff); ++ uc = ((c[0] & 0x3ff) << 10 | (c[1] & 0x3ff)) + 0x10000; ++ } ++ ++ assert(wchars); ++ ++ /* Encode UTF-8 */ ++ /* All non-printable characters are encoded, this is easier to proof-read */ ++ if (printable(uc)) { ++ printf("%c", uc); ++ } else { ++ if (uc < 0x80) { ++ printf(F8, uc); ++ } else if (uc < 0x800) { ++ printf(F8 F8, 0xc0 | ((uc >> 6) & 0x1f), U8B(uc, 0)); ++ } else if (uc < 0x10000) { ++ printf(F8 F8 F8, 0xe0 | ((uc >> 12) & 0xf), U8B(uc, 1), U8B(uc, 0)); ++ } else { ++ assert(uc < 0x110000); ++ printf(F8 F8 F8 F8, 0xf0 | ((uc >> 18) & 0x7), U8B(uc, 2), U8B(uc, 1), ++ U8B(uc, 0)); ++ } ++ } ++ ++ return wchars; ++} ++ + /* Converts the supplied path (UTF-8 on Unix and UCS-2ish on Windows) to a valid + C string literal. On Windows, this is always a wchar_t* (L"..."). */ +-static void encode_C_literal(const char_os * path) ++static void encode_C_literal(const char_os * path, bool utf8) + { + char_os c; + +-#ifdef _WIN32 +- putchar('L'); +-#endif ++ ++ if(!utf8) putchar('L'); + putchar('"'); + +- while ((c = *path++) != 0) { +- /* Escape \, " and \n */ ++ while ((c = *path) != 0) { ++ /* Escape \, ", \n and \r */ + if (c == '\\') { + printf("\\\\"); + } else if (c == '"') { + printf("\\\""); + } else if (c == '\n') { + printf("\\n"); +-#ifndef _WIN32 +- /* On Unix, nothing else needs escaping */ ++ } else if (c == '\r') { ++ printf("\\r"); + } else { +- putchar(c); ++#ifndef _WIN32 ++ if (utf8) { ++ /* On Unix, nothing else needs escaping */ ++ putchar(c); ++ } else { ++ path += print_utf8_as_utf16(path) - 1; ++ } + #else +- /* On Windows, allow 7-bit printable characters to be displayed literally +- and escape everything else (using the older \x notation for increased +- compatibility, rather than the newer \U. */ +- } else if (c < 0x80 && iswprint(c)) { +- putwchar(c); +- } else { +- printf("\\x%04x", c); ++ if (utf8) { ++ path += print_utf16_as_utf8(path) - 1; ++ } else { ++ /* On Windows, allow 7-bit printable characters to be displayed ++ literally and escape everything else. */ ++ if (printable(c)) { ++ putwchar(c); ++ } else { ++ printf(F16, c); ++ } ++ } + #endif + } ++ path++; + } + + putchar('"'); +@@ -89,8 +201,10 @@ static void encode_C_literal(const char_os * path) + + int main_os(int argc, char_os **argv) + { +- if (argc == 3 && !strcmp_os(argv[1], T("encode-C-literal"))) { +- encode_C_literal(argv[2]); ++ if (argc == 3 && !strcmp_os(argv[1], T("encode-C-utf8-literal"))) { ++ encode_C_literal(argv[2], true); ++ } else if (argc == 3 && !strcmp_os(argv[1], T("encode-C-utf16-literal"))) { ++ encode_C_literal(argv[2], false); + } else { + usage(); + return 1; +diff --git a/utils/config.common.ml.in b/utils/config.common.ml.in +index 3603fe6c60c7..bd74c06504bd 100644 +--- a/utils/config.common.ml.in ++++ b/utils/config.common.ml.in +@@ -58,7 +58,7 @@ let max_young_wosize = 256 + let stack_threshold = 32 (* see runtime/caml/config.h *) + let stack_safety_margin = 6 + let default_executable_name = +- match Sys.os_type with ++ match target_os_type with + "Unix" -> "a.out" + | "Win32" | "Cygwin" -> "camlprog.exe" + | _ -> "camlprog" +@@ -105,7 +105,7 @@ let configuration_variables () = + p "ext_asm" ext_asm; + p "ext_lib" ext_lib; + p "ext_dll" ext_dll; +- p "os_type" Sys.os_type; ++ p "os_type" target_os_type; + p "default_executable_name" default_executable_name; + p_bool "systhread_supported" systhread_supported; + p "host" host; +diff --git a/utils/config.fixed.ml b/utils/config.fixed.ml +index 807b92935531..fd11c8fb0446 100644 +--- a/utils/config.fixed.ml ++++ b/utils/config.fixed.ml +@@ -57,6 +57,8 @@ let tsan = false + let architecture = "none" + let model = "default" + let system = "unknown" ++let target_os_type = ++ "The boot compiler should not be using Config.target_os_type" + let asm = boot_cannot_call "the assembler" + let asm_cfi_supported = false + let with_frame_pointers = false +diff --git a/utils/config.generated.ml.in b/utils/config.generated.ml.in +index aa0345540968..0401e57c9311 100644 +--- a/utils/config.generated.ml.in ++++ b/utils/config.generated.ml.in +@@ -70,6 +70,7 @@ let native_compiler = @native_compiler@ + let architecture = {@QS@|@arch@|@QS@} + let model = {@QS@|@model@|@QS@} + let system = {@QS@|@system@|@QS@} ++let target_os_type = {@QS@|@target_os_type@|@QS@} + + let asm = {@QS@|@AS@|@QS@} + let asm_cfi_supported = @asm_cfi_supported@ +diff --git a/utils/config.mli b/utils/config.mli +index 51e31a37294c..df133343c357 100644 +--- a/utils/config.mli ++++ b/utils/config.mli +@@ -163,6 +163,12 @@ val model: string + val system: string + (** Name of operating system for the native-code compiler *) + ++val target_os_type: string ++(** Operating system targetted by the native-code compiler. One of ++- ["Unix"] (for all Unix versions, including Linux and macOS), ++- ["Win32"] (for MS-Windows, OCaml compiled with MSVC++ or MinGW-w64), ++- ["Cygwin"] (for MS-Windows, OCaml compiled with Cygwin). *) ++ + val asm: string + (** The assembler (and flags) to use for assembling + ocamlopt-generated code. *) diff --git a/0_RootFS/OCaml@5.3/bundled/patches/0002-Add-a-Makefile-to-generate-an-ocamlfind-toolchain-co.patch b/0_RootFS/OCaml@5.3/bundled/patches/0002-Add-a-Makefile-to-generate-an-ocamlfind-toolchain-co.patch new file mode 100644 index 00000000000..ee2156c75cd --- /dev/null +++ b/0_RootFS/OCaml@5.3/bundled/patches/0002-Add-a-Makefile-to-generate-an-ocamlfind-toolchain-co.patch @@ -0,0 +1,48 @@ +From 6a35790d3170235c471db2040ae8bc7057c7e071 Mon Sep 17 00:00:00 2001 +From: Samuel Hym +Date: Wed, 8 Jan 2025 13:09:40 +0100 +Subject: [PATCH 2/6] Add a Makefile to generate an ocamlfind toolchain + configuration + +--- + Makefile.ocamlfindconf | 28 ++++++++++++++++++++++++++++ + 1 file changed, 28 insertions(+) + create mode 100644 Makefile.ocamlfindconf + +diff --git a/Makefile.ocamlfindconf b/Makefile.ocamlfindconf +new file mode 100644 +index 0000000000..e560fa067d +--- /dev/null ++++ b/Makefile.ocamlfindconf +@@ -0,0 +1,28 @@ ++# Generate an ocamlfind toolchain configuration ++ ++# This will drop the ocaml-, ocaml-cross- and cross- prefixes of the generated ++# file name, so that the opam install instructions can simply use the package ++# name (probably using such a prefix) to generate the toolchain configuration ++ ++%.conf: ++ mkdir -p $(@D) ++ $(MAKE) --no-print-directory --quiet -f Makefile.ocamlfindconf \ ++ print-$(patsubst cross-%,%,$(patsubst ocaml-%,%,$(*F))) \ ++ > $(@D)/$(patsubst cross-%,%,$(patsubst ocaml-%,%,$(@F))) ++ ++# To get $(prefix) and $(EXE) ++include Makefile.config ++ ++# Phony but generic rule, so without a `.PHONY` declaration ++# Fail if `prefix` is empty (but still display the content) ++print-%: ++ @test -n "$(prefix:%=x)" ++ $(info path($*) = "$(prefix)/lib/ocaml:$(prefix)/lib") ++ $(info destdir($*) = "$(prefix)/lib") ++ $(info stdlib($*) = "$(prefix)/lib/ocaml") ++ $(info ocamlopt($*) = "$(prefix)/bin/ocamlopt.opt$(EXE)") ++ $(info ocamlc($*) = "$(prefix)/bin/ocamlc.opt$(EXE)") ++ $(info ocamlmklib($*) = "$(prefix)/bin/ocamlmklib$(EXE)") ++ $(info ocamldep($*) = "$(prefix)/bin/ocamldep.opt$(EXE)") ++ $(info ocamlcp($*) = "$(prefix)/bin/ocamlcp$(EXE)") ++ $(info ldconf($*) = "$(prefix)/lib/ocaml/ld.conf") +-- +2.50.0 + diff --git a/0_RootFS/OCaml@5.3/bundled/patches/0003-Add-relative-path-fallback-for-libdir-bindir.patch b/0_RootFS/OCaml@5.3/bundled/patches/0003-Add-relative-path-fallback-for-libdir-bindir.patch new file mode 100644 index 00000000000..7ecc66065c5 --- /dev/null +++ b/0_RootFS/OCaml@5.3/bundled/patches/0003-Add-relative-path-fallback-for-libdir-bindir.patch @@ -0,0 +1,415 @@ +From b335dd9fd9b41b21ea3f7f9569d7f73df28d5c72 Mon Sep 17 00:00:00 2001 +From: Tim Besard +Date: Fri, 27 Jun 2025 18:07:59 +0200 +Subject: [PATCH 3/6] Add relative path fallback for libdir / bindir +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The existing `OCAMLLIB` environment variable already allows you to use +a standard library installed elsewhere, but it doesn't let you re-locate +an existing installation. As one might expect, the problem is that the +stdlib itself contains absolute references to its own paths. + +This patch tries to hook into both places where that happens and do an +on-the-fly replacement of the standard library path, if it turns out +this is the standard library that OCaml that was built with (just +moved). + +This kicks in if the default hard-coded `%%LIBDIR%%`/`%%BINDIR%%` cannot +be found. + +🤖 Generated with [Claude Code](https://claude.ai/code) + +Co-Authored-By: Claude +--- + bytecomp/bytelink.ml | 5 +- + runtime/caml/misc.h | 140 +++++++++++++++++++++++++++++++++++ + runtime/dynlink.c | 63 ++++++++++++++-- + utils/config.common.ml.in | 27 ++++++- + utils/config.fixed.ml | 2 +- + utils/config.generated.ml.in | 2 +- + utils/config.mli | 3 + + 7 files changed, 232 insertions(+), 10 deletions(-) + +diff --git a/bytecomp/bytelink.ml b/bytecomp/bytelink.ml +index db4fa18e76..005d893b9d 100644 +--- a/bytecomp/bytelink.ml ++++ b/bytecomp/bytelink.ml +@@ -342,7 +342,10 @@ let read_runtime_launch_info file = + try + let bindir_start = String.index buffer '\n' + 1 in + let bindir_end = String.index_from buffer bindir_start '\000' in +- let bindir = String.sub buffer bindir_start (bindir_end - bindir_start) in ++ let bindir = ++ let relocate_bindir = Misc.replace_substring ~before:Config.bindir_default ~after:Config.bindir ++ and raw_bindir = String.sub buffer bindir_start (bindir_end - bindir_start) in ++ relocate_bindir raw_bindir in + let executable_offset = bindir_end + 2 in + let launcher = + let kind = String.sub buffer 0 (bindir_start - 1) in +diff --git a/runtime/caml/misc.h b/runtime/caml/misc.h +index 8325cd8cfb..851433f757 100644 +--- a/runtime/caml/misc.h ++++ b/runtime/caml/misc.h +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + #include "camlatomic.h" + +@@ -418,6 +419,141 @@ extern double caml_log1p(double); + #define main_os wmain + #endif + ++static wchar_t * __cdecl _wdirname(wchar_t *path); ++ ++// Adapted to wchar_t from ++// https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-crt/misc/dirname.c ++ ++#include ++#include ++#include ++ ++static wchar_t * __cdecl ++_wdirname(wchar_t *path) ++{ ++ static wchar_t *retfail = NULL; ++ size_t len = wcslen(path); ++ ++ if (path && *path) ++ { ++ wchar_t *refpath = path; ++ ++ /* SUSv3 identifies a special case, where path is exactly equal to "//"; ++ * (we will also accept "\\" in the Win32 context, but not "/\" or "\/", ++ * and neither will we consider paths with an initial drive designator). ++ * For this special case, SUSv3 allows the implementation to choose to ++ * return "/" or "//", (or "\" or "\\", since this is Win32); we will ++ * simply return the path unchanged, (i.e. "//" or "\\"). */ ++ if (len > 1 && (refpath[0] == L'/' || refpath[0] == L'\\')) ++ { ++ if (refpath[1] == refpath[0] && refpath[2] == L'\0') ++ { ++ return path; ++ } ++ } ++ /* For all other cases ... ++ * step over the drive designator, if present ... */ ++ else if (len > 1 && refpath[1] == L':') ++ { ++ /* FIXME: maybe should confirm *refpath is a valid drive designator. */ ++ refpath += 2; ++ } ++ /* check again, just to ensure we still have a non-empty path name ... */ ++ if (*refpath) ++ { ++# undef basename ++# define basename __the_basename /* avoid shadowing. */ ++ /* reproduce the scanning logic of the "basename" function ++ * to locate the basename component of the current path string, ++ * (but also remember where the dirname component starts). */ ++ wchar_t *refname, *basename; ++ for (refname = basename = refpath; *refpath; ++refpath) ++ { ++ if (*refpath == L'/' || *refpath == L'\\') ++ { ++ /* we found a dir separator ... ++ * step over it, and any others which immediately follow it. */ ++ while (*refpath == L'/' || *refpath == L'\\') ++ ++refpath; ++ /* if we didn't reach the end of the path string ... */ ++ if (*refpath) ++ /* then we have a new candidate for the base name. */ ++ basename = refpath; ++ else ++ /* we struck an early termination of the path string, ++ * with trailing dir separators following the base name, ++ * so break out of the for loop, to avoid overrun. */ ++ break; ++ } ++ } ++ /* now check, ++ * to confirm that we have distinct dirname and basename components. */ ++ if (basename > refname) ++ { ++ /* and, when we do ... ++ * backtrack over all trailing separators on the dirname component, ++ * (but preserve exactly two initial dirname separators, if identical), ++ * and add a NUL terminator in their place. */ ++ do --basename; ++ while (basename > refname && (*basename == L'/' || *basename == L'\\')); ++ if (basename == refname && (refname[0] == L'/' || refname[0] == L'\\') ++ && refname[1] == refname[0] && refname[2] != L'/' && refname[2] != L'\\') ++ ++basename; ++ *++basename = L'\0'; ++ /* if the resultant dirname begins with EXACTLY two dir separators, ++ * AND both are identical, then we preserve them. */ ++ refpath = path; ++ while ((*refpath == L'/' || *refpath == L'\\')) ++ ++refpath; ++ if ((refpath - path) > 2 || path[1] != path[0]) ++ refpath = path; ++ /* and finally ... ++ * we remove any residual, redundantly duplicated separators from the dirname, ++ * reterminate, and return it. */ ++ refname = refpath; ++ while (*refpath) ++ { ++ if ((*refname++ = *refpath) == L'/' || *refpath++ == L'\\') ++ { ++ while (*refpath == L'/' || *refpath == L'\\') ++ ++refpath; ++ } ++ } ++ *refname = L'\0'; ++ } ++ else ++ { ++ /* either there were no dirname separators in the path name, ++ * or there was nothing else ... */ ++ if (*refname == L'/' || *refname == L'\\') ++ { ++ /* it was all separators, so return one. */ ++ ++refname; ++ } ++ else ++ { ++ /* there were no separators, so return '.'. */ ++ *refname++ = L'.'; ++ } ++ /* add a NUL terminator, in either case, ++ * then transform to the multibyte char domain, ++ * using our own buffer. */ ++ *refname = L'\0'; ++ } ++ return path; ++ } ++# undef basename ++ } ++ /* path is NULL, or an empty string; default return value is "." ... ++ * return this in our own buffer, regenerated by wide char transform, ++ * in case the caller trashed it after a previous call. ++ */ ++ retfail = realloc(retfail, 2 * sizeof(wchar_t)); ++ retfail[0] = L'.'; ++ retfail[1] = L'\0'; ++ return retfail; ++} ++ + #define access_os _waccess + #define open_os _wopen + #define stat_os _wstati64 +@@ -435,11 +571,13 @@ extern double caml_log1p(double); + #define execvp_os _wexecvp + #define execvpe_os _wexecvpe + #define strcmp_os wcscmp ++#define strncmp_os wcsncmp + #define strlen_os wcslen + #define sscanf_os swscanf + #define strcpy_os wcscpy + #define mktemp_os _wmktemp + #define fopen_os _wfopen ++#define dirname_os _wdirname + + #define clock_os caml_win32_clock + +@@ -477,11 +615,13 @@ extern double caml_log1p(double); + #define execvp_os execvp + #define execvpe_os execvpe + #define strcmp_os strcmp ++#define strncmp_os strncmp + #define strlen_os strlen + #define sscanf_os sscanf + #define strcpy_os strcpy + #define mktemp_os mktemp + #define fopen_os fopen ++#define dirname_os dirname + + #define clock_os clock + +diff --git a/runtime/dynlink.c b/runtime/dynlink.c +index c06f8adb9a..87b3f5de29 100644 +--- a/runtime/dynlink.c ++++ b/runtime/dynlink.c +@@ -83,18 +83,62 @@ static c_primitive lookup_primitive(char * name) + + #define LD_CONF_NAME T("ld.conf") + ++static int is_directory(char_os * p) ++{ ++#ifdef _WIN32 ++ struct _stati64 st; ++#else ++ struct stat st; ++#endif ++ int ret; ++ ++ ret = stat_os(p, &st); ++ if (ret == -1) return -1; ++ if (st.st_mode == -1) return -1; ++ ++#ifdef S_ISDIR ++ return S_ISDIR(st.st_mode) ? 1 : 0; ++#else ++ return st.st_mode & S_IFDIR ? 1 : 0; ++#endif ++} ++ + CAMLexport char_os * caml_get_stdlib_location(void) + { +- char_os * stdlib; +- stdlib = caml_secure_getenv(T("OCAMLLIB")); +- if (stdlib == NULL) stdlib = caml_secure_getenv(T("CAMLLIB")); +- if (stdlib == NULL) stdlib = OCAML_STDLIB_DIR; ++ const char_os * bindir; ++ char_os * exe; ++ ++ static char_os * stdlib = NULL; ++ if (stdlib != NULL) ++ return stdlib; ++ ++ stdlib = (char_os *)caml_secure_getenv(T("OCAMLLIB")); ++ if (stdlib == NULL) stdlib = (char_os *)caml_secure_getenv(T("CAMLLIB")); ++ if (stdlib == NULL && is_directory(OCAML_STDLIB_DIR) == 1) ++ stdlib = (char_os *)OCAML_STDLIB_DIR; ++ ++ if (stdlib == NULL) { ++ exe = caml_executable_name(); ++ bindir = dirname_os(exe); ++ ++ stdlib = caml_stat_strconcat_os(7, ++ bindir, T("/"), "..", T("/"), "lib", T("/"), "ocaml"); ++ ++ caml_stat_free(exe); ++ } ++ + return stdlib; + } + ++int starts_with(const char_os *str, const char_os * pre) ++{ ++ return strncmp_os(pre, str, strlen_os(pre)) == 0; ++} ++ + CAMLexport char_os * caml_parse_ld_conf(void) + { +- char_os * stdlib, * ldconfname, * wconfig, * p, * q; ++ const char_os * stdlib; ++ char_os * ldconfname, * wconfig, * tail, * replaced, * p, * q; + char * config; + #ifdef _WIN32 + struct _stati64 st; +@@ -126,7 +170,14 @@ CAMLexport char_os * caml_parse_ld_conf(void) + for (p = wconfig; *p != 0; p++) { + if (*p == '\n') { + *p = 0; +- caml_ext_table_add(&caml_shared_libs_path, q); ++ if (starts_with(q, OCAML_STDLIB_DIR)) { ++ // replace 'OCAML_STDLIB_DIR' with 'stdlib' ++ tail = q + strlen_os(OCAML_STDLIB_DIR); ++ replaced = caml_stat_strconcat_os(2, stdlib, tail); ++ caml_ext_table_add(&caml_shared_libs_path, replaced); ++ } else { ++ caml_ext_table_add(&caml_shared_libs_path, q); ++ } + q = p + 1; + } + } +diff --git a/utils/config.common.ml.in b/utils/config.common.ml.in +index bd74c06504..bc2d42abbb 100644 +--- a/utils/config.common.ml.in ++++ b/utils/config.common.ml.in +@@ -20,6 +20,20 @@ + (* The main OCaml version string has moved to ../build-aux/ocaml_version.m4 *) + let version = Sys.ocaml_version + ++let bindir = ++ let relative_path = Filename.dirname Sys.executable_name in ++ try ++ if Sys.is_directory bindir_default then ++ bindir_default ++ else ++ relative_path ++ with Sys_error(_) -> ++ relative_path ++ ++let standard_library_relative = ++ let dir_sep = Filename.dir_sep in ++ ".." ^ dir_sep ^ "lib" ^ dir_sep ^ "ocaml" ++ + let standard_library = + try + Sys.getenv "OCAMLLIB" +@@ -27,7 +41,17 @@ let standard_library = + try + Sys.getenv "CAMLLIB" + with Not_found -> +- standard_library_default ++ let dirname = Filename.dirname ++ and dir_sep = Filename.dir_sep ++ and executable_name = Sys.executable_name in ++ let relative_path = (dirname executable_name) ^ dir_sep ^ standard_library_relative in ++ try ++ if Sys.is_directory standard_library_default then ++ standard_library_default ++ else ++ relative_path ++ with Sys_error(_) -> ++ relative_path + + let exec_magic_number = {magic|@EXEC_MAGIC_NUMBER@|magic} + (* exec_magic_number is duplicated in runtime/caml/exec.h *) +@@ -74,6 +98,7 @@ let configuration_variables () = + [ + p "version" version; + p "standard_library_default" standard_library_default; ++ p "standard_library_relative" standard_library_relative; + p "standard_library" standard_library; + p "ccomp_type" ccomp_type; + p "c_compiler" c_compiler; +diff --git a/utils/config.fixed.ml b/utils/config.fixed.ml +index fd11c8fb04..799fbb7d6b 100644 +--- a/utils/config.fixed.ml ++++ b/utils/config.fixed.ml +@@ -20,7 +20,7 @@ + + let boot_cannot_call s = "/ The boot compiler should not call " ^ s + +-let bindir = "/tmp" ++let bindir_default = "/tmp" + let standard_library_default = "/tmp" + let ccomp_type = "n/a" + let c_compiler = boot_cannot_call "the C compiler" +diff --git a/utils/config.generated.ml.in b/utils/config.generated.ml.in +index 0401e57c93..6ec01c6919 100644 +--- a/utils/config.generated.ml.in ++++ b/utils/config.generated.ml.in +@@ -18,7 +18,7 @@ + (* This file is included in config_main.ml during the build rather + than compiled on its own *) + +-let bindir = {@QS@|@ocaml_bindir@|@QS@} ++let bindir_default = {@QS@|@ocaml_bindir@|@QS@} + + let standard_library_default = {@QS@|@ocaml_libdir@|@QS@} + +diff --git a/utils/config.mli b/utils/config.mli +index df133343c3..420230c586 100644 +--- a/utils/config.mli ++++ b/utils/config.mli +@@ -26,6 +26,9 @@ val version: string + val bindir: string + (** The directory containing the binary programs *) + ++val bindir_default: string ++(** The directory containing the binary programs (at build-time) *) ++ + val standard_library: string + (** The directory containing the standard libraries *) + +-- +2.50.0 + diff --git a/0_RootFS/OCaml@5.3/bundled/patches/0004-Avoid-using-_Float16-in-older-GCC.patch b/0_RootFS/OCaml@5.3/bundled/patches/0004-Avoid-using-_Float16-in-older-GCC.patch new file mode 100644 index 00000000000..dc6e0af0a17 --- /dev/null +++ b/0_RootFS/OCaml@5.3/bundled/patches/0004-Avoid-using-_Float16-in-older-GCC.patch @@ -0,0 +1,33 @@ +From f1d5f943aac26b89bebc4e9095f17945f6920763 Mon Sep 17 00:00:00 2001 +From: Tim Besard +Date: Fri, 27 Jun 2025 18:08:10 +0200 +Subject: [PATCH 4/6] Avoid using `_Float16` in older GCC +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This was not introduced until GCC 7, even for AArch64. + +🤖 Generated with [Claude Code](https://claude.ai/code) + +Co-Authored-By: Claude +--- + runtime/bigarray.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/runtime/bigarray.c b/runtime/bigarray.c +index 0fa0c808c0..9b9aa1d258 100644 +--- a/runtime/bigarray.c ++++ b/runtime/bigarray.c +@@ -37,7 +37,7 @@ + + /* Half-precision floating point numbers */ + +-#if defined(__GNUC__) && defined(__aarch64__) ++#if defined(__GNUC__) && defined(__aarch64__) && (__GNUC__ >= 7) + + union float16_bits { uint16_t i; _Float16 f; }; + +-- +2.50.0 + diff --git a/0_RootFS/OCaml@5.3/bundled/patches/0005-Don-t-use-clock_gettime_nsec_np-on-x86-64-macOS.patch b/0_RootFS/OCaml@5.3/bundled/patches/0005-Don-t-use-clock_gettime_nsec_np-on-x86-64-macOS.patch new file mode 100644 index 00000000000..f7117d7d3a4 --- /dev/null +++ b/0_RootFS/OCaml@5.3/bundled/patches/0005-Don-t-use-clock_gettime_nsec_np-on-x86-64-macOS.patch @@ -0,0 +1,34 @@ +From 4ec7243bf3c3e5e3cf2e4cf551ea0609cb632889 Mon Sep 17 00:00:00 2001 +From: Tim Besard +Date: Fri, 27 Jun 2025 18:08:12 +0200 +Subject: [PATCH 5/6] Don't use `clock_gettime_nsec_np` on x86-64 macOS +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This was not introduced until Darwin 16, which is much newer than what +BinaryBuilder runs with by default. + +🤖 Generated with [Claude Code](https://claude.ai/code) + +Co-Authored-By: Claude +--- + runtime/unix.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/runtime/unix.c b/runtime/unix.c +index e19d5a26a8..78e4c37972 100644 +--- a/runtime/unix.c ++++ b/runtime/unix.c +@@ -423,7 +423,7 @@ char *caml_secure_getenv (char const *var) + + uint64_t caml_time_counter(void) + { +-#if defined(HAS_CLOCK_GETTIME_NSEC_NP) ++#if defined(HAS_CLOCK_GETTIME_NSEC_NP) && !(defined(__APPLE__) && defined(__x86_64__)) + return (clock_gettime_nsec_np(CLOCK_UPTIME_RAW)); + #elif defined(HAS_POSIX_MONOTONIC_CLOCK) + struct timespec t; +-- +2.50.0 + diff --git a/0_RootFS/OCaml@5.3/bundled/patches/0006-Guard-_WIN32_WINNT-definition.patch b/0_RootFS/OCaml@5.3/bundled/patches/0006-Guard-_WIN32_WINNT-definition.patch new file mode 100644 index 00000000000..589a867336a --- /dev/null +++ b/0_RootFS/OCaml@5.3/bundled/patches/0006-Guard-_WIN32_WINNT-definition.patch @@ -0,0 +1,65 @@ +From d5d2f04992ab678d7b984164fd24bd94cff05578 Mon Sep 17 00:00:00 2001 +From: Tim Besard +Date: Fri, 27 Jun 2025 18:08:13 +0200 +Subject: [PATCH 6/6] Guard `_WIN32_WINNT` definition +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +🤖 Generated with [Claude Code](https://claude.ai/code) + +Co-Authored-By: Claude +--- + ocamltest/run_win32.c | 2 ++ + runtime/win32.c | 2 ++ + yacc/wstr.c | 4 ++++ + 3 files changed, 8 insertions(+) + +diff --git a/ocamltest/run_win32.c b/ocamltest/run_win32.c +index 5f55206237..c04f9265ca 100644 +--- a/ocamltest/run_win32.c ++++ b/ocamltest/run_win32.c +@@ -16,7 +16,9 @@ + /* Run programs with redirections and timeouts under Windows */ + + /* GetTickCount64() requires Windows Vista or Server 2008 */ ++#ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0600 ++#endif + + #include + #include +diff --git a/runtime/win32.c b/runtime/win32.c +index 3ec659d42a..7e4fdeab9a 100644 +--- a/runtime/win32.c ++++ b/runtime/win32.c +@@ -20,7 +20,9 @@ + /* FILE_INFO_BY_HANDLE_CLASS and FILE_NAME_INFO are only available from Windows + Vista onwards */ + #undef _WIN32_WINNT ++#ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0600 ++#endif + + #define WIN32_LEAN_AND_MEAN + #include +diff --git a/yacc/wstr.c b/yacc/wstr.c +index 78c334e691..3ec9b751fb 100644 +--- a/yacc/wstr.c ++++ b/yacc/wstr.c +@@ -13,8 +13,12 @@ + /**************************************************************************/ + + /* Need at least Windows Vista for WC_ERR_INVALID_CHARS */ ++#ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x600 ++#endif ++#ifndef WINVER + #define WINVER 0x600 ++#endif + #include + + /* See corresponding values in runtime/win32.c */ +-- +2.50.0 + diff --git a/0_RootFS/OCaml@5.4/build_tarballs.jl b/0_RootFS/OCaml@5.4/build_tarballs.jl new file mode 100644 index 00000000000..6c766e4e3f4 --- /dev/null +++ b/0_RootFS/OCaml@5.4/build_tarballs.jl @@ -0,0 +1,30 @@ +### Instructions for adding a new version of the OCaml toolchain +# +# * update the `version` variable and `sources` +# * To deploy the shard and automatically update your BinaryBuilderBase's +# `Artifacts.toml`, use the `--deploy` flag to the `build_tarballs.jl` script. +# You can build & deploy by running: +# +# julia build_tarballs.jl --debug --verbose --deploy TARGET +# + +using BinaryBuilderBase, BinaryBuilder, Pkg.Artifacts + +include("../common.jl") + +name = "OCamlBase" +version = v"5.4.0" + +sources = [ + GitSource("https://github.com/ocaml/ocaml", + "ff1ab416a5503c8bde9fa3fae5f2bb21c7ddc81e"), # 5.4.0~alpha1 + GitSource("https://github.com/ocaml/dune", + "76c0c3941798f81dcc13a305d7abb120c191f5fa"), # 3.19.1 + GitSource("https://github.com/ocaml/ocamlbuild", + "131ba63a1b96d00f3986c8187677c8af61d20a08"), # 0.16.1 + GitSource("https://github.com/ocaml/ocamlfind", + "bd9aad183f0d1c2caf3ec29e4f52bc69361f266d"), # 1.9.8 + DirectorySource("./bundled"), +] + +include("../ocaml_common.jl") diff --git a/0_RootFS/OCaml@5.4/bundled/patches/00001-ocaml-relative-libdir.patch b/0_RootFS/OCaml@5.4/bundled/patches/00001-ocaml-relative-libdir.patch new file mode 100644 index 00000000000..6212557be0a --- /dev/null +++ b/0_RootFS/OCaml@5.4/bundled/patches/00001-ocaml-relative-libdir.patch @@ -0,0 +1,395 @@ +commit 06fe917b0104b55dc80ac0abe8a1e0915446394f +Author: Cody Tapscott +Date: Thu May 8 19:08:26 2025 -0400 + + Add relative path fallback for libdir / bindir + + The existing `OCAMLLIB` environment variable already allows you to use + a standard library installed elsewhere, but it doesn't let you re-locate + an existing installation. As one might expect, the problem is that the + stdlib itself contains absolute references to its own paths. + + This patch tries to hook into both places where that happens and do an + on-the-fly replacement of the standard library path, if it turns out + this is the standard library that OCaml that was built with (just + moved). + + This kicks in if the default hard-coded `%%LIBDIR%%`/`%%BINDIR%%` cannot + be found. + +diff --git a/bytecomp/bytelink.ml b/bytecomp/bytelink.ml +index c55224fab8..1b5b0aa99f 100644 +--- a/bytecomp/bytelink.ml ++++ b/bytecomp/bytelink.ml +@@ -344,7 +344,10 @@ let read_runtime_launch_info file = + try + let bindir_start = String.index buffer '\n' + 1 in + let bindir_end = String.index_from buffer bindir_start '\000' in +- let bindir = String.sub buffer bindir_start (bindir_end - bindir_start) in ++ let bindir = ++ let relocate_bindir = Misc.replace_substring ~before:Config.bindir_default ~after:Config.bindir ++ and raw_bindir = String.sub buffer bindir_start (bindir_end - bindir_start) in ++ relocate_bindir raw_bindir in + let executable_offset = bindir_end + 2 in + let launcher = + let kind = String.sub buffer 0 (bindir_start - 1) in +diff --git a/runtime/caml/misc.h b/runtime/caml/misc.h +index 1182b72808..1c16cf48f8 100644 +--- a/runtime/caml/misc.h ++++ b/runtime/caml/misc.h +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + /* Detection of available C attributes and compiler extensions */ + +@@ -491,6 +492,141 @@ extern double caml_log1p(double); + #define main_os wmain + #endif + ++static wchar_t * __cdecl _wdirname(wchar_t *path); ++ ++// Adapted to wchar_t from ++// https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-crt/misc/dirname.c ++ ++#include ++#include ++#include ++ ++static wchar_t * __cdecl ++_wdirname(wchar_t *path) ++{ ++ static wchar_t *retfail = NULL; ++ size_t len = wcslen(path); ++ ++ if (path && *path) ++ { ++ wchar_t *refpath = path; ++ ++ /* SUSv3 identifies a special case, where path is exactly equal to "//"; ++ * (we will also accept "\\" in the Win32 context, but not "/\" or "\/", ++ * and neither will we consider paths with an initial drive designator). ++ * For this special case, SUSv3 allows the implementation to choose to ++ * return "/" or "//", (or "\" or "\\", since this is Win32); we will ++ * simply return the path unchanged, (i.e. "//" or "\\"). */ ++ if (len > 1 && (refpath[0] == L'/' || refpath[0] == L'\\')) ++ { ++ if (refpath[1] == refpath[0] && refpath[2] == L'\0') ++ { ++ return path; ++ } ++ } ++ /* For all other cases ... ++ * step over the drive designator, if present ... */ ++ else if (len > 1 && refpath[1] == L':') ++ { ++ /* FIXME: maybe should confirm *refpath is a valid drive designator. */ ++ refpath += 2; ++ } ++ /* check again, just to ensure we still have a non-empty path name ... */ ++ if (*refpath) ++ { ++# undef basename ++# define basename __the_basename /* avoid shadowing. */ ++ /* reproduce the scanning logic of the "basename" function ++ * to locate the basename component of the current path string, ++ * (but also remember where the dirname component starts). */ ++ wchar_t *refname, *basename; ++ for (refname = basename = refpath; *refpath; ++refpath) ++ { ++ if (*refpath == L'/' || *refpath == L'\\') ++ { ++ /* we found a dir separator ... ++ * step over it, and any others which immediately follow it. */ ++ while (*refpath == L'/' || *refpath == L'\\') ++ ++refpath; ++ /* if we didn't reach the end of the path string ... */ ++ if (*refpath) ++ /* then we have a new candidate for the base name. */ ++ basename = refpath; ++ else ++ /* we struck an early termination of the path string, ++ * with trailing dir separators following the base name, ++ * so break out of the for loop, to avoid overrun. */ ++ break; ++ } ++ } ++ /* now check, ++ * to confirm that we have distinct dirname and basename components. */ ++ if (basename > refname) ++ { ++ /* and, when we do ... ++ * backtrack over all trailing separators on the dirname component, ++ * (but preserve exactly two initial dirname separators, if identical), ++ * and add a NUL terminator in their place. */ ++ do --basename; ++ while (basename > refname && (*basename == L'/' || *basename == L'\\')); ++ if (basename == refname && (refname[0] == L'/' || refname[0] == L'\\') ++ && refname[1] == refname[0] && refname[2] != L'/' && refname[2] != L'\\') ++ ++basename; ++ *++basename = L'\0'; ++ /* if the resultant dirname begins with EXACTLY two dir separators, ++ * AND both are identical, then we preserve them. */ ++ refpath = path; ++ while ((*refpath == L'/' || *refpath == L'\\')) ++ ++refpath; ++ if ((refpath - path) > 2 || path[1] != path[0]) ++ refpath = path; ++ /* and finally ... ++ * we remove any residual, redundantly duplicated separators from the dirname, ++ * reterminate, and return it. */ ++ refname = refpath; ++ while (*refpath) ++ { ++ if ((*refname++ = *refpath) == L'/' || *refpath++ == L'\\') ++ { ++ while (*refpath == L'/' || *refpath == L'\\') ++ ++refpath; ++ } ++ } ++ *refname = L'\0'; ++ } ++ else ++ { ++ /* either there were no dirname separators in the path name, ++ * or there was nothing else ... */ ++ if (*refname == L'/' || *refname == L'\\') ++ { ++ /* it was all separators, so return one. */ ++ ++refname; ++ } ++ else ++ { ++ /* there were no separators, so return '.'. */ ++ *refname++ = L'.'; ++ } ++ /* add a NUL terminator, in either case, ++ * then transform to the multibyte char domain, ++ * using our own buffer. */ ++ *refname = L'\0'; ++ } ++ return path; ++ } ++# undef basename ++ } ++ /* path is NULL, or an empty string; default return value is "." ... ++ * return this in our own buffer, regenerated by wide char transform, ++ * in case the caller trashed it after a previous call. ++ */ ++ retfail = realloc(retfail, 2 * sizeof(wchar_t)); ++ retfail[0] = L'.'; ++ retfail[1] = L'\0'; ++ return retfail; ++} ++ + #define access_os _waccess + #define open_os _wopen + #define stat_os _wstati64 +@@ -508,11 +644,13 @@ extern double caml_log1p(double); + #define execvp_os _wexecvp + #define execvpe_os _wexecvpe + #define strcmp_os wcscmp ++#define strncmp_os wcsncmp + #define strlen_os wcslen + #define sscanf_os swscanf + #define strcpy_os wcscpy + #define mktemp_os _wmktemp + #define fopen_os _wfopen ++#define dirname_os _wdirname + + #define clock_os caml_win32_clock + +@@ -553,11 +691,13 @@ extern double caml_log1p(double); + #define execvp_os execvp + #define execvpe_os execvpe + #define strcmp_os strcmp ++#define strncmp_os strncmp + #define strlen_os strlen + #define sscanf_os sscanf + #define strcpy_os strcpy + #define mktemp_os mktemp + #define fopen_os fopen ++#define dirname_os dirname + + #define clock_os clock + +diff --git a/runtime/dynlink.c b/runtime/dynlink.c +index d3e6b1b534..105c699589 100644 +--- a/runtime/dynlink.c ++++ b/runtime/dynlink.c +@@ -83,19 +83,62 @@ static c_primitive lookup_primitive(const char * name) + + #define LD_CONF_NAME T("ld.conf") + ++static int is_directory(char_os * p) ++{ ++#ifdef _WIN32 ++ struct _stati64 st; ++#else ++ struct stat st; ++#endif ++ int ret; ++ ++ ret = stat_os(p, &st); ++ if (ret == -1) return -1; ++ if (st.st_mode == -1) return -1; ++ ++#ifdef S_ISDIR ++ return S_ISDIR(st.st_mode) ? 1 : 0; ++#else ++ return st.st_mode & S_IFDIR ? 1 : 0; ++#endif ++} ++ + CAMLexport const char_os * caml_get_stdlib_location(void) + { +- const char_os * stdlib; ++ const char_os * bindir; ++ char_os * exe; ++ ++ static const char_os * stdlib = NULL; ++ if (stdlib != NULL) ++ return stdlib; ++ + stdlib = caml_secure_getenv(T("OCAMLLIB")); + if (stdlib == NULL) stdlib = caml_secure_getenv(T("CAMLLIB")); +- if (stdlib == NULL) stdlib = OCAML_STDLIB_DIR; ++ if (stdlib == NULL && is_directory(OCAML_STDLIB_DIR) == 1) ++ stdlib = OCAML_STDLIB_DIR; ++ ++ if (stdlib == NULL) { ++ exe = caml_executable_name(); ++ bindir = dirname_os(exe); ++ ++ stdlib = caml_stat_strconcat_os(7, ++ bindir, T("/"), "..", T("/"), "lib", T("/"), "ocaml"); ++ ++ caml_stat_free(exe); ++ } ++ + return stdlib; + } + ++int starts_with(const char_os *str, const char_os * pre) ++{ ++ return strncmp_os(pre, str, strlen_os(pre)) == 0; ++} ++ + CAMLexport char_os * caml_parse_ld_conf(void) + { + const char_os * stdlib; +- char_os * ldconfname, * wconfig, * p, * q; ++ char_os * ldconfname, * wconfig, * tail, * replaced, * p, * q; + char * config; + #ifdef _WIN32 + struct _stati64 st; +@@ -127,7 +170,14 @@ CAMLexport char_os * caml_parse_ld_conf(void) + for (p = wconfig; *p != 0; p++) { + if (*p == '\n') { + *p = 0; +- caml_ext_table_add(&caml_shared_libs_path, q); ++ if (starts_with(q, OCAML_STDLIB_DIR)) { ++ // replace 'OCAML_STDLIB_DIR' with 'stdlib' ++ tail = q + strlen_os(OCAML_STDLIB_DIR); ++ replaced = caml_stat_strconcat_os(2, stdlib, tail); ++ caml_ext_table_add(&caml_shared_libs_path, replaced); ++ } else { ++ caml_ext_table_add(&caml_shared_libs_path, q); ++ } + q = p + 1; + } + } +diff --git a/utils/config.common.ml.in b/utils/config.common.ml.in +index 0f956d2fbc..d21f9becc1 100644 +--- a/utils/config.common.ml.in ++++ b/utils/config.common.ml.in +@@ -20,6 +20,20 @@ + (* The main OCaml version string has moved to ../build-aux/ocaml_version.m4 *) + let version = Sys.ocaml_version + ++let bindir = ++ let relative_path = Filename.dirname Sys.executable_name in ++ try ++ if Sys.is_directory bindir_default then ++ bindir_default ++ else ++ relative_path ++ with Sys_error(_) -> ++ relative_path ++ ++let standard_library_relative = ++ let dir_sep = Filename.dir_sep in ++ ".." ^ dir_sep ^ "lib" ^ dir_sep ^ "ocaml" ++ + let standard_library = + try + Sys.getenv "OCAMLLIB" +@@ -27,7 +41,17 @@ let standard_library = + try + Sys.getenv "CAMLLIB" + with Not_found -> +- standard_library_default ++ let dirname = Filename.dirname ++ and dir_sep = Filename.dir_sep ++ and executable_name = Sys.executable_name in ++ let relative_path = (dirname executable_name) ^ dir_sep ^ standard_library_relative in ++ try ++ if Sys.is_directory standard_library_default then ++ standard_library_default ++ else ++ relative_path ++ with Sys_error(_) -> ++ relative_path + + let exec_magic_number = {magic|@EXEC_MAGIC_NUMBER@|magic} + (* exec_magic_number is duplicated in runtime/caml/exec.h *) +@@ -74,6 +98,7 @@ let configuration_variables () = + [ + p "version" version; + p "standard_library_default" standard_library_default; ++ p "standard_library_relative" standard_library_relative; + p "standard_library" standard_library; + p "ccomp_type" ccomp_type; + p "c_compiler" c_compiler; +diff --git a/utils/config.fixed.ml b/utils/config.fixed.ml +index a334b1d76f..5e42ce990d 100644 +--- a/utils/config.fixed.ml ++++ b/utils/config.fixed.ml +@@ -20,7 +20,7 @@ + + let boot_cannot_call s = "/ The boot compiler should not call " ^ s + +-let bindir = "/tmp" ++let bindir_default = "/tmp" + let standard_library_default = "/tmp" + let ccomp_type = "n/a" + let c_compiler = boot_cannot_call "the C compiler" +diff --git a/utils/config.generated.ml.in b/utils/config.generated.ml.in +index e5e1b15d31..ff8a9a4513 100644 +--- a/utils/config.generated.ml.in ++++ b/utils/config.generated.ml.in +@@ -18,7 +18,7 @@ + (* This file is included in config_main.ml during the build rather + than compiled on its own *) + +-let bindir = {@QS@|@ocaml_bindir@|@QS@} ++let bindir_default = {@QS@|@ocaml_bindir@|@QS@} + + let standard_library_default = {@QS@|@ocaml_libdir@|@QS@} + +diff --git a/utils/config.mli b/utils/config.mli +index 3e61d6e66b..c1a90bd8f3 100644 +--- a/utils/config.mli ++++ b/utils/config.mli +@@ -26,6 +26,9 @@ val version: string + val bindir: string + (** The directory containing the binary programs *) + ++val bindir_default: string ++(** The directory containing the binary programs (at build-time) *) ++ + val standard_library: string + (** The directory containing the standard libraries *) + diff --git a/0_RootFS/OCaml@5.4/bundled/patches/00002-_Float16-version-guard.patch b/0_RootFS/OCaml@5.4/bundled/patches/00002-_Float16-version-guard.patch new file mode 100644 index 00000000000..c5649e2fd47 --- /dev/null +++ b/0_RootFS/OCaml@5.4/bundled/patches/00002-_Float16-version-guard.patch @@ -0,0 +1,21 @@ +commit a08e30cf5f3f156893fca360efc4dff22247ce09 +Author: Cody Tapscott +Date: Thu May 8 19:17:14 2025 -0400 + + Avoid using `_Float16` in older GCC + + This was not introduced until GCC 7, even for AArch64. + +diff --git a/runtime/bigarray.c b/runtime/bigarray.c +index bd3ce896eb..ec77a16c57 100644 +--- a/runtime/bigarray.c ++++ b/runtime/bigarray.c +@@ -37,7 +37,7 @@ + + /* Half-precision floating point numbers */ + +-#if defined(__GNUC__) && defined(__aarch64__) ++#if defined(__GNUC__) && defined(__aarch64__) && (__GNUC__ >= 7) + + union float16_bits { uint16_t i; _Float16 f; }; + diff --git a/0_RootFS/OCaml@5.4/bundled/patches/00003-old-clock_gettime-darwin.patch b/0_RootFS/OCaml@5.4/bundled/patches/00003-old-clock_gettime-darwin.patch new file mode 100644 index 00000000000..cbfa3e7e228 --- /dev/null +++ b/0_RootFS/OCaml@5.4/bundled/patches/00003-old-clock_gettime-darwin.patch @@ -0,0 +1,22 @@ +commit bb13d39852529bcc78292befdbb8bfbd20299942 +Author: Cody Tapscott +Date: Thu May 8 20:18:35 2025 -0400 + + Don't use `clock_gettime_nsec_np` on x86-64 macOS + + This was not introduced until Darwin 16, which is much newer than what + BinaryBuilder runs with by default. + +diff --git a/runtime/unix.c b/runtime/unix.c +index e58c77cf51..7201e037f3 100644 +--- a/runtime/unix.c ++++ b/runtime/unix.c +@@ -424,7 +424,7 @@ char *caml_secure_getenv (char const *var) + + uint64_t caml_time_counter(void) + { +-#if defined(HAS_CLOCK_GETTIME_NSEC_NP) ++#if defined(HAS_CLOCK_GETTIME_NSEC_NP) && !(defined(__APPLE__) && defined(__x86_64__)) + return (clock_gettime_nsec_np(CLOCK_UPTIME_RAW)); + #elif defined(HAS_POSIX_MONOTONIC_CLOCK) + struct timespec t; diff --git a/0_RootFS/OCaml@5.4/bundled/patches/00004-redundant-win32-define.patch b/0_RootFS/OCaml@5.4/bundled/patches/00004-redundant-win32-define.patch new file mode 100644 index 00000000000..6f1919c0663 --- /dev/null +++ b/0_RootFS/OCaml@5.4/bundled/patches/00004-redundant-win32-define.patch @@ -0,0 +1,51 @@ +commit 519375c631557f5c339b1312d2e2eedfdb7744e4 +Author: Cody Tapscott +Date: Thu May 8 20:43:18 2025 -0400 + + Guard `_WIN32_WINNT` definition + +diff --git a/ocamltest/run_win32.c b/ocamltest/run_win32.c +index 5f55206237..c04f9265ca 100644 +--- a/ocamltest/run_win32.c ++++ b/ocamltest/run_win32.c +@@ -16,7 +16,9 @@ + /* Run programs with redirections and timeouts under Windows */ + + /* GetTickCount64() requires Windows Vista or Server 2008 */ ++#ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0600 ++#endif + + #include + #include +diff --git a/runtime/win32.c b/runtime/win32.c +index 8a5c8ff4b0..4f5a521fe7 100644 +--- a/runtime/win32.c ++++ b/runtime/win32.c +@@ -19,7 +19,9 @@ + + /* FILE_INFO_BY_HANDLE_CLASS, FILE_NAME_INFO, and INIT_ONCE are only + available from Windows Vista onwards */ ++#ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0600 /* _WIN32_WINNT_VISTA */ ++#endif + + #define WIN32_LEAN_AND_MEAN + #define _CRT_RAND_S +diff --git a/yacc/wstr.c b/yacc/wstr.c +index 78c334e691..3ec9b751fb 100644 +--- a/yacc/wstr.c ++++ b/yacc/wstr.c +@@ -13,8 +13,12 @@ + /**************************************************************************/ + + /* Need at least Windows Vista for WC_ERR_INVALID_CHARS */ ++#ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x600 ++#endif ++#ifndef WINVER + #define WINVER 0x600 ++#endif + #include + + /* See corresponding values in runtime/win32.c */ diff --git a/0_RootFS/Rootfs/bundled/testsuite/Makefile b/0_RootFS/Rootfs/bundled/testsuite/Makefile index 2e0a05d4989..ed09f3e694c 100644 --- a/0_RootFS/Rootfs/bundled/testsuite/Makefile +++ b/0_RootFS/Rootfs/bundled/testsuite/Makefile @@ -21,6 +21,7 @@ $(eval $(call enable_language,cxx,c++)) $(eval $(call enable_language,fortran,gfortran)) $(eval $(call enable_language,go,go)) $(eval $(call enable_language,rust,rustc)) +$(eval $(call enable_language,ocaml,ocamlopt)) define unesc $(subst -,/,$1) diff --git a/0_RootFS/Rootfs/bundled/testsuite/common.mk b/0_RootFS/Rootfs/bundled/testsuite/common.mk index e33002b2e05..e791fc4e3da 100644 --- a/0_RootFS/Rootfs/bundled/testsuite/common.mk +++ b/0_RootFS/Rootfs/bundled/testsuite/common.mk @@ -60,6 +60,7 @@ CXX ?= $(target)-c++ FC ?= $(target)-f77 GO ?= $(target)-go RUSTC ?= $(target)-rustc +OCAMLOPT ?= $(target)-ocamlopt # Create default rule for that directory so it can be created, if need be: $(PROJECT_BUILD): diff --git a/0_RootFS/Rootfs/bundled/testsuite/ocaml/hello_world/Makefile b/0_RootFS/Rootfs/bundled/testsuite/ocaml/hello_world/Makefile new file mode 100644 index 00000000000..549ed5052e1 --- /dev/null +++ b/0_RootFS/Rootfs/bundled/testsuite/ocaml/hello_world/Makefile @@ -0,0 +1,7 @@ +PROJECT_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) +BINS = $(PROJECT_NAME)$(exeext) + +include ../../common.mk + +$(PROJECT_BUILD)/$(PROJECT_NAME)$(exeext): $(PROJECT_NAME).ml + $(call color,$(OCAMLOPT),-o $@ $<) diff --git a/0_RootFS/Rootfs/bundled/testsuite/ocaml/hello_world/hello_world.ml b/0_RootFS/Rootfs/bundled/testsuite/ocaml/hello_world/hello_world.ml new file mode 100644 index 00000000000..7bf6048f46d --- /dev/null +++ b/0_RootFS/Rootfs/bundled/testsuite/ocaml/hello_world/hello_world.ml @@ -0,0 +1 @@ +let () = print_endline "Hello, World!" diff --git a/0_RootFS/ocaml_common.jl b/0_RootFS/ocaml_common.jl new file mode 100644 index 00000000000..e25bab5592c --- /dev/null +++ b/0_RootFS/ocaml_common.jl @@ -0,0 +1,157 @@ +name = "OCaml" +version = v"5.3" + +compiler_target = try + parse(Platform, ARGS[end]) +catch + error("This is not a typical build_tarballs.jl! Must provide exactly one platform as the last argument!") +end +deleteat!(ARGS, length(ARGS)) + +# These are the targets we support right now: +# x86_64-linux-musl +# x86_64-linux-gnu +# x86_64-w64-mingw32 +# x86_64-apple-darwin14 +# aarch64-apple-darwin20 +# aarch64-linux-gnu +# aarch64-linux-musl +# riscv64-linux-gnu +# riscv64-linux-musl +# powerpc64le-linux-gnu +# +# Always build x86_64-linux-musl first, since the other targets depend on it. +# +# Not supported: +# i686: OCaml 5.0 dropped support for 32-bit platforms +# freebsd: `POSIX threads are required but not supported on this platform` + +script = "host=$(BinaryBuilder.aatriplet(host_platform))\n" *raw""" +cd ${WORKSPACE}/srcdir/ocaml +git submodule update --init + +# Apply patches +for f in ${WORKSPACE}/srcdir/patches/*.patch; do + atomic_patch -p1 ${f} +done + +# OCaml is not relocatable, so configure it with the prefix where the shards will end up. +# This should improve in the future: https://github.com/ocaml/RFCs/pull/53 +# Alternatively, consider using the https://github.com/dra27/ocaml repository. +runtime_prefix=$(echo /opt/${target}*) +rsync --archive $runtime_prefix/ ${WORKSPACE}/initial_prefix/ + +# unset compiler env vars so that configure can detect them properly +unset CC CXX LD STRIP AS + + +## host compiler & tools + +if [[ "${host}" == "${target}" ]]; then + ./configure --prefix=${runtime_prefix} + make -j${nproc} + make install + + # Dune + cd ${WORKSPACE}/srcdir/dune + ./configure --prefix $runtime_prefix + make release + make install + + # OCamlbuild + # XXX: OCamlbuild takes its configuration values from ocamlc, so picks up host settings... + cd ${WORKSPACE}/srcdir/ocamlbuild + make configure OCAMLBUILD_PREFIX=$runtime_prefix OCAMLBUILD_BINDIR=$runtime_prefix/bin OCAMLBUILD_LIBDIR=$runtime_prefix/lib/ocaml + make -j${nproc} + make install PREFIX=$runtime_prefix BINDIR=$runtime_prefix/bin LIBDIR=$runtime_prefix/lib/ocaml + + # ocamlfind + cd ${WORKSPACE}/srcdir/ocamlfind + ./configure -bindir $runtime_prefix/bin -mandir $runtime_prefix/man -sitelib $runtime_prefix/lib/ocaml -config $runtime_prefix/etc/findlib.conf -no-topfind + make -j ${nproc} + make install prefix="" +else + # Build a temporary host compiler for bootstrapping the cross-compiler. + # We could re-use the host shard, but that complicates the rootfs selection logic. + ./configure --prefix=${host_prefix} --build=${host} --host=${host} + make -j${nproc} + make install + + # Make sure the host prefix takes precedence over the runtime prefix. + # This matters when, during installation of the cross-compiler, + # its `ocamlrun` would otherwise (fail to) execute instead. + export PATH=${host_prefix}/bin:$PATH +fi + + +## cross compiler + +if [[ "${host}" != "${target}" ]]; then + cd ${WORKSPACE}/srcdir/ocaml + make distclean + + # Build a cross-compiler + ./configure --prefix=${runtime_prefix} --build=${host} --host=${host} --target=${target} + make crossopt -j${nproc} + make installcross + + # Fix shebang of ocamlrun scripts to not hardcode a path of the build environment + for bin in $(file ${runtime_prefix}/bin/* | grep "a \S*/ocamlrun script" | cut -d: -f1); do + abspath=$(file ${bin} | grep -oh "a \S*/ocamlrun script" | cut -d' ' -f2) + sed -i "s?${abspath}?/usr/bin/env ocamlrun?" "${bin}" + done + + # Fix extensions of native binaries + if [[ "${target}" == *-mingw* ]]; then + for bin in ${runtime_prefix}/bin/*.exe; do + # (links to) target binaries should retain their extension + if file -L $bin | grep 'PE32' >/dev/null; then + continue + fi + + # if this is a symlink, update both the name of the link and the target + if [[ -L $bin ]]; then + path=$(readlink $bin) + rm $bin + ln -s $(basename ${path} .exe) ${runtime_prefix}/bin/$(basename ${bin} .exe) + + # if this is a file, simply rename it + elif [[ -f $bin ]]; then + mv $bin ${runtime_prefix}/bin/$(basename ${bin} .exe) + fi + done + fi +fi + + +## finalize + +# Move the installed files to the expected location +rsync --archive --compare-dest=$WORKSPACE/initial_prefix/ $runtime_prefix/ $prefix/ +find $prefix/ -type d -empty -delete +rsync --archive --delete ${WORKSPACE}/initial_prefix/ $runtime_prefix/ +rm -rf ${WORKSPACE}/initial_prefix +""" + +platforms = Platform[ host_platform ] +products = Product[ + # build with no products since all of our products are for the host, not the target + + # ExecutableProduct("ocamlopt.opt", :ocamlopt), + # ExecutableProduct("ocamlc.opt", :ocamlc), + # ExecutableProduct("ocamlrun", :ocamlrun), +] +dependencies = Dependency[] + +# Build the tarballs. This needs to run in the target's environment, as the OCaml build +# system needs a target compiler to assemble the runtime libraries. +ndARGS, deploy_target = find_deploy_arg(ARGS) +build_info = build_tarballs(ndARGS, name, version, sources, script, [compiler_target], products, dependencies; + skip_audit=true, julia_compat="1.6", preferred_gcc_version=v"6") + +build_info = Dict(host_platform => first(values(build_info))) + +# Upload the artifacts (if requested) +if deploy_target !== nothing + upload_and_insert_shards(deploy_target, name, version, build_info; target=compiler_target) +end diff --git a/H/HelloWorldOCaml/build_tarballs.jl b/H/HelloWorldOCaml/build_tarballs.jl new file mode 100644 index 00000000000..a86c7dd6141 --- /dev/null +++ b/H/HelloWorldOCaml/build_tarballs.jl @@ -0,0 +1,39 @@ +using BinaryBuilder + +name = "HelloWorldOCaml" +version = v"1.0.0" + +# sources generated inline below +sources = [ +] + +# Bash recipe for building across all platforms +script = raw""" +mkdir -p ${bindir} +echo 'let () = print_endline "hello world"' > hello.ml +ocamlopt -o ${bindir}/hello_world${exeext} hello.ml +install_license /usr/share/licenses/MIT +""" + +# These are the platforms we will build for by default, unless further +# platforms are passed in on the command line +platforms = supported_platforms() + +# OCaml 5.0 dropped support for 32-bit targets +filter!(p -> nbits(p) != 32, platforms) + +# Not yet supported by our OCaml toolchain +filter!(p -> !(Sys.isfreebsd(p)), platforms) + +# The products that we will ensure are always built +products = [ + ExecutableProduct("hello_world", :hello_world), +] + +# Dependencies that must be installed before this package can be built +dependencies = Dependency[ +] + +# Build the tarballs, and possibly a `build.jl` as well. +build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; + compilers=[:c, :ocaml], julia_compat="1.6")