meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
programming:makefile [2024/03/22 09:25] niziak |
programming:makefile [2024/03/22 09:30] (current) niziak |
||
---|---|---|---|
Line 16: | Line 16: | ||
cd $(<D) | cd $(<D) | ||
gobble $(<F) > ../$@ | gobble $(<F) > ../$@ | ||
+ | </code> | ||
+ | |||
+ | === disable built-in rules === | ||
+ | |||
+ | <code makefile> | ||
+ | # Disable built-in rules and variables | ||
+ | MAKEFLAGS += --no-builtin-rules | ||
+ | MAKEFLAGS += --no-builtin-variables | ||
</code> | </code> | ||
=== VPATH === | === VPATH === | ||
+ | |||
[[https://www.gnu.org/software/make/manual/html_node/General-Search.html]] | [[https://www.gnu.org/software/make/manual/html_node/General-Search.html]] | ||
Line 30: | Line 39: | ||
If any //$(objects)// has to be build, then //obj// has to be build first. | If any //$(objects)// has to be build, then //obj// has to be build first. | ||
But if //obj// is out of date or missing, this doesn't force //$(objects)// to built. | But if //obj// is out of date or missing, this doesn't force //$(objects)// to built. | ||
+ | |||
+ | |||
<code make> | <code make> | ||
$(objects): | obj | $(objects): | obj | ||
Line 49: | Line 60: | ||
It can be useful, when target needs to be updated and command to update target depends on which prerequisite file caused the update. | It can be useful, when target needs to be updated and command to update target depends on which prerequisite file caused the update. | ||
- | <code makefile> | + | <code make> |
all:: | all:: | ||
</code> | </code> | ||
Line 55: | Line 66: | ||
Another scenario is to find source .c file in different dirs | Another scenario is to find source .c file in different dirs | ||
- | <code makefile> | + | <code make> |
build/%.o:: test/%.c | build/%.o:: test/%.c | ||
$(COMPILE) $(CFLAGS) $< -o $@ | $(COMPILE) $(CFLAGS) $< -o $@ | ||
Line 70: | Line 81: | ||
* if no prereq, command is always executed | * if no prereq, command is always executed | ||
* Order of execution is not guaranteed | * Order of execution is not guaranteed | ||
- | |||
- | === macros === | ||
- | |||
- | * *$(dir /path/to/file.txt)* get path part only | ||
- | * *$(basename src/foo.c src-1.0/bar hacks)* - produces the result ‘src/foo src-1.0/bar hacks’. | ||
- | * *$(notdir src/foo.c hacks)* - result ‘foo.c hacks’. | ||
- | |||
====== Parallel make ====== | ====== Parallel make ====== | ||
Line 84: | Line 88: | ||
For whole file: <code makefile>.NOTPARALLEL:</code> | For whole file: <code makefile>.NOTPARALLEL:</code> | ||
For single target: | For single target: | ||
- | <code makefile> | + | |
+ | <code make> | ||
.NOTPARALLEL: %.a | .NOTPARALLEL: %.a | ||
.NOTPARALLEL: foo.c bar.c | .NOTPARALLEL: foo.c bar.c | ||
</code> | </code> | ||
- | [[https://stackoverflow.com/questions/8496135/parallel-makefile-requires-dependency-ordering|Parallel makefile requires dependency ordering | + | [[https://stackoverflow.com/questions/8496135/parallel-makefile-requires-dependency-ordering|Parallel makefile requires dependency ordering]] |
- | ]] | + | |
===== Prevent one target from parallel run ===== | ===== Prevent one target from parallel run ===== |