linux的makefile分析

目录:
1.顶层makefile简介
2.压缩内核镜像bzimage构建
2.1 bzimage由来
2.2 setup.bin构建
2.3 vmlinux.bin构建
摘要:
本文假定读者具有的前提:粗略的makefile知识,编译x86平台linux内核,内核版本为2.6.35.13-正在执行如下动作make menuconfig,make bzimage, make modules , make modules_install。
1 顶层makefile简介
怎么配置内核?
先定义config-targets := 0,在这个逻辑中:
$(srctree)/Makefile:

427:ifeq ($(KBUILD_EXTMOD),) // KBUILD_EXTMOD变量用于选定module编译到指定目录,默认目录为代码树的module目录
ifneq ($(filter config %config,$(MAKECMDGOALS)),) // MAKECMDGOALS为执行make时命令行中的make的参数。
config-targets := 1
ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
mixed-targets := 1
endif
endif
434:endif

判断此刻不是编译module,如果有config对象,则config-targets赋值为1;若还有其他对象,则为mixed-targets,mixed-targets指同时包括config对象和镜像对象(注:行号,对应的版本2.6.35.13版本的makefile,若是其他版本可以忽略,由于添加注释缘故,行号会有些出入,所以行号本身并不重要,但余念想彼时大学园中,孤诣coding,凡事必究其原因,大耗精力,若今日有此类读者,故添之,亦不必强迫纠结无行号之痒)。

顶层makefile的主要逻辑:
$(srctree)/Makefile:

436:ifeq ($(mixed-targets),1)
//编译混合对象
444:else
445: ifeq ($(config-targets),1)
include $(srctree)/arch/$(SRCARCH)/Makefile // $(srctree)变量即为当前代码树的目录
//编译配置对象
464: else
include $(srctree)/arch/$(SRCARCH)/Makefile
// 编译vmlinux
// 编译modules
1376: endif
1377:endif

怎么得到特定体系结构?
$(srctree)/Makefile:

162: SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/
-e s/arm.*/arm/ -e s/sa110/arm/
-e s/s390x/s390/ -e s/parisc64/parisc/
-e s/ppc.*/powerpc/ -e s/mips.*/mips/
-e s/sh[234].*/sh/ )
189: ARCH ?= $(SUBARCH)
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值