There are two places to build a module. It depends on whether you want people to enable the module by themselves or not using the kernel config interface.
Building your first module
The module's makefile
A makefile is a special file used to execute a set of actions, among which the most important is the compilation of programs. There is a dedicated tool to parse makefiles, called make. Prior to jumping to the description of the whole make file, let's introduce the obj-<X> kbuild variable.
In almost every kernel makefile, you will see at least one instance of an obj<-X> variable. This actually corresponds to the obj-<X> pattern, where <X> should be either y, m, left blank, or n. This is used...