This could or not be a duplicate of Makefile Variable Assignment Executes Early
Is it possible to define a condition and reuse it later?
MAIN_FILE_PATH := main
define copy_resulting_pdf=
if [[ -f "${MAIN_FILE_PATH}" ]] \
then \
cp "${MAIN_FILE_PATH}" "${MAIN_FILE_PATH}.pdf"; \
else \
$(error Error: The PDF ${MAIN_FILE_PATH} was not generated!); \
fi
endef
all:
echo doing other things.
$(copy_resulting_pdf)
other:
echo doing more other things.
$(copy_resulting_pdf)
When run this, make does not even start to build the all
rule. It just throws out:
Makefile:14: *** Error: The PDF main was not generated!. Stop.