Skip to content

Instantly share code, notes, and snippets.

@xlab
Created May 16, 2016 22:02
Show Gist options
  • Save xlab/05198ba4f7727b5d61ebfa16e821c87c to your computer and use it in GitHub Desktop.
Save xlab/05198ba4f7727b5d61ebfa16e821c87c to your computer and use it in GitHub Desktop.
func stealDefinesFromCC() (defs string, ok bool) {
cc, ok := os.LookupEnv("CC")
if !ok { // second chance for CPP
cc, ok = os.LookupEnv("CPP")
if !ok {
return
}
}
cmd := exec.Command(cc, "-dM", "-E", "-x", "c", "/dev/null")
buf, err := cmd.CombinedOutput()
if err != nil {
log.Println("[WARN]:", err)
return
}
defs = string(buf)
return defs, true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment