2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

How to pass args or environment variables with Makefile and make command on #Linux

Last updated at Posted at 2019-12-09

arg in Makefile

$(FOO)

env variable

FOO=BAR make

command arg

make FOO=BAR

Makefile

send:
	echo $(MESSAGE1) $(MESSAGE2)

Run

$ make send MESSAGE1=YES MESSAGE2=OK
echo YES OK
YES OK
$ make send MESSAGE1= MESSAGE2=
echo

$ make send
echo

environment variable

# specify env variables directly

$ MESSAGE1=YES MESSAGE2=OK make send
echo YES OK
YES OK

$ MESSAGE1=YES make send MESSAGE2=OK
echo YES OK
YES OK

# args overwrite env ?

$ MESSAGE1=NO MESSAGE2=NG make send
echo NO NG
NO NG
$ MESSAGE1=NO MESSAGE2=NG make send MESSAGE1=YES MESSAGE2=OK
echo YES OK
YES OK

# export env variable works

$ export MESSAGE1=YES
$ make send
echo YES
YES

$ export MESSAGE2=OK
$ make send
echo YES OK
YES OK

Ref

makefile - Passing additional variables from command line to make - Stack Overflow

JP

make コマンドに引数を渡す方法

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?