func CreateArgv(pkgs []*dag.Package) { var argv []string includeLen := len(includes) for y := 0; y < len(pkgs); y++ { argv = make([]string, 0) argv = append(argv, pathCompiler) argv = append(argv, "-I") argv = append(argv, libroot) for y := 0; y < includeLen; y++ { argv = append(argv, "-I") argv = append(argv, includes[y]) } golibs := handy.GoPathImports(global.GetString("-backend")) for j := 0; j < len(golibs); j++ { argv = append(argv, "-I") argv = append(argv, golibs[j]) } switch global.GetString("-backend") { case "gcc", "gccgo": argv = append(argv, "-c") } argv = append(argv, "-o") argv = append(argv, filepath.Join(libroot, pkgs[y].Name)+suffix) for z := 0; z < len(pkgs[y].Files); z++ { argv = append(argv, pkgs[y].Files[z]) } pkgs[y].Argv = argv } }
func ForkLink(output string, pkgs []*dag.Package, extra []*dag.Package, up2date bool) { var mainPKG *dag.Package gotMain := make([]*dag.Package, 0) for i := 0; i < len(pkgs); i++ { if pkgs[i].ShortName == "main" { gotMain = append(gotMain, pkgs[i]) } } if len(gotMain) == 0 { log.Fatal("[ERROR] (linking) no main package found\n") } if len(gotMain) > 1 { choice := mainChoice(gotMain) mainPKG = gotMain[choice] } else { mainPKG = gotMain[0] } compiled := filepath.Join(libroot, mainPKG.Name) + suffix if up2date && !global.GetBool("-dryrun") && handy.IsFile(output) { if handy.ModifyTimestamp(compiled) < handy.ModifyTimestamp(output) { say.Printf("up 2 date: %s\n", output) return } } argv := make([]string, 0) argv = append(argv, pathLinker) switch global.GetString("-backend") { case "gc", "express": argv = append(argv, "-L") argv = append(argv, libroot) if global.GetString("-backend") == "gc" { golibs := handy.GoPathImports("gc") for j := 0; j < len(golibs); j++ { argv = append(argv, "-L") argv = append(argv, golibs[j]) } if global.GetBool("-strip") { argv = append(argv, "-s") } } } argv = append(argv, "-o") argv = append(argv, output) // static only for non-gcc if global.GetString("-backend") == "gc" && global.GetBool("-static") { argv = append(argv, "-d") } switch global.GetString("-backend") { case "gccgo", "gcc": walker.IncludeFile = func(s string) bool { return strings.HasSuffix(s, ".o") } walker.IncludeDir = func(s string) bool { return true } for y := 0; y < len(includes); y++ { argv = append(argv, walker.PathWalk(includes[y])...) } case "gc", "express": for y := 0; y < len(includes); y++ { argv = append(argv, "-L") argv = append(argv, includes[y]) } } argv = append(argv, compiled) if global.GetString("-backend") == "gcc" || global.GetString("-backend") == "gccgo" { ss := stringset.New() if len(extra) > 0 { for j := 0; j < len(extra); j++ { // main package untestable using GCC if extra[j].ShortName != "main" { ss.Add(filepath.Join(libroot, extra[j].Name) + suffix) } } } else { for k := 0; k < len(pkgs); k++ { ss.Add(filepath.Join(libroot, pkgs[k].Name) + suffix) } ss.Remove(compiled) } if ss.Len() > 0 { argv = append(argv, ss.Slice()...) } } if global.GetBool("-dryrun") { linker := filepath.Base(pathLinker) fmt.Printf("%s %s || exit 1\n", linker, strings.Join(argv[1:], " ")) } else { say.Println("linking :", output) handy.StdExecve(argv, true) } }