From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/gnu_make/parsing-makefiles.html | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 devdocs/gnu_make/parsing-makefiles.html (limited to 'devdocs/gnu_make/parsing-makefiles.html') diff --git a/devdocs/gnu_make/parsing-makefiles.html b/devdocs/gnu_make/parsing-makefiles.html new file mode 100644 index 00000000..2210e939 --- /dev/null +++ b/devdocs/gnu_make/parsing-makefiles.html @@ -0,0 +1,23 @@ +

How Makefiles Are Parsed

GNU make parses makefiles line-by-line. Parsing proceeds using the following steps:

  1. Read in a full logical line, including backslash-escaped lines (see Splitting Long Lines).
  2. +
  3. Remove comments (see What Makefiles Contain).
  4. +
  5. If the line begins with the recipe prefix character and we are in a rule context, add the line to the current recipe and read the next line (see Recipe Syntax).
  6. +
  7. Expand elements of the line which appear in an immediate expansion context (see How make Reads a Makefile).
  8. +
  9. Scan the line for a separator character, such as ‘:’ or ‘=’, to determine whether the line is a macro assignment or a rule (see Recipe Syntax).
  10. +
  11. Internalize the resulting operation and read the next line.
  12. +

An important consequence of this is that a macro can expand to an entire rule, if it is one line long. This will work:

myrule = target : ; echo built
+
+$(myrule)
+
+

However, this will not work because make does not re-split lines after it has expanded them:

define myrule
+target:
+        echo built
+endef
+
+$(myrule)
+
+

The above makefile results in the definition of a target ‘target’ with prerequisites ‘echo’ and ‘built’, as if the makefile contained target: echo built, rather than a rule with a recipe. Newlines still present in a line after expansion is complete are ignored as normal whitespace.

In order to properly expand a multi-line macro you must use the eval function: this causes the make parser to be run on the results of the expanded macro (see Eval Function).

+

+ Copyright © 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Free Software Foundation, Inc.
Licensed under the GNU Free Documentation License.
+ https://www.gnu.org/software/make/manual/html_node/Parsing-Makefiles.html +

+
-- cgit v1.2.3