1//===- zdefaultcc.go - default compiler locations -------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides default locations for cc, cxx and llgo.
10//
11//===----------------------------------------------------------------------===//
12
13package main
14
15import (
16	"path/filepath"
17	"os"
18	"os/exec"
19)
20
21var defaultGCCGO, defaultCC, defaultCXX string
22
23func getInstPrefix() (string, error) {
24	path, err := exec.LookPath(os.Args[0])
25	if err != nil {
26		return "", err
27	}
28
29	path, err = filepath.EvalSymlinks(path)
30	if err != nil {
31		return "", err
32	}
33
34	prefix := filepath.Join(path, "..", "..")
35	return prefix, nil
36}
37
38func init() {
39	prefix, err := getInstPrefix()
40	if err != nil {
41		panic(err.Error())
42	}
43
44	defaultCC = filepath.Join(prefix, "bin", "clang")
45	defaultCXX = filepath.Join(prefix, "bin", "clang++")
46	defaultGCCGO = filepath.Join(prefix, "bin", "llgo")
47	toolDir = filepath.Join(prefix, "lib", "go", "llgo-@LLGO_VERSION@")
48
49	gccgoName = os.Getenv("GCCGO")
50	if gccgoName == "" {
51		gccgoName = defaultGCCGO
52	}
53	gccgoBin, _ = exec.LookPath(gccgoName)
54}
55