linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Markus Mayer <mmayer@broadcom.com>
To: Masahiro Yamada <masahiroy@kernel.org>
Cc: Kbuild Mailing List <linux-kbuild@vger.kernel.org>
Subject: Re: Module build problems with gmake 3.x
Date: Fri, 10 Sep 2021 15:45:47 -0700	[thread overview]
Message-ID: <CAGt4E5u3YAM16HgoRAbW3Zs3LVJWKosCzp0rDqvQfmzZeXz2nA@mail.gmail.com> (raw)
In-Reply-To: <CAK7LNASbE5=rMGCf6=Jr597okmZChy4t5sNt0O8Z9PACb=DsKg@mail.gmail.com>

On Thu, 9 Sept 2021 at 05:20, Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> I sometimes test GNU make 3.81 for kernel builds, but I have not tested
> the -e option.
>
> Now I tested the -e option, and it worked for me.
> Both $(M) and $(KBUILD_EXTMOD) were correctly set.
>
> So, I did not observe anything you claim.

Thanks for trying it out. See below for a summary of my test comparing
GNUmake 3.81 and 4.1. All the tests have been performed on Ubuntu
14.04. (Yes, I know that's old.)

> I ran this Makefile with GNU Make 3.81
>
> masahiro@oscar:~/workspace/hello$ cat Makefile
> obj-m += hello.o
>
> KERNEL_DIR := $(HOME)/ref/linux
>
> all:
>         ${MAKE} -C $(KERNEL_DIR) -e M=$(PWD) modules
>
> clean:
>         make -C $(KERNEL_DIR) M=$(PWD) clean
> masahiro@oscar:~/workspace/hello$ make-3.81 --version
> GNU Make 3.81
> Copyright (C) 2006  Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.
> There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
> PARTICULAR PURPOSE.
>
> This program built for x86_64-unknown-linux-gnu
> masahiro@oscar:~/workspace/hello$ make-3.81
> make-3.81 -C /home/masahiro/ref/linux -e
> M=/home/masahiro/workspace/hello modules
> make-3.81[1]: Entering directory `/home/masahiro/ref/linux'
> make-3.81[2]: Entering directory `/home/masahiro/ref/linux'
>   CC [M]  /home/masahiro/workspace/hello/hello.o
>   MODPOST /home/masahiro/workspace/hello/Module.symvers
>   CC [M]  /home/masahiro/workspace/hello/hello.mod.o
>   LD [M]  /home/masahiro/workspace/hello/hello.ko
> make-3.81[2]: Leaving directory `/home/masahiro/ref/linux'
> make-3.81[1]: Leaving directory `/home/masahiro/ref/linux'
> masahiro@oscar:~/workspace/hello$ ls hello*
> hello.c  hello.ko  hello.mod  hello.mod.c  hello.mod.o  hello.o
>
> hello.ko was successfully built.
>
> Entering/Leaving directory is eye-sores,
> but presumably it is because MAKEFLAGS is overridden
> by the environment since you gave -e.

Here is what I have.

$ cat Makefile

export KERNEL_DIR = /local/users/mmayer/linux-5.4
export CFLAGS_MODULE = -DGREETING_NAME='"Linux"'

obj-m += hello-1.o

all:
    ${MAKE} -C $(KERNEL_DIR) -e -r M=$(PWD) modules

clean:
    make -C $(KERNEL_DIR) M=$(PWD) clean

$ cat hello-1.c
/*
 *  hello-1.c - The simplest kernel module.
 */
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */

int init_module(void)
{
    printk(KERN_INFO "Hello " GREETING_NAME ".\n");
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO "Goodbye " GREETING_NAME ".\n");
}

MODULE_LICENSE("GPL");

Now, if I run make 3.81, this happens. Please note that I added some
extra output to the top-level Linux Makefile, which is where some of
the extra output is coming from.

$ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu

$ make
hello: CFLAGS_MODULE=-DGREETING_NAME='"Linux"'
hello: KBUILD_EXTMOD=
make -C /local/users/mmayer/linux-5.4 -e -r M=/local/users/mmayer/hello modules
need-sub-make
make[1]: Entering directory `/local/users/mmayer/linux-5.4'
1) CFLAGS_MODULE=-DGREETING_NAME='Linux'
KBUILD_CFLAGS_MODULE=
CFLAGS_MODULE[make]=-DGREETING_NAME='Linux'
CFLAGS_MODULE[env]=-DGREETING_NAME='"Linux"'
Invoking sub-make...
abs_srctree=/local/users/mmayer/linux-5.4
MAKECMDGOALS=modules
make -C /local/users/mmayer/linux-5.4 -f
/local/users/mmayer/linux-5.4/Makefile modules
make[2]: Entering directory `/local/users/mmayer/linux-5.4'
KBUILD_CFLAGS_MODULE=-DMODULE
CFLAGS_MODULE=
KBUILD_CFLAGS_MODULE=-DMODULE
CFLAGS_MODULE=
KBUILD_CFLAGS_MODULE=-DMODULE
CFLAGS_MODULE=
  CALL    scripts/checksyscalls.sh
  CALL    scripts/atomic/check-atomics.sh
warning: Cannot use CONFIG_STACK_VALIDATION=y, please install
libelf-dev, libelf-devel or elfutils-libelf-devel
2) KBUILD_CFLAGS_MODULE=-DMODULE
2) CFLAGS_MODULE=
build=-f ./scripts/Makefile.build obj, @=init
2) KBUILD_CFLAGS_MODULE=-DMODULE
2) CFLAGS_MODULE=
build=-f ./scripts/Makefile.build obj, @=usr
2) KBUILD_CFLAGS_MODULE=-DMODULE
2) CFLAGS_MODULE=
build=-f ./scripts/Makefile.build obj, @=arch/x86
[...]

As you can see, it doesn't pass the value of $(M). Instead, it is
running "make modules" because it sees $(M) as empty.

If I use make 4.1, it works, even though nothing has changed except
for "make" itself.

$ ../make-4.2.1/make --version
GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ ../make-4.2.1/make
hello: CFLAGS_MODULE=-DGREETING_NAME='"Linux"'
hello: KBUILD_EXTMOD=
M=/local/users/mmayer/hello modules
/local/users/mmayer/hello/../make-4.2.1/make -C
/local/users/mmayer/linux-5.4 -e -r M=/local/users/mmayer/hello
modules
make[1]: Entering directory '/local/users/mmayer/linux-5.4'
KBUILD_CFLAGS_MODULE=-DMODULE
CFLAGS_MODULE[make]=-DGREETING_NAME='Linux'
CFLAGS_MODULE[env]=-DGREETING_NAME='"Linux"'
2) KBUILD_CFLAGS_MODULE=-DMODULE
2) CFLAGS_MODULE=-DGREETING_NAME='Linux'
build=-f ./scripts/Makefile.build obj, @=/local/users/mmayer/hello
make[2]: Entering directory '/local/users/mmayer/linux-5.4'
hello: CFLAGS_MODULE=-DGREETING_NAME='"Linux"'
hello: KBUILD_EXTMOD=/local/users/mmayer/hello
  CC [M]  /local/users/mmayer/hello/hello-1.o
make[2]: Leaving directory '/local/users/mmayer/linux-5.4'
make[2]: Entering directory '/local/users/mmayer/linux-5.4'
hello: CFLAGS_MODULE=-DGREETING_NAME='"Linux"'
hello: KBUILD_EXTMOD=/local/users/mmayer/hello
  Building modules, stage 2.
  MODPOST 1 modules
make[3]: Entering directory '/local/users/mmayer/linux-5.4'
  CC [M]  /local/users/mmayer/hello/hello-1.mod.o
  LD [M]  /local/users/mmayer/hello/hello-1.ko
make[3]: Leaving directory '/local/users/mmayer/linux-5.4'
make[2]: Leaving directory '/local/users/mmayer/linux-5.4'
make[1]: Leaving directory '/local/users/mmayer/linux-5.4'

$ lsb_release -d
Description: Ubuntu 14.04.5 LTS

> I do not understand your motivation for using -e, though.

I am not entirely clear on that either, but I have been told it is
needed in that particular build environment.

Regards,
-Markus

  reply	other threads:[~2021-09-10 22:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-03 22:06 Module build problems with gmake 3.x Markus Mayer
2021-09-09 12:19 ` Masahiro Yamada
2021-09-10 22:45   ` Markus Mayer [this message]
2021-09-12 16:03     ` Masahiro Yamada
2021-09-21 23:58       ` Markus Mayer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGt4E5u3YAM16HgoRAbW3Zs3LVJWKosCzp0rDqvQfmzZeXz2nA@mail.gmail.com \
    --to=mmayer@broadcom.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).