Compilation failure upon running `opam install mechaml`

I used to have XCode on my Mac but removed it cause it took so much storage.
Installed OCaml(via brew install ocaml) and Opam successfully but failed on opam install mechaml.

This is the error log:

I used to have XCode on my Mac but removed it cause it took so much storage.
Installed OCaml(via brew install ocaml) and Opam successfully but failed on opam install mechaml.

This is the error log:

The following actions will be performed:
  ∗ install seq                     base    [required by re]
  ∗ install dune                    2.6.0   [required by mechaml]
  ∗ install conf-m4                 1       [required by ocamlfind]
  ∗ install ocamlbuild              0.14.0  [required by jsonm, logs]
  ∗ install cmdliner                1.0.4   [required by cohttp-lwt-unix]
  ∗ install stdlib-shims            0.1.0   [required by cohttp]
  ∗ install sexplib0                v0.13.0 [required by cohttp, cohttp-lwt]
  ∗ install result                  1.5     [required by lwt]
  ∗ install re                      1.9.0   [required by cohttp]
  ∗ install ppx_derivers            1.2.1   [required by ppxlib]
  ∗ install ocaml-syntax-shims      1.0.0   [required by mechaml]
  ∗ install ocaml-compiler-libs     v0.12.1 [required by ppxlib]
  ∗ install mmap                    1.1.0   [required by lwt]
  ∗ install magic-mime              1.1.2   [required by cohttp-lwt-unix]
  ∗ install macaddr                 5.0.0   [required by ipaddr]
  ∗ install dune-private-libs       2.6.0   [required by dune-configurator]
  ∗ install cppo                    1.6.6   [required by lwt]
  ∗ install ocamlfind               1.8.1   [required by jsonm, logs]
  ∗ install uchar                   0.0.2   [required by jsonm, markup]
  ∗ install ocaml-migrate-parsetree 1.7.3   [required by ppxlib]
  ∗ install dune-configurator       2.6.0   [required by base64]
  ∗ install topkg                   1.0.1   [required by jsonm, logs]
  ∗ install num                     1.3     [required by sexplib]
  ∗ install base-bytes              base    [required by base64, stringext]
  ∗ install base                    v0.13.2 [required by ppx_fields_conv, fieldslib,
                                            ppx_sexp_conv]
  ∗ install uutf                    1.0.2   [required by jsonm, markup]
  ∗ install fmt                     0.8.8   [required by cohttp-lwt-unix]
  ∗ install stringext               1.6.0   [required by cohttp]
  ∗ install ocplib-endian           1.1     [required by lwt]
  ∗ install base64                  3.4.0   [required by cohttp]
  ∗ install astring                 0.8.3   [required by conduit]
  ∗ install stdio                   v0.13.0 [required by ppxlib]
  ∗ install parsexp                 v0.13.0 [required by sexplib]
  ∗ install fieldslib               v0.13.0 [required by cohttp]
  ∗ install markup                  0.8.2   [required by lambdasoup]
  ∗ install jsonm                   1.0.1   [required by cohttp]
  ∗ install uri                     3.1.0   [required by mechaml]
  ∗ install lwt                     5.3.0   [required by mechaml]
  ∗ install domain-name             0.3.0   [required by ipaddr]
  ∗ install ppxlib                  0.13.0  [required by ppx_fields_conv, ppx_sexp_conv]
  ∗ install sexplib                 v0.13.0 [required by conduit-lwt]
  ∗ install lambdasoup              0.6.4   [required by mechaml]
  ∗ install logs                    0.7.0   [required by cohttp-lwt, cohttp-lwt-unix]
  ∗ install ipaddr                  5.0.0   [required by conduit-lwt-unix]
  ∗ install ppx_sexp_conv           v0.13.0 [required by cohttp, cohttp-lwt]
  ∗ install ppx_fields_conv         v0.13.0 [required by cohttp]
  ∗ install uri-sexp                3.1.0   [required by cohttp]
  ∗ install ipaddr-sexp             5.0.0   [required by conduit-lwt-unix]
  ∗ install cohttp                  2.5.1   [required by mechaml]
  ∗ install conduit                 2.1.0   [required by conduit-lwt]
  ∗ install cohttp-lwt              2.5.1   [required by mechaml]
  ∗ install conduit-lwt             2.1.0   [required by conduit-lwt-unix]
  ∗ install conduit-lwt-unix        2.2.2   [required by cohttp-lwt-unix]
  ∗ install cohttp-lwt-unix         2.5.1   [required by mechaml]
  ∗ install mechaml                 1.2.0
