Files
hakurei/internal/rosa/make.go
Ophestra 1791b604b5
All checks were successful
Test / Create distribution (push) Successful in 29s
Test / ShareFS (push) Successful in 36s
Test / Sandbox (race detector) (push) Successful in 43s
Test / Sandbox (push) Successful in 44s
Test / Hakurei (race detector) (push) Successful in 49s
Test / Hpkg (push) Successful in 46s
Test / Hakurei (push) Successful in 2m50s
Test / Flake checks (push) Successful in 1m46s
internal/rosa/make: configurable configure and install
This makes the helper useful for non-autotools build systems.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2026-02-12 01:19:40 +09:00

179 lines
4.1 KiB
Go

package rosa
import (
"slices"
"strings"
"hakurei.app/internal/pkg"
)
func (t Toolchain) newMake() pkg.Artifact {
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,
)))
}
func init() { artifactsF[Make] = Toolchain.newMake }
// MakeAttr holds the project-specific attributes that will be applied to a new
// [pkg.Artifact] compiled via [Make].
type MakeAttr struct {
// Mount the source tree writable.
Writable bool
// Do not include default extras.
OmitDefaults bool
// Dependencies not provided by stage0.
NonStage0 []pkg.Artifact
// Additional environment variables.
Env []string
// Runs before configure.
ScriptEarly string
// Runs after configure.
ScriptConfigured string
// Runs after install.
Script string
// Remain in working directory set up during ScriptEarly.
InPlace bool
// Whether to skip running the configure script.
SkipConfigure bool
// Flags passed to the configure script.
Configure [][2]string
// Extra make targets.
Make []string
// Target triple, zero value is equivalent to the Rosa OS triple.
Build string
// Whether to skip the check target.
SkipCheck bool
// Name of the check target, zero value is equivalent to "check".
CheckName string
// Replaces the default install command.
ScriptInstall string
// Suffix appended to the source pathname.
SourceSuffix string
// Passed through to [Toolchain.New], before source.
Paths []pkg.ExecPath
// Passed through to [Toolchain.New].
Flag int
}
// NewViaMake returns a [pkg.Artifact] for compiling and installing via [Make].
func (t Toolchain) NewViaMake(
name, version string,
source pkg.Artifact,
attr *MakeAttr,
extra ...pkg.Artifact,
) pkg.Artifact {
if name == "" || version == "" {
panic("names must be non-empty")
}
if attr == nil {
attr = new(MakeAttr)
}
build := `"${ROSA_TRIPLE}"`
if attr.Build != "" {
build = attr.Build
}
var configure string
if !attr.SkipConfigure {
configure += `
/usr/src/` + name + `/configure \
--prefix=/system`
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[1] == "" || (v[0] != "" &&
v[0][0] >= 'a' &&
v[0][0] <= 'z') {
s = "--" + s
}
if v[1] != "" {
s += "=" + v[1]
}
if !yield(s) {
return
}
}
}),
sep,
)
}
}
makeTargets := make([]string, 1, 2+len(attr.Make))
if !attr.SkipCheck {
if attr.CheckName == "" {
makeTargets = append(makeTargets, "check")
} else {
makeTargets = append(makeTargets, attr.CheckName)
}
}
makeTargets = append(makeTargets, attr.Make...)
if len(makeTargets) == 1 {
makeTargets = nil
}
finalExtra := []pkg.Artifact{
t.Load(Make),
}
if attr.OmitDefaults || attr.Flag&TEarly == 0 {
finalExtra = append(finalExtra,
t.Load(Gawk),
t.Load(Coreutils),
)
}
finalExtra = append(finalExtra, extra...)
scriptEarly := attr.ScriptEarly
if !attr.InPlace {
scriptEarly += "\ncd \"$(mktemp -d)\""
} else if scriptEarly == "" {
panic("cannot remain in root")
}
scriptInstall := attr.ScriptInstall
if scriptInstall == "" {
scriptInstall = "make DESTDIR=/work install"
}
scriptInstall += "\n"
return t.New(name+"-"+version, attr.Flag, stage0Concat(t,
attr.NonStage0,
finalExtra...,
), nil, attr.Env, scriptEarly+configure+attr.ScriptConfigured+`
make "-j$(nproc)"`+strings.Join(makeTargets, " ")+`
`+scriptInstall+attr.Script, slices.Concat(attr.Paths, []pkg.ExecPath{
pkg.Path(AbsUsrSrc.Append(
name+attr.SourceSuffix,
), attr.Writable, source),
})...)
}