func (cl *CLib) Build(c *build.Context) error { params := []string{"-c"} params = append(params, cl.CompilerOptions...) params = append(params, cl.LinkerOptions...) params = append(params, cl.Sources...) params = append(params, cl.Includes.Includes()...) if err := c.Exec(Compiler(), CCENV, params); err != nil { c.Println(err.Error()) return fmt.Errorf(cl.buf.String()) } libName := fmt.Sprintf("%s.a", cl.Name) params = []string{"-rs", libName} params = append(params, cl.LinkerOptions...) // This is done under the assumption that each src file put in this thing // here will comeout as a .o file for _, f := range cl.Sources { _, filename := filepath.Split(f) params = append(params, fmt.Sprintf("%s.o", filename[:strings.LastIndex(filename, ".")])) } if err := c.Exec(Archiver(), CCENV, params); err != nil { c.Println(err.Error()) return fmt.Errorf(cl.buf.String()) } return nil }
func (s *Strip) Build(c *build.Context) error { params := []string{"-o"} params = append(params, s.Name) params = append(params, filepath.Join("bin", split(s.Dependencies[0], ":"))) if err := c.Exec(Stripper(), nil, params); err != nil { return fmt.Errorf(err.Error()) } return nil }
func (g *GenRule) Build(c *build.Context) error { for _, cmd := range g.Commands { strs := strings.Split(cmd, " ") if err := c.Exec(strs[0], nil, strs[1:]); err != nil { c.Println(err.Error()) return err } } return nil }
func (oc *ObjCopy) Build(c *build.Context) error { params := []string{} params = append(params, "-I") params = append(params, oc.In) params = append(params, "-O") params = append(params, oc.Out) params = append(params, filepath.Join("bin", split(oc.Dependencies[0], ":"))) params = append(params, oc.Name) if err := c.Exec(Copier(), nil, params); err != nil { return fmt.Errorf(err.Error()) } return nil }
func (y *Yacc) Build(c *build.Context) error { params := []string{} params = append(params, y.YaccOptions...) params = append(params, y.Sources...) c.Println(strings.Join(append([]string{"yacc"}, params...), " ")) if err := c.Exec("yacc", nil, params); err != nil { c.Println(err.Error()) return fmt.Errorf(y.buf.String()) } return nil }
func (mp *ManPage) Build(c *build.Context) error { for _, m := range mp.Sources { params := []string{"<"} params = append(params, m) params = append(params, ">") params = append(params, fmt.Sprintf("%s.html", m)) c.Println(strings.Join(append([]string{"man2html"}, params...), " ")) if err := c.Exec("man2html", nil, params); err != nil { return err } } return nil }
func (npm *NpmPackage) Build(c *build.Context) error { if npm.Version == "" { return fmt.Errorf("NPM package %s failed to install, no version string") } params := []string{} params = append(params, "install") params = append(params, fmt.Sprintf("%s@%s", npm.Name, npm.Version)) c.Println(strings.Join(append([]string{"npm"}, params...), " ")) if err := c.Exec("npm", nil, params); err != nil { c.Println(err.Error()) return fmt.Errorf(err.Error()) } return nil }
func (cb *CBin) Build(c *build.Context) error { c.Println(prettyprint.AsJSON(cb)) params := []string{} params = append(params, cb.CompilerOptions...) params = append(params, cb.Sources...) params = append(params, cb.Includes.Includes()...) if err := c.Exec(Compiler(), CCENV, params); err != nil { return fmt.Errorf(err.Error()) } ldparams := []string{"-o", cb.Name} ldparams = append(ldparams, cb.LinkerOptions...) if cb.LinkerFile != "" { ldparams = append(ldparams, cb.LinkerFile) } // This is done under the assumption that each src file put in this thing // here will comeout as a .o file for _, f := range cb.Sources { _, fname := filepath.Split(f) ldparams = append(ldparams, fmt.Sprintf("%s.o", fname[:strings.LastIndex(fname, ".")])) } ldparams = append(ldparams, "-L", "lib") for _, dep := range cb.Dependencies { d := split(dep, ":") if len(d) < 3 { continue } if d[:3] == "lib" { ldparams = append(ldparams, fmt.Sprintf("-l%s", d[3:])) } } if err := c.Exec(Linker(), CCENV, ldparams); err != nil { return fmt.Errorf(err.Error()) } return nil }