all: compile and link using clang, where possible

This commit is contained in:
Ayke van Laethem
2018-11-22 13:24:13 +01:00
parent 4a8ced590b
commit 62d74d8329
15 changed files with 133 additions and 100 deletions
+21 -4
View File
@@ -10,6 +10,7 @@ import (
"os/exec"
"os/signal"
"path/filepath"
"strconv"
"strings"
"syscall"
@@ -161,14 +162,30 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
cachePath, _ = filepath.Split(librt)
}
// Link the object file with the system compiler.
// Prepare link command.
executable := filepath.Join(dir, "main")
tmppath := executable // final file
args := append(spec.PreLinkArgs, "-o", executable, objfile)
ldflags := append(spec.LDFlags, "-o", executable, objfile)
if spec.RTLib == "compiler-rt" {
args = append(args, "-L", cachePath, "-lrt-"+spec.Triple)
ldflags = append(ldflags, "-L", cachePath, "-lrt-"+spec.Triple)
}
cmd := exec.Command(spec.Linker, args...)
// Compile extra files.
for i, path := range spec.ExtraFiles {
outpath := filepath.Join(dir, "extra-"+strconv.Itoa(i)+"-"+filepath.Base(path)+".o")
cmd := exec.Command(spec.Compiler, append(spec.CFlags, "-c", "-o", outpath, path)...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = sourceDir()
err := cmd.Run()
if err != nil {
return err
}
ldflags = append(ldflags, outpath)
}
// Link the object files together.
cmd := exec.Command(spec.Linker, ldflags...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = sourceDir()