# Makefile How to use variables defined in a config file

It took me a while to clarify how to import variables from a config file.

We have makefile.env and define environment variables there.

VM_HOST=192.168.100.1

This variable needs to be used in a makefile.

echo:
echo3:
@echo '$(VM_HOST),${VM_HOST}, $${VM_HOST}' The environment variable can be accessed by (VM_HOST) or {VM_HOST}. The environment is handled as a Make variable. Use a single dollar sign in this case. ### Read the config file on the same line The second solution is to read the file on the same line. # , , 192.168.100.1 echo: @. ./makefile.env && echo (VM_HOST), {VM_HOST},$${VM_HOST}

# , , 192.168.100.1,
echo2:
@. ./makefile.env && echo "$(VM_HOST),${VM_HOST}, $${VM_HOST},$$(VM_HOST)"

# , , $${VM_HOST}, (HDH_HOST) echo3: @. ./makefile.env && echo '(VM_HOST), {VM_HOST},$${VM_HOST}, $$(VM_HOST)' The environment variable can be accessed by $${VM_HOST}. Parentheses can’t be used for this.

The environment is handled as a Shell variable. Use two dollar sign in this case.

Be aware that if $${VM_HOST} is used in single quotes, it is handled as a string ### Shell variable becomes empty if config file is read on another line Don’t use the variable on a different line. It can’t be used in this case. # 192.168.56.102 # HOST: echo: @. ./makefile.env && echo$${HDH_HOST}
@echo "HOST: {HDH_HOST}"