简体   繁体   English

Makefile,在用户运行任何目标之前运行环境检查目标

[英]Makefile, Run environment check target before user run any targets

I want to run following environment check target checkenv before any of other targets, 我想在其他任何目标之前先执行环境检查目标checkenv

all: build_sub_target1 build_target2
clean: clean_sub_target1 clean_target2
...
...

checkenv:
    $(if $(PROJECT_ROOT), , \
      $(error $(shell echo -e '\033[41;33mFATAL: Please load project settings first. \
        Run "source PROJECT_ROOT_DIR/envsetup.sh"\033[0m')) \
    )

I want every other target run checkenv target before they actually do their task, how can I do this? 我希望每个其他目标在实际执行任务之前都运行checkenv目标,我该怎么做? Any other way except that I add checkenv to the depends list of each targets? 除了我将checkenv添加到每个目标的依赖列表之外,还有其他方法吗?
Since I have many targets in this file, and I think it's not cool to add into each targets... Should there be any potential rules to do this? 由于此文件中有许多目标,因此我认为将其添加到每个目标中并不是一件很酷的事情。
Thanks a lot for your help! 非常感谢你的帮助!

You could use make conditionals for that, so that this condition is checked while the makefile is being read and before targets get evaluated: 您可以为此使用make条件 ,以便在读取makefile时以及在评估目标之前检查此条件:

ifndef PROJECT_ROOT
$(error "Please load project settings first. Run source PROJECT_ROOT_DIR/envsetup.sh")
endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM