Kbuild Makefile#
These aren’t plain GNU Make, Kbuild (the kernel’s build system) reads them with special meaning when you run
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules.
| |
CFLAGS_main.o- per-object compiler flags. Onlymain.ogets-DDEBUG; if you hadmain.oandhelper.o, only the first sees the macro. Useful for debug-gating one file without recompiling the whole module noisily.ccflags-y- flags applied to every.oin this Makefile (the module-wide equivalent ofCFLAGS). Here it forcesgnu99and definesENABLE_DEBUGglobally.proc_fs_basic-objs- when a module is built from more than one source file, this lists what gets linked into the final.ko. Pattern is<module_name>-objs := a.o b.o c.o(Kbuild also accepts-yinstead of-objsin newer trees).obj-m- the actual build trigger.obj-m= build as a loadable module →proc_fs_basic.ko. Swap it forobj-yand it’d get compiled directly into the kernel image instead.
Order of resolution:
obj-m→ Kbuild seesproc_fs_basic.ois wanted → checks forproc_fs_basic-objs→ pulls inmain.o→ appliesCFLAGS_main.o+ccflags-ywhile compiling it.
references: