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

时间:2021-01-27 06:58:38

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? Any other way except that I add checkenv to the depends list of each targets?
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!

我希望每个其他目标在实际执行任务之前运行checkenv目标,我该怎么做?除了我将checkenv添加到每个目标的依赖列表之外的任何其他方式?由于我在此文件中有许多目标,并且我认为添加到每个目标中并不酷...应该有任何潜在的规则来执行此操作吗?非常感谢你的帮助!

1 个解决方案

#1


1  

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

#1


1  

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