| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: suff.c,v 1.273 2020/11/21 20:04:10 rillig Exp $ */ | | 1 | /* $NetBSD: suff.c,v 1.274 2020/11/21 20:12:08 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. |
| @@ -104,27 +104,27 @@ | | | @@ -104,27 +104,27 @@ |
104 | * Suff_FindDeps Find implicit sources for and the location of | | 104 | * Suff_FindDeps Find implicit sources for and the location of |
105 | * a target based on its suffix. Returns the | | 105 | * a target based on its suffix. Returns the |
106 | * bottom-most node added to the graph or NULL | | 106 | * bottom-most node added to the graph or NULL |
107 | * if the target had no implicit sources. | | 107 | * if the target had no implicit sources. |
108 | * | | 108 | * |
109 | * Suff_FindPath Return the appropriate path to search in order to | | 109 | * Suff_FindPath Return the appropriate path to search in order to |
110 | * find the node. | | 110 | * find the node. |
111 | */ | | 111 | */ |
112 | | | 112 | |
113 | #include "make.h" | | 113 | #include "make.h" |
114 | #include "dir.h" | | 114 | #include "dir.h" |
115 | | | 115 | |
116 | /* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */ | | 116 | /* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */ |
117 | MAKE_RCSID("$NetBSD: suff.c,v 1.273 2020/11/21 20:04:10 rillig Exp $"); | | 117 | MAKE_RCSID("$NetBSD: suff.c,v 1.274 2020/11/21 20:12:08 rillig Exp $"); |
118 | | | 118 | |
119 | #define SUFF_DEBUG0(text) DEBUG0(SUFF, text) | | 119 | #define SUFF_DEBUG0(text) DEBUG0(SUFF, text) |
120 | #define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1) | | 120 | #define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1) |
121 | #define SUFF_DEBUG2(fmt, arg1, arg2) DEBUG2(SUFF, fmt, arg1, arg2) | | 121 | #define SUFF_DEBUG2(fmt, arg1, arg2) DEBUG2(SUFF, fmt, arg1, arg2) |
122 | | | 122 | |
123 | typedef List SuffixList; | | 123 | typedef List SuffixList; |
124 | typedef ListNode SuffixListNode; | | 124 | typedef ListNode SuffixListNode; |
125 | | | 125 | |
126 | typedef List SrcList; | | 126 | typedef List SrcList; |
127 | typedef ListNode SrcListNode; | | 127 | typedef ListNode SrcListNode; |
128 | | | 128 | |
129 | static SuffixList *sufflist; /* List of suffixes */ | | 129 | static SuffixList *sufflist; /* List of suffixes */ |
130 | #ifdef CLEANUP | | 130 | #ifdef CLEANUP |
| @@ -202,27 +202,26 @@ typedef struct Src { | | | @@ -202,27 +202,26 @@ typedef struct Src { |
202 | SrcList *childrenList; | | 202 | SrcList *childrenList; |
203 | #endif | | 203 | #endif |
204 | } Src; | | 204 | } Src; |
205 | | | 205 | |
206 | | | 206 | |
207 | /* TODO: Document the difference between nullSuff and emptySuff. */ | | 207 | /* TODO: Document the difference between nullSuff and emptySuff. */ |
208 | /* The NULL suffix for this run */ | | 208 | /* The NULL suffix for this run */ |
209 | static Suffix *nullSuff; | | 209 | static Suffix *nullSuff; |
210 | /* The empty suffix required for POSIX single-suffix transformation rules */ | | 210 | /* The empty suffix required for POSIX single-suffix transformation rules */ |
211 | static Suffix *emptySuff; | | 211 | static Suffix *emptySuff; |
212 | | | 212 | |
213 | | | 213 | |
214 | static void SuffFindDeps(GNode *, SrcList *); | | 214 | static void SuffFindDeps(GNode *, SrcList *); |
215 | static void SuffExpandWildcards(GNodeListNode *, GNode *); | | | |
216 | | | 215 | |
217 | static Suffix * | | 216 | static Suffix * |
218 | Suffix_Ref(Suffix *suff) | | 217 | Suffix_Ref(Suffix *suff) |
219 | { | | 218 | { |
220 | suff->refCount++; | | 219 | suff->refCount++; |
221 | return suff; | | 220 | return suff; |
222 | } | | 221 | } |
223 | | | 222 | |
224 | /* Change the value of a Suffix variable, adjusting the reference counts. */ | | 223 | /* Change the value of a Suffix variable, adjusting the reference counts. */ |
225 | static void | | 224 | static void |
226 | Suffix_Reassign(Suffix **var, Suffix *suff) | | 225 | Suffix_Reassign(Suffix **var, Suffix *suff) |
227 | { | | 226 | { |
228 | if (*var != NULL) | | 227 | if (*var != NULL) |
| @@ -1114,26 +1113,70 @@ SuffFindCmds(Src *targ, SrcList *slst) | | | @@ -1114,26 +1113,70 @@ SuffFindCmds(Src *targ, SrcList *slst) |
1114 | * again (ick)), and return the new structure. | | 1113 | * again (ick)), and return the new structure. |
1115 | */ | | 1114 | */ |
1116 | ret = SrcNew(bmake_strdup(sgn->name), targ->pref, suff, targ, sgn); | | 1115 | ret = SrcNew(bmake_strdup(sgn->name), targ->pref, suff, targ, sgn); |
1117 | targ->numChildren++; | | 1116 | targ->numChildren++; |
1118 | #ifdef DEBUG_SRC | | 1117 | #ifdef DEBUG_SRC |
1119 | debug_printf("3 add targ %p ret %p\n", targ, ret); | | 1118 | debug_printf("3 add targ %p ret %p\n", targ, ret); |
1120 | Lst_Append(targ->childrenList, ret); | | 1119 | Lst_Append(targ->childrenList, ret); |
1121 | #endif | | 1120 | #endif |
1122 | Lst_Append(slst, ret); | | 1121 | Lst_Append(slst, ret); |
1123 | SUFF_DEBUG1("\tusing existing source %s\n", sgn->name); | | 1122 | SUFF_DEBUG1("\tusing existing source %s\n", sgn->name); |
1124 | return ret; | | 1123 | return ret; |
1125 | } | | 1124 | } |
1126 | | | 1125 | |
| | | 1126 | static void |
| | | 1127 | SuffExpandWildcards(GNodeListNode *cln, GNode *pgn) |
| | | 1128 | { |
| | | 1129 | GNode *cgn = cln->datum; |
| | | 1130 | StringList *expansions; |
| | | 1131 | |
| | | 1132 | if (!Dir_HasWildcards(cgn->name)) |
| | | 1133 | return; |
| | | 1134 | |
| | | 1135 | /* |
| | | 1136 | * Expand the word along the chosen path |
| | | 1137 | */ |
| | | 1138 | expansions = Lst_New(); |
| | | 1139 | Dir_Expand(cgn->name, Suff_FindPath(cgn), expansions); |
| | | 1140 | |
| | | 1141 | while (!Lst_IsEmpty(expansions)) { |
| | | 1142 | GNode *gn; |
| | | 1143 | /* |
| | | 1144 | * Fetch next expansion off the list and find its GNode |
| | | 1145 | */ |
| | | 1146 | char *cp = Lst_Dequeue(expansions); |
| | | 1147 | |
| | | 1148 | SUFF_DEBUG1("%s...", cp); |
| | | 1149 | gn = Targ_GetNode(cp); |
| | | 1150 | |
| | | 1151 | /* Add gn to the parents child list before the original child */ |
| | | 1152 | Lst_InsertBefore(pgn->children, cln, gn); |
| | | 1153 | Lst_Append(gn->parents, pgn); |
| | | 1154 | pgn->unmade++; |
| | | 1155 | } |
| | | 1156 | |
| | | 1157 | Lst_Free(expansions); |
| | | 1158 | |
| | | 1159 | SUFF_DEBUG0("\n"); |
| | | 1160 | |
| | | 1161 | /* |
| | | 1162 | * Now the source is expanded, remove it from the list of children to |
| | | 1163 | * keep it from being processed. |
| | | 1164 | */ |
| | | 1165 | pgn->unmade--; |
| | | 1166 | Lst_Remove(pgn->children, cln); |
| | | 1167 | Lst_Remove(cgn->parents, Lst_FindDatum(cgn->parents, pgn)); |
| | | 1168 | } |
| | | 1169 | |
1127 | /* Expand the names of any children of a given node that contain variable | | 1170 | /* Expand the names of any children of a given node that contain variable |
1128 | * expressions or file wildcards into actual targets. | | 1171 | * expressions or file wildcards into actual targets. |
1129 | * | | 1172 | * |
1130 | * The expanded node is removed from the parent's list of children, and the | | 1173 | * The expanded node is removed from the parent's list of children, and the |
1131 | * parent's unmade counter is decremented, but other nodes may be added. | | 1174 | * parent's unmade counter is decremented, but other nodes may be added. |
1132 | * | | 1175 | * |
1133 | * Input: | | 1176 | * Input: |
1134 | * cln Child to examine | | 1177 | * cln Child to examine |
1135 | * pgn Parent node being processed | | 1178 | * pgn Parent node being processed |
1136 | */ | | 1179 | */ |
1137 | static void | | 1180 | static void |
1138 | SuffExpandChildren(GNodeListNode *cln, GNode *pgn) | | 1181 | SuffExpandChildren(GNodeListNode *cln, GNode *pgn) |
1139 | { | | 1182 | { |
| @@ -1269,70 +1312,26 @@ SuffExpandChildren(GNodeListNode *cln, G | | | @@ -1269,70 +1312,26 @@ SuffExpandChildren(GNodeListNode *cln, G |
1269 | } | | 1312 | } |
1270 | | | 1313 | |
1271 | SUFF_DEBUG0("\n"); | | 1314 | SUFF_DEBUG0("\n"); |
1272 | | | 1315 | |
1273 | /* | | 1316 | /* |
1274 | * Now the source is expanded, remove it from the list of children to | | 1317 | * Now the source is expanded, remove it from the list of children to |
1275 | * keep it from being processed. | | 1318 | * keep it from being processed. |
1276 | */ | | 1319 | */ |
1277 | pgn->unmade--; | | 1320 | pgn->unmade--; |
1278 | Lst_Remove(pgn->children, cln); | | 1321 | Lst_Remove(pgn->children, cln); |
1279 | Lst_Remove(cgn->parents, Lst_FindDatum(cgn->parents, pgn)); | | 1322 | Lst_Remove(cgn->parents, Lst_FindDatum(cgn->parents, pgn)); |
1280 | } | | 1323 | } |
1281 | | | 1324 | |
1282 | static void | | | |
1283 | SuffExpandWildcards(GNodeListNode *cln, GNode *pgn) | | | |
1284 | { | | | |
1285 | GNode *cgn = cln->datum; | | | |
1286 | StringList *expansions; | | | |
1287 | | | | |
1288 | if (!Dir_HasWildcards(cgn->name)) | | | |
1289 | return; | | | |
1290 | | | | |
1291 | /* | | | |
1292 | * Expand the word along the chosen path | | | |
1293 | */ | | | |
1294 | expansions = Lst_New(); | | | |
1295 | Dir_Expand(cgn->name, Suff_FindPath(cgn), expansions); | | | |
1296 | | | | |
1297 | while (!Lst_IsEmpty(expansions)) { | | | |
1298 | GNode *gn; | | | |
1299 | /* | | | |
1300 | * Fetch next expansion off the list and find its GNode | | | |
1301 | */ | | | |
1302 | char *cp = Lst_Dequeue(expansions); | | | |
1303 | | | | |
1304 | SUFF_DEBUG1("%s...", cp); | | | |
1305 | gn = Targ_GetNode(cp); | | | |
1306 | | | | |
1307 | /* Add gn to the parents child list before the original child */ | | | |
1308 | Lst_InsertBefore(pgn->children, cln, gn); | | | |
1309 | Lst_Append(gn->parents, pgn); | | | |
1310 | pgn->unmade++; | | | |
1311 | } | | | |
1312 | | | | |
1313 | Lst_Free(expansions); | | | |
1314 | | | | |
1315 | SUFF_DEBUG0("\n"); | | | |
1316 | | | | |
1317 | /* | | | |
1318 | * Now the source is expanded, remove it from the list of children to | | | |
1319 | * keep it from being processed. | | | |
1320 | */ | | | |
1321 | pgn->unmade--; | | | |
1322 | Lst_Remove(pgn->children, cln); | | | |
1323 | Lst_Remove(cgn->parents, Lst_FindDatum(cgn->parents, pgn)); | | | |
1324 | } | | | |
1325 | | | | |
1326 | /* Find a path along which to expand the node. | | 1325 | /* Find a path along which to expand the node. |
1327 | * | | 1326 | * |
1328 | * If the node has a known suffix, use that path. | | 1327 | * If the node has a known suffix, use that path. |
1329 | * If it has no known suffix, use the default system search path. | | 1328 | * If it has no known suffix, use the default system search path. |
1330 | * | | 1329 | * |
1331 | * Input: | | 1330 | * Input: |
1332 | * gn Node being examined | | 1331 | * gn Node being examined |
1333 | * | | 1332 | * |
1334 | * Results: | | 1333 | * Results: |
1335 | * The appropriate path to search for the GNode. | | 1334 | * The appropriate path to search for the GNode. |
1336 | */ | | 1335 | */ |
1337 | SearchPath * | | 1336 | SearchPath * |
1338 | Suff_FindPath(GNode* gn) | | 1337 | Suff_FindPath(GNode* gn) |