Skip to content

Commit 3c9c577

Browse files
envshiphydf
authored andcommitted
Auto get include
1 parent be94c10 commit 3c9c577

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

tools/generrmsg.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log"
77
"os"
8+
"os/exec"
89
"strings"
910

1011
"github.com/go-clang/v3.4/clang"
@@ -20,9 +21,23 @@ func main() {
2021
copy(tuArgs, flag.Args()[1:])
2122
}
2223
_ = tuArgs
23-
cmdArgs := []string{
24-
"-std=c99",
25-
"-I/usr/lib/clang/3.4/include"}
24+
25+
// auto find clang include dir
26+
clincdir := "/usr/lib/clang/3.4/include"
27+
clexe, err := exec.LookPath("clang")
28+
if err != nil {
29+
log.Println(err)
30+
} else {
31+
cmdo := exec.Command(clexe, "-print-resource-dir")
32+
output, err := cmdo.CombinedOutput()
33+
if err != nil {
34+
log.Println(err)
35+
} else {
36+
clincdir = strings.TrimSpace(string(output))
37+
}
38+
}
39+
40+
cmdArgs := []string{"-std=c99", fmt.Sprintf("-I%s/include", clincdir)}
2641
tu := idx.ParseTranslationUnit("/usr/local/include/tox/tox.h", cmdArgs, nil, 0)
2742
defer tu.Dispose()
2843

@@ -90,6 +105,6 @@ func main() {
90105
}
91106

92107
/*
93-
结构:
108+
result structure:
94109
var _enumName_S map[int]string
95110
*/

0 commit comments

Comments
 (0)