environment variable not set in makefile

左心房为你撑大大i 提交于 2020-06-18 11:16:30

问题


I want to trigger unit test and integration test in a Makefile, my current implementation is like this:

all: unittest integration
unittest:
    $(ECHO) @echo 'Running unittest'
    @unset TYPE
    @nosetests
integration:
    $(ECHO) @echo 'Running integration test'
    @export TYPE=integration
    @nosetests

but I'm having problems with setting environment variables, when I run make integration , the TYPE environment variable would not be set, if I set the environment variable manually with export TYPE=integration, then I run make unittest, the environment variable would not be unset. How to solve this?


回答1:


Each command in a recipe is run in a separate shell. The shell which runs export TYPE immediately exits; then the next command is run in a new, fresh instance, which of course does not have this setting.

The shell has specific syntax for setting a variable for the duration of one command; use that.

all: unittest integration
unittest:
    echo 'Running unittest'
    TYPE= nosetests
integration:
    echo 'Running integration test'
    TYPE=integration nosetests

Incidentally, you should not use upper case for your own variables; these names are reserved for system use.



来源:https://stackoverflow.com/questions/34943849/environment-variable-not-set-in-makefile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!