Search code examples
clinuxmakefilelinux-kernelkbuild

Why did not we have ccflags-m, but ccflags-y?


I'm analyzing Linux Kernel Makefiles bundle. We can define an additional compiler flag to build external module with ccflags-y += -std=gnu11 -Wno-declaration-after-statement -Werror. I looked at Makefile.build which external module build goes down to and did not even notice ccflags-m option defined. The full list of options:

obj-y :=
obj-m :=
lib-y :=
lib-m :=
always :=
targets :=
subdir-y :=
subdir-m :=
EXTRA_AFLAGS   :=
EXTRA_CFLAGS   :=
EXTRA_CPPFLAGS :=
EXTRA_LDFLAGS  :=
asflags-y  :=
ccflags-y  :=
cppflags-y :=
ldflags-y  :=

subdir-asflags-y :=
subdir-ccflags-y :=

As far as I understand what y and m means in kbuild, m - for loadable modules, y - for builtins. So it does not seem logical to specify compiler options with ccflags-y, not ccflags-m.

QUESTION: Why does not ccflags-y have -m counterpart ccflags-m for loadable modules?


Solution

  • Actually, different suffixes -m and -y are needed only for determine the final purpose of the object files:

    1. obj-y are for build given object files as built-in, and obj-m for build them as modules
    2. subdir-y and subdir-m are for more complex things.
    3. lib-y and lib-m are the same: both builds objects into the library.

    But flags (compiler or linker) are applied for the objects unconditionally, thus they have only -y suffix.

    Typical scenario in Makefile looks like:

    obj-$(CONFIG_FOO) := foo.o
    ccflags-$(CONFIG_FOO_DEBUG)  := -DFOO_DEBUG
    

    Here CONFIG_FOO is a tristate option (y/m/n) but CONFIG_FOO_DEBUG is a bool (y/n).