📄 makefile.txt
字号:
# 将c文件编绎成汇编文件的规则,
$@为目标对象。
%.s: %.c
$(CC) $(CFLAGS)
$(EXTRA_CFLAGS) $(CFLAGS_$@)
-S $< -o $@
# 将c文件生成预处理文件的规则。
%.i: %.c
$(CPP) $(CFLAGS) $(EXTRA_CFLAGS)
$(CFLAGS_$@) $< > $@
# 将c文件编绎成目标文件的规则,
$<为第一个所依赖的对象;
#
在目标文件的目录下生成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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -