internal/rosa/make: configurable configure and install
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

This makes the helper useful for non-autotools build systems.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-02-11 23:51:10 +09:00
parent 59ff6db7ec
commit 1791b604b5
6 changed files with 161 additions and 133 deletions

View File

@@ -51,6 +51,8 @@ type MakeAttr struct {
// 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.
@@ -61,10 +63,14 @@ type MakeAttr struct {
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
}
@@ -87,34 +93,39 @@ func (t Toolchain) NewViaMake(
build = attr.Build
}
var configureFlags string
if len(attr.Configure) > 0 {
const sep = " \\\n\t"
configureFlags += 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,
)
}
var configure string
if !attr.SkipConfigure {
configure += `
/usr/src/` + name + `/configure \
--prefix=/system`
var buildFlag string
if attr.Build != `""` {
buildFlag = ` \
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))
@@ -148,15 +159,20 @@ func (t Toolchain) NewViaMake(
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+`
/usr/src/`+name+`/configure \
--prefix=/system`+buildFlag+configureFlags+attr.ScriptConfigured+`
), nil, attr.Env, scriptEarly+configure+attr.ScriptConfigured+`
make "-j$(nproc)"`+strings.Join(makeTargets, " ")+`
make DESTDIR=/work install
`+attr.Script, pkg.Path(AbsUsrSrc.Append(
name+attr.SourceSuffix,
), attr.Writable, source))
`+scriptInstall+attr.Script, slices.Concat(attr.Paths, []pkg.ExecPath{
pkg.Path(AbsUsrSrc.Append(
name+attr.SourceSuffix,
), attr.Writable, source),
})...)
}