I'm trying to put together some complicated makefile rules to automate building a project against multiple compilers. I have one rule that creates some dynamically generated variables and assigns variables to them, then passes those variables along to a call to build a separate rule.
.PHONY: all
all:
@echo "Detected CPULIST:${CPULIST_DETECTED}"
@echo "CPULIST:${CPULIST}"
@for cpu in $(CPULIST_DETECTED); do \
echo "CPU:$${cpu}:"; \
eval VARIANTLIST_DETECTED=$(shell 2>&1 find ./.build/linux/$$cpu -mindepth 1 -maxdepth 1 | grep -v '\.svn' | grep -v warning ); \
eval echo "Detected Variant List:$${VARIANTLIST_DETECTED}"; \
eval variant_$${cpu}=$${cpu}; \
eval echo "variant_\$${cpu}:\$${variant_$${cpu}}"; \
$(MAKE) build CPULIST=$${cpu}; \
done
.PHONY: build
build: sanity_check $(TARGET)
@true
I'm having two issues. The first is that, despite double-escaping cpu
via $$cpu
, it translates to null in the line:
eval VARIANTLIST_DETECTED=$(shell 2>&1 find ./.build/linux/$$cpu -mindepth 1 -maxdepth 1 | grep -v '\.svn' | grep -v warning ); \
So, the find command searches against ./.build/linux/
for each iteration of the loop rather than looping through ./.build/linux/arm
and ./.build/linux/x86
like I would expect. I've included a post where this is described in the references below. I suspect this might be causing a problem because I'm attempting this within a rule itself rather than in the global assignment portion of the makefile (before the rules).
The other problem is occurring at the exact same line. It seems that the shell
command is evaluated, assigned to VARIANTLIST_DETECTED
, but then VARIANTLIST_DETECTED
is executed as if it were a command, since I get the following error during build:
Detected CPULIST:arm x86
CPULIST:
CPU:arm:
/bin/sh: 3: ./.build/linux/x86: Permission denied
Detected Variant List:
variant_arm:arm
It's attempting to run the first result in my query as if it were a command. That line should also be something like ./.build/linux/x86/so
.
How do I go about resolving these two issues? They are the last two thorns impeding completion of my makefiles.
Thanks!
References
- Assign a makefile variable value to a bash command result?, Accessed 2014-06-19,
<https://stackoverflow.com/questions/2373081/assign-a-makefile-variable-value-to-a-bash-command-result>