Skip to content

Instantly share code, notes, and snippets.

@tamakiii
Last active December 11, 2023 05:52
Show Gist options
  • Save tamakiii/cd0df1c29b7da4966da2f01ac46042a8 to your computer and use it in GitHub Desktop.
Save tamakiii/cd0df1c29b7da4966da2f01ac46042a8 to your computer and use it in GitHub Desktop.
GNU Make: export AWS_PROFILE with `:=`, `=` and `?=`

With export AWS_PROFILE :=

$ cat Makefile
.PHONY: test

export AWS_PROFILE := acme
export AWS_REGION := us-west-2

test:
        @echo "AWS_PROFILE=$(AWS_PROFILE) (origin: $(origin AWS_PROFILE))"
        @echo "AWS_REGION=$(AWS_REGION) (origin: $(origin AWS_REGION))"

$ make
AWS_PROFILE=acme (origin: file)
AWS_REGION=us-west-2 (origin: file)

$ make AWS_PROFILE=hoge
AWS_PROFILE=hoge (origin: command line)
AWS_REGION=us-west-2 (origin: file)

$ AWS_PROFILE=fuga make
AWS_PROFILE=acme (origin: file)
AWS_REGION=us-west-2 (origin: file)

$ (export AWS_PROFILE=vaa && make)
AWS_PROFILE=acme (origin: file)
AWS_REGION=us-west-2 (origin: file)

With export AWS_PROFILE ?=

$ cat Makefile
.PHONY: test

export AWS_PROFILE ?= acme
export AWS_REGION ?= us-west-2

test:
        @echo "AWS_PROFILE=$(AWS_PROFILE) (origin: $(origin AWS_PROFILE))"
        @echo "AWS_REGION=$(AWS_REGION) (origin: $(origin AWS_REGION))"

$ make
AWS_PROFILE=acme (origin: file)
AWS_REGION=us-west-2 (origin: file)

$ make AWS_PROFILE=hoge
AWS_PROFILE=hoge (origin: command line)
AWS_REGION=us-west-2 (origin: file)

$ AWS_PROFILE=fuga make
AWS_PROFILE=fuga (origin: environment)
AWS_REGION=us-west-2 (origin: file)

$ (export AWS_PROFILE=vaa && make)
AWS_PROFILE=vaa (origin: environment)
AWS_REGION=us-west-2 (origin: file)

With export AWS_PROFILE =

$ cat Makefile
.PHONY: test

export AWS_PROFILE = acme
export AWS_REGION = us-west-2

test:
        @echo "AWS_PROFILE=$(AWS_PROFILE) (origin: $(origin AWS_PROFILE))"
        @echo "AWS_REGION=$(AWS_REGION) (origin: $(origin AWS_REGION))"

$ make
AWS_PROFILE=acme (origin: file)
AWS_REGION=us-west-2 (origin: file)

$ make AWS_PROFILE=hoge
AWS_PROFILE=hoge (origin: command line)
AWS_REGION=us-west-2 (origin: file)

$ AWS_PROFILE=fuga make
AWS_PROFILE=acme (origin: file)
AWS_REGION=us-west-2 (origin: file)

$ (export AWS_PROFILE=vaa && make)
AWS_PROFILE=acme (origin: file)
AWS_REGION=us-west-2 (origin: file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment