In my Makefile, I have some code that checks for network connectivity. This code takes a decent amount of time to run and I would only like to run it if another target fails to build.
all: files network
# compile files
files:
# get files from network resources
network:
# check for network connectivity
# echo and return an error if it's not available
Execution Order:
if not network:
# exit with error
if not files:
# exit with error
if not all:
# exit with error
In the above example, I would like the network target to be "made", only if the files target fails to get "made".
Execution Order:
if not files:
if not network:
# exit with error
if not all:
# exit with error
To ignore errors in a recipe line, write a ' - ' at the beginning of the line's text (after the initial tab). The ' - ' is discarded before the line is passed to the shell for execution.
When you type make or make [target] , the Make will look through your current directory for a Makefile. This file must be called makefile or Makefile . Make will then look for the corresponding target in the makefile. If you don't provide a target, Make will just run the first target it finds.
The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.
A simple makefile consists of “rules” with the following shape: target … : prerequisites … recipe … … A target is usually the name of a file that is generated by a program; examples of targets are executable or object files. A target can also be the name of an action to carry out, such as ' clean ' (see Phony Targets).
Recursive make is your friend here I'm afraid.
.PHONY: all
all:
${MAKE} files || ${MAKE} network
If make files succeeds, your work is done and the exit code is success. On failure, the exit code is that for make network.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With