meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
programming:makefile [2024/03/22 09:26] niziakprogramming:makefile [2025/04/16 13:31] (current) niziak
Line 3: Line 3:
 Quick reference [[https://www.gnu.org/software/make/manual/html_node/Quick-Reference.html]] Quick reference [[https://www.gnu.org/software/make/manual/html_node/Quick-Reference.html]]
  
-[[http://aegis.sourceforge.net/auug97.pdf|Recursive Make Considered Harmfull]] +Recursive Make Considered Harmful: 
- +  * [[http://aegis.sourceforge.net/auug97.pdf|Recursive Make Considered Harmfull]] 
-[[http://make.mad-scientist.net/papers/rules-of-makefiles/]]+  * [[https://accu.org/journals/overload/14/71/miller_2004/|Recursive Make Considered Harmful]] 
 +  * [[https://news.ycombinator.com/item?id=20014348]] 
 +  [[http://make.mad-scientist.net/papers/rules-of-makefiles/]]
  
  
 === one shell === === one shell ===
  
 +NOTE: read carefully issues introduced with "one shell":
 [[https://www.gnu.org/software/make/manual/html_node/One-Shell.html|5.3.1 Using One Shell]] [[https://www.gnu.org/software/make/manual/html_node/One-Shell.html|5.3.1 Using One Shell]]
 +
 <code make> <code make>
 .ONESHELL: .ONESHELL:
Line 16: Line 20:
         cd $(<D)         cd $(<D)
         gobble $(<F) > ../$@         gobble $(<F) > ../$@
 +</code>
 +
 +alternatives w/o ''.ONESHELL''
 +
 +<code make>
 +target:
 + $(Q)( \
 + set -eo pipefail ; \
 + if [ -x "/opt/SEGGER/JLink/JLinkExe" ]; then \
 + echo "Skipping JLINK intallation (reason: already installed)."; \
 + exit 0; \
 + fi; \
 + \
 + wget -c -P /tmp --post-data "accept_license_agreement=accepted" --progress=dot:giga \
 + "https://www.segger.com/downloads/jlink/$(JLINK_VERSION).deb"; \
 + \
 + $(SUDO) apt-get update; \
 + $(SUDO) apt-get -y --fix-broken install "/tmp/$(JLINK_VERSION).deb"; \
 + \
 + rm "/tmp/${JLINK_VERSION}.deb"; \
 + make .jlink-workaround; \
 + make jlink-notice; \
 + )
 +
 </code> </code>
  
Line 37: Line 65:
  
 Special pipe "|" character is used.  Special pipe "|" character is used. 
-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
  
 obj: obj:
-  @mkdir -p $@''+  @mkdir -p $@
 </code> </code>
  
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.
  
-<code makefile>+<code make>
 all:: all::
 </code> </code>
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
  
-<code makefile>+<code make>
 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 /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 93: Line 116:
 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 =====