In short, the build system comes up with to add the line MODULE_INFO(intree, "Y"); to the file "modulename.mod.c" if and only if the module is being built intro.
There is an obvious way to trick the system by adding this line to one of your regular .c files, but I'm not sure why you want it.
Longer version ....
External modules are usually built with a command like this:
$ make M=`pwd` modules
or old syntax:
$ make SUBDIRS=`pwd` modules
The presence of a non-empty M or SUBDIRS forces the top-level "Makefile" of the kernel to set the variable KBUILD_EXTMOD . It will not be installed for normal kernel assembly.
For stage 2 of building the module (when the message "Building modules, stage 2" is displayed), make runs the makefile "scripts / Makefile.modpost". This works scripts/mod/modpost with various parameters when KBUILD_EXTMOD set. In particular, the -I option is used when KBUILD_EXTMOD set.
Looking at the source of modpost in "scripts / mod / modpost.c", the external_module variable has an initial value of 0, but the -I parameter sets it to 1. The add_intree_flag() function is called with the second is_intree parameter set to !external_module . The add_intree_flag() function writes MODULE_INFO(intree, "Y"); to the file "modulename.mod.c" if and only if the is_intree parameter is true.
Thus, the difference between intree modules and external modules is the presence of the macro MODULE_INFO(intree, "Y"); in the file "modulename.mod.c". This compiles to "modulename.mod.o" and is connected to a module of other object files to form the file "modulename.ko".
source share