meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
programming:makefile [2024/03/19 13:00] – niziak | programming:makefile [2025/04/16 13:31] (current) – niziak | ||
---|---|---|---|
Line 3: | Line 3: | ||
Quick reference [[https:// | Quick reference [[https:// | ||
- | [[http:// | + | Recursive Make Considered Harmful: |
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
- | [[http:// | ||
+ | === one shell === | ||
+ | NOTE: read carefully issues introduced with "one shell": | ||
+ | [[https:// | ||
+ | <code make> | ||
+ | .ONESHELL: | ||
+ | foo : bar/lose | ||
+ | cd $(<D) | ||
+ | gobble $(<F) > ../$@ | ||
+ | </ | ||
+ | |||
+ | alternatives w/o '' | ||
+ | |||
+ | <code make> | ||
+ | target: | ||
+ | $(Q)( \ | ||
+ | set -eo pipefail ; \ | ||
+ | if [ -x "/ | ||
+ | echo " | ||
+ | exit 0; \ | ||
+ | fi; \ | ||
+ | \ | ||
+ | wget -c -P /tmp --post-data " | ||
+ | " | ||
+ | \ | ||
+ | $(SUDO) apt-get update; \ | ||
+ | $(SUDO) apt-get -y --fix-broken install "/ | ||
+ | \ | ||
+ | rm "/ | ||
+ | make .jlink-workaround; | ||
+ | make jlink-notice; | ||
+ | ) | ||
+ | |||
+ | </ | ||
+ | |||
+ | === disable built-in rules === | ||
+ | |||
+ | <code makefile> | ||
+ | # Disable built-in rules and variables | ||
+ | MAKEFLAGS += --no-builtin-rules | ||
+ | MAKEFLAGS += --no-builtin-variables | ||
+ | </ | ||
=== VPATH === | === VPATH === | ||
+ | |||
[[https:// | [[https:// | ||
Line 18: | Line 63: | ||
=== order only prereq === | === order only prereq === | ||
+ | |||
Special pipe " | Special pipe " | ||
- | If any //$(objects)// has to be build, then //obj// has to be build first. | + | If any '' |
- | But if //obj// is out of date or missing, this doesn' | + | But if '' |
+ | |||
<code make> | <code make> | ||
$(objects): | obj | $(objects): | obj | ||
obj: | obj: | ||
- | @mkdir -p $@'' | + | @mkdir -p $@ |
</ | </ | ||
Line 35: | Line 83: | ||
=== double colon rules === | === double colon rules === | ||
+ | |||
[[https:// | [[https:// | ||
- | It can be usefull, when target needs to be updates 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. |
+ | |||
+ | < | ||
all:: | all:: | ||
</ | </ | ||
Line 44: | Line 94: | ||
Another scenario is to find source .c file in different dirs | Another scenario is to find source .c file in different dirs | ||
- | < | + | < |
build/%.o:: test/%.c | build/%.o:: test/%.c | ||
$(COMPILE) $(CFLAGS) $< -o $@ | $(COMPILE) $(CFLAGS) $< -o $@ | ||
Line 59: | Line 109: | ||
* 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 / | ||
- | * *$(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 72: | Line 116: | ||
For whole file: <code makefile> | For whole file: <code makefile> | ||
For single target: | For single target: | ||
- | < | + | |
+ | < | ||
.NOTPARALLEL: | .NOTPARALLEL: | ||
.NOTPARALLEL: | .NOTPARALLEL: | ||
</ | </ | ||
- | [[https:// | + | [[https:// |
- | ]] | + | |
===== Prevent one target from parallel run ===== | ===== Prevent one target from parallel run ===== |