#!/bin/sh
# This is a masquerading script for clang
# There are too many kernels on piCore 32-bit
# making hardship for clang finding gcc installation

gcc_chk() {
  GCC=/usr/local/lib/gcc/*/*/crtbegin.o
  # expect only one installation
  # /usr/local/lib/gcc/armv7l-unknown-linux-gnueabihf/13.2.0
  echo $GCC | awk 'NF == 1 {
    sub(/\/crtbegin.o/, "")
    print "--gcc-install-dir=" $0
  }'
}

# silence the warnings
distcc clang++ $(gcc_chk) -Wno-unused-command-line-argument \
  -Wl,-L/usr/local/lib -Wl,-O1 -Wl,-rpath=/usr/local/lib "$@"
# some other LDFLAGS that may not be passed by configure, cmake ... etc.