110110# variable assignment: a single variable can be assigned per rule
111111#
112112# with normal-prerequisites and order-only-prerequisites being space separated lists
113- # of target names. Note that while:
114- #
115- # t:; @echo 1
116- # @echo 2
117- #
118- # defines one rule, the following defines two (both of which have a recipe):
119- #
120- # t:; @echo 1
121- # t:
122- # @echo 2
123- #
124- # and, in the second case, Make will complain:
125- # warning: overriding recipe for target 't'
126- # warning: ignoring old recipe for target 't'
127- # THe following defines three rules only the last of which has a recipe:
128- #
129- # t: A := 1
130- # t: B := 2
131- # t: u v | x y ; @echo 1
132- # @echo 2
133- #
113+ # of target names.
134114# + Recipe: a sequence of commands executed in the shell. A recipe (and thus a rule)
135- # ends at the next target line, variable assignment, define ... endef
115+ # ends at the next target line, variable assignment, define ... endef
136116# + Target: an abstraction representing a task/goal to achieve which is defined in
137- # terms of, potentially, many rules.
117+ # terms of, potentially, many rules.
118+ # + Normal (single-colon) targets can have only one recipe and to mirror this we
119+ # allow for them to have only one description.
120+ # + double-colon targets (i.e., targets defined by double-colon rules) can have
121+ # multiple descriptions (as they can have multiple recipes).
138122# + Target line: the top-line (the header) of a Makefile rule
139123# + Target name: a (string) label for a target
140124# + Description of a rule: comments starting with ##, ##! or ##% placed above the
141- # target line of a rule or inline. Inline descriptions cannot be placed
142- # after a inline recipe.
143- # + Description precedense:
144- # + An inline description of a rule is ignorred if a top description for that rule
145- # is present.
146- # + A description of a rule with a target line on like K overrides a description of
147- # a rule defined prioer to line K. A warning is issued when this happes. This
148- # means that, in the end, the documentation of a (non-double-colon) target is
149- # taken from only one of its defining rules (the same thing applies for the recipe
150- # used to build a target).
151- # + Double-colon targets: a double-colon target is a target that can have multiple
152- # recipes and each one of them can have its own description.
125+ # target line of a rule or inline. Inline descriptions cannot be placed after an
126+ # inline recipe.
127+ # + The last rule with a description defines the description of a normal target, while
128+ # every double-colon rule with a description defines a double-colon target with a
129+ # new ~index.
153130
154131function max (x , y ) {
155132 return (x >= y) ? x : y
@@ -900,8 +877,9 @@ BEGIN {
900877 # 5. Targets of the form $(TARGET-NAME) and ${TARGET-NAME} are detected.
901878 # 6. FS = ":" is assumed.
902879 #
903- # Since we cannot use negative lookahead, (:|::)([^=:]|$)( *|.*;) simulates no = after the last colon.
904- # We need to add a colon in the negative character class to prevent matching e.g., x ::= 1
880+ # Since we cannot use negative lookahead, (:|::)([^=:]|$)( *|.*;) simulates no = after
881+ # the last colon. We need to add a colon in the negative character class to prevent
882+ # matching e.g., x ::= 1
905883 #
906884 # Note: we have to use *(:|::) instead of *{1,2} because the latter doesn't work in mawk.
907885 TARGETS_REGEX = TARGETS_REGEX == " " ? " ^ *[^.#][ ,a-zA-Z0-9$_/%.(){}-]* *&?(:|::)([^=:]|$)( *|.*;)" : TARGETS_REGEX
@@ -926,7 +904,7 @@ BEGIN {
926904 # a section uses a targtet / variable as an anchor
927905 split (" " , TARGETS_SECTION_DATA)
928906
929- # the index for the next double-colon target (the key doesn't include ~k)
907+ # the index for the next double-colon rule with description (the key doesn't include ~k)
930908 split (" " , TARGETS_DC_COUNTER)
931909
932910 # map index to target name (order is important)
@@ -959,7 +937,7 @@ BEGIN {
959937 FILES_PROCESSED = " "
960938 SPACES_TABS_REGEX = " ^[ \t ]+|[ \t ]+$"
961939
962- # used to signify double-colon targets in the documentation
940+ # used to decorate double-colon targets in the documentation
963941 DOUBLE_COLON_SEPARATOR = " ~"
964942
965943 IN_MULTILINE_BACKSLASH_COMMENT = 0
@@ -986,18 +964,14 @@ FNR == 1 {
986964 }
987965}
988966
989- # Skip backslash multiline comment
967+ # Skip backslash multiline comments
990968# FIXME: at some point we might allow for them to constitute anchor documentation
991969# but for the moment they are simply ignored
992970/^ * #[^ \\ ]*? ([\\ ]{2 } )* \\ $ / || IN_MULTILINE_BACKSLASH_COMMENT {
993971 if (! IN_MULTILINE_BACKSLASH_COMMENT) {
994- # printf("--> LINE: %s (start of a backslash multiline comment) %s\n", FNR, $0)
995972 IN_MULTILINE_BACKSLASH_COMMENT = 1
996973 } else if (! ($0 ~ /^ [^ \\ ]*? ([\\ ]{2 } )* \\ $ /)) {
997- # printf("--> LINE: %s (last line of backslash multiline comment) %s\n", FNR, $0)
998974 IN_MULTILINE_BACKSLASH_COMMENT = 0
999- } else {
1000- # printf("--> LINE: %s (still in backslash multiline comment) %s\n", FNR, $0)
1001975 }
1002976
1003977 next
@@ -1013,17 +987,12 @@ FNR == 1 {
1013987}
1014988
1015989IN_RULE && $0 ~ RECIPEPREFIX || IN_MULTILINE_BACKSLASH_COMMAND {
1016- # printf("--> LINE: %s (in recipe of rule: %s)\n", FNR, IN_RULE)
1017990 forget_descriptions_data()
1018991
1019992 # match odd number of slashes at the end
1020993 if ($0 ~ sprintf (" %s[^\\\\ ]*?([\\\\ ]{2})*\\\\ $" , RECIPEPREFIX)) {
1021- # printf("--> LINE: %s (in backslash multiline command) %s\n", FNR, $0)
1022994 IN_MULTILINE_BACKSLASH_COMMAND = 1
1023995 } else {
1024- if (IN_MULTILINE_BACKSLASH_COMMAND) {
1025- # printf("--> LINE: %s (last line of backslash multiline command) %s\n", FNR, $0)
1026- }
1027996 IN_MULTILINE_BACKSLASH_COMMAND = 0
1028997 }
1029998
@@ -1105,7 +1074,7 @@ $0 ~ VARIABLES_REGEX {
11051074 PATTERN_RULE_MATCHED = 1
11061075}
11071076
1108- # keep here for debugging purposes
1077+ # keep here for debugging purposes (it is commented-out because of a goawk bug)
11091078# PATTERN_RULE_MATCHED == 0 {
11101079#
11111080# }
0 commit comments