Linux Makefile obj-m obj-y

Source: Internet
Author: User

The goal definition is the main part of Kbuild makefile and is also the core part. The main definition is to compile the file, all the options, and to which subdirectories to perform the recursive operation. The simplest kbuild makefile contains only one line: example: obj-y + = foo.o This example tells Kbuild that there is a target file named foo.o in this directory. FOO.O will be from FOO.C or foo. s file compiled. If FOO.O is to be compiled into a module, it will be used obj-m. The following form is used: Example: obj-$ (config_foo) + = FOO.O $ (config_foo) can be Y (compiled into the kernel) or m (compiled into a module). If Config_foo is not y and M, then the file will not be compiled and joined.


Linux all levels of kernel source code are makefile, most of the makefile to be embedded in the main directory Rule.make,rule.make will identify the various makefile defined in the variables. The variable obj-y represents a collection of target file names that need to be yi into the kernel, and defines o_target as the destination file that connects Obj-y to a o_target name, and defines l_target as a library file that merges obj-y into a l_target name. The same obj-m represents a collection of target filenames that need to be Yi into modules. If you still need to make subdirectories, you need to define SUBDIR-Y and subdir-m. In makefile, use "obj-$ (config_binfmt_elf) + = BINFMT_ELF.O" and "subdir-$ (config_ext2_fs) + = ext2" In this form automatically for Obj-y, Obj-m, Subdir-y, subdir-m Add file name. Sometimes, the situation is not so simple, and you need to use conditional statements to treat them individually. There are other variables in makefile, such as mod-subdirs that define all the module subdirectories except Subdir-m.


How is rules.make making make into a subdirectory? First of all, subdir-y is how to deal with, in the Rules.make, each of the subdir-y in the name of the prefix "_subdir_" and then to sort out the Subdir-list collection, and then as a target set, each of which produces a sub-make , and the prefix of the target name is removed to get the subdirectory name as the starting directory parameter of the child make. Subdir-m is similar to subdir-y, but the situation is slightly more complicated. Since there may be a module definition in subdir-y, the mod-subdirs variable is used to extract the module catalog from the subdir-y and then synthesize a large mod_sub_dirs collection with subdir-m. The prefix used for the subdir-m target is "_modsubdir_".


Note that the makefile and Rules.make in subdirectories are not embedded in the. config file, which is done by passing the makefiles variable down through the main makefile. Makefiles is a variable that makes self-identified, and make will first load the file referred to by makefiles before executing the new makefile. In the main makefile it points to. config.

Linux Makefile obj-m obj-y

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.