Last active
March 5, 2016 08:23
-
-
Save mstrehler/056d025b49eed7b1eb04 to your computer and use it in GitHub Desktop.
Flexible handling of variables in a makefile
This file contains 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
# Example for the ultimate flexible variable handling in a makefile. | |
# Code adapted from "The GNU Make Book", pos. 300 (e-book). | |
# | |
# Case 1: Default in makefile | |
# With no environment variable and no option set in command line, | |
# TEST contains foo: | |
# $ make | |
# foo file | |
# | |
# Case 2: Environment variable | |
# With environment variable set, TEST contains bar | |
# $ export TEST=bar | |
# $ make | |
# bar environment | |
# | |
# Case 3: Command line variable | |
# Setting the variable via command line beats all. | |
# $ make TEST=foobar | |
# foobar command line | |
# if TEST is not set, it will set to foo; | |
# otherwise, it is left unchanged. | |
TEST ?= foo | |
PHONY: all | |
all: | |
$(info $(TEST) $(origin TEST)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment