1// Copyright 2018 Tobias Klauser. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5//go:build ignore 6// +build ignore 7 8package main 9 10import ( 11 "fmt" 12 "go/format" 13 "io/ioutil" 14 "os" 15 "os/exec" 16 "runtime" 17) 18 19func gensysconf(in, out string) error { 20 if _, err := os.Stat(in); err != nil { 21 if os.IsNotExist(err) { 22 return nil 23 } else { 24 return err 25 } 26 } 27 28 cmd := exec.Command("go", "tool", "cgo", "-godefs", in) 29 defer os.RemoveAll("_obj") 30 b, err := cmd.CombinedOutput() 31 if err != nil { 32 fmt.Fprintln(os.Stderr, string(b)) 33 return err 34 } 35 b, err = format.Source(b) 36 if err != nil { 37 return err 38 } 39 if err := ioutil.WriteFile(out, b, 0644); err != nil { 40 return err 41 } 42 return nil 43} 44 45func main() { 46 goos := runtime.GOOS 47 if goos == "illumos" { 48 goos = "solaris" 49 } 50 defs := fmt.Sprintf("sysconf_defs_%s.go", goos) 51 if err := gensysconf(defs, "z"+defs); err != nil { 52 fmt.Fprintln(os.Stderr, err) 53 os.Exit(1) 54 } 55 56 vals := fmt.Sprintf("sysconf_values_%s.go", runtime.GOOS) 57 // sysconf variable values are GOARCH-specific, thus write per GOARCH 58 zvals := fmt.Sprintf("zsysconf_values_%s_%s.go", runtime.GOOS, runtime.GOARCH) 59 if err := gensysconf(vals, zvals); err != nil { 60 fmt.Fprintln(os.Stderr, err) 61 os.Exit(1) 62 } 63} 64