===== ∗ 55 =====
Do you want to continue? [Y/n] Y

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
[base64.3.4.0] downloaded from cache at https  ://opam.ocaml.org/cache
[astring.0.8.3] downloaded from cache at https  ://opam.ocaml.org/cache
[base.v0.13.2] downloaded from cache at https  ://opam.ocaml.org/cache
[cmdliner.1.0.4] downloaded from cache at https  ://opam.ocaml.org/cache
[cohttp.2.5.1] downloaded from cache at https  ://opam.ocaml.org/cache
[conduit.2.1.0] downloaded from cache at https  ://opam.ocaml.org/cache
[conduit-lwt.2.1.0] found in cache
[cohttp-lwt.2.5.1] downloaded from cache at https  ://opam.ocaml.org/cache
[cohttp-lwt-unix.2.5.1] downloaded from cache at https  ://opam.ocaml.org/cache
[conduit-lwt-unix.2.2.2] downloaded from cache at https  ://opam.ocaml.org/cache
[cppo.1.6.6] downloaded from cache at https  ://opam.ocaml.org/cache
[domain-name.0.3.0] downloaded from cache at https  ://opam.ocaml.org/cache
[dune.2.6.0] downloaded from cache at https  ://opam.ocaml.org/cache
[dune-private-libs.2.6.0] downloaded from cache at https ://opam.ocaml.org/cache
[fieldslib.v0.13.0] downloaded from cache at https ://opam.ocaml.org/cache
[dune-configurator.2.6.0] downloaded from cache at https ://opam.ocaml.org/cache
[fmt.0.8.8] downloaded from cache at https ://opam.ocaml.org/cache
[ipaddr.5.0.0] downloaded from cache at https ://opam.ocaml.org/cache
[jsonm.1.0.1] downloaded from cache at https ://opam.ocaml.org/cache
[lambdasoup.0.6.4] downloaded from cache at https ://opam.ocaml.org/cache
[ipaddr-sexp.5.0.0] downloaded from cache at https ://opam.ocaml.org/cache
[macaddr.5.0.0] found in cache
[logs.0.7.0] downloaded from cache at https ://opam.ocaml.org/cache
[magic-mime.1.1.2] downloaded from cache at https ://opam.ocaml.org/cache
[lwt.5.3.0] downloaded from cache at https ://opam.ocaml.org/cache
[markup.0.8.2] downloaded from cache at https ://opam.ocaml.org/cache
[mechaml.1.2.0] downloaded from cache at https ://opam.ocaml.org/cache
[mmap.1.1.0] downloaded from cache at https ://opam.ocaml.org/cache
[ocaml-compiler-libs.v0.12.1] downloaded from cache at https ://opam.ocaml.org/cache
[ocaml-syntax-shims.1.0.0] downloaded from cache at https ://opam.ocaml.org/cache
[ocaml-migrate-parsetree.1.7.3] downloaded from cache at https ://opam.ocaml.org/cache
[ocamlbuild.0.14.0] downloaded from cache at https ://opam.ocaml.org/cache
[ocamlfind.1.8.1] downloaded from cache at https ://opam.ocaml.org/cache
[parsexp.v0.13.0] downloaded from cache at https ://opam.ocaml.org/cache
[num.1.3] downloaded from https ://github.com/ocaml/num/archive/v1.3.tar.gz
[ppx_derivers.1.2.1] downloaded from cache at https ://opam.ocaml.org/cache
[ppx_fields_conv.v0.13.0] downloaded from cache at https ://opam.ocaml.org/cache
[ocplib-endian.1.1] downloaded from https ://github.com/OCamlPro/ocplib-endian/archive/1.1.tar.gz
[ppx_sexp_conv.v0.13.0] downloaded from cache at https ://opam.ocaml.org/cache
[ppxlib.0.13.0] downloaded from cache at https ://opam.ocaml.org/cache
[re.1.9.0] downloaded from cache at https ://opam.ocaml.org/cache
[result.1.5] downloaded from cache at https ://opam.ocaml.org/cache
[sexplib0.v0.13.0] downloaded from cache at https ://opam.ocaml.org/cache
[stdio.v0.13.0] downloaded from cache at https ://opam.ocaml.org/cache
[stdlib-shims.0.1.0] downloaded from cache at https ://opam.ocaml.org/cache
[stringext.1.6.0] downloaded from cache at https ://opam.ocaml.org/cache
[topkg.1.0.1] downloaded from cache at https ://opam.ocaml.org/cache
[uri.3.1.0] downloaded from cache at https ://opam.ocaml.org/cache
[uri-sexp.3.1.0] found in cache
[uchar.0.0.2] downloaded from cache at https ://opam.ocaml.org/cache
[uutf.1.0.2] downloaded from cache at https ://opam.ocaml.org/cache
[sexplib.v0.13.0] downloaded from cache at https ://opam.ocaml.org/cache

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
∗ installed seq.base
[ERROR] The compilation of ocamlbuild failed at
        "/Users/jani/.opam/opam-init/hooks/sandbox.sh build make -f configure.make all
        OCAMLBUILD_PREFIX=/Users/jani/.opam/default
        OCAMLBUILD_BINDIR=/Users/jani/.opam/default/bin
        OCAMLBUILD_LIBDIR=/Users/jani/.opam/default/lib
        OCAMLBUILD_MANDIR=/Users/jani/.opam/default/man OCAML_NATIVE=true
        OCAML_NATIVE_TOOLS=true".
∗ installed conf-m4.1
[ERROR] The compilation of dune failed at "/Users/jani/.opam/opam-init/hooks/sandbox.sh
        build ocaml bootstrap.ml -j 7".
