Skip to content

Commit

Permalink
chore(pkg/driverbuiler): avoid overriding CC at build time.
Browse files Browse the repository at this point in the history
Instead, set CMAKE_C_COMPILER variable at cmake configure step.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Mar 7, 2024
1 parent 0753b39 commit 8db4a3c
Show file tree
Hide file tree
Showing 19 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pkg/driverbuilder/builder/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
-DGIT_COMMIT=%s \
-DDRIVER_DEVICE_NAME=%s \
-DPROBE_DEVICE_NAME=%s \
-DCMAKE_C_COMPILER=%s \
.. && \
sed -i s/'DRIVER_COMMIT ""'/'DRIVER_COMMIT "%s"'/g driver/src/driver_config.h`
)
Expand Down Expand Up @@ -76,7 +77,6 @@ type commonTemplateData struct {
ModuleFullPath string
BuildModule bool
BuildProbe bool
GCCVersion string
CmakeCmd string
}

Expand Down Expand Up @@ -311,7 +311,6 @@ func (c Config) toTemplateData(b Builder, kr kernelrelease.KernelRelease) common
ModuleFullPath: c.ToDriverFullPath(),
BuildModule: len(c.ModuleFilePath) > 0,
BuildProbe: len(c.ProbeFilePath) > 0,
GCCVersion: c.GCCVersion,
CmakeCmd: fmt.Sprintf(cmakeCmdFmt,
c.DriverName,
c.DriverName,
Expand All @@ -320,6 +319,7 @@ func (c Config) toTemplateData(b Builder, kr kernelrelease.KernelRelease) common
c.DriverVersion,
c.DeviceName,
c.DeviceName,
"/usr/bin/gcc-"+c.GCCVersion,
c.DriverVersion),
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/driverbuilder/builder/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type localTemplateData struct {
DownloadSrc bool
DriverVersion string
KernelRelease string
GCCPath string
}

func (l *LocalBuilder) TemplateData(c Config, kr kernelrelease.KernelRelease, _ []string) interface{} {
Expand All @@ -54,7 +55,6 @@ func (l *LocalBuilder) TemplateData(c Config, kr kernelrelease.KernelRelease, _
ModuleFullPath: l.GetModuleFullPath(c, kr),
BuildModule: len(c.ModuleFilePath) > 0,
BuildProbe: len(c.ProbeFilePath) > 0,
GCCVersion: l.GccPath,
CmakeCmd: fmt.Sprintf(cmakeCmdFmt,
c.DriverName,
c.DriverName,
Expand All @@ -63,12 +63,14 @@ func (l *LocalBuilder) TemplateData(c Config, kr kernelrelease.KernelRelease, _
c.DriverVersion,
c.DeviceName,
c.DeviceName,
l.GccPath,
c.DriverVersion),
},
UseDKMS: l.UseDKMS,
DownloadSrc: len(l.SrcDir) == 0, // if no srcdir is provided, download src!
DriverVersion: c.DriverVersion,
KernelRelease: c.KernelRelease,
GCCPath: l.GccPath,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/alinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver
make KERNELDIR=/tmp/kernel driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/almalinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver
make KERNELDIR=/tmp/kernel driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/amazonlinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel LD=/usr/bin/ld.bfd CROSS_COMPILE="" driver
make KERNELDIR=/tmp/kernel LD=/usr/bin/ld.bfd CROSS_COMPILE="" driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/archlinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver
make KERNELDIR=/tmp/kernel driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/centos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver
make KERNELDIR=/tmp/kernel driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=$sourcedir driver
make KERNELDIR=$sourcedir driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/fedora.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver
make KERNELDIR=/tmp/kernel driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/flatcar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver
make KERNELDIR=/tmp/kernel driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
6 changes: 3 additions & 3 deletions pkg/driverbuilder/builder/templates/local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ mkdir -p build && cd build
echo "* Building kmod with DKMS"
# Build the module using DKMS
echo "#!/usr/bin/env bash" > "/tmp/falco-dkms-make"
echo "make CC={{ .GCCVersion }} \$@" >> "/tmp/falco-dkms-make"
echo "make CC={{ .GCCPath }} \$@" >> "/tmp/falco-dkms-make"
chmod +x "/tmp/falco-dkms-make"
dkms install --directive="MAKE='/tmp/falco-dkms-make'" -m "{{ .ModuleDriverName }}" -v "{{ .DriverVersion }}" -k "{{ .KernelRelease }}"
rm -Rf "/tmp/falco-dkms-make"
{{ else }}
echo "* Building kmod"
{{ if .DownloadSrc }}
# Build the module - cmake configured
make CC={{ .GCCVersion }} driver
make driver
{{ else }}
# Build the module - preconfigured sources
make CC={{ .GCCVersion }}
make CC={{ .GCCPath }}
{{ end }}
strip -g {{ .ModuleFullPath }}
# Print results
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/opensuse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=$sourcedir driver
make KERNELDIR=$sourcedir driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/oracle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver
make KERNELDIR=/tmp/kernel driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/photonos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver
make KERNELDIR=/tmp/kernel driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/redhat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver
make KERNELDIR=/tmp/kernel driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/rocky.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver
make KERNELDIR=/tmp/kernel driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/sles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=$sourcedir driver
make KERNELDIR=$sourcedir driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=$sourcedir driver
make KERNELDIR=$sourcedir driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/vanilla.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mkdir -p build && cd build

{{ if .BuildModule }}
# Build the module
make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver
make KERNELDIR=/tmp/kernel driver
strip -g {{ .ModuleFullPath }}
# Print results
modinfo {{ .ModuleFullPath }}
Expand Down

0 comments on commit 8db4a3c

Please sign in to comment.