Last active
June 7, 2021 12:05
-
-
Save pnowosie/b1d7cab1f1c31668f0dc3283c392b025 to your computer and use it in GitHub Desktop.
Makefile - Parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Don't fear the Makefile | |
| # ...but learn to used it efectively | |
| InMakeVar = "Make var" | |
| FromEnvWithDefault ?= "default from make" | |
| before_var = "something" | |
| all: | |
| echo "Zmienna zdefiniowana w env vars: $${HOME}" | |
| # we can provide additional variables to the invocation | |
| #> `ItsMe=PAWEL make` or `make [target] ItsMe=PaWeL` | |
| echo "Zmienna $${ItsMe}" | |
| # use a variable defined in the file | |
| echo "This was define above: ${InMakeVar}" | |
| # we can provide default values if not define by env | |
| # make FromEnvWithDefault="from env" | |
| echo "Where this comes from: ${FromEnvWithDefault}" | |
| echo: | |
| # To test invocations with a target | |
| #> make echo ItsMe=PawLo | |
| echo "Hello, it's me $${ItsMe} from $${HOME}." | |
| time: | |
| # and we can exec commands and store results | |
| # we need '$$' as it works here as env var - also note the ';' | |
| @now=$$(date +'%Y-%m-%d %H:%M:%S'); \ | |
| echo "Today is nice day $${now}" | |
| # we can provide target specific variable, which even can be calculated | |
| # note: task name needs to be repeated | |
| time2: day_of_week = $$(date +'%A -[%S]') | |
| # We can set another target specific var repeating the form | |
| time2: other_var := "other var" | |
| time2: | |
| echo "Today is ${day_of_week}, but the other is ${other_var}" | |
| # Note param to 'step-before' is provided here, not just before the task | |
| # also try to change assignment operator to `+=` so it combine both values: `"something" "Is it even possible?"` | |
| step-before: before_var := "Is it even possible?" | |
| cascade: step-before | |
| # but we don't get value set in `step-before` but the value set above | |
| echo "Actually variable set in file: ${before_var}" | |
| step-before: | |
| echo "In before step: ${before_var}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment