$(call if_changed,some_target_command )

if_changed是Linux内核Makefile中的关键函数,用于检测目标文件是否需重新构建。它通过比较依赖文件的时间戳和命令行参数变化,避免不必要的编译,提高效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

call if_changed 是在Linux内核的Makefile系统中使用的一个函数,它的目的是检查指定的目标文件是否需要重新构建。这个函数通常在Makefile中使用,以决定是否需要执行某些操作,比如编译源代码或者链接对象文件。

 

在Makefile中,if_changed 函数的基本用法如下:

 

$(obj)/some_target: $(deps)

 $(call if_changed, some_target_command )

 

 

这里,$(obj)/some_target 是目标文件,$(deps) 是依赖文件列表。如果任何依赖文件比目标文件新,或者如果命令行参数发生变化,if_changed 函数将返回非零值,导致Make执行后面跟着的命令。如果没有变化,则不会执行任何操作。

 

if_changed 函数内部使用了一些其他的Makefile函数,比如 filter-out 和 wildcard,来确定哪些依赖文件是新的或者是否存在。它还使用了 set -e 来确保如果命令失败,Make进程将立即退出。

 

在Linux内核的编译过程中,if_changed 函数经常被用来避免不必要的重复编译,从而节省时间。例如,如果一个源文件没有改变,那么编译它生成的对象文件就不应该再次进行链接,除非有其他的依赖项发生了变化 #1 #2 #4。

warning: sys-info@0.9.1: c/linux.c:96:11: error: call to undeclared library function 'index' with type 'char *(const char *, int)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] warning: sys-info@0.9.1: 96 | mount = index(procline, ' '); warning: sys-info@0.9.1: | ^ warning: sys-info@0.9.1: c/linux.c:96:11: note: include the header <strings.h> or explicitly provide a declaration for 'index' warning: sys-info@0.9.1: 1 error generated. error: failed to run custom build command for `sys-info v0.9.1` Caused by: process didn't exit successfully: `/data/data/com.termux/files/home/uv/target/release/build/sys-info-71663c4fe1c5422a/build-script-build` (exit status: 1) --- stdout OUT_DIR = Some(/data/data/com.termux/files/home/uv/target/release/build/sys-info-37439f1d31a224ca/out) OPT_LEVEL = Some(3) TARGET = Some(aarch64-linux-android) HOST = Some(aarch64-linux-android) cargo:rerun-if-env-changed=CC_aarch64-linux-android CC_aarch64-linux-android = None cargo:rerun-if-env-changed=CC_aarch64_linux_android CC_aarch64_linux_android = None cargo:rerun-if-env-changed=HOST_CC HOST_CC = None cargo:rerun-if-env-changed=CC CC = None cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT RUSTC_WRAPPER = None cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS CRATE_CC_NO_DEFAULTS = None DEBUG = Some(false) cargo:rerun-if-env-changed=CFLAGS_aarch64-linux-android CFLAGS_aarch64-linux-android = None cargo:rerun-if-env-changed=CFLAGS_aarch64_linux_android CFLAGS_aarch64_linux_android = None cargo:rerun-if-env-changed=HOST_CFLAGS HOST_CFLAGS = None cargo:rerun-if-env-changed=CFLAGS CFLAGS = Some(-D_GNU_SOURCE) cargo:rerun-if-env-changed=CC_SHELL_ESCAPED_FLAGS CC_SHELL_ESCAPED_FLAGS = None CARGO_ENCODED_RUSTFLAGS = Some() cargo:warning=c/linux.c:96:11: error: call to undeclared library function 'index' with type 'char *(const char *, int)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] cargo:warning= 96 | mount = index(procline, ' '); cargo:warning= | ^ cargo:warning=c/linux.c:96:11: note: include the header <strings.h> or explicitly provide a declaration for 'index' cargo:warning=1 error generated. --- stderr error occurred in cc-rs: Command LC_ALL="C" "aarch64-linux-android-gcc" "-O3" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-D_GNU_SOURCE" "-o" "/data/data/com.termux/files/home/uv/target/release/build/sys-info-37439f1d31a224ca/out/a1edd97dd51cd48d-linux.o" "-c" "c/linux.c" with args aarch64-linux-android-gcc did not execute successfully (status code exit status: 1). warning: build failed, waiting for other jobs to finish... 又是什么问题
最新发布
07-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值