5 ms·
This introduction neglects to mention that Makefile rules are primarily rules to derive files (usually from other files). Make will not re-run a rule when the t
by shoo 10y ago
This introduction neglects to mention that Makefile rules are primarily rules to derive files (usually from other files). Make will not re-run a rule when the target (file) generated by the rule is already up to date.
From this perspective, a well structured Makefile can be thought of as a pipeline/graph of functions, that derive values (files) from previously known values (files).
Expressing a build process in this kind of way makes it possible to support incremental / distributed build in a fairly natural / obvious way.
It is less obvious how to support incremental / distributed builds for the more general kind of imperative build script that does a bunch of side effects (e.g. the style of build script you'd get using something like ant).
- nneonneo 10y agoFor anyone who's curious: you can use a ".PHONY" target to force targets to be rebuilt (i.e. that they don't correspond to real files). All dependencies of the .PHONY pseudo-target will be rebuilt unconditionally when encountered. Typically, "all", "clean", "install", etc. will all be phony targets as the goal isn't to literally make a file called "all". The syntax is simple: .PHONY: all clean install marks "all", "clean" and "install" as phony. Even if the file "all" happens to exist, "make all" will still trigger the build.
- Bromskloss 10y ago> All dependencies of the .PHONY pseudo-target will be rebuilt unconditionally when encountered. To be clear, they will rebuilt only if they are not already up to date relative to their own dependencies, right?
- rahkiin 10y agoyes. Phony is only about making sure that 'all' is seen as target, not as file or folder
- lifthrasiir 10y agoI prefer to put the phony rule right before the actual rules, it's better for understanding: .PHONY: all all: ... .PHONY: clean clean: ...
- ahawkins 10y agoYes, not mentioning .PHONY encourages people to do things incorrectly and not inline with how make actually works.
- amelius 10y agoThis sounds nice, except that the only kinds of dependencies are files (e.g. variables are excluded), and the dependencies should be mentioned explicitly, or things get ugly, especially when using non-standard compilers/tools.
- gkya 10y agoNo need to explicitly declare dependencies, you have wildcards and macros at hand to manage redundancy (1). If the compiler/program accepts a file and produces another, it can be used just as easily as the C compiler. My website uses awk, m4 and html-tidy on a pipeline to produce HTML, and with 45 lines of make (with about 10-15% whitespace) I build everything, with html-tidy being optional.
- amelius 10y agoBut some languages allow an "#include / import" construct. You'll have to somehow walk all those dependencies and convert them into something Make understands.
- coldtea 10y agoWhy would that be the responsibility of Make? Of course you need to convert those externally -- with e.g. the C preprocessor for C files...
- amelius 10y agoWell, Make could figure them out, for example by using the Linux ptrace syscall, or by using libfuse. However, my biggest problem with Make is still that it does not allow for dependencies in the form of variables.
- LukeShu 10y agoWhat do you mean by "dependencies in the form of variables"?