diff mbox series

package/zfs: Fix cross-platform-compilations

Message ID 20210822200519.1757151-1-salvador.joseluis@gmail.com
State Changes Requested
Headers show
Series package/zfs: Fix cross-platform-compilations | expand

Commit Message

José Luis Salvador Rufo Aug. 22, 2021, 8:05 p.m. UTC
This patch fixes the `make` executed from the `kernel.m4` in
cross-platform-compilations environments:
https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588

Signed-off-by: José Luis Salvador Rufo <salvador.joseluis@gmail.com>
---
Hello all.

@Romain Naour, this patch will fix the buildroot gitlab CI.

@Philippe Serbruyns, this patch will fix your issue with your rpi4.

 package/zfs/zfs.mk | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Romain Naour Aug. 22, 2021, 8:27 p.m. UTC | #1
Hello José Luis,

Le 22/08/2021 à 22:05, José Luis Salvador Rufo a écrit :
> This patch fixes the `make` executed from the `kernel.m4` in
> cross-platform-compilations environments:
> https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588
> 
> Signed-off-by: José Luis Salvador Rufo <salvador.joseluis@gmail.com>
> ---
> Hello all.
> 
> @Romain Naour, this patch will fix the buildroot gitlab CI.

Indeed it fix the issue!

Tested-by: Romain Naour <romain.naour@gmail.com>

> 
> @Philippe Serbruyns, this patch will fix your issue with your rpi4.
> 
>  package/zfs/zfs.mk | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/package/zfs/zfs.mk b/package/zfs/zfs.mk
> index 3b1afb419a..24064cba82 100644
> --- a/package/zfs/zfs.mk
> +++ b/package/zfs/zfs.mk
> @@ -13,6 +13,19 @@ ZFS_CPE_ID_PRODUCT = openzfs
>  
>  ZFS_AUTORECONF = YES
>  
> +# cross compile environment for linux kernel module
> +ZFS_MAKE_ENV = \
> +	HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
> +	ARCH=$(KERNEL_ARCH) \
> +	CROSS_COMPILE="$(TARGET_CROSS)" \
> +	DEPMOD=$(HOST_DIR)/sbin/depmod

You can replace all 4 lines with $(LINUX_MAKE_FLAGS) here instead.

> +# `./configure` will execute a `make modules` test case
> +ZFS_CONF_ENV = \
> +	HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
> +	ARCH=$(KERNEL_ARCH) \
> +	CROSS_COMPILE="$(TARGET_CROSS)" \
> +	DEPMOD=$(HOST_DIR)/sbin/depmod

Same here.



> +
>  ZFS_DEPENDENCIES = libaio openssl udev util-linux zlib
>  
>  # sysvinit installs only a commented-out modules-load.d/ config file
>
José Luis Salvador Rufo Aug. 22, 2021, 8:38 p.m. UTC | #2
Hello Romain,

El dom, 22 ago 2021 a las 22:27, Romain Naour (<romain.naour@gmail.com>)
escribió:

