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/22 09:26] – 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:// | |
- | [[http:// | + | * [[https:// |
+ | * [[https:// | ||
+ | | ||
=== one shell === | === one shell === | ||
+ | NOTE: read carefully issues introduced with "one shell": | ||
[[https:// | [[https:// | ||
+ | |||
<code make> | <code make> | ||
.ONESHELL: | .ONESHELL: | ||
Line 16: | Line 20: | ||
cd $(<D) | cd $(<D) | ||
gobble $(<F) > ../$@ | 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; | ||
+ | ) | ||
+ | |||
</ | </ | ||
Line 37: | Line 65: | ||
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 58: | Line 88: | ||
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. | ||
- | < | + | < |
all:: | all:: | ||
</ | </ | ||
Line 64: | 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 79: | 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 93: | 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 ===== |