Skip to content

Instantly share code, notes, and snippets.

@tamakiii
Created December 11, 2023 06:05
Show Gist options
  • Save tamakiii/e800a37c356a36cffe766cd60c185df2 to your computer and use it in GitHub Desktop.
Save tamakiii/e800a37c356a36cffe766cd60c185df2 to your computer and use it in GitHub Desktop.
Variable and Environment Variable in GNU Make
$ cat Makefile
.PHONY: all

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

all:
        @echo AWS_PROFILE=$(origin AWS_PROFILE)
        @echo AWS_REGION=$(origin AWS_REGION)
        bash test.sh

$ cat test.sh
#!/bin/bash

echo AWS_PROFILE=$AWS_PROFILE
echo AWS_REGION=$AWS_REGION

$ make
AWS_PROFILE=file
AWS_REGION=file
bash test.sh
AWS_PROFILE=acme
AWS_REGION=

$ make AWS_PROFILE=hoge AWS_REGION=fuga
AWS_PROFILE=command line
AWS_REGION=command line
bash test.sh
AWS_PROFILE=hoge
AWS_REGION=fuga
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment