Issue
I am facing an issue with my makefile, as it hangs when I issue make debug
.
Here is the directory's tree:
├── makefile
└── src
└── config
├── config_192_168_3_226.h
└── config.h
And here is the content of the three files:
makefile:
BOARD := $(shell awk '/BOARD_VERS/{print $NF}' $(echo "src/config/$(grep -oP "(?<=\")(.*?)(?=\")" src/config/config.h)"))
.PHONY: debug
# Debug rule
debug:
@echo 'BOARD :' $(BOARD)
config.h:
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config_192_168_3_226.h"
#endif /* _CONFIG_H */
config_192_168_3_226.h:
#define BOARD_VERS V1
The command I use to set BOARD variable is working correctly, but it does not when issued inside my makefile.
awk '/BOARD_VERS/{print $NF}' $(echo "src/config/$(grep -oP "(?<=\")(.*?)(?=\")" src/config/config.h)")
What is wrong with my makefile? Thank you.
Solution
The $
is special to make. If you want to pass it to the shell, in BOTH a recipe AND in a $(shell ...)
function, you have to escape it as $$
.
So here:
BOARD := $(shell awk '/BOARD_VERS/{print $NF}' $(echo "src/config/$(grep -oP "(?<=\")(.*?)(?=\")" src/config/config.h)"))
The $(echo ...)
is seen by make as a make variable with a long, bizarre name and expands to the empty string. So basically you're passing no arguments to awk
which means that it's reading stdin to operate on, which is why it appears to hang.
You have to double all the $
that are not make variables:
BOARD := $(shell awk '/BOARD_VERS/{print $$NF}' $$(echo "src/config/$$(grep -oP "(?<=\")(.*?)(?=\")" src/config/config.h)"))
Answered By - MadScientist