forked from tklauser/go-sysconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mksysconf.go
44 lines (39 loc) · 843 Bytes
/
mksysconf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2018 Tobias Klauser. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
import (
"fmt"
"go/format"
"io/ioutil"
"os"
"os/exec"
"runtime"
)
func gensysconf() error {
defs := "sysconf_defs_" + runtime.GOOS + ".go"
cmd := exec.Command("go", "tool", "cgo", "-godefs", defs)
defer os.RemoveAll("_obj")
b, err := cmd.CombinedOutput()
if err != nil {
fmt.Fprint(os.Stderr, string(b))
return err
}
b, err = format.Source(b)
if err != nil {
return err
}
zsysconf := "z" + defs
// TODO(tk): differentiate per GOARCH?
if err := ioutil.WriteFile(zsysconf, b, 0644); err != nil {
return err
}
return nil
}
func main() {
if err := gensysconf(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}