Is it bad practice to have something like:
all:
in a Makefile, to enforce the user to specify the target, and ignore the default one?
By default, the goal is the first target in the makefile (not counting targets that start with a period). Therefore, makefiles are usually written so that the first target is for compiling the entire program or programs they describe.
The default behavior of make is to run the first target in the Makefile if you don't specify a target as a command-line argument. If you like to override this behavior, there is the . DEFAULT: special target.
With no argument, make runs as many jobs simultaneously as possible. If there is more than one `-j' option, the last one is effective. See section Parallel Execution, for more information on how commands are run. Note that this option is ignored on MS-DOS.
Without arguments, make builds the first target that appears in its makefile, which is traditionally a target named all. make decides whether a target needs to be regenerated by comparing file modification times.
all
is not necessarily the default target. The default target is the first one defined in your makefile. Also, if you leave an empty target as the default one (and are sure that there's no other all
target with rules somewhere else in the makefile), make
's behavior might be a little bit puzzling. I'd suggest to let the default behavior print an appropriate error message, such as:
error:
@echo "Please choose one of the following target: compile, install, uninstall"
@# Alternatively: "Please RTFI(nstall)F(ile)"
@exit 2
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