Skip to content

Commit

Permalink
kernels: add a extra_make_args parameter
Browse files Browse the repository at this point in the history
This can be used for adding extra arguments to make, as it is used to
build kernels.

For example:
```
{
    "name": "4.19",
    "url": "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git?depth=1#linux-4.19.y"
    "extra_make_args": [
	    "V=1",
	    "HOSTCC=gcc-10",
	    "CC=gcc-10"
    ]
}
```

Signed-off-by: Kornilios Kourtis <[email protected]>
  • Loading branch information
kkourt committed Jan 10, 2024
1 parent 4c4ce91 commit 06c67d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pkg/kernels/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type KernelConf struct {
URL string `json:"url"`
// config options
Opts []ConfigOption `json:"opts,omitempty"`
// Extra make args
ExtraMakeArgs []string `json:"extra_make_args,omitempty"`
}

type Conf struct {
Expand Down
21 changes: 17 additions & 4 deletions pkg/kernels/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ func kcfonfigValidate(opts []ConfigOption) error {
return ret
}

func runAndLogMake(
ctx context.Context,
log *logrus.Logger,
kc *KernelConf,
makeArgs ...string,
) error {
if len(kc.ExtraMakeArgs) > 0 {
makeArgs = append(makeArgs, kc.ExtraMakeArgs...)
}
return logcmd.RunAndLogCommandContext(ctx, log, MakeBinary, makeArgs...)
}

func (kd *KernelsDir) configureKernel(ctx context.Context, log *logrus.Logger, kc *KernelConf) error {
srcDir := filepath.Join(kd.Dir, kc.Name)

Expand All @@ -144,7 +156,7 @@ func (kd *KernelsDir) configureKernel(ctx context.Context, log *logrus.Logger, k

configOptions := kd.Conf.getOptions(kc)

if err := logcmd.RunAndLogCommandContext(ctx, log, MakeBinary, "defconfig", "prepare"); err != nil {
if err := runAndLogMake(ctx, log, kc, "defconfig", "prepare"); err != nil {
return err
}

Expand All @@ -170,7 +182,7 @@ func (kd *KernelsDir) configureKernel(ctx context.Context, log *logrus.Logger, k
}

// run make olddefconfig to clean up the config file, and ensure that everything is in order
if err := logcmd.RunAndLogCommandContext(ctx, log, MakeBinary, "olddefconfig"); err != nil {
if err := runAndLogMake(ctx, log, kc, "olddefconfig"); err != nil {
return err
}

Expand Down Expand Up @@ -203,11 +215,12 @@ func (kd *KernelsDir) buildKernel(ctx context.Context, log *logrus.Logger, kc *K
}

ncpus := fmt.Sprintf("%d", runtime.NumCPU())
if err := logcmd.RunAndLogCommandContext(ctx, log, MakeBinary, "-C", srcDir, "-j", ncpus, "bzImage", "modules"); err != nil {
ncpus = "1"
if err := runAndLogMake(ctx, log, kc, "-C", srcDir, "-j", ncpus, "bzImage", "modules"); err != nil {
return fmt.Errorf("buiding bzImage && modules failed: %w", err)
}

if err := logcmd.RunAndLogCommandContext(ctx, log, MakeBinary, "-C", srcDir, "tar-pkg"); err != nil {
if err := runAndLogMake(ctx, log, kc, "-C", srcDir, "tar-pkg"); err != nil {
return fmt.Errorf("build dir failed: %w", err)
}

Expand Down

0 comments on commit 06c67d1

Please sign in to comment.