关于makefile中,一直显示“XXX is up to date”的解决方法

本文探讨了Makefile中出现“isuptodate”提示的原因,并介绍了如何通过使用.PHONY来解决由target和目录名冲突导致的问题。

最近更新一个项目的makefile文件,在添加一个makefile target的时候,发现总是出现“is up to date”的提示,书写语法无任何不妥,始终找不到原因,最后google了下,找到了解决方案。


在stackoverflow上,有人给出的问题原因如下:

Your have directories with the same name as your targets.

Since your targets don't depend on anything, they'll always be considered up to date.


可见这是makefile target和dir名字冲突造成的,解决方法则是借助.PHONY。


在GNU的官网上,是这么解释的:

A phony target is one that is not really the name of a file; rather it is just a name for a recipe to be executed when you make an explicit request. There are two reasons to use a phony target: to avoid a conflict with a file of the same name, and to improve performance.

If you write a rule whose recipe will not create the target file, the recipe will be executed every time the target comes up for remaking. 


出处: http://www.gnu.org/software/make/manual/html_node/Phony-Targets.html


不难看出,GNU默认makefile target是一个文件,因此他会先检测同级目录下是否已存在这个文件,如果存在,则会abort掉make 进程,但目标不是文件的话,则会出现up to date的情况,这种情况需要.PHONY来避免问题的出现,phony的意思是“赝品”,在这里可以形象的理解成“不是文件”。


make V=s toolchain/compile ERROR: please fix package/tplink/wlan_tplink/Makefile - see logs/package/tplink/wlan_tplink/dump.txt for details ERROR: please fix package/mtk/applications/luci-app-mtk/Makefile - see logs/package/mtk/applications/luci-app-mtk/dump.txt for details ERROR: please fix package/mtk/drivers/applications/luci-app-mtk/Makefile - see logs/package/mtk/drivers/applications/luci-app-mtk/dump.txt for details Collecting package info: done WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig! make[1]: Entering directory '/home/felix/mydisk/enterprise_gateway' + mkdir -p /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1 + cd /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1 + mkdir -p bin lib include stamp mkdir -p /home/felix/mydisk/enterprise_gateway/build_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/stamp touch /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/.prepared make[2]: Entering directory '/home/felix/mydisk/enterprise_gateway' + mkdir -p /home/felix/mydisk/enterprise_gateway/staging_dir/host + cd /home/felix/mydisk/enterprise_gateway/staging_dir/host + mkdir -p bin lib include stamp mkdir -p /home/felix/mydisk/enterprise_gateway/build_dir/host/stamp /home/felix/mydisk/enterprise_gateway/staging_dir/host/include/sys install -m0644 /home/felix/mydisk/enterprise_gateway/tools/include/*.h /home/felix/mydisk/enterprise_gateway/staging_dir/host/include/ install -m0644 /home/felix/mydisk/enterprise_gateway/tools/include/sys/*.h /home/felix/mydisk/enterprise_gateway/staging_dir/host/include/sys/ ln -sf lib /home/felix/mydisk/enterprise_gateway/staging_dir/host/lib64 touch /home/felix/mydisk/enterprise_gateway/staging_dir/host/.prepared make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/patch' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/patch' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/patch' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/patch' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/m4' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/m4' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/m4' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/m4' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/sed' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/sed' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/sed' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/sed' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/libtool' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/libtool' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/libtool' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/libtool' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/autoconf' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/autoconf' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/autoconf' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/autoconf' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/pkg-config' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/pkg-config' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/pkg-config' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/pkg-config' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/xz' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/xz' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/xz' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/xz' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/automake' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/automake' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/automake' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/automake' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/flex' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/flex' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/flex' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/flex' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/bison' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/bison' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/bison' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/bison' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/mklibs' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/mklibs' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/mklibs' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/mklibs' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/sstrip' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/sstrip' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/sstrip' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/sstrip' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/ipkg-utils' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/ipkg-utils' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/ipkg-utils' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/ipkg-utils' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/genext2fs' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/genext2fs' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/genext2fs' make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/genext2fs' make[3]: Entering directory '/home/felix/mydisk/enterprise_gateway/tools/e2fsprogs' make -C /home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8 make[4]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[5]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[5]: 'util/subst.conf' is up to date. make[5]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[5]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[5]: 'lib/config.h' is up to date. make[5]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[5]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[5]: 'lib/dirpaths.h' is up to date. make[5]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[5]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[5]: 'lib/ext2fs/ext2_types.h' is up to date. make[5]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[5]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[5]: 'lib/blkid/blkid_types.h' is up to date. make[5]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[5]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[5]: 'lib/uuid/uuid_types.h' is up to date. make[5]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[5]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/lib/et' make[5]: 'compile_et' is up to date. make[5]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/lib/et' make[5]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/lib/ext2fs' make[5]: 'ext2_err.h' is up to date. make[5]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/lib/ext2fs' make libs make[5]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[6]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[6]: 'util/subst.conf' is up to date. make[6]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[6]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[6]: 'lib/config.h' is up to date. make[6]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[6]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[6]: 'lib/dirpaths.h' is up to date. make[6]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[6]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[6]: 'lib/ext2fs/ext2_types.h' is up to date. make[6]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[6]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[6]: 'lib/blkid/blkid_types.h' is up to date. make[6]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[6]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[6]: 'lib/uuid/uuid_types.h' is up to date. make[6]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' make[6]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/lib/et' make[6]: 'compile_et' is up to date. make[6]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/lib/et' make[6]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/lib/ext2fs' make[6]: 'ext2_err.h' is up to date. make[6]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/lib/ext2fs' making all in lib/et make[6]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/lib/et' CC error_message.c CC et_name.c CC init_et.c CC com_err.c CC com_right.c GEN_LIB libcom_err.a make[6]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/lib/et' making all in lib/ss make[6]: Entering directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/lib/ss' SUBST mk_cmds COMPILE_ET ss_err.et chmod: ss_err.h: new permissions are r--rw-rw-, not r--r--r-- chmod: ss_err.c: new permissions are r--rw-rw-, not r--r--r-- Makefile:389: recipe for target 'ss_err.c' failed make[6]: *** [ss_err.c] Error 1 make[6]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/lib/ss' Makefile:366: recipe for target 'all-libs-recursive' failed make[5]: *** [all-libs-recursive] Error 1 make[5]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' Makefile:293: recipe for target 'all' failed make[4]: *** [all] Error 2 make[4]: Leaving directory '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8' Makefile:52: recipe for target '/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/.built' failed make[3]: *** [/home/felix/mydisk/enterprise_gateway/build_dir/host/e2fsprogs-1.42.8/.built] Error 2 make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/tools/e2fsprogs' tools/Makefile:173: recipe for target 'tools/e2fsprogs/compile' failed make[2]: *** [tools/e2fsprogs/compile] Error 2 make[2]: Leaving directory '/home/felix/mydisk/enterprise_gateway' tools/Makefile:172: recipe for target '/home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/stamp/.tools_install_n' failed make[1]: *** [/home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/stamp/.tools_install_n] Error 2 make[1]: Leaving directory '/home/felix/mydisk/enterprise_gateway' /home/felix/mydisk/enterprise_gateway/include/toplevel.mk:171: recipe for target 'toolchain/compile' failed make: *** [toolchain/compile] Error 2
07-30
在 OpenWrt 编译过程中,`toolchain/compile` 报错 `Error 2` 通常与交叉编译工具链的构建失败有关。该错误可能由多种因素引起,包括依赖项缺失、配置不完整、源码同步问题或文件路径权限问题等。 ### 1. 检查交叉编译工具链的依赖项 OpenWrt 的 toolchain 编译依赖于主机上的多个开发库和工具。若某些依赖项未正确安装,可能导致工具链构建失败。确保安装了如下依赖: - `gcc`, `g++` - `libncurses5-dev` - `libssl-dev` - `flex`, `bison` - `libtool`, `autoconf`, `automake` 在基于 Debian/Ubuntu 的系统上,可使用如下命令安装: ```bash sudo apt-get install build-essential libncurses5-dev flex bison libssl-dev libtool autoconf automake ``` ### 2. 清理并重新构建工具链 有时,工具链的中间文件或缓存可能损坏,导致编译失败。可以尝试清理并重新构建工具链: ```bash make toolchain/clean make toolchain/compile V=s ``` `V=s` 参数用于启用详细输出,有助于定位具体的失败原因。 ### 3. 检查文件路径和权限问题 工具链编译过程中会生成多个中间文件和目录,例如 `/build_dir/target-xxx/toolchain/.pkgdir/` 下的内容。若这些路径不存在或权限不足,可能导致编译失败。确保构建目录存在,并且编译用户具有读写权限。 例如,检查如下路径是否存在: ```bash ls /home/hahaya/lede/build_dir/target-x86_64_musl/toolchain/.pkgdir/ ``` 若路径缺失,可以手动创建: ```bash mkdir -p /home/hahaya/lede/build_dir/target-x86_64_musl/toolchain/.pkgdir/ ``` ### 4. 检查源码完整性和配置 OpenWrt 的 toolchain 编译依赖于完整的源码和正确的配置。如果源码未完全同步或配置错误,可能导致工具链编译失败。执行如下命令清理并重新配置: ```bash make distclean make menuconfig ``` 在 `menuconfig` 中,确保目标平台(Target System)和子平台(Target Profile)选择正确,并保存配置后重新编译。 ### 5. 使用最新版本的 OpenWrt 和操作系统 某些旧版本的 OpenWrt 可能存在工具链编译的兼容性问题。根据经验,使用较新的 Ubuntu 系统(如 Ubuntu 22.04)和最新的 OpenWrt 源码可以避免许多已知问题,尤其是与工具链相关的兼容性问题 [^4]。 ### 6. 检查磁盘空间和内存 工具链编译过程对系统资源要求较高。确保系统有足够的磁盘空间(建议至少 20GB)和内存(建议至少 4GB RAM),否则可能导致编译中断或失败。 ### 7. 查看详细的错误日志 工具链编译失败时,Makefile 通常会输出具体的错误信息。启用详细输出模式可以更清晰地定位问题: ```bash make toolchain/compile V=s ``` 在输出中查找类似如下的错误: ``` Makefile:750: recipe for target '/home/hahaya/lede/build_dir/target-x86_64_musl/toolchain/.pkgdir/libc.installed' failed ``` 该信息表明在构建 `libc` 安装包时失败,可能由于源码下载失败、路径错误或权限问题导致 [^3]。 ---
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值