| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: parse.c,v 1.330 2020/09/25 23:39:51 rillig Exp $ */ | | 1 | /* $NetBSD: parse.c,v 1.331 2020/09/26 00:03:29 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1988, 1989, 1990, 1993 | | 4 | * Copyright (c) 1988, 1989, 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Adam de Boor. | | 8 | * Adam de Boor. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -121,27 +121,27 @@ | | | @@ -121,27 +121,27 @@ |
121 | #ifndef MAP_FILE | | 121 | #ifndef MAP_FILE |
122 | #define MAP_FILE 0 | | 122 | #define MAP_FILE 0 |
123 | #endif | | 123 | #endif |
124 | #ifndef MAP_COPY | | 124 | #ifndef MAP_COPY |
125 | #define MAP_COPY MAP_PRIVATE | | 125 | #define MAP_COPY MAP_PRIVATE |
126 | #endif | | 126 | #endif |
127 | | | 127 | |
128 | #include "make.h" | | 128 | #include "make.h" |
129 | #include "dir.h" | | 129 | #include "dir.h" |
130 | #include "job.h" | | 130 | #include "job.h" |
131 | #include "pathnames.h" | | 131 | #include "pathnames.h" |
132 | | | 132 | |
133 | /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ | | 133 | /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ |
134 | MAKE_RCSID("$NetBSD: parse.c,v 1.330 2020/09/25 23:39:51 rillig Exp $"); | | 134 | MAKE_RCSID("$NetBSD: parse.c,v 1.331 2020/09/26 00:03:29 rillig Exp $"); |
135 | | | 135 | |
136 | /* types and constants */ | | 136 | /* types and constants */ |
137 | | | 137 | |
138 | /* | | 138 | /* |
139 | * Structure for a file being read ("included file") | | 139 | * Structure for a file being read ("included file") |
140 | */ | | 140 | */ |
141 | typedef struct IFile { | | 141 | typedef struct IFile { |
142 | char *fname; /* name of file */ | | 142 | char *fname; /* name of file */ |
143 | Boolean fromForLoop; /* simulated .include by the .for loop */ | | 143 | Boolean fromForLoop; /* simulated .include by the .for loop */ |
144 | int lineno; /* current line number in file */ | | 144 | int lineno; /* current line number in file */ |
145 | int first_lineno; /* line number of start of text */ | | 145 | int first_lineno; /* line number of start of text */ |
146 | int cond_depth; /* 'if' nesting when file opened */ | | 146 | int cond_depth; /* 'if' nesting when file opened */ |
147 | Boolean depending; /* state of doing_depend on EOF */ | | 147 | Boolean depending; /* state of doing_depend on EOF */ |
| @@ -783,50 +783,48 @@ ParseMessage(char *line) | | | @@ -783,50 +783,48 @@ ParseMessage(char *line) |
783 | struct ParseLinkSrcArgs { | | 783 | struct ParseLinkSrcArgs { |
784 | GNode *cgn; | | 784 | GNode *cgn; |
785 | | | 785 | |
786 | /* The special target of the current dependency line. */ | | 786 | /* The special target of the current dependency line. */ |
787 | /* Example: for ".END: action", it is 'End'. */ | | 787 | /* Example: for ".END: action", it is 'End'. */ |
788 | ParseSpecial specType; | | 788 | ParseSpecial specType; |
789 | }; | | 789 | }; |
790 | | | 790 | |
791 | /* Add the child to the parent's children. | | 791 | /* Add the child to the parent's children. |
792 | * | | 792 | * |
793 | * Add the parent to the child's parents, but only if the target is not | | 793 | * Add the parent to the child's parents, but only if the target is not |
794 | * special. An example for such a special target is .END, which does not | | 794 | * special. An example for such a special target is .END, which does not |
795 | * need to be informed once the child target has been made. */ | | 795 | * need to be informed once the child target has been made. */ |
796 | static int | | 796 | static void |
797 | ParseLinkSrc(void *pgnp, void *data) | | 797 | ParseLinkSrc(void *pgnp, void *data) |
798 | { | | 798 | { |
799 | const struct ParseLinkSrcArgs *args = data; | | 799 | const struct ParseLinkSrcArgs *args = data; |
800 | GNode *pgn = pgnp; | | 800 | GNode *pgn = pgnp; |
801 | GNode *cgn = args->cgn; | | 801 | GNode *cgn = args->cgn; |
802 | | | 802 | |
803 | if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(pgn->cohorts)) | | 803 | if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(pgn->cohorts)) |
804 | pgn = LstNode_Datum(Lst_Last(pgn->cohorts)); | | 804 | pgn = LstNode_Datum(Lst_Last(pgn->cohorts)); |
805 | | | 805 | |
806 | Lst_Append(pgn->children, cgn); | | 806 | Lst_Append(pgn->children, cgn); |
807 | pgn->unmade += 1; | | 807 | pgn->unmade += 1; |
808 | | | 808 | |
809 | if (args->specType == Not) | | 809 | if (args->specType == Not) |
810 | Lst_Append(cgn->parents, pgn); | | 810 | Lst_Append(cgn->parents, pgn); |
811 | | | 811 | |
812 | if (DEBUG(PARSE)) { | | 812 | if (DEBUG(PARSE)) { |
813 | fprintf(debug_file, "# %s: added child %s - %s\n", | | 813 | fprintf(debug_file, "# %s: added child %s - %s\n", |
814 | __func__, pgn->name, cgn->name); | | 814 | __func__, pgn->name, cgn->name); |
815 | Targ_PrintNode(pgn, 0); | | 815 | Targ_PrintNode(pgn, 0); |
816 | Targ_PrintNode(cgn, 0); | | 816 | Targ_PrintNode(cgn, 0); |
817 | } | | 817 | } |
818 | | | | |
819 | return 0; | | | |
820 | } | | 818 | } |
821 | | | 819 | |
822 | /*- | | 820 | /*- |
823 | *--------------------------------------------------------------------- | | 821 | *--------------------------------------------------------------------- |
824 | * ParseDoOp -- | | 822 | * ParseDoOp -- |
825 | * Apply the parsed operator to the given target node. Used in a | | 823 | * Apply the parsed operator to the given target node. Used in a |
826 | * Lst_ForEachUntil call by ParseDoDependency once all targets have | | 824 | * Lst_ForEachUntil call by ParseDoDependency once all targets have |
827 | * been found and their operator parsed. If the previous and new | | 825 | * been found and their operator parsed. If the previous and new |
828 | * operators are incompatible, a major error is taken. | | 826 | * operators are incompatible, a major error is taken. |
829 | * | | 827 | * |
830 | * Input: | | 828 | * Input: |
831 | * gnp The node to which the operator is to be applied | | 829 | * gnp The node to which the operator is to be applied |
832 | * opp The operator to apply | | 830 | * opp The operator to apply |
| @@ -944,27 +942,27 @@ ParseDoSrc(int tOp, const char *src, Par | | | @@ -944,27 +942,27 @@ ParseDoSrc(int tOp, const char *src, Par |
944 | * have happened, it is given a dependency on the each | | 942 | * have happened, it is given a dependency on the each |
945 | * previous child back to and previous .WAIT node. | | 943 | * previous child back to and previous .WAIT node. |
946 | * The next child won't be scheduled until the .WAIT node | | 944 | * The next child won't be scheduled until the .WAIT node |
947 | * is built. | | 945 | * is built. |
948 | * We give each .WAIT node a unique name (mainly for diag). | | 946 | * We give each .WAIT node a unique name (mainly for diag). |
949 | */ | | 947 | */ |
950 | snprintf(wait_src, sizeof wait_src, ".WAIT_%u", ++wait_number); | | 948 | snprintf(wait_src, sizeof wait_src, ".WAIT_%u", ++wait_number); |
951 | gn = Targ_FindNode(wait_src, TARG_NOHASH); | | 949 | gn = Targ_FindNode(wait_src, TARG_NOHASH); |
952 | if (doing_depend) | | 950 | if (doing_depend) |
953 | ParseMark(gn); | | 951 | ParseMark(gn); |
954 | gn->type = OP_WAIT | OP_PHONY | OP_DEPENDS | OP_NOTMAIN; | | 952 | gn->type = OP_WAIT | OP_PHONY | OP_DEPENDS | OP_NOTMAIN; |
955 | if (targets != NULL) { | | 953 | if (targets != NULL) { |
956 | struct ParseLinkSrcArgs args = { gn, specType }; | | 954 | struct ParseLinkSrcArgs args = { gn, specType }; |
957 | Lst_ForEachUntil(targets, ParseLinkSrc, &args); | | 955 | Lst_ForEach(targets, ParseLinkSrc, &args); |
958 | } | | 956 | } |
959 | return; | | 957 | return; |
960 | } | | 958 | } |
961 | } | | 959 | } |
962 | } | | 960 | } |
963 | | | 961 | |
964 | switch (specType) { | | 962 | switch (specType) { |
965 | case Main: | | 963 | case Main: |
966 | /* | | 964 | /* |
967 | * If we have noted the existence of a .MAIN, it means we need | | 965 | * If we have noted the existence of a .MAIN, it means we need |
968 | * to add the sources of said target to the list of things | | 966 | * to add the sources of said target to the list of things |
969 | * to create. The string 'src' is likely to be free, so we | | 967 | * to create. The string 'src' is likely to be free, so we |
970 | * must make a new copy of it. Note that this will only be | | 968 | * must make a new copy of it. Note that this will only be |
| @@ -1015,27 +1013,27 @@ ParseDoSrc(int tOp, const char *src, Par | | | @@ -1015,27 +1013,27 @@ ParseDoSrc(int tOp, const char *src, Par |
1015 | * the 'cohorts' list of the node) or all the cohorts are linked | | 1013 | * the 'cohorts' list of the node) or all the cohorts are linked |
1016 | * to all the targets. | | 1014 | * to all the targets. |
1017 | */ | | 1015 | */ |
1018 | | | 1016 | |
1019 | /* Find/create the 'src' node and attach to all targets */ | | 1017 | /* Find/create the 'src' node and attach to all targets */ |
1020 | gn = Targ_FindNode(src, TARG_CREATE); | | 1018 | gn = Targ_FindNode(src, TARG_CREATE); |
1021 | if (doing_depend) | | 1019 | if (doing_depend) |
1022 | ParseMark(gn); | | 1020 | ParseMark(gn); |
1023 | if (tOp) { | | 1021 | if (tOp) { |
1024 | gn->type |= tOp; | | 1022 | gn->type |= tOp; |
1025 | } else { | | 1023 | } else { |
1026 | if (targets != NULL) { | | 1024 | if (targets != NULL) { |
1027 | struct ParseLinkSrcArgs args = { gn, specType }; | | 1025 | struct ParseLinkSrcArgs args = { gn, specType }; |
1028 | Lst_ForEachUntil(targets, ParseLinkSrc, &args); | | 1026 | Lst_ForEach(targets, ParseLinkSrc, &args); |
1029 | } | | 1027 | } |
1030 | } | | 1028 | } |
1031 | break; | | 1029 | break; |
1032 | } | | 1030 | } |
1033 | } | | 1031 | } |
1034 | | | 1032 | |
1035 | /*- | | 1033 | /*- |
1036 | *----------------------------------------------------------------------- | | 1034 | *----------------------------------------------------------------------- |
1037 | * ParseFindMain -- | | 1035 | * ParseFindMain -- |
1038 | * Find a real target in the list and set it to be the main one. | | 1036 | * Find a real target in the list and set it to be the main one. |
1039 | * Called by ParseDoDependency when a main target hasn't been found | | 1037 | * Called by ParseDoDependency when a main target hasn't been found |
1040 | * yet. | | 1038 | * yet. |
1041 | * | | 1039 | * |
| @@ -1053,64 +1051,36 @@ ParseDoSrc(int tOp, const char *src, Par | | | @@ -1053,64 +1051,36 @@ ParseDoSrc(int tOp, const char *src, Par |
1053 | static int | | 1051 | static int |
1054 | ParseFindMain(void *gnp, void *dummy MAKE_ATTR_UNUSED) | | 1052 | ParseFindMain(void *gnp, void *dummy MAKE_ATTR_UNUSED) |
1055 | { | | 1053 | { |
1056 | GNode *gn = (GNode *)gnp; | | 1054 | GNode *gn = (GNode *)gnp; |
1057 | if (!(gn->type & OP_NOTARGET)) { | | 1055 | if (!(gn->type & OP_NOTARGET)) { |
1058 | mainNode = gn; | | 1056 | mainNode = gn; |
1059 | Targ_SetMain(gn); | | 1057 | Targ_SetMain(gn); |
1060 | return 1; | | 1058 | return 1; |
1061 | } else { | | 1059 | } else { |
1062 | return 0; | | 1060 | return 0; |
1063 | } | | 1061 | } |
1064 | } | | 1062 | } |
1065 | | | 1063 | |
1066 | /*- | | 1064 | static void |
1067 | *----------------------------------------------------------------------- | | | |
1068 | * ParseAddDir -- | | | |
1069 | * Front-end for Dir_AddDir to make sure Lst_ForEachUntil keeps going | | | |
1070 | * | | | |
1071 | * Results: | | | |
1072 | * === 0 | | | |
1073 | * | | | |
1074 | * Side Effects: | | | |
1075 | * See Dir_AddDir. | | | |
1076 | * | | | |
1077 | *----------------------------------------------------------------------- | | | |
1078 | */ | | | |
1079 | static int | | | |
1080 | ParseAddDir(void *path, void *name) | | 1065 | ParseAddDir(void *path, void *name) |
1081 | { | | 1066 | { |
1082 | (void)Dir_AddDir(path, name); | | 1067 | (void)Dir_AddDir(path, name); |
1083 | return 0; | | | |
1084 | } | | 1068 | } |
1085 | | | 1069 | |
1086 | /*- | | 1070 | static void |
1087 | *----------------------------------------------------------------------- | | 1071 | ParseClearPath(void *path, void *unused MAKE_ATTR_UNUSED) |
1088 | * ParseClearPath -- | | | |
1089 | * Front-end for Dir_ClearPath to make sure Lst_ForEachUntil keeps going | | | |
1090 | * | | | |
1091 | * Results: | | | |
1092 | * === 0 | | | |
1093 | * | | | |
1094 | * Side Effects: | | | |
1095 | * See Dir_ClearPath | | | |
1096 | * | | | |
1097 | *----------------------------------------------------------------------- | | | |
1098 | */ | | | |
1099 | static int | | | |
1100 | ParseClearPath(void *path, void *dummy MAKE_ATTR_UNUSED) | | | |
1101 | { | | 1072 | { |
1102 | Dir_ClearPath(path); | | 1073 | Dir_ClearPath(path); |
1103 | return 0; | | | |
1104 | } | | 1074 | } |
1105 | | | 1075 | |
1106 | /* | | 1076 | /* |
1107 | * We got to the end of the line while we were still looking at targets. | | 1077 | * We got to the end of the line while we were still looking at targets. |
1108 | * | | 1078 | * |
1109 | * Ending a dependency line without an operator is a Bozo no-no. As a | | 1079 | * Ending a dependency line without an operator is a Bozo no-no. As a |
1110 | * heuristic, this is also often triggered by undetected conflicts from | | 1080 | * heuristic, this is also often triggered by undetected conflicts from |
1111 | * cvs/rcs merges. | | 1081 | * cvs/rcs merges. |
1112 | */ | | 1082 | */ |
1113 | static void | | 1083 | static void |
1114 | ParseErrorNoDependency(const char *lstart, const char *line) | | 1084 | ParseErrorNoDependency(const char *lstart, const char *line) |
1115 | { | | 1085 | { |
1116 | if ((strncmp(line, "<<<<<<", 6) == 0) || | | 1086 | if ((strncmp(line, "<<<<<<", 6) == 0) || |
| @@ -1551,27 +1521,27 @@ ParseDoDependency(char *line) | | | @@ -1551,27 +1521,27 @@ ParseDoDependency(char *line) |
1551 | Suff_ClearSuffixes(); | | 1521 | Suff_ClearSuffixes(); |
1552 | break; | | 1522 | break; |
1553 | case Precious: | | 1523 | case Precious: |
1554 | allPrecious = TRUE; | | 1524 | allPrecious = TRUE; |
1555 | break; | | 1525 | break; |
1556 | case Ignore: | | 1526 | case Ignore: |
1557 | ignoreErrors = TRUE; | | 1527 | ignoreErrors = TRUE; |
1558 | break; | | 1528 | break; |
1559 | case Silent: | | 1529 | case Silent: |
1560 | beSilent = TRUE; | | 1530 | beSilent = TRUE; |
1561 | break; | | 1531 | break; |
1562 | case ExPath: | | 1532 | case ExPath: |
1563 | if (paths != NULL) | | 1533 | if (paths != NULL) |
1564 | Lst_ForEachUntil(paths, ParseClearPath, NULL); | | 1534 | Lst_ForEach(paths, ParseClearPath, NULL); |
1565 | Dir_SetPATH(); | | 1535 | Dir_SetPATH(); |
1566 | break; | | 1536 | break; |
1567 | #ifdef POSIX | | 1537 | #ifdef POSIX |
1568 | case Posix: | | 1538 | case Posix: |
1569 | Var_Set("%POSIX", "1003.2", VAR_GLOBAL); | | 1539 | Var_Set("%POSIX", "1003.2", VAR_GLOBAL); |
1570 | break; | | 1540 | break; |
1571 | #endif | | 1541 | #endif |
1572 | default: | | 1542 | default: |
1573 | break; | | 1543 | break; |
1574 | } | | 1544 | } |
1575 | } else if (specType == MFlags) { | | 1545 | } else if (specType == MFlags) { |
1576 | /* | | 1546 | /* |
1577 | * Call on functions in main.c to deal with these arguments and | | 1547 | * Call on functions in main.c to deal with these arguments and |
| @@ -1627,27 +1597,27 @@ ParseDoDependency(char *line) | | | @@ -1627,27 +1597,27 @@ ParseDoDependency(char *line) |
1627 | * and will cause make to do a new chdir to that path. | | 1597 | * and will cause make to do a new chdir to that path. |
1628 | */ | | 1598 | */ |
1629 | while (*cp && !ch_isspace(*cp)) { | | 1599 | while (*cp && !ch_isspace(*cp)) { |
1630 | cp++; | | 1600 | cp++; |
1631 | } | | 1601 | } |
1632 | savec = *cp; | | 1602 | savec = *cp; |
1633 | *cp = '\0'; | | 1603 | *cp = '\0'; |
1634 | switch (specType) { | | 1604 | switch (specType) { |
1635 | case Suffixes: | | 1605 | case Suffixes: |
1636 | Suff_AddSuffix(line, &mainNode); | | 1606 | Suff_AddSuffix(line, &mainNode); |
1637 | break; | | 1607 | break; |
1638 | case ExPath: | | 1608 | case ExPath: |
1639 | if (paths != NULL) | | 1609 | if (paths != NULL) |
1640 | Lst_ForEachUntil(paths, ParseAddDir, line); | | 1610 | Lst_ForEach(paths, ParseAddDir, line); |
1641 | break; | | 1611 | break; |
1642 | case Includes: | | 1612 | case Includes: |
1643 | Suff_AddInclude(line); | | 1613 | Suff_AddInclude(line); |
1644 | break; | | 1614 | break; |
1645 | case Libs: | | 1615 | case Libs: |
1646 | Suff_AddLib(line); | | 1616 | Suff_AddLib(line); |
1647 | break; | | 1617 | break; |
1648 | case Null: | | 1618 | case Null: |
1649 | Suff_SetNull(line); | | 1619 | Suff_SetNull(line); |
1650 | break; | | 1620 | break; |
1651 | case ExObjdir: | | 1621 | case ExObjdir: |
1652 | Main_SetObjdir("%s", line); | | 1622 | Main_SetObjdir("%s", line); |
1653 | break; | | 1623 | break; |
| @@ -2826,38 +2796,37 @@ ParseReadLine(void) | | | @@ -2826,38 +2796,37 @@ ParseReadLine(void) |
2826 | "Unexpected end of file in for loop."); | | 2796 | "Unexpected end of file in for loop."); |
2827 | break; | | 2797 | break; |
2828 | } | | 2798 | } |
2829 | } while (For_Accum(line)); | | 2799 | } while (For_Accum(line)); |
2830 | /* Stash each iteration as a new 'input file' */ | | 2800 | /* Stash each iteration as a new 'input file' */ |
2831 | For_Run(lineno); | | 2801 | For_Run(lineno); |
2832 | /* Read next line from for-loop buffer */ | | 2802 | /* Read next line from for-loop buffer */ |
2833 | continue; | | 2803 | continue; |
2834 | } | | 2804 | } |
2835 | return line; | | 2805 | return line; |
2836 | } | | 2806 | } |
2837 | } | | 2807 | } |
2838 | | | 2808 | |
2839 | static int | | 2809 | static void |
2840 | SuffEndTransform(void *target, void *unused MAKE_ATTR_UNUSED) | | 2810 | SuffEndTransform(void *target, void *unused MAKE_ATTR_UNUSED) |
2841 | { | | 2811 | { |
2842 | Suff_EndTransform(target); | | 2812 | Suff_EndTransform(target); |
2843 | return 0; | | | |
2844 | } | | 2813 | } |
2845 | | | 2814 | |
2846 | static void | | 2815 | static void |
2847 | FinishDependencyGroup(void) | | 2816 | FinishDependencyGroup(void) |
2848 | { | | 2817 | { |
2849 | if (targets != NULL) { | | 2818 | if (targets != NULL) { |
2850 | Lst_ForEachUntil(targets, SuffEndTransform, NULL); | | 2819 | Lst_ForEach(targets, SuffEndTransform, NULL); |
2851 | Lst_Destroy(targets, ParseHasCommands); | | 2820 | Lst_Destroy(targets, ParseHasCommands); |
2852 | } | | 2821 | } |
2853 | targets = NULL; | | 2822 | targets = NULL; |
2854 | } | | 2823 | } |
2855 | | | 2824 | |
2856 | /* Add the command to each target from the current dependency spec. */ | | 2825 | /* Add the command to each target from the current dependency spec. */ |
2857 | static void | | 2826 | static void |
2858 | ParseLine_ShellCommand(char *cp) | | 2827 | ParseLine_ShellCommand(char *cp) |
2859 | { | | 2828 | { |
2860 | for (; ch_isspace(*cp); cp++) | | 2829 | for (; ch_isspace(*cp); cp++) |
2861 | continue; | | 2830 | continue; |
2862 | | | 2831 | |
2863 | if (*cp == '\0') | | 2832 | if (*cp == '\0') |