package rosa import ( "slices" "strings" "hakurei.app/internal/pkg" ) func (t Toolchain) newMake() (pkg.Artifact, string) { const ( version = "4.4.1" checksum = "YS_B07ZcAy9PbaK5_vKGj64SrxO2VMpnMKfc9I0Q9IC1rn0RwOH7802pJoj2Mq4a" ) return t.New("make-"+version, TEarly, nil, nil, nil, ` cd "$(mktemp -d)" /usr/src/make/configure \ --prefix=/system \ --build="${ROSA_TRIPLE}" \ --disable-dependency-tracking ./build.sh ./make DESTDIR=/work install check `, pkg.Path(AbsUsrSrc.Append("make"), false, pkg.NewHTTPGetTar( nil, "https://ftpmirror.gnu.org/gnu/make/make-"+version+".tar.gz", mustDecode(checksum), pkg.TarGzip, ))), version } func init() { artifactsM[Make] = Metadata{ f: Toolchain.newMake, Name: "make", Description: "a tool which controls the generation of executables and other non-source files", Website: "https://www.gnu.org/software/make/", } } // MakeHelper is the [Make] build system helper. type MakeHelper struct { // Do not include default extras. OmitDefaults bool // Command to generate the build system. Generate string // Runs before make. ScriptMakeEarly string // Runs before check. ScriptCheckEarly string // Runs after install. Script string // Remain in current directory. InPlace bool // Whether to skip running the configure script. SkipConfigure bool // Alternative name for the configure script. ConfigureName string // Flags passed to the configure script. Configure [][2]string // Host target triple, zero value is equivalent to the Rosa OS triple. Host string // Target triple, zero value is equivalent to the Rosa OS triple. Build string // Extra make targets. Make []string // Whether to skip the check target. SkipCheck bool // Name of the check target, zero value is equivalent to "check". Check []string // Replaces the default install command. Install string } var _ Helper = new(MakeHelper) // name returns its arguments joined with '-'. func (*MakeHelper) name(name, version string) string { return name + "-" + version } // extra returns make and other optional dependencies. func (attr *MakeHelper) extra(flag int) []PArtifact { extra := []PArtifact{Make} if (attr == nil || !attr.OmitDefaults) && flag&TEarly == 0 { extra = append(extra, Gawk, Coreutils, ) } return extra } // wantsChmod returns whether the build system needs to be generated. func (attr *MakeHelper) wantsChmod() bool { return attr != nil && attr.Generate != "" } // wantsWrite is equivalent to wantsChmod. func (attr *MakeHelper) wantsWrite() bool { return attr.wantsChmod() } // scriptEarly returns the optional build system generation segment. func (attr *MakeHelper) scriptEarly() string { if attr == nil { return "" } generate := attr.Generate if len(generate) > 0 && generate[len(generate)-1] != '\n' { generate += "\n" } return generate } // createDir returns false. func (*MakeHelper) createDir() bool { return false } // wantsDir requests a new directory in TMPDIR, or omits the cd statement if InPlace. func (attr *MakeHelper) wantsDir() string { if attr != nil && attr.InPlace { return helperInPlace } return `"$(mktemp -d)"` } // script generates the cure script. func (attr *MakeHelper) script(name string) string { if attr == nil { attr = new(MakeHelper) } var configure string if !attr.SkipConfigure { configure = attr.ConfigureName if configure == "" { configure += `/usr/src/` + name + `/configure \ --prefix=/system` host := `"${ROSA_TRIPLE}"` if attr.Host != "" { host = attr.Host } if attr.Host != `""` { configure += ` \ --host=` + host } build := `"${ROSA_TRIPLE}"` if attr.Build != "" { build = attr.Build } if attr.Build != `""` { configure += ` \ --build=` + build } } if len(attr.Configure) > 0 { const sep = " \\\n\t" configure += sep + strings.Join( slices.Collect(func(yield func(string) bool) { for _, v := range attr.Configure { s := v[0] if v[0] != "" && v[0][0] >= 'a' && v[0][0] <= 'z' { s = "--" + s } else if len(v[0]) > 1 && v[0][0] == 'D' && v[0][1] >= 'a' && v[0][1] <= 'z' { s = "-" + s } if v[1] != "" { s += "=" + v[1] } if !yield(s) { return } } }), sep, ) } } scriptMake := ` make \ "-j$(nproc)"` if len(attr.Make) > 0 { scriptMake += " \\\n\t" + strings.Join(attr.Make, " \\\n\t") } scriptMake += "\n" if !attr.SkipCheck { scriptMake += attr.ScriptCheckEarly + `make \ "-j$(nproc)" \ ` if len(attr.Check) > 0 { scriptMake += strings.Join(attr.Check, " \\\n\t") } else { scriptMake += "check" } scriptMake += "\n" } scriptInstall := attr.Install if scriptInstall == "" { scriptInstall = "make DESTDIR=/work install" } scriptInstall += "\n" return configure + attr.ScriptMakeEarly + scriptMake + scriptInstall + attr.Script }