[ERROR] The compilation of cmdliner failed at "/Users/jani/.opam/opam-init/hooks/sandbox.sh
        build make all PREFIX=/Users/jani/.opam/default".
[ERROR] The compilation of ocamlfind failed at
        "/Users/jani/.opam/opam-init/hooks/sandbox.sh build ./configure -bindir
        /Users/jani/.opam/default/bin -sitelib /Users/jani/.opam/default/lib -mandir
        /Users/jani/.opam/default/man -config /Users/jani/.opam/default/lib/findlib.conf
        -no-custom -no-topfind".

#=== ERROR while compiling ocamlfind.1.8.1 ====================================#
# context     2.0.7 | macos/x86_64 | ocaml-system.4.09.0 | https ://opam.ocaml.org#64fa67c5
# path        ~/.opam/default/.opam-switch/build/ocamlfind.1.8.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build ./configure -bindir /Users/jani/.opam/default/bin -sitelib /Users/jani/.opam/default/lib -mandir /Users/jani/.opam/default/man -config /Users/jani/.opam/default/lib/findlib.conf -no-custom -no-topfind
# exit-code   1
# env-file    ~/.opam/log/ocamlfind-55340-068f80.env
# output-file ~/.opam/log/ocamlfind-55340-068f80.out
### output ###
# [...]
# graphics: not found
# Configuration for dynlink written to site-lib-src/dynlink/META
# Configuration for str written to site-lib-src/str/META
# Configuration for threads written to site-lib-src/threads/META
# Configuration for unix written to site-lib-src/unix/META
# Configuration for stdlib written to site-lib-src/stdlib/META
# Configuration for bigarray written to site-lib-src/bigarray/META
# Configuration for ocamldoc written to site-lib-src/ocamldoc/META
# Configuration for compiler-libs written to site-lib-src/compiler-libs/META
# Configuration for bytes written to site-lib-src/bytes/META
# Configuration for raw_spacetime written to site-lib-src/raw_spacetime/META
# Detecting compiler arguments: FAILED (see the file ocargs.log for details)


#=== ERROR while compiling ocamlbuild.0.14.0 ==================================#
# context     2.0.7 | macos/x86_64 | ocaml-system.4.09.0 | https ://opam.ocaml.org#64fa67c5
# path        ~/.opam/default/.opam-switch/build/ocamlbuild.0.14.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build make -f configure.make all OCAMLBUILD_PREFIX=/Users/jani/.opam/default OCAMLBUILD_BINDIR=/Users/jani/.opam/default/bin OCAMLBUILD_LIBDIR=/Users/jani/.opam/default/lib OCAMLBUILD_MANDIR=/Users/jani/.opam/default/man OCAML_NATIVE=true OCAML_NATIVE_TOOLS=true
# exit-code   1
# env-file    ~/.opam/log/ocamlbuild-55340-096938.env
# output-file ~/.opam/log/ocamlbuild-55340-096938.out
### output ###
# xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist
# Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
# See `man xcode-select` for more details.


#=== ERROR while compiling dune.2.6.0 =========================================#
# context     2.0.7 | macos/x86_64 | ocaml-system.4.09.0 | https ://opam.ocaml.org#64fa67c5
# path        ~/.opam/default/.opam-switch/build/dune.2.6.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build ocaml bootstrap.ml -j 7
# exit-code   2
# env-file    ~/.opam/log/dune-55340-bd5e5c.env
# output-file ~/.opam/log/dune-55340-bd5e5c.out
### output ###
# ocamlc -custom -w -24 -g -o .duneboot.exe -I boot unix.cma boot/libs.ml boot/duneboot.ml
# xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist
# Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
# See `man xcode-select` for more details.
# File "boot/duneboot.ml", line 1:
# Error: Error while building custom runtime system


#=== ERROR while compiling cmdliner.1.0.4 =====================================#
# context     2.0.7 | macos/x86_64 | ocaml-system.4.09.0 | https ://opam.ocaml.org#64fa67c5
# path        ~/.opam/default/.opam-switch/build/cmdliner.1.0.4
# command     ~/.opam/opam-init/hooks/sandbox.sh build make all PREFIX=/Users/jani/.opam/default
# exit-code   1
# env-file    ~/.opam/log/cmdliner-55340-d22aeb.env
# output-file ~/.opam/log/cmdliner-55340-d22aeb.out
### output ###
# xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist
# Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
# See `man xcode-select` for more details.



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
┌─ The following actions failed
│ λ build cmdliner   1.0.4
│ λ build dune       2.6.0
│ λ build ocamlbuild 0.14.0
│ λ build ocamlfind  1.8.1
└─
┌─ The following changes have been performed (the rest was aborted)
│ ∗ install conf-m4 1
│ ∗ install seq     base
└─

The former state can be restored with:
    opam switch import
"/Users/jani/.opam/default/.opam-switch/backup/state-20200616205551.export"

For the sake of saving time from future users I’ve managed to fix the compilation error by resetting xcode build tools path via:

sudo xcode-select --reset

If you don’t have command line tools you probably need to run:

xcode-select --install