# How to add a c file to the kernel



## chen8002004 (May 1, 2009)

Hi, everyone:

I am new to FreeBSD kernel. Can anyone tell me how to add a c file to the kernel, not a new module? In user space, you can add your c file name to Makefile, but there seems too few Makefile in the kernel. I am working in netipsec and there seems no Makefile related to this module.

Thank you so much.
Max


----------



## rwatson@ (May 16, 2009)

All .c files in the kernel are listed in either src/sys/conf/files or src/sys/${arch}/conf/files, which are used by config(8) to generate makefiles for building the kernel. These files have two columns: the first is the kernel source tree filename, and the second is the kernel option(s) it is associated with.  Put 'standard' beside the file if it should always be built into the kernel, or otherwise specify options.

If you're adding a new kernel option, you also need to add it to src/sys/conf/options or src/sys/${arch}/conf/options, which contain a list of all available kernel options. You will probably also want to document new options in src/sys/conf/NOTES or src/sys/${arch}/conf/NOTES so that it's built into the LINT kernel.

Many optional kernel components can be built in using a kernel built option or using a module, catering to different requirements (embedded system designers often prefer options to modules, for example).

When you modify conf/files or conf/options, make sure to re-config your kernel. If you're using buildkernel, this is done automatically, but if you're building by hand you need to remember to do this as well.


----------

