glibc编译及makefile机制

本文只列出glibc的makefile中比较难以找出的一些规则,一些细节可以详细阅读glibc的makefile系统。

 

I.编译

[redhat@localhost build]$ ../glibc-2.16.0/configure --disable-sanity-checks
[redhat@localhost build]$ make | tee make.log


i.默认规则:

Makefile

 30 all: lib others


ii.lib规则:

[redhat@localhost glibc-2.16.0]$ grep -n "^include" Makefile
25:include Makeconfig
78:include Makerules

[redhat@localhost glibc-2.16.0]$ grep -n "lib:" Makeconfig Makerules Makefile
Makerules:703:lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
Makerules:704:lib-noranlib: libobjs
Makerules:718:subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
Makerules:829:install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
Makerules:1134:cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
Makefile:122:lib-noranlib: subdir_lib
Makefile:126:lib: $(common-objpfx)libc.so
Makefile:128:lib: $(common-objpfx)linkobj/libc.so


iii.libc.so

lib的一个重要前提是libc.so,libc.so生成的一过程大致如下:
a.递归子目录,对源文件进行编译
b.由子目录生成的object文件生成libc_pic.a
c.由libc_pic.a及其它object文件生成libc.so

 

II.递归子目录

i.递归规则
Makefile

 51 # These are the targets that are made by making them in each subdirectory.
 52 +subdir_targets := subdir_lib objects objs others subdir_mostlyclean    \
 53                    subdir_clean subdir_distclean subdir_realclean       \
 54                    tests xtests subdir_lint.out                         \
 55                    subdir_update-abi subdir_check-abi                   \
 56                    subdir_echo-headers                                  \
 57                    subdir_install                                       \
 58                    subdir_objs subdir_stubs subdir_testclean            \
 59                    $(addprefix install-, no-libc.a bin lib data headers others)

223 # For each target, make it depend on DIR/target for each subdirectory DIR.
224 $(+subdir_targets): %: $(addsuffix /%,$(subdirs))
225 
226 # Compute a list of all those targets.
227 all-subdirs-targets := $(foreach dir,$(subdirs),\
228                                  $(addprefix $(dir)/,$(+subdir_targets)))
229 
230 # The action for each of those is to cd into the directory and make the
231 # target there.
232 $(all-subdirs-targets):
233         $(MAKE) $(PARALLELMFLAGS) $(subdir-target-args) $(@F)
234 
235 define subdir-target-args
236 subdir=$(@D)$(if $($(@D)-srcdir),\
237 -C $($(@D)-srcdir) ..=`pwd`/,\
238 -C $(@D) ..=../)
239 endef

由以上可以看出,subdir_lib规则就是递归子目录去执行make,由子目录下的Makefile负责子目录的编译。

ii.子目录
Makeconfig

769 -include $(common-objpfx)sysd-sorted
770 subdirs = $(sorted-subdirs)

921 # These are the 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值