好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

makefilesimplyanalyze(简单地分析文件).doc

17页
  • 卖家[上传人]:ss****gk
  • 文档编号:209417075
  • 上传时间:2021-11-10
  • 文档格式:DOC
  • 文档大小:66KB
  • / 17 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • make file simply analyze (简单地分析文件)学习linux 2. 6内核makefile分析2010 - 04 01 12: 47来源 与非网 博客.关键字makefile linux配置.[摘要]由于linux的独特优势,使越来越多的企业和科研机构把目 光转向linux的开发和研究上.目前linux最新的稳定内核版本为 2. 6. 17,但是当今绝大部分对于linux makefile的介绍文章都是基 于2. 4内核的,可以说关于2. 6内核makefile相关的文章凤毛麟角, 笔者抽时间完成了这篇分析文章,让读者迅速熟悉linux最新 makefile体系,从而加深对内核的理解,同时也希望能对linux在 公司的推广起到一定的推动作用,算是抛砖引玉吧.1 makefile组织层次linux的make体系由如下几部分组成.????顶层 makefile顶层makefile通过读取配置文件,递归编译内核代码树的相关目录, 从而产生两个重要的目标文件:vnilirmx和模块.????内核相关makefile位于arch / $ (arch)目录下,为顶层makefile提供与具体硬件体 协结构相关的信息.????公共编译规则定义文件. 包括 makefile .build 、 makefile ・ clea n、 makefile .1 ib、 makefile, host等文件组成•这些文件位于scripts目录中,定义了 编译需要的公共的规则和定义.????内核配置文件.config通过调用make menuconfig或者make xconfig命令,用户可以选择 需要的配置来生成期望的目标文件.????其他 makefile主要为整个makefile体系提供各自模块的目标文件定义,上层 makefile根据它所定义的冃标来完成各自模块的编译.2 makefile的使用在编译内核之前,用户必须首先完成必要的配置.linux内核提供了 数不胜数的功能,支持众多的硬件体系结构,这就需要用户对将要 生成的内核进行裁减.内核提供了多种不同的工具来简化内核的配置, 最简单的一种是字符界面下命令行工具.make config这个工具会依次遍历内核所有的配置项,要求用户进行逐项的选择 配置•这个工具会耗费用户太多时间,除非万不得以(你的编译主机 不支持其他配置工具)一般不建议使用.用户还可以使用利用ncurse库编制的图形界面工具,这就是大名鼎 鼎的.make menuconfig 相信以前对2. 4内核比较熟悉的用户一定不会陌生•当然在2. 6内核 中提供了更漂亮和方便的基于xll的图形配置工具.make xconfig当用户使用这个工具对limix内核进行配置时,界面下方会出现这 个配置项相关的帮助信息和简单描述,当你对内核配置选项不太熟 悉时,建议你使用这个工具来进行内核配置.When the user completes the configuration, the configuration tool automatically generates the .Config file, which is stored in the root directory of the kernel code tree・ Users can easily find it and, of course, users can make simple changes to the file directly. However, after you have modified the configuration file, you must validate and update the configuration by following the command:Make oldconfigThe difference with version 2.4 is that the user does not need to display the call make dep command to generate dependency files, and the kernel automatically maintains dependencies between the code・When everything is done, the user simply needs to type make, and all the rest of the work will be done automatically for you by makefile・3 Makefile compilation f1owWhen the user compiles the kernel version with Liniixs Makefile, the Makefile compilation process follows:Use the command line or graphical interface configuration tool to cut the kernel and generate the .Config configuration fileSave the kernel version information to include/1 inux/vers io n. hProduces symbolic link include/asm, pointing to the actual directory include/asm-$(ARCH)Make necessary preparations for the final goal file generationRecursively enters directories such as /init, /core, /drivers, /net, /lib, and subdirectories to compile and generate all of the target filesThe target file generated by linking the above process generates vmlinux, and the vmlinux is stored in the root directory of the kernel code treeFinally, the final image boot image is created based on the later compiled processing rules defined by the arch/$(ARCH) /Makefile file, including creation of boot records, preparation of initrd mappings, and associated processing4 Makefile key rules and definitions are described1) goal definitionThe target is defined as the core part of the Makefile file, define the target according to the special need to notify the Makefile compiler options link object files which generate the target file, at the same time, to control which is compiled into subdirectories recursively.This example, the Makefile file, is located in the /fs/ext2 directory:#Makefile for the Linux ext2-filesystem routines・ ##Obj-$(C0NFIG_EXT2_FS)二 ext2.oExt2一y:二 balloc・o, bitmap・o, dir.o, file・o, fsync・o, ialloc・o, inode・ o \Ioct 1. o namei・ o super.o symlink.oExt2-$(C0NFIG_EXT2_FS_XATTR)二 xattr.o xattr_user. o xattr_trusted・ oExt2-$(C0NFIG_EXT2_FS_P0SIX_ACL)二 acl. oExt2-$(C0NFIG_EXT2_FS_SECURITY)二 xattr_security. oExt2-$(C0NFIG_EXT2_FS_XIP)二 xip. oThis representation is associated with the ext2 object file consists of the definition of ext2-y file list, including ext2-$(*) is decided by the configuration of. Config kernel configuration file, Makefile will eventually generate a unified ext2. o file in this directory (by obj-$ (C0NFIG_EXT2_FS) decision)・ Where obj-y represents the set of target files required to generate the vmlinux file,The specific file depends on the kernel configuration.Makefile compiles all the files defined in $(obj-y), and then calls the linker to link these files to the built-in. o file・ Finally, the built-in.o file is linked to the vmlinux through the top-level Makefile・ It is important to note that the order of $ (obj-y) files is important・ The list file can be repeated・ The file will be linked to built-in. o for the first time, and the later name file will be ignored. The order of documents determines the order in which they are invoked, which requires special attention.The reader may find the lib-y definition in some Makefile, and all the target files included in the lib-y definition will be compiled into a unified library file in that direc。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.