I'm using $(shell ...) gnu make function in a Makefile recipe, and it runs first before the preceding rows. Why?
A very simple example:
.PHONY: all
all:
@echo 1
@echo $(eval a=$(shell echo 2a 1>&2))2b
@echo 3 $(a)
The output is:
2a
1
2b
3
First runs the $(shell ...) line (2a), then the other lines. How can I manage to run the $(shell ...) function when its row runs in the recipe, in this order?
1
2a
2b
3
Edit:
Without $(shell ...) it works as I expected:
.PHONY: all
all:
@echo 1
$(eval a=a)
@echo 2 $(a)
$(eval a=b)
@echo 3 $(a)
Output:
1
2 a
3 b
Edit 2:
Here is a part of the original Makefile. The pieces at >>> show the essence of my problem: I want to put the output of udisksctl into a make variable instead of file [email protected] (and do the same with [email protected]).
$(HDIMG): $(BOOTBLOCK_MBR_BIN) $(BOOTBLOCK_EXT2_BIN) $(LOADER_BIN) | $(DESTDIR)
dd if=/dev/zero [email protected] bs=1 seek=$(PSIZEB) count=0 2>/dev/null
$(MKFSEXT2) -F [email protected] >/dev/null
dd if=$(word 2,$^) [email protected] conv=notrunc 2>/dev/null
cp $< $@
dd if=/dev/zero of=$@ bs=1 seek=$(HDSIZEB) count=0 2>/dev/null
echo $(PFDISK) | $(TR) | $(FDISK) $@ >/dev/null
dd [email protected] of=$@ bs=512 seek=$(PSTART) conv=sparse,notrunc iflag=fullblock 2>/dev/null
>>> udisksctl loop-setup --file $@ --offset $(PSTARTB) --size $(PSIZEB) >[email protected]
sed -i -e 's/.* //;s/\.//' [email protected]
cat [email protected]
>>> udisksctl mount --block-device $$(cat [email protected]) >[email protected]
sed -i -e 's/.* //;s/\.//' [email protected]
cat [email protected]
#
mkdir -p $$(cat [email protected])/boot/
cp $(word 2,$^) $$(cat [email protected])/boot/
#/sbin/filefrag -b512 -e /
#
udisksctl unmount --block-device $$(cat [email protected])
udisksctl loop-delete --block-device $$(cat [email protected])
rm [email protected]
.ONESHELLfeature so that the entire recipe is passed to the same shell without needing semicolon/backslash. See gnu.org/software/make/manual/html_node/One-Shell.html - MadScientist