简体   繁体   中英

environment variable not set in makefile

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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