#!/usr/bin/env bash
set -euo pipefail

function abspath() {
  # Trim off any leading PWD/, if present, and then add it back.
  echo $(pwd)/"${1#"$(pwd)/"}"
}

# This script should be invoked as:
#   `$bin_root/third_party/external/emscripten/generate_config`.
# Removing the last two path parts moves us back up to `$bin_root`, which
# contains the `external` directory with the emscripten workspace.
bin_root="$(abspath "$(dirname "$0")")/../.."
config_file="$1"

cat >"$config_file" <<EOF
BINARYEN_ROOT = "$bin_root/$ZX_EMSCRIPTEN_WORKSPACE_ROOT/$ZX_BINARYEN_ROOT"
EMSCRIPTEN_ROOT = "$bin_root/$ZX_EMSCRIPTEN_WORKSPACE_ROOT/$ZX_EMSCRIPTEN_ROOT"
LLVM_ROOT = "$bin_root/$ZX_EMSCRIPTEN_WORKSPACE_ROOT/$ZX_LLVM_ROOT"
NODE_JS = "$bin_root/$ZX_EMSCRIPTEN_WORKSPACE_ROOT/$ZX_NODE_JS"
JAVA = "java"
EOF