> Hello José Luis,
>
> Le 22/08/2021 à 22:05, José Luis Salvador Rufo a écrit :
> > This patch fixes the `make` executed from the `kernel.m4` in
> > cross-platform-compilations environments:
> > https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588
> >
> > Signed-off-by: José Luis Salvador Rufo <salvador.joseluis@gmail.com>
> > ---
> > Hello all.
> >
> > @Romain Naour, this patch will fix the buildroot gitlab CI.
>
> Indeed it fix the issue!
>
> Tested-by: Romain Naour <romain.naour@gmail.com>
>
> >
> > @Philippe Serbruyns, this patch will fix your issue with your rpi4.
> >
> >  package/zfs/zfs.mk | 13 +++++++++++++
> >  1 file changed, 13 insertions(+)
> >
> > diff --git a/package/zfs/zfs.mk b/package/zfs/zfs.mk
> > index 3b1afb419a..24064cba82 100644
> > --- a/package/zfs/zfs.mk
> > +++ b/package/zfs/zfs.mk
> > @@ -13,6 +13,19 @@ ZFS_CPE_ID_PRODUCT = openzfs
> >
> >  ZFS_AUTORECONF = YES
> >
> > +# cross compile environment for linux kernel module
> > +ZFS_MAKE_ENV = \
> > +     HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
> > +     ARCH=$(KERNEL_ARCH) \
> > +     CROSS_COMPILE="$(TARGET_CROSS)" \
> > +     DEPMOD=$(HOST_DIR)/sbin/depmod
>
> You can replace all 4 lines with $(LINUX_MAKE_FLAGS) here instead.
>
Sorry, you can not. LINUX_MAKE_FLAGS includes INSTALL_MOD_PATH, and must be
empty for kernel modules. If we use LINUX_MAKE_FLAGS, the module output
will be TARGET_DIR/INSTALL_MOD_PATH, as you can see in pkg-generic.mk at
line 77. I already lost ~1-2h because of this :-(.

The alternative to using $(LINUX_MAKE_FLAGS) is empty the INSTALL_MOD_PATH
as follows:
ZFS_MAKE_ENV = \
     $(LINUX_MAKE_FLAGS) \
     INSTALL_MOD_PATH=

What do you prefer?

>
> > +# `./configure` will execute a `make modules` test case
> > +ZFS_CONF_ENV = \
> > +     HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
> > +     ARCH=$(KERNEL_ARCH) \
> > +     CROSS_COMPILE="$(TARGET_CROSS)" \
> > +     DEPMOD=$(HOST_DIR)/sbin/depmod
>
> Same here.
>
>
>
> > +
> >  ZFS_DEPENDENCIES = libaio openssl udev util-linux zlib
> >
> >  # sysvinit installs only a commented-out modules-load.d/ config file
> >
>
>
Romain Naour Aug. 22, 2021, 8:52 p.m. UTC | #3
Hello José Luis,

Le 22/08/2021 à 22:38, José Luis Salvador Rufo a écrit :
> Hello Romain,
> 
> El dom, 22 ago 2021 a las 22:27, Romain Naour (<romain.naour@gmail.com
> <mailto:romain.naour@gmail.com>>) escribió:
> 
>     Hello José Luis,
> 
>     Le 22/08/2021 à 22:05, José Luis Salvador Rufo a écrit :
>     > This patch fixes the `make` executed from the `kernel.m4` in
>     > cross-platform-compilations environments:
>     > https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588
>     <https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588>
>     >
>     > Signed-off-by: José Luis Salvador Rufo <salvador.joseluis@gmail.com
>     <mailto:salvador.joseluis@gmail.com>>
>     > ---
>     > Hello all.
>     >
>     > @Romain Naour, this patch will fix the buildroot gitlab CI.
> 
>     Indeed it fix the issue!
> 
>     Tested-by: Romain Naour <romain.naour@gmail.com <mailto:romain.naour@gmail.com>>
> 
>     >
>     > @Philippe Serbruyns, this patch will fix your issue with your rpi4.
>     >
>     >  package/zfs/zfs.mk <http://zfs.mk> | 13 +++++++++++++
>     >  1 file changed, 13 insertions(+)
>     >
>     > diff --git a/package/zfs/zfs.mk <http://zfs.mk> b/package/zfs/zfs.mk
>     <http://zfs.mk>
>     > index 3b1afb419a..24064cba82 100644
>     > --- a/package/zfs/zfs.mk <http://zfs.mk>
>     > +++ b/package/zfs/zfs.mk <http://zfs.mk>
>     > @@ -13,6 +13,19 @@ ZFS_CPE_ID_PRODUCT = openzfs
>     > 
>     >  ZFS_AUTORECONF = YES
>     > 
>     > +# cross compile environment for linux kernel module
>     > +ZFS_MAKE_ENV = \
>     > +     HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
>     > +     ARCH=$(KERNEL_ARCH) \
>     > +     CROSS_COMPILE="$(TARGET_CROSS)" \
>     > +     DEPMOD=$(HOST_DIR)/sbin/depmod
> 
>     You can replace all 4 lines with $(LINUX_MAKE_FLAGS) here instead.
> 
> Sorry, you can not. LINUX_MAKE_FLAGS includes INSTALL_MOD_PATH, and must be
> empty for kernel modules. If we use LINUX_MAKE_FLAGS, the module output will be
> TARGET_DIR/INSTALL_MOD_PATH, as you can see in pkg-generic.mk
> <http://pkg-generic.mk> at line 77. I already lost ~1-2h because of this :-(.

This check allow to detect issues on a build system.
Other packages building an out of tree kernel module is able to use
LINUX_MAKE_FLAGS (except linux-fusion).

>  
> The alternative to using $(LINUX_MAKE_FLAGS) is empty the INSTALL_MOD_PATH as
> follows:
> ZFS_MAKE_ENV = \
>      $(LINUX_MAKE_FLAGS) \
>      INSTALL_MOD_PATH=
> 
> What do you prefer?

If possible, a zfs patch.

Otherwise I would suggest to add a comment about the reason why LINUX_MAKE_FLAGS
can't be used.

Best regards,
Romain


> 
> 
>     > +# `./configure` will execute a `make modules` test case
>     > +ZFS_CONF_ENV = \
>     > +     HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
>     > +     ARCH=$(KERNEL_ARCH) \
>     > +     CROSS_COMPILE="$(TARGET_CROSS)" \
>     > +     DEPMOD=$(HOST_DIR)/sbin/depmod
> 
>     Same here.
> 
> 
> 
>     > +
>     >  ZFS_DEPENDENCIES = libaio openssl udev util-linux zlib
>     > 
>     >  # sysvinit installs only a commented-out modules-load.d/ config file
>     >
>
José Luis Salvador Rufo Aug. 22, 2021, 9:27 p.m. UTC | #4
Hello Romain Naour,

El dom, 22 ago 2021 a las 22:52, Romain Naour (<romain.naour@gmail.com>)
escribió:

> Hello José Luis,
>
> Le 22/08/2021 à 22:38, José Luis Salvador Rufo a écrit :
> > Hello Romain,
> >
> > El dom, 22 ago 2021 a las 22:27, Romain Naour (<romain.naour@gmail.com
> > <mailto:romain.naour@gmail.com>>) escribió:
> >
> >     Hello José Luis,
> >
> >     Le 22/08/2021 à 22:05, José Luis Salvador Rufo a écrit :
> >     > This patch fixes the `make` executed from the `kernel.m4` in
> >     > cross-platform-compilations environments:
> >     >
> https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588
> >     <https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588
> >
> >     >
> >     > Signed-off-by: José Luis Salvador Rufo <
> salvador.joseluis@gmail.com
> >     <mailto:salvador.joseluis@gmail.com>>
> >     > ---
> >     > Hello all.
> >     >
> >     > @Romain Naour, this patch will fix the buildroot gitlab CI.
> >
> >     Indeed it fix the issue!
> >
> >     Tested-by: Romain Naour <romain.naour@gmail.com <mailto:
> romain.naour@gmail.com>>
> >
> >     >
> >     > @Philippe Serbruyns, this patch will fix your issue with your rpi4.
> >     >
> >     >  package/zfs/zfs.mk <http://zfs.mk> | 13 +++++++++++++
> >     >  1 file changed, 13 insertions(+)
> >     >
> >     > diff --git a/package/zfs/zfs.mk <http://zfs.mk> b/package/zfs/
> zfs.mk
> >     <http://zfs.mk>
> >     > index 3b1afb419a..24064cba82 100644
> >     > --- a/package/zfs/zfs.mk <http://zfs.mk>
> >     > +++ b/package/zfs/zfs.mk <http://zfs.mk>
> >     > @@ -13,6 +13,19 @@ ZFS_CPE_ID_PRODUCT = openzfs
> >     >
> >     >  ZFS_AUTORECONF = YES
> >     >
> >     > +# cross compile environment for linux kernel module
> >     > +ZFS_MAKE_ENV = \
> >     > +     HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
> >     > +     ARCH=$(KERNEL_ARCH) \
> >     > +     CROSS_COMPILE="$(TARGET_CROSS)" \
> >     > +     DEPMOD=$(HOST_DIR)/sbin/depmod
> >
> >     You can replace all 4 lines with $(LINUX_MAKE_FLAGS) here instead.
> >
> > Sorry, you can not. LINUX_MAKE_FLAGS includes INSTALL_MOD_PATH, and must
> be
> > empty for kernel modules. If we use LINUX_MAKE_FLAGS, the module output
> will be
> > TARGET_DIR/INSTALL_MOD_PATH, as you can see in pkg-generic.mk
> > <http://pkg-generic.mk> at line 77. I already lost ~1-2h because of
> this :-(.
>
> This check allow to detect issues on a build system.
> Other packages building an out of tree kernel module is able to use
> LINUX_MAKE_FLAGS (except linux-fusion).
>
> >
> > The alternative to using $(LINUX_MAKE_FLAGS) is empty
> the INSTALL_MOD_PATH as
> > follows:
> > ZFS_MAKE_ENV = \
> >      $(LINUX_MAKE_FLAGS) \
> >      INSTALL_MOD_PATH=
> >
> > What do you prefer?
>
> If possible, a zfs patch.
>
Here is the "problem":

https://github.com/openzfs/zfs/blob/zfs-2.0.5/module/Makefile.in#L79
> INSTALL_MOD_PATH=$(DESTDIR)$(INSTALL_MOD_PATH)

and

https://git.buildroot.net/buildroot/tree/package/pkg-generic.mk?h=2021.08-rc2#n77
> $(if $(filter end,$(1)),$(call
step_check_build_dir_one,$(3),$(TARGET_DIR)/$(O))))

Buildroot already does that, so when `make modules_install` is executed,
the output modules directory will be TARGET_DIR/TARGET_DIR/INSTALL_MOD_PATH.

I have no idea who is the one that must change its behavior. :-(
Any suggestions on how to proceed?

Maybe I can unexport DESTDIR before `make modules_install`...

Attached alternative patch with LINUX_MAKE_FLAGS and empty INSTALL_MOD_PATH.

>
> Otherwise I would suggest to add a comment about the reason why
> LINUX_MAKE_FLAGS
> can't be used.
>
> Best regards,
> Romain
>
>
> >
> >
> >     > +# `./configure` will execute a `make modules` test case
> >     > +ZFS_CONF_ENV = \
> >     > +     HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
> >     > +     ARCH=$(KERNEL_ARCH) \
> >     > +     CROSS_COMPILE="$(TARGET_CROSS)" \
> >     > +     DEPMOD=$(HOST_DIR)/sbin/depmod
> >
> >     Same here.
> >
> >
> >
> >     > +
> >     >  ZFS_DEPENDENCIES = libaio openssl udev util-linux zlib
> >     >
> >     >  # sysvinit installs only a commented-out modules-load.d/ config
> file
> >     >
> >
>
>
Greetings!
Romain Naour Aug. 22, 2021, 9:43 p.m. UTC | #5
Le 22/08/2021 à 23:27, José Luis Salvador Rufo a écrit :
> Hello Romain Naour,
> 
> El dom, 22 ago 2021 a las 22:52, Romain Naour (<romain.naour@gmail.com
> <mailto:romain.naour@gmail.com>>) escribió:
> 
>     Hello José Luis,
> 
>     Le 22/08/2021 à 22:38, José Luis Salvador Rufo a écrit :
>     > Hello Romain,
>     >
>     > El dom, 22 ago 2021 a las 22:27, Romain Naour (<romain.naour@gmail.com
>     <mailto:romain.naour@gmail.com>
>     > <mailto:romain.naour@gmail.com <mailto:romain.naour@gmail.com>>>) escribió:
>     >
>     >     Hello José Luis,
>     >
>     >     Le 22/08/2021 à 22:05, José Luis Salvador Rufo a écrit :
>     >     > This patch fixes the `make` executed from the `kernel.m4` in
>     >     > cross-platform-compilations environments:
>     >     > https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588
>     <https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588>
>     >     <https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588
>     <https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588>>
>     >     >
>     >     > Signed-off-by: José Luis Salvador Rufo <salvador.joseluis@gmail.com
>     <mailto:salvador.joseluis@gmail.com>
>     >     <mailto:salvador.joseluis@gmail.com <mailto:salvador.joseluis@gmail.com>>>
>     >     > ---
>     >     > Hello all.
>     >     >
>     >     > @Romain Naour, this patch will fix the buildroot gitlab CI.
>     >
>     >     Indeed it fix the issue!
>     >
>     >     Tested-by: Romain Naour <romain.naour@gmail.com
>     <mailto:romain.naour@gmail.com> <mailto:romain.naour@gmail.com
>     <mailto:romain.naour@gmail.com>>>
>     >
>     >     >
>     >     > @Philippe Serbruyns, this patch will fix your issue with your rpi4.
>     >     >
>     >     >  package/zfs/zfs.mk <http://zfs.mk> <http://zfs.mk <http://zfs.mk>>
>     | 13 +++++++++++++
>     >     >  1 file changed, 13 insertions(+)
>     >     >
>     >     > diff --git a/package/zfs/zfs.mk <http://zfs.mk> <http://zfs.mk
>     <http://zfs.mk>> b/package/zfs/zfs.mk <http://zfs.mk>
>     >     <http://zfs.mk <http://zfs.mk>>
>     >     > index 3b1afb419a..24064cba82 100644
>     >     > --- a/package/zfs/zfs.mk <http://zfs.mk> <http://zfs.mk <http://zfs.mk>>
>     >     > +++ b/package/zfs/zfs.mk <http://zfs.mk> <http://zfs.mk <http://zfs.mk>>
>     >     > @@ -13,6 +13,19 @@ ZFS_CPE_ID_PRODUCT = openzfs
>     >     > 
>     >     >  ZFS_AUTORECONF = YES
>     >     > 
>     >     > +# cross compile environment for linux kernel module
>     >     > +ZFS_MAKE_ENV = \
>     >     > +     HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
>     >     > +     ARCH=$(KERNEL_ARCH) \
>     >     > +     CROSS_COMPILE="$(TARGET_CROSS)" \
>     >     > +     DEPMOD=$(HOST_DIR)/sbin/depmod
>     >
>     >     You can replace all 4 lines with $(LINUX_MAKE_FLAGS) here instead.
>     >
>     > Sorry, you can not. LINUX_MAKE_FLAGS includes INSTALL_MOD_PATH, and must be
>     > empty for kernel modules. If we use LINUX_MAKE_FLAGS, the module output
>     will be
>     > TARGET_DIR/INSTALL_MOD_PATH, as you can see in pkg-generic.mk
>     <http://pkg-generic.mk>
>     > <http://pkg-generic.mk <http://pkg-generic.mk>> at line 77. I already lost
>     ~1-2h because of this :-(.
> 
>     This check allow to detect issues on a build system.
>     Other packages building an out of tree kernel module is able to use
>     LINUX_MAKE_FLAGS (except linux-fusion).
> 
>     >  
>     > The alternative to using $(LINUX_MAKE_FLAGS) is empty the INSTALL_MOD_PATH as
>     > follows:
>     > ZFS_MAKE_ENV = \
>     >      $(LINUX_MAKE_FLAGS) \
>     >      INSTALL_MOD_PATH=
>     >
>     > What do you prefer?
> 
>     If possible, a zfs patch.
> 
> Here is the "problem":
> 
> https://github.com/openzfs/zfs/blob/zfs-2.0.5/module/Makefile.in#L79
> <https://github.com/openzfs/zfs/blob/zfs-2.0.5/module/Makefile.in#L79>
>> INSTALL_MOD_PATH=$(DESTDIR)$(INSTALL_MOD_PATH)

This is the problem. I guess you have to remove DESTDIR when used with
INSTALL_MOD_PATH.

> 
> and
> 
> https://git.buildroot.net/buildroot/tree/package/pkg-generic.mk?h=2021.08-rc2#n77 <https://git.buildroot.net/buildroot/tree/package/pkg-generic.mk?h=2021.08-rc2#n77>
>> $(if $(filter end,$(1)),$(call step_check_build_dir_one,$(3),$(TARGET_DIR)/$(O))))
> 
> Buildroot already does that, so when `make modules_install` is executed, the
> output modules directory will be TARGET_DIR/TARGET_DIR/INSTALL_MOD_PATH.
> 
> I have no idea who is the one that must change its behavior. :-(
> Any suggestions on how to proceed?
> 
> Maybe I can unexport DESTDIR before `make modules_install`...

Yes, DESTDIR is sometime miss used (see buildroot gitlog for example).

It's a bug if DESTDIR and INSTALL_MOD_PATH are used together:

https://www.gnu.org/prep/standards/html_node/DESTDIR.html

https://www.kernel.org/doc/Documentation/kbuild/modules.txt (INSTALL_MOD_PATH)

Best regards,
Romain


> 
> Attached alternative patch with LINUX_MAKE_FLAGS and empty INSTALL_MOD_PATH.
> 
> 
>     Otherwise I would suggest to add a comment about the reason why LINUX_MAKE_FLAGS
>     can't be used.
> 
>     Best regards,
>     Romain
> 
> 
>     >
>     >
>     >     > +# `./configure` will execute a `make modules` test case
>     >     > +ZFS_CONF_ENV = \
>     >     > +     HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
>     >     > +     ARCH=$(KERNEL_ARCH) \
>     >     > +     CROSS_COMPILE="$(TARGET_CROSS)" \
>     >     > +     DEPMOD=$(HOST_DIR)/sbin/depmod
>     >
>     >     Same here.
>     >
>     >
>     >
>     >     > +
>     >     >  ZFS_DEPENDENCIES = libaio openssl udev util-linux zlib
>     >     > 
>     >     >  # sysvinit installs only a commented-out modules-load.d/ config file
>     >     >
>     >
> 
> 
> Greetings!
José Luis Salvador Rufo Aug. 22, 2021, 10:54 p.m. UTC | #6
Hello Romain Naour,

El dom, 22 ago 2021 a las 23:43, Romain Naour (<romain.naour@gmail.com>)
escribió:

> Le 22/08/2021 à 23:27, José Luis Salvador Rufo a écrit :
> > Hello Romain Naour,
> >
> > El dom, 22 ago 2021 a las 22:52, Romain Naour (<romain.naour@gmail.com
> > <mailto:romain.naour@gmail.com>>) escribió:
> >
> >     Hello José Luis,
> >
> >     Le 22/08/2021 à 22:38, José Luis Salvador Rufo a écrit :
> >     > Hello Romain,
> >     >
> >     > El dom, 22 ago 2021 a las 22:27, Romain Naour (<
> romain.naour@gmail.com
> >     <mailto:romain.naour@gmail.com>
> >     > <mailto:romain.naour@gmail.com <mailto:romain.naour@gmail.com>>>)
> escribió:
> >     >
> >     >     Hello José Luis,
> >     >
> >     >     Le 22/08/2021 à 22:05, José Luis Salvador Rufo a écrit :
> >     >     > This patch fixes the `make` executed from the `kernel.m4` in
> >     >     > cross-platform-compilations environments:
> >     >     >
> https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588
> >     <https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588
> >
> >     >     <
> https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588
> >     <https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588
> >>
> >     >     >
> >     >     > Signed-off-by: José Luis Salvador Rufo <
> salvador.joseluis@gmail.com
> >     <mailto:salvador.joseluis@gmail.com>
> >     >     <mailto:salvador.joseluis@gmail.com <mailto:
> salvador.joseluis@gmail.com>>>
> >     >     > ---
> >     >     > Hello all.
> >     >     >
> >     >     > @Romain Naour, this patch will fix the buildroot gitlab CI.
> >     >
> >     >     Indeed it fix the issue!
> >     >
> >     >     Tested-by: Romain Naour <romain.naour@gmail.com
> >     <mailto:romain.naour@gmail.com> <mailto:romain.naour@gmail.com
> >     <mailto:romain.naour@gmail.com>>>
> >     >
> >     >     >
> >     >     > @Philippe Serbruyns, this patch will fix your issue with
> your rpi4.
> >     >     >
> >     >     >  package/zfs/zfs.mk <http://zfs.mk> <http://zfs.mk <
> http://zfs.mk>>
> >     | 13 +++++++++++++
> >     >     >  1 file changed, 13 insertions(+)
> >     >     >
> >     >     > diff --git a/package/zfs/zfs.mk <http://zfs.mk> <
> http://zfs.mk
> >     <http://zfs.mk>> b/package/zfs/zfs.mk <http://zfs.mk>
> >     >     <http://zfs.mk <http://zfs.mk>>
> >     >     > index 3b1afb419a..24064cba82 100644
> >     >     > --- a/package/zfs/zfs.mk <http://zfs.mk> <http://zfs.mk <
> http://zfs.mk>>
> >     >     > +++ b/package/zfs/zfs.mk <http://zfs.mk> <http://zfs.mk <
> http://zfs.mk>>
> >     >     > @@ -13,6 +13,19 @@ ZFS_CPE_ID_PRODUCT = openzfs
> >     >     >
> >     >     >  ZFS_AUTORECONF = YES
> >     >     >
> >     >     > +# cross compile environment for linux kernel module
> >     >     > +ZFS_MAKE_ENV = \
> >     >     > +     HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
> >     >     > +     ARCH=$(KERNEL_ARCH) \
> >     >     > +     CROSS_COMPILE="$(TARGET_CROSS)" \
> >     >     > +     DEPMOD=$(HOST_DIR)/sbin/depmod
> >     >
> >     >     You can replace all 4 lines with $(LINUX_MAKE_FLAGS) here
> instead.
> >     >
> >     > Sorry, you can not. LINUX_MAKE_FLAGS includes INSTALL_MOD_PATH,
> and must be
> >     > empty for kernel modules. If we use LINUX_MAKE_FLAGS, the module
> output
> >     will be
> >     > TARGET_DIR/INSTALL_MOD_PATH, as you can see in pkg-generic.mk
> >     <http://pkg-generic.mk>
> >     > <http://pkg-generic.mk <http://pkg-generic.mk>> at line 77. I
> already lost
> >     ~1-2h because of this :-(.
> >
> >     This check allow to detect issues on a build system.
> >     Other packages building an out of tree kernel module is able to use
> >     LINUX_MAKE_FLAGS (except linux-fusion).
> >
> >     >
> >     > The alternative to using $(LINUX_MAKE_FLAGS) is empty
> the INSTALL_MOD_PATH as
> >     > follows:
> >     > ZFS_MAKE_ENV = \
> >     >      $(LINUX_MAKE_FLAGS) \
> >     >      INSTALL_MOD_PATH=
> >     >
> >     > What do you prefer?
> >
> >     If possible, a zfs patch.
> >
> > Here is the "problem":
> >
> > https://github.com/openzfs/zfs/blob/zfs-2.0.5/module/Makefile.in#L79
> > <https://github.com/openzfs/zfs/blob/zfs-2.0.5/module/Makefile.in#L79>
> >> INSTALL_MOD_PATH=$(DESTDIR)$(INSTALL_MOD_PATH)
>
> This is the problem. I guess you have to remove DESTDIR when used with
> INSTALL_MOD_PATH.
>
> I found that DESTDIR is already empty. Sorry, my bad.

>
> > and
> >
> >
> https://git.buildroot.net/buildroot/tree/package/pkg-generic.mk?h=2021.08-rc2#n77
> <
> https://git.buildroot.net/buildroot/tree/package/pkg-generic.mk?h=2021.08-rc2#n77
> >
> >> $(if $(filter end,$(1)),$(call
> step_check_build_dir_one,$(3),$(TARGET_DIR)/$(O))))
>

So I made:
```
diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
index 97ee204b80..c406b32acf 100644
--- a/package/pkg-generic.mk
+++ b/package/pkg-generic.mk
@@ -71,6 +71,7 @@ define step_check_build_dir_one
 endef

 define step_check_build_dir
+       echo -e "TARGET_DIR $(TARGET_DIR)\nO $(O)\n" > /tmp/output
        $(if $(filter install-staging,$(2)),\
                $(if $(filter end,$(1)),$(call
step_check_build_dir_one,$(3),$(STAGING_DIR)/$(O))))
        $(if $(filter install-target,$(2)),\
```

And here is the output:
```
TARGET_DIR /home/jlsalvador/src/buildroot-rpi4-tmp/per-package/zfs/target
O /home/jlsalvador/src/buildroot-rpi4-tmp
```

So the installation path will be
`/home/jlsalvador/src/buildroot-rpi4-tmp/per-package/zfs/target//home/jlsalvador/src/buildroot-rpi4-tmp`

`/home/jlsalvador/src/buildroot-rpi4-tmp` is an out-of-tree buildroot
directory that was created with the following command:

```
mkdir ~/src/buildroot-rpi4-tmp
cd ~/src/buildroot-rpi4-tmp
make O=$(pwd) -C ../buildroot menuconfig
```

Maybe this is the problem? Is `$(TARGET_DIR)/$(O)` right?


> >
> > Buildroot already does that, so when `make modules_install` is executed,
> the
> > output modules directory will be TARGET_DIR/TARGET_DIR/INSTALL_MOD_PATH.
> >
> > I have no idea who is the one that must change its behavior. :-(
> > Any suggestions on how to proceed?
> >
> > Maybe I can unexport DESTDIR before `make modules_install`...
>
> Yes, DESTDIR is sometime miss used (see buildroot gitlog for example).
>
> It's a bug if DESTDIR and INSTALL_MOD_PATH are used together:
>
> https://www.gnu.org/prep/standards/html_node/DESTDIR.html
>
> https://www.kernel.org/doc/Documentation/kbuild/modules.txt
> (INSTALL_MOD_PATH)
>
> Best regards,
> Romain
>
>
> >
> > Attached alternative patch with LINUX_MAKE_FLAGS and empty
> INSTALL_MOD_PATH.
> >
> >
> >     Otherwise I would suggest to add a comment about the reason why
> LINUX_MAKE_FLAGS
> >     can't be used.
> >
> >     Best regards,
> >     Romain
> >
> >
> >     >
> >     >
> >     >     > +# `./configure` will execute a `make modules` test case
> >     >     > +ZFS_CONF_ENV = \
> >     >     > +     HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
> >     >     > +     ARCH=$(KERNEL_ARCH) \
> >     >     > +     CROSS_COMPILE="$(TARGET_CROSS)" \
> >     >     > +     DEPMOD=$(HOST_DIR)/sbin/depmod
> >     >
> >     >     Same here.
> >     >
> >     >
> >     >
> >     >     > +
> >     >     >  ZFS_DEPENDENCIES = libaio openssl udev util-linux zlib
> >     >     >
> >     >     >  # sysvinit installs only a commented-out modules-load.d/
> config file
> >     >     >
> >     >
> >
> >
> > Greetings!
>
>
Thomas Petazzoni Aug. 24, 2021, 9:53 p.m. UTC | #7
On Sun, 22 Aug 2021 22:05:19 +0200
José Luis Salvador Rufo <salvador.joseluis@gmail.com> wrote:

> This patch fixes the `make` executed from the `kernel.m4` in
> cross-platform-compilations environments:
> https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588
> 
> Signed-off-by: José Luis Salvador Rufo <salvador.joseluis@gmail.com>
> ---
> Hello all.

Thanks for your contribution. Based on the feedback from Romain, I have
marked this patch as "Changes Requested".

Best regards,

Thomas
José Luis Salvador Rufo Sept. 21, 2021, 7:58 a.m. UTC | #8
Hello Romain, all

I sent today a Pull Request to OpenZFS:
https://github.com/openzfs/zfs/pull/12577

Greetings.

El mar, 24 ago 2021 a las 23:53, Thomas Petazzoni (<
thomas.petazzoni@bootlin.com>) escribió:

> On Sun, 22 Aug 2021 22:05:19 +0200
> José Luis Salvador Rufo <salvador.joseluis@gmail.com> wrote:
>
> > This patch fixes the `make` executed from the `kernel.m4` in
> > cross-platform-compilations environments:
> > https://github.com/openzfs/zfs/blob/zfs-2.0.5/config/kernel.m4#L588
> >
> > Signed-off-by: José Luis Salvador Rufo <salvador.joseluis@gmail.com>
> > ---
> > Hello all.
>
> Thanks for your contribution. Based on the feedback from Romain, I have
> marked this patch as "Changes Requested".
>
> Best regards,
>
> Thomas
> --
> Thomas Petazzoni, CTO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
diff mbox series

Patch

diff --git a/package/zfs/zfs.mk b/package/zfs/zfs.mk
index 3b1afb419a..24064cba82 100644
--- a/package/zfs/zfs.mk
+++ b/package/zfs/zfs.mk
@@ -13,6 +13,19 @@  ZFS_CPE_ID_PRODUCT = openzfs
 
 ZFS_AUTORECONF = YES
 
+# cross compile environment for linux kernel module
+ZFS_MAKE_ENV = \
+	HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
+	ARCH=$(KERNEL_ARCH) \
+	CROSS_COMPILE="$(TARGET_CROSS)" \
+	DEPMOD=$(HOST_DIR)/sbin/depmod
+# `./configure` will execute a `make modules` test case
+ZFS_CONF_ENV = \
+	HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
+	ARCH=$(KERNEL_ARCH) \
+	CROSS_COMPILE="$(TARGET_CROSS)" \
+	DEPMOD=$(HOST_DIR)/sbin/depmod
+
 ZFS_DEPENDENCIES = libaio openssl udev util-linux zlib
 
 # sysvinit installs only a commented-out modules-load.d/ config file