如何在Makefile中设置环境变量 [英] How to set environment variable in Makefile

查看:2712
本文介绍了如何在Makefile中设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改这个Makefile:

I would like to change this Makefile:

SHELL := /bin/bash
PATH  := node_modules/.bin:$(PATH)

boot:
    @supervisor         \
      --harmony         \
      --watch etc,lib       \
      --extensions js,json      \
      --no-restart-on error     \
        lib

test:
    NODE_ENV=test mocha         \
      --harmony             \
      --reporter spec       \
        test

clean:
    @rm -rf node_modules

.PHONY: test clean

to:

SHELL := /bin/bash
PATH  := node_modules/.bin:$(PATH)

boot:
    @supervisor         \
      --harmony         \
      --watch etc,lib       \
      --extensions js,json      \
      --no-restart-on error     \
        lib

test: NODE_ENV=test
test:
    mocha                   \
      --harmony             \
      --reporter spec       \
        test

clean:
    @rm -rf node_modules

.PHONY: test clean

不幸的是第二个不起作用过程仍然使用默认的 NODE_ENV

Unfortunately the second one does not work (the node process still runs with the default NODE_ENV.

我错过了什么?

推荐答案

默认情况下,使变量未导出到进程环境中调用...。但是,您可以使用make的导出强制他们这样做。更改:

Make variables are not exported into the environment of processes make invokes... by default. However you can use make's export to force them to do so. Change:

test: NODE_ENV = test

test: export NODE_ENV = test

(假设你有一个足够现代的GNU make版本)。

(assuming you have a sufficiently modern version of GNU make).

这篇关于如何在Makefile中设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