歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> linux下面Makefile探索

linux下面Makefile探索

日期:2017/2/27 9:49:13   编辑:更多Linux
Makefile 初探

==========================================

Linux的內核配置文件有兩個,一個是隱含的.config文件,嵌入到主Makefile中;另一個是include/linux/autoconf.h,嵌入到各個c源文件中,它們由make config、make menUConfig、make xconfig這些過程創建。幾乎所有的源文件都會通過linux/config.h而嵌入autoconf.h,如果按照通常方法建立文件依賴關系(.depend),只要更新過autoconf.h,就會造成所有源代碼的重新編繹。


為了優化make過程,減少不必要的重新編繹,linux開發了專用的mkdep工具,用它來取代gcc來生成.depend文件。mkdep在處理源文件時,忽略linux/config.h這樣的頭文件,識別源文件宏指令中具有"CONFIG_"特征的行。例如,如果有"#ifdef CONFIG_SMP"這樣的行,它就會在.depend文件中輸出$(wildcard /usr/src/linux/include/config/smp.h)。


include/config/下的文件是另一個工具split-include從autoconf.h中生成,它利用autoconf.h中的CONFIG_標記,生成與mkdep相對應的文件。例如,如果autoconf.h中有"#undef CONFIG_SMP"這一行,它就生成include/config/smp.h文件,內容為"#undef CONFIG_SMP"。這些文件名只在.depend文件中出現,內核源文件是不會嵌入它們的。每配置一次內核,運行split-include一次。split-include會檢查舊的子文件的內容,確定是不是要更新它們。這樣,不管autoconf.h修改日期如何,只要其配置不變,make就不會重新編繹內核。


如果系統的編繹選項發生了變化,linux也能進行增量編繹。為了做到這一點,make每編繹一個源文件時生成一個flags文件。例如編繹sched.c時,會在相同的目錄下生成隱含的.sched.o.flags文件。它是Makefile的一個片斷,當make進入某個子目錄編繹時,會搜索其中的flags文件,將它們嵌入到Makefile中。這些flags代碼測試當前的編繹選項與原來的是不是相同,如果相同,就將自已對應的目標文件加入FILES_FLAGS_UP_TO_DATE列表,然後,系統從編繹對象表中刪除它們,得到FILES_FLAGS_CHANGED列表,最後,將它們設為目標進行更新。


下一步准備逐步深入的剖析Makefile代碼。


==========================================

Makefile解讀之二: sub-make

==========================================

linux各級內核源代碼的子目錄下都有Makefile,大多數Makefile要嵌入主目錄下的Rule.make,Rule.make將識別各個Makefile中所定義的一些變量。變量obj-y表示需要編繹到內核中的目標文件名集合,定義O_TARGET表示將obj-y連接為一個O_TARGET名稱的目標文件,定義L_TARGET表示將obj-y合並為一個L_TARGET名稱的庫文件。同樣obj-m表示需要編繹成模塊的目標文件名集合。如果還需進行子目錄make,則需要定義subdir-y和subdir-m。在Makefile中,用"obj-$(CONFIG_BINFMT_ELF) += binfmt_elf.o"和"subdir-$(CONFIG_EXT2_FS) += ext2"這種形式自動為obj-y、obj-m、subdir-y、subdir-m添加文件名。有時,情況沒有這麼單純,還需要使用條件語句個別對待。Makefile中還有其它一些變量,如mod-subdirs定義了subdir-m以外的所有模塊子目錄。


Rules.make是如何使make進入子目錄的呢? 先來看subdir-y是如何處理的,在Rules.make中,先對subdir-y中的每一個文件名加上前綴"_subdir_"再進行排序生成subdir-list集合,再以它作為目標集,對其中每一個目標產生一個子make,同時將目標名的前綴去掉得到子目錄名,作為子make的起始目錄參數。subdir-m與subdir-y類似,但情況稍微復雜一些。由於subdir-y中可能有模塊定義,因此利用mod-subdirs變量將subdir-y中模塊目錄提取出來,再與subdir-m合成一個大的MOD_SUB_DIRS集合。subdir-m的目標所用的前綴是"_modsubdir_"。


一點說明,子目錄中的Makefile與Rules.make都沒有嵌入.config文件,它是通過主Makefile向下傳遞MAKEFILES變量完成的。MAKEFILES是make自已識別的一個變量,在執行新的Makefile之前,make會首先加載MAKEFILES所指的文件。在主Makefile中它即指向.config。



==========================================

Makefile解讀之三: 模塊的版本化處理

==========================================

模塊的版本化是內核與模塊接口之間進行嚴格類型匹配的一種方法。當內核配置了CONFIG_MODVERSIONS之後,make dep操作會在include/linux/modules/目錄下為各級Makefile中eXPort-objs變量所對應的源文件生成擴展名為.ver的文件。





例如對於kernel/ksyms.c,make用以下命令生成對應的ksyms.ver:


gcc -E -D__KERNEL__ -D__GENKSYMS__ ksyms.c /sbin/genksyms -k 2.4.1 > ksyms.ver


-D__GENKSYMS__的作用是使ksyms.c中的EXPORT_SYMBOL宏不進行擴展。genksyms命令識別EXPORT_SYMBOL()中的函數名和對應的原型,再根據其原型計算出該函數的版本號。


例如ksyms.c中有一行:

EXPORT_SYMBOL(kmalloc);

kmalloc原型是:

void *kmalloc(size_t, int);

genksyms程序對應的輸出為:

#define __ver_kmalloc 93d4cfe6

#define kmalloc _set_ver(kmalloc)

在內核符號表和模塊中,kmalloc將變成kmalloc_R93d4cfe6。


在生成完所有的.ver文件後,make將重建include/linux/modversions.h文件,它包含一系列#include指令行嵌入各個.ver文件。在編繹內核本身export-objs中的文件時,make會增加一個"-DEXPORT_SYMTAB"編繹標志,它使源文件嵌入modversions.h文件,將EXPORT_SYMBOL宏展開中的函數名字符串進行版本名擴展;同時,它也定義_set_ver()宏為一空操作,使代碼中的函數名不受其影響。

在編繹模塊時,make會增加"-include=linux/modversion.h -DMODVERSIONS"編繹標志,使模塊中代碼的函數名得到相應版本擴展。


由於生成.ver文件比較費時,make還為每個.ver創建了一個後綴為.stamp時戳文件。在make dep時,如果其.stamp文件比源文件舊才重新生成.ver文件,否則只是更新.stamp文件時戳。另外,在生成.ver和modversions.h文件時,make都會比較新文件和舊文件的內容,保持它們修改時間為最舊。



==========================================

Makefile解讀之四: Rules.make的注釋

==========================================

代碼:


#

# This file contains rules which are shared between multiple Makefiles.

#


#

# False targets.

#

#

.PHONY: dummy


#

# Special variables which should not be exported

#

# 取消這些變量通過環境向make子進程傳遞。

unexport EXTRA_AFLAGS # as 的開關

unexport EXTRA_CFLAGS # cc 的開關

unexport EXTRA_LDFLAGS # ld 的開關

unexport EXTRA_ARFLAGS # ar 的開關

unexport SUBDIRS #

unexport SUB_DIRS # 編繹內核需進入的子目錄,等於subdir-y

unexport ALL_SUB_DIRS # 所有的子目錄

unexport MOD_SUB_DIRS # 編繹模塊需進入的子目錄

unexport O_TARGET # ld合並的輸出對象

unexport ALL_MOBJS # 所有的模塊名


unexport obj-y # 編繹成內核的文件集

unexport obj-m # 編繹成模塊的文件集

unexport obj-n #

unexport obj- #

unexport export-objs # 需進行版本處理的文件集

unexport subdir-y # 編繹內核所需進入的子目錄

unexport subdir-m # 編繹模塊所需進入的子目錄

unexport subdir-n

unexport subdir-


#

# Get things started.

#

first_rule: sub_dirs

$(MAKE) all_targets


# 在內核編繹子目錄中過濾出可以作為模塊的子目錄。

both-m := $(filter $(mod-subdirs), $(subdir-y))

SUB_DIRS := $(subdir-y)

# 求出總模塊子目錄

MOD_SUB_DIRS := $(sort $(subdir-m) $(both-m))

# 求出總子目錄

ALL_SUB_DIRS := $(sort $(subdir-y) $(subdir-m) $(subdir-n) $(subdir-))



#

# Common rules

#

# 將c文件編繹成匯編文件的規則,$@為目標對象。

%.s: %.c

$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -S $< -o $@

# 將c文件生成預處理文件的規則。

%.i: %.c

$(CPP) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) $< > $@

# 將c文件編繹成目標文件的規則,$<為第一個所依賴的對象;
br>
#

在目標文件的目錄下生成flags文件,strip刪除多余的空格,subst將逗號替換成冒號



%.o: %.c

$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $<



@ (

echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS)

$(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS)

$$(CFLAGS_$@))))' ;

echo 'FILES_FLAGS_UP_TO_DATE += $@' ;

echo 'endif'

) > $(dir $@)/.$(notdir $@).flags

# 匯編文件生成目標文件的規則。

%.o: %.s

$(AS) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $<


# Old makefiles define their own rules for compiling .S files,

# but these standard rules are available for any Makefile that

# wants to use them. Our plan is to incrementally convert all

# the Makefiles to these standard rules. -- rmk, mec


ifdef USE_STANDARD_AS_RULE

# 匯編文件生成預處理文件的標准規則。

%.s: %.S

$(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@

# 匯編文件生成目標文件的標准規則。

%.o: %.S

$(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $<


endif

# c文件生成調試列表文件的規則,$*擴展為目標的主文件名。

%.lst: %.c

$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -g -c -o $*.o $<

$(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP)

#

#

#

all_targets: $(O_TARGET) $(L_TARGET)


#

# Rule to compile a set of .o files into one .o file

#

ifdef O_TARGET

$(O_TARGET): $(obj-y)

rm -f $@

# $^擴展為全部依賴對象,如果obj-y為空就生成一個同名空的庫文件。

ifneq "$(strip $(obj-y))" ""

$(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^)

else

$(AR) rcs $@

endif

# 生成flags文件的shell語句。

@ (

echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS)

$(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(obj-y))))' ;



echo 'FILES_FLAGS_UP_TO_DATE += $@' ;

echo 'endif'

) > $(dir $@)/.$(notdir $@).flags

endif # O_TARGET


#

# Rule to compile a set of .o files into one .a file

#

# 將obj-y組合成庫L_TARGET的方法。

ifdef L_TARGET

$(L_TARGET): $(obj-y)

rm -f $@

$(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)

@ (

echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS)

$(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(obj-y))))' ;



echo 'FILES_FLAGS_UP_TO_DATE += $@' ;

echo 'endif'

) > $(dir $@)/.$(notdir $@).flags

endif



#

# This make dependencies quickly

#

# wildcard為查找目錄中的文件名的宏。

fastdep: dummy

$(TOPDIR)/scripts/mkdep $(wildcard *.[chS] local.h.master) > .depend

ifdef ALL_SUB_DIRS

#

將ALL_SUB_DIRS中的目錄名加上前綴_sfdep_作為目標運行子make,並將ALL_SUB_DIRS

通過

# 變量_FASTDEP_ALL_SUB_DIRS傳遞給子make。

$(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS))

_FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"

endif


ifdef _FASTDEP_ALL_SUB_DIRS

#

與上一段相對應,定義子目錄目標,並將目標名還原為目錄名,進入該子目錄make。

$(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):

$(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep



endif



#

# A rule to make subDirectories

#

# 下面2段完成內核編繹子目錄中的make。

subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS)))

sub_dirs: dummy $(subdir-list)


ifdef SUB_DIRS

$(subdir-list) : dummy

$(MAKE) -C $(patsubst _subdir_%,%,$@)

endif


#

# A rule to make modules

#

# 求出有效的模塊文件表。

ALL_MOBJS = $(filter-out $(obj-y), $(obj-m))

ifneq "$(strip $(ALL_MOBJS))" ""

# 取主目錄TOPDIR到當前目錄的路徑。

PDWN=$(shell $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh)

endif


unexport MOD_DIRS

MOD_DIRS := $(MOD_SUB_DIRS) $(MOD_IN_SUB_DIRS)

# 編繹模塊時,進入模塊子目錄的方法。

ifneq "$(strip $(MOD_DIRS))" ""

.PHONY: $(patsubst %,_modsubdir_%,$(MOD_DIRS))

$(patsubst %,_modsubdir_%,$(MOD_DIRS)) : dummy

$(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules

# 安裝模塊時,進入模塊子目錄的方法。

.PHONY: $(patsubst %,_modinst_%,$(MOD_DIRS))

$(patsubst %,_modinst_%,$(MOD_DIRS)) : dummy

$(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install

endif


# make modules 的入口。

.PHONY: modules

modules: $(ALL_MOBJS) dummy

$(patsubst %,_modsubdir_%,$(MOD_DIRS))


.PHONY: _modinst__

# 拷貝模塊的過程。

_modinst__: dummy

ifneq "$(strip $(ALL_MOBJS))" ""

mkdir -p $(MODLIB)/kernel/$(PDWN)

cp $(ALL_MOBJS) $(MODLIB)/kernel/$(PDWN)

endif


# make modules_install 的入口,進入子目錄安裝。

.PHONY: modules_install

modules_install: _modinst__

$(patsubst %,_modinst_%,$(MOD_DIRS))


#

# A rule to do nothing

#

dummy:


#

# This is useful for testing

#

script:

$(SCRIPT)


#

# This sets version suffixes on exported symbols

# Separate the object into "normal" objects and "exporting" objects

# Exporting objects are: all objects that define symbol tables

#

ifdef CONFIG_MODULES

# list-multi列出那些由多個文件復合而成的模塊;

# 從編繹文件表和模塊文件表中過濾出復合模塊名。

multi-used := $(filter $(list-multi), $(obj-y) $(obj-m))

# 取復合模塊的構成表。

multi-objs := $(foreach m, $(multi-used), $($(basename $(m))-objs))

# 求出需進行編譯的總模塊表。

active-objs := $(sort $(multi-objs) $(obj-y) $(obj-m))


ifdef CONFIG_MODVERSIONS

ifneq "$(strip $(export-objs))" ""

# 如果有需要進行版本化的文件。

MODINCL = $(TOPDIR)/include/linux/modules


# The -w option (enable warnings) for genksyms will return here in 2.1

# So where has it gone?

#

# Added the SMP separator to stop module accidents between uniprocessor

# and SMP Intel boxes - AC - from bits by Michael Chastain

#


ifdef CONFIG_SMP

genksyms_smp_prefix := -p smp_

else

genksyms_smp_prefix :=

endif

# 從源文件計算版本文件的規則。



$(MODINCL)/%.ver: %.c

@if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then

echo '$(CC) $(CFLAGS) -E -D__GENKSYMS__ $<';

echo ' $(GENKSYMS) $(genksyms_smp_prefix) -k

$(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > [email protected]';

$(CC) $(CFLAGS) -E -D__GENKSYMS__ $<

$(GENKSYMS) $(genksyms_smp_prefix) -k

$(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > [email protected];

if [ -r $@ ] && cmp -s $@ [email protected]; then echo $@ is unchanged; rm -f

[email protected];

else echo mv [email protected] $@; mv -f [email protected] $@; fi;

fi; touch $(MODINCL)/$*.stamp

#

將版本處理源文件的擴展名改為.ver,並加上完整的路徑名,它們依賴於autoconf.h?br>?br>$(addprefix $(MODINCL)/,$(export-objs:.o=.ver)):

$(TOPDIR)/include/linux/autoconf.h


# updates .ver files but not modversions.h

# 通過fastdep,逐個生成export-objs對應的版本文件。

fastdep: $(addprefix $(MODINCL)/,$(export-objs:.o=.ver))


# updates .ver files and modversions.h like before (is this needed?)

# make dep過程的入口

dep: fastdep update-modverfile


endif # export-objs


# update modversions.h, but only if it would change

# 刷新版本文件的過程。

update-modverfile:

@(echo "#ifndef _LINUX_MODVERSIONS_H";

echo "#define _LINUX_MODVERSIONS_H";

echo "#include <linux/modsetver.h>";

cd $(TOPDIR)/include/linux/modules;

for f in *.ver; do

if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi;

done;

echo "#endif";

) > $(TOPDIR)/include/linux/modversions.h.tmp

@if [ -r $(TOPDIR)/include/linux/modversions.h ] && cmp -s

$(TOPDIR)/include/linux/modversions.h

$(TOPDIR)/include/linux/modversions.h.tmp; then

echo $(TOPDIR)/include/linux/modversions.h was not updated;

rm -f $(TOPDIR)/include/linux/modversions.h.tmp;

else

echo $(TOPDIR)/include/linux/modversions.h was updated;

mv -f $(TOPDIR)/include/linux/modversions.h.tmp

$(TOPDIR)/include/linux/modversions.h;

fi

$(active-objs): $(TOPDIR)/include/linux/modversions.h


else

# 如果沒有配置版本化,modversions.h的內容。

$(TOPDIR)/include/linux/modversions.h:

@echo "#include <linux/modsetver.h>" > $@


endif # CONFIG_MODVERSIONS


ifneq "$(strip $(export-objs))" ""

# 版本化目標文件的編繹方法。

$(export-objs): $(export-objs:.o=.c) $(TOPDIR)/include/linux/modversions.h

$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c)

@ (

echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS)

$(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS)

$$(EXTRA_CFLAGS) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ;

echo 'FILES_FLAGS_UP_TO_DATE += $@' ;

echo 'endif'

) > $(dir $@)/.$(notdir $@).flags

endif


endif # CONFIG_MODULES



#

# include dependency files if they exist



#

# 嵌入源文件之間的依賴關系。

ifneq ($(wildcard .depend),)

include .depend

endif

# 嵌入頭文件之間的依賴關系。

ifneq ($(wildcard $(TOPDIR)/.hdepend),)

include $(TOPDIR)/.hdepend

endif


#

# Find files whose flags have changed and force recompilation.

# For safety, this works in the converse direction:

# every file is forced, except those whose flags are positively

up-to-date.

#

# 已經更新過的文件列表。

FILES_FLAGS_UP_TO_DATE :=


# For use in expunging commas from flags, which mung our checking.

comma = ,

# 將當前目錄下所有flags文件嵌入。

FILES_FLAGS_EXIST := $(wildcard .*.flags)

ifneq ($(FILES_FLAGS_EXIST),)

include $(FILES_FLAGS_EXIST)

endif

# 將無需更新的文件從總的對象中刪除。

FILES_FLAGS_CHANGED := $(strip

$(filter-out $(FILES_FLAGS_UP_TO_DATE),

$(O_TARGET) $(L_TARGET) $(active-objs)

))


# A kludge: .S files don't get flag dependencies (yet),

# because that will involve changing a lot of Makefiles. Also

# suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).

# This allows handling of assembly files that get translated into

# multiple object files (see arch/ia64/lib/idiv.S, for example).

#

# 將由匯編文件生成的目件文件從FILES_FLAGS_CHANGED刪除。

FILES_FLAGS_CHANGED := $(strip

$(filter-out $(patsubst %.S, %.o, $(wildcard *.S)

$(IGNORE_FLAGS_OBJS)),

$(FILES_FLAGS_CHANGED)))

# 將FILES_FLAGS_CHANGED設為目標。

ifneq ($(FILES_FLAGS_CHANGED),)

$(FILES_FLAGS_CHANGED): dummy

endif

</pre>




#

# 嵌入源文件之間的依賴關系。

ifneq ($(wildcard .depend),)

include .depend

endif

# 嵌入頭文件之間的依賴關系。

ifneq ($(wildcard $(TOPDIR)/.hdepend),)

include $(TOPDIR)/.hdepend

endif


#

# Find files whose flags have changed and force recompilation.

# For safety, this works in the converse direction:

# every file is forced, except those whose flags are positively

up-to-date.

#

# 已經更新過的文件列表。

FILES_FLAGS_UP_TO_DATE :=


# For use in expunging commas from flags, which mung our checking.

comma = ,

# 將當前目錄下所有flags文件嵌入。

FILES_FLAGS_EXIST := $(wildcard .*.flags)

ifneq ($(FILES_FLAGS_EXIST),)

include $(FILES_FLAGS_EXIST)

endif

# 將無需更新的文件從總的對象中刪除。

FILES_FLAGS_CHANGED := $(strip

$(filter-out $(FILES_FLAGS_UP_TO_DATE),

$(O_TARGET) $(L_TARGET) $(active-objs)

))


# A kludge: .S files don't get flag dependencies (yet),

# because that will involve changing a lot of Makefiles. Also

# suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).

# This allows handling of assembly files that get translated into

# multiple object files (see arch/ia64/lib/idiv.S, for example).

#

# 將由匯編文件生成的目件文件從FILES_FLAGS_CHANGED刪除。

FILES_FLAGS_CHANGED := $(strip

$(filter-out $(patsubst %.S, %.o, $(wildcard *.S)

$(IGNORE_FLAGS_OBJS)),

$(FILES_FLAGS_CHANGED)))

# 將FILES_FLAGS_CHANGED設為目標。

ifneq ($(FILES_FLAGS_CHANGED),)

$(FILES_FLAGS_CHANGED): dummy

endif

</pre>




@echo "#include <linux/modsetver.h>" > $@


endif # CONFIG_MODVERSIONS


ifneq "$(strip $(export-objs))" ""

# 版本化目標文件的編繹方法。

$(export-objs): $(export-objs:.o=.c) $(TOPDIR)/include/linux/modversions.h

$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c)

@ (

echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS)

$(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS)

$$(EXTRA_CFLAGS) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ;

echo 'FILES_FLAGS_UP_TO_DATE += $@' ;

echo 'endif'

) > $(dir $@)/.$(notdir $@).flags

endif


endif # CONFIG_MODULES



#

# include dependency files if they exist

#

# 嵌入源文件之間的依賴關系。

ifneq ($(wildcard .depend),)

include .depend

endif

# 嵌入頭文件之間的依賴關系。

ifneq ($(wildcard $(TOPDIR)/.hdepend),)

include $(TOPDIR)/.hdepend

endif


#

# Find files whose flags have changed and force recompilation.

# For safety, this works in the converse direction:

# every file is forced, except those whose flags are positively

up-to-date.

#

# 已經更新過的文件列表。

FILES_FLAGS_UP_TO_DATE :=


# For use in expunging commas from flags, which mung our checking.

comma = ,

# 將當前目錄下所有flags文件嵌入。

FILES_FLAGS_EXIST := $(wildcard .*.flags)

ifneq ($(FILES_FLAGS_EXIST),)

include $(FILES_FLAGS_EXIST)

endif

# 將無需更新的文件從總的對象中刪除。

FILES_FLAGS_CHANGED := $(strip

$(filter-out $(FILES_FLAGS_UP_TO_DATE),

$(O_TARGET) $(L_TARGET) $(active-objs)

))


# A kludge: .S files don't get flag dependencies (yet),

# because that will involve changing a lot of Makefiles. Also

# suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).

# This allows handling of assembly files that get translated into



# multiple object files (see arch/ia64/lib/idiv.S, for example).

#

# 將由匯編文件生成的目件文件從FILES_FLAGS_CHANGED刪除。

FILES_FLAGS_CHANGED := $(strip

$(filter-out $(patsubst %.S, %.o, $(wildcard *.S)

$(IGNORE_FLAGS_OBJS)),

$(FILES_FLAGS_CHANGED)))

# 將FILES_FLAGS_CHANGED設為目標。

ifneq ($(FILES_FLAGS_CHANGED),)

$(FILES_FLAGS_CHANGED): dummy

endif

</pre>



Copyright © Linux教程網 All Rights Reserved