How to set child process' environment variable in Makefile

前端 未结 4 1703
半阙折子戏
半阙折子戏 2020-11-28 05:08

I would like to change this Makefile:

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

boot:
    @supervisor         \\
      --harmony         \\
             


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 05:19

    As MadScientist pointed out, you can export individual variables with:

    export MY_VAR = foo  # Available for all targets
    

    Or export variables for a specific target (target-specific variables):

    my-target: export MY_VAR_1 = foo
    my-target: export MY_VAR_2 = bar
    my-target: export MY_VAR_3 = baz
    
    my-target: dependency_1 dependency_2
      echo do something
    

    You can also specify the .EXPORT_ALL_VARIABLES target to—you guessed it!—EXPORT ALL THE THINGS!!!:

    .EXPORT_ALL_VARIABLES:
    
    MY_VAR_1 = foo
    MY_VAR_2 = bar
    MY_VAR_3 = baz
    
    test:
      @echo $$MY_VAR_1 $$MY_VAR_2 $$MY_VAR_3
    

    see .EXPORT_ALL_VARIABLES

提交回复
热议问题