| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: suff.c,v 1.281 2020/11/21 23:51:28 rillig Exp $ */ | | 1 | /* $NetBSD: suff.c,v 1.282 2020/11/22 09:30:22 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,37 +104,37 @@ | | | @@ -104,37 +104,37 @@ |
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.281 2020/11/21 23:51:28 rillig Exp $"); | | 117 | MAKE_RCSID("$NetBSD: suff.c,v 1.282 2020/11/22 09:30:22 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; /* XXX: rename to CandidateList */ |
127 | typedef ListNode SrcListNode; | | 127 | typedef ListNode SrcListNode; /* XXX: rename to CandidateListNode */ |
128 | | | 128 | |
129 | static SuffixList *sufflist; /* List of suffixes */ | | 129 | static SuffixList *sufflist; /* List of suffixes */ |
130 | #ifdef CLEANUP | | 130 | #ifdef CLEANUP |
131 | static SuffixList *suffClean; /* List of suffixes to be cleaned */ | | 131 | static SuffixList *suffClean; /* List of suffixes to be cleaned */ |
132 | #endif | | 132 | #endif |
133 | | | 133 | |
134 | /* List of transformation rules, such as ".c.o" */ | | 134 | /* List of transformation rules, such as ".c.o" */ |
135 | static GNodeList *transforms; | | 135 | static GNodeList *transforms; |
136 | | | 136 | |
137 | static int sNum = 0; /* Counter for assigning suffix numbers */ | | 137 | static int sNum = 0; /* Counter for assigning suffix numbers */ |
138 | | | 138 | |
139 | typedef enum SuffixFlags { | | 139 | typedef enum SuffixFlags { |
140 | SUFF_INCLUDE = 0x01, /* One which is #include'd */ | | 140 | SUFF_INCLUDE = 0x01, /* One which is #include'd */ |
| @@ -174,40 +174,40 @@ typedef struct Suffix { | | | @@ -174,40 +174,40 @@ typedef struct Suffix { |
174 | * XXX: These lists are used nowhere, they are just appended to, for no | | 174 | * XXX: These lists are used nowhere, they are just appended to, for no |
175 | * apparent reason. They do have the side effect of increasing refCount | | 175 | * apparent reason. They do have the side effect of increasing refCount |
176 | * though. */ | | 176 | * though. */ |
177 | SuffixListList *ref; | | 177 | SuffixListList *ref; |
178 | } Suffix; | | 178 | } Suffix; |
179 | | | 179 | |
180 | /* | | 180 | /* |
181 | * A candidate when searching for implied sources. | | 181 | * A candidate when searching for implied sources. |
182 | * | | 182 | * |
183 | * For example, when "src.o" is to be made, a typical candidate is "src.c" | | 183 | * For example, when "src.o" is to be made, a typical candidate is "src.c" |
184 | * via the transformation rule ".c.o". If that doesn't exist, maybe there is | | 184 | * via the transformation rule ".c.o". If that doesn't exist, maybe there is |
185 | * another transformation rule ".pas.c" that would make "src.pas" an indirect | | 185 | * another transformation rule ".pas.c" that would make "src.pas" an indirect |
186 | * candidate as well. The first such chain that leads to an existing file or | | 186 | * candidate as well. The first such chain that leads to an existing file or |
187 | * node is finally made. | | 187 | * node is finally chosen to be made. |
188 | */ | | 188 | */ |
189 | typedef struct Src { | | 189 | typedef struct Candidate { |
190 | char *file; /* The file to look for */ | | 190 | char *file; /* The file to look for */ |
191 | char *pref; /* Prefix from which file was formed */ | | 191 | char *pref; /* Prefix from which file was formed */ |
192 | Suffix *suff; /* The suffix on the file */ | | 192 | Suffix *suff; /* The suffix on the file */ |
193 | struct Src *parent; /* The Src for which this is a source */ | | 193 | struct Candidate *parent; /* The candidate for which this is a source */ |
194 | GNode *node; /* The node describing the file */ | | 194 | GNode *node; /* The node describing the file */ |
195 | int numChildren; /* Count of existing children (so we don't free | | 195 | int numChildren; /* Count of existing children (so we don't free |
196 | * this thing too early or never nuke it) */ | | 196 | * this thing too early or never nuke it) */ |
197 | #ifdef DEBUG_SRC | | 197 | #ifdef DEBUG_SRC |
198 | SrcList *childrenList; | | 198 | SrcList *childrenList; |
199 | #endif | | 199 | #endif |
200 | } Src; | | 200 | } Candidate; |
201 | | | 201 | |
202 | | | 202 | |
203 | /* TODO: Document the difference between nullSuff and emptySuff. */ | | 203 | /* TODO: Document the difference between nullSuff and emptySuff. */ |
204 | /* The NULL suffix for this run */ | | 204 | /* The NULL suffix for this run */ |
205 | static Suffix *nullSuff; | | 205 | static Suffix *nullSuff; |
206 | /* The empty suffix required for POSIX single-suffix transformation rules */ | | 206 | /* The empty suffix required for POSIX single-suffix transformation rules */ |
207 | static Suffix *emptySuff; | | 207 | static Suffix *emptySuff; |
208 | | | 208 | |
209 | | | 209 | |
210 | static Suffix * | | 210 | static Suffix * |
211 | Suffix_Ref(Suffix *suff) | | 211 | Suffix_Ref(Suffix *suff) |
212 | { | | 212 | { |
213 | suff->refCount++; | | 213 | suff->refCount++; |
| @@ -857,107 +857,102 @@ Suff_AddLib(const char *sname) | | | @@ -857,107 +857,102 @@ Suff_AddLib(const char *sname) |
857 | /********** Implicit Source Search Functions *********/ | | 857 | /********** Implicit Source Search Functions *********/ |
858 | | | 858 | |
859 | #ifdef DEBUG_SRC | | 859 | #ifdef DEBUG_SRC |
860 | static void | | 860 | static void |
861 | SrcList_PrintAddrs(SrcList *srcList) | | 861 | SrcList_PrintAddrs(SrcList *srcList) |
862 | { | | 862 | { |
863 | SrcListNode *ln; | | 863 | SrcListNode *ln; |
864 | for (ln = srcList->first; ln != NULL; ln = ln->next) | | 864 | for (ln = srcList->first; ln != NULL; ln = ln->next) |
865 | debug_printf(" %p", ln->datum); | | 865 | debug_printf(" %p", ln->datum); |
866 | debug_printf("\n"); | | 866 | debug_printf("\n"); |
867 | } | | 867 | } |
868 | #endif | | 868 | #endif |
869 | | | 869 | |
870 | static Src * | | 870 | static Candidate * |
871 | SrcNew(char *name, char *pref, Suffix *suff, Src *parent, GNode *gn) | | 871 | Candidate_New(char *name, char *pref, Suffix *suff, Candidate *parent, |
872 | { | | 872 | GNode *gn) |
873 | Src *src = bmake_malloc(sizeof *src); | | 873 | { |
874 | | | 874 | Candidate *cand = bmake_malloc(sizeof *cand); |
875 | src->file = name; | | 875 | |
876 | src->pref = pref; | | 876 | cand->file = name; |
877 | src->suff = Suffix_Ref(suff); | | 877 | cand->pref = pref; |
878 | src->parent = parent; | | 878 | cand->suff = Suffix_Ref(suff); |
879 | src->node = gn; | | 879 | cand->parent = parent; |
880 | src->numChildren = 0; | | 880 | cand->node = gn; |
| | | 881 | cand->numChildren = 0; |
881 | #ifdef DEBUG_SRC | | 882 | #ifdef DEBUG_SRC |
882 | src->childrenList = Lst_New(); | | 883 | cand->childrenList = Lst_New(); |
883 | #endif | | 884 | #endif |
884 | | | 885 | |
885 | return src; | | 886 | return cand; |
886 | } | | 887 | } |
887 | | | 888 | |
888 | static void | | 889 | static void |
889 | SrcList_Add(SrcList *srcList, char *srcName, Src *targ, Suffix *suff, | | 890 | SrcList_Add(SrcList *srcList, char *srcName, Candidate *targ, Suffix *suff, |
890 | const char *debug_tag) | | 891 | const char *debug_tag) |
891 | { | | 892 | { |
892 | Src *src = SrcNew(srcName, targ->pref, suff, targ, NULL); | | 893 | Candidate *src = Candidate_New(srcName, targ->pref, suff, targ, NULL); |
893 | targ->numChildren++; | | 894 | targ->numChildren++; |
894 | Lst_Append(srcList, src); | | 895 | Lst_Append(srcList, src); |
895 | #ifdef DEBUG_SRC | | 896 | #ifdef DEBUG_SRC |
896 | Lst_Append(targ->childrenList, src); | | 897 | Lst_Append(targ->childrenList, src); |
897 | debug_printf("%s add suff %p src %p to list %p:", | | 898 | debug_printf("%s add suff %p src %p to list %p:", |
898 | debug_tag, targ, src, srcList); | | 899 | debug_tag, targ, src, srcList); |
899 | SrcList_PrintAddrs(srcList); | | 900 | SrcList_PrintAddrs(srcList); |
900 | #endif | | 901 | #endif |
901 | } | | 902 | } |
902 | | | 903 | |
903 | /* Add a suffix as a Src structure to the given list with its parent | | 904 | /* |
904 | * being the given Src structure. If the suffix is the null suffix, | | 905 | * Add a new candidate to the list, formed from the candidate's prefix and |
905 | * the prefix is used unaltered as the filename in the Src structure. | | 906 | * the suffix. |
906 | * | | | |
907 | * Input: | | | |
908 | * suff suffix for which to create a Src structure | | | |
909 | * srcList list for the new Src | | | |
910 | * targ parent for the new Src | | | |
911 | */ | | 907 | */ |
912 | static void | | 908 | static void |
913 | AddSources(Suffix *suff, SrcList *srcList, Src *targ) | | 909 | AddSources(Suffix *suff, SrcList *srcList, Candidate *targ) |
914 | { | | 910 | { |
915 | if ((suff->flags & SUFF_NULL) && suff->name[0] != '\0') { | | 911 | if ((suff->flags & SUFF_NULL) && suff->name[0] != '\0') { |
916 | /* | | 912 | /* |
917 | * If the suffix has been marked as the NULL suffix, also create a Src | | 913 | * If the suffix has been marked as the NULL suffix, also create a |
918 | * structure for a file with no suffix attached. Two birds, and all | | 914 | * candidate for a file with no suffix attached. |
919 | * that... | | | |
920 | */ | | 915 | */ |
921 | SrcList_Add(srcList, bmake_strdup(targ->pref), targ, suff, "1"); | | 916 | SrcList_Add(srcList, bmake_strdup(targ->pref), targ, suff, "1"); |
922 | } | | 917 | } |
923 | SrcList_Add(srcList, str_concat2(targ->pref, suff->name), targ, suff, "2"); | | 918 | SrcList_Add(srcList, str_concat2(targ->pref, suff->name), targ, suff, "2"); |
924 | } | | 919 | } |
925 | | | 920 | |
926 | /* Add all the children of targ to the list. */ | | 921 | /* Add all the children of targ to the list. */ |
927 | static void | | 922 | static void |
928 | AddLevel(SrcList *srcs, Src *targ) | | 923 | AddLevel(SrcList *srcs, Candidate *targ) |
929 | { | | 924 | { |
930 | SrcListNode *ln; | | 925 | SrcListNode *ln; |
931 | for (ln = targ->suff->children->first; ln != NULL; ln = ln->next) { | | 926 | for (ln = targ->suff->children->first; ln != NULL; ln = ln->next) { |
932 | Suffix *childSuff = ln->datum; | | 927 | Suffix *childSuff = ln->datum; |
933 | AddSources(childSuff, srcs, targ); | | 928 | AddSources(childSuff, srcs, targ); |
934 | } | | 929 | } |
935 | } | | 930 | } |
936 | | | 931 | |
937 | /* Free the first Src in the list that is not referenced anymore. | | 932 | /* Free the first candidate in the list that is not referenced anymore. |
938 | * Return whether a Src was removed. */ | | 933 | * Return whether a candidate was removed. */ |
939 | static Boolean | | 934 | static Boolean |
940 | RemoveSrc(SrcList *srcs) | | 935 | RemoveSrc(SrcList *srcs) |
941 | { | | 936 | { |
942 | SrcListNode *ln; | | 937 | SrcListNode *ln; |
943 | | | 938 | |
944 | #ifdef DEBUG_SRC | | 939 | #ifdef DEBUG_SRC |
945 | debug_printf("cleaning list %p:", srcs); | | 940 | debug_printf("cleaning list %p:", srcs); |
946 | SrcList_PrintAddrs(srcs); | | 941 | SrcList_PrintAddrs(srcs); |
947 | #endif | | 942 | #endif |
948 | | | 943 | |
949 | for (ln = srcs->first; ln != NULL; ln = ln->next) { | | 944 | for (ln = srcs->first; ln != NULL; ln = ln->next) { |
950 | Src *src = ln->datum; | | 945 | Candidate *src = ln->datum; |
951 | | | 946 | |
952 | if (src->numChildren == 0) { | | 947 | if (src->numChildren == 0) { |
953 | free(src->file); | | 948 | free(src->file); |
954 | if (src->parent == NULL) | | 949 | if (src->parent == NULL) |
955 | free(src->pref); | | 950 | free(src->pref); |
956 | else { | | 951 | else { |
957 | #ifdef DEBUG_SRC | | 952 | #ifdef DEBUG_SRC |
958 | SrcListNode *ln2 = Lst_FindDatum(src->parent->childrenList, src); | | 953 | SrcListNode *ln2 = Lst_FindDatum(src->parent->childrenList, src); |
959 | if (ln2 != NULL) | | 954 | if (ln2 != NULL) |
960 | Lst_Remove(src->parent->childrenList, ln2); | | 955 | Lst_Remove(src->parent->childrenList, ln2); |
961 | #endif | | 956 | #endif |
962 | src->parent->numChildren--; | | 957 | src->parent->numChildren--; |
963 | } | | 958 | } |
| @@ -973,33 +968,33 @@ RemoveSrc(SrcList *srcs) | | | @@ -973,33 +968,33 @@ RemoveSrc(SrcList *srcs) |
973 | #ifdef DEBUG_SRC | | 968 | #ifdef DEBUG_SRC |
974 | else { | | 969 | else { |
975 | debug_printf("keep: list %p src %p children %d:", | | 970 | debug_printf("keep: list %p src %p children %d:", |
976 | srcs, src, src->numChildren); | | 971 | srcs, src, src->numChildren); |
977 | SrcList_PrintAddrs(src->childrenList); | | 972 | SrcList_PrintAddrs(src->childrenList); |
978 | } | | 973 | } |
979 | #endif | | 974 | #endif |
980 | } | | 975 | } |
981 | | | 976 | |
982 | return FALSE; | | 977 | return FALSE; |
983 | } | | 978 | } |
984 | | | 979 | |
985 | /* Find the first existing file/target in srcs. */ | | 980 | /* Find the first existing file/target in srcs. */ |
986 | static Src * | | 981 | static Candidate * |
987 | FindThem(SrcList *srcs, SrcList *slst) | | 982 | FindThem(SrcList *srcs, SrcList *slst) |
988 | { | | 983 | { |
989 | Src *retsrc = NULL; | | 984 | Candidate *retsrc = NULL; |
990 | | | 985 | |
991 | while (!Lst_IsEmpty(srcs)) { | | 986 | while (!Lst_IsEmpty(srcs)) { |
992 | Src *src = Lst_Dequeue(srcs); | | 987 | Candidate *src = Lst_Dequeue(srcs); |
993 | | | 988 | |
994 | SUFF_DEBUG1("\ttrying %s...", src->file); | | 989 | SUFF_DEBUG1("\ttrying %s...", src->file); |
995 | | | 990 | |
996 | /* | | 991 | /* |
997 | * A file is considered to exist if either a node exists in the | | 992 | * A file is considered to exist if either a node exists in the |
998 | * graph for it or the file actually exists. | | 993 | * graph for it or the file actually exists. |
999 | */ | | 994 | */ |
1000 | if (Targ_FindNode(src->file) != NULL) { | | 995 | if (Targ_FindNode(src->file) != NULL) { |
1001 | #ifdef DEBUG_SRC | | 996 | #ifdef DEBUG_SRC |
1002 | debug_printf("remove from list %p src %p\n", srcs, src); | | 997 | debug_printf("remove from list %p src %p\n", srcs, src); |
1003 | #endif | | 998 | #endif |
1004 | retsrc = src; | | 999 | retsrc = src; |
1005 | break; | | 1000 | break; |
| @@ -1019,45 +1014,40 @@ FindThem(SrcList *srcs, SrcList *slst) | | | @@ -1019,45 +1014,40 @@ FindThem(SrcList *srcs, SrcList *slst) |
1019 | | | 1014 | |
1020 | SUFF_DEBUG0("not there\n"); | | 1015 | SUFF_DEBUG0("not there\n"); |
1021 | | | 1016 | |
1022 | AddLevel(srcs, src); | | 1017 | AddLevel(srcs, src); |
1023 | Lst_Append(slst, src); | | 1018 | Lst_Append(slst, src); |
1024 | } | | 1019 | } |
1025 | | | 1020 | |
1026 | if (retsrc) { | | 1021 | if (retsrc) { |
1027 | SUFF_DEBUG0("got it\n"); | | 1022 | SUFF_DEBUG0("got it\n"); |
1028 | } | | 1023 | } |
1029 | return retsrc; | | 1024 | return retsrc; |
1030 | } | | 1025 | } |
1031 | | | 1026 | |
1032 | /* See if any of the children of the target in the Src structure is one from | | 1027 | /* |
1033 | * which the target can be transformed. If there is one, a Src structure is | | 1028 | * See if any of the children of the candidate's GNode is one from which the |
1034 | * put together for it and returned. | | 1029 | * target can be transformed. If there is one, a candidate is put together |
1035 | * | | 1030 | * for it and returned. |
1036 | * Input: | | | |
1037 | * targ Src to play with | | | |
1038 | * | | | |
1039 | * Results: | | | |
1040 | * The Src of the "winning" child, or NULL. | | | |
1041 | */ | | 1031 | */ |
1042 | static Src * | | 1032 | static Candidate * |
1043 | FindCmds(Src *targ, SrcList *slst) | | 1033 | FindCmds(Candidate *targ, SrcList *slst) |
1044 | { | | 1034 | { |
1045 | GNodeListNode *gln; | | 1035 | GNodeListNode *gln; |
1046 | GNode *tgn; /* Target GNode */ | | 1036 | GNode *tgn; /* Target GNode */ |
1047 | GNode *sgn; /* Source GNode */ | | 1037 | GNode *sgn; /* Source GNode */ |
1048 | size_t prefLen; /* The length of the defined prefix */ | | 1038 | size_t prefLen; /* The length of the defined prefix */ |
1049 | Suffix *suff; /* Suffix on matching beastie */ | | 1039 | Suffix *suff; /* Suffix on matching beastie */ |
1050 | Src *ret; /* Return value */ | | 1040 | Candidate *ret; /* Return value */ |
1051 | char *cp; | | 1041 | char *cp; |
1052 | | | 1042 | |
1053 | tgn = targ->node; | | 1043 | tgn = targ->node; |
1054 | prefLen = strlen(targ->pref); | | 1044 | prefLen = strlen(targ->pref); |
1055 | | | 1045 | |
1056 | for (gln = tgn->children->first; gln != NULL; gln = gln->next) { | | 1046 | for (gln = tgn->children->first; gln != NULL; gln = gln->next) { |
1057 | sgn = gln->datum; | | 1047 | sgn = gln->datum; |
1058 | | | 1048 | |
1059 | if (sgn->type & OP_OPTIONAL && Lst_IsEmpty(tgn->commands)) { | | 1049 | if (sgn->type & OP_OPTIONAL && Lst_IsEmpty(tgn->commands)) { |
1060 | /* | | 1050 | /* |
1061 | * We haven't looked to see if .OPTIONAL files exist yet, so | | 1051 | * We haven't looked to see if .OPTIONAL files exist yet, so |
1062 | * don't use one as the implicit source. | | 1052 | * don't use one as the implicit source. |
1063 | * This allows us to use .OPTIONAL in .depend files so make won't | | 1053 | * This allows us to use .OPTIONAL in .depend files so make won't |
| @@ -1084,33 +1074,27 @@ FindCmds(Src *targ, SrcList *slst) | | | @@ -1084,33 +1074,27 @@ FindCmds(Src *targ, SrcList *slst) |
1084 | * It even has a known suffix, see if there's a transformation | | 1074 | * It even has a known suffix, see if there's a transformation |
1085 | * defined between the node's suffix and the target's suffix. | | 1075 | * defined between the node's suffix and the target's suffix. |
1086 | * | | 1076 | * |
1087 | * XXX: Handle multi-stage transformations here, too. | | 1077 | * XXX: Handle multi-stage transformations here, too. |
1088 | */ | | 1078 | */ |
1089 | | | 1079 | |
1090 | if (Lst_FindDatum(suff->parents, targ->suff) != NULL) | | 1080 | if (Lst_FindDatum(suff->parents, targ->suff) != NULL) |
1091 | break; | | 1081 | break; |
1092 | } | | 1082 | } |
1093 | | | 1083 | |
1094 | if (gln == NULL) | | 1084 | if (gln == NULL) |
1095 | return NULL; | | 1085 | return NULL; |
1096 | | | 1086 | |
1097 | /* | | 1087 | ret = Candidate_New(bmake_strdup(sgn->name), targ->pref, suff, targ, sgn); |
1098 | * Hot Damn! Create a new Src structure to describe | | | |
1099 | * this transformation (making sure to duplicate the | | | |
1100 | * source node's name so Suff_FindDeps can free it | | | |
1101 | * again (ick)), and return the new structure. | | | |
1102 | */ | | | |
1103 | ret = SrcNew(bmake_strdup(sgn->name), targ->pref, suff, targ, sgn); | | | |
1104 | targ->numChildren++; | | 1088 | targ->numChildren++; |
1105 | #ifdef DEBUG_SRC | | 1089 | #ifdef DEBUG_SRC |
1106 | debug_printf("3 add targ %p ret %p\n", targ, ret); | | 1090 | debug_printf("3 add targ %p ret %p\n", targ, ret); |
1107 | Lst_Append(targ->childrenList, ret); | | 1091 | Lst_Append(targ->childrenList, ret); |
1108 | #endif | | 1092 | #endif |
1109 | Lst_Append(slst, ret); | | 1093 | Lst_Append(slst, ret); |
1110 | SUFF_DEBUG1("\tusing existing source %s\n", sgn->name); | | 1094 | SUFF_DEBUG1("\tusing existing source %s\n", sgn->name); |
1111 | return ret; | | 1095 | return ret; |
1112 | } | | 1096 | } |
1113 | | | 1097 | |
1114 | static void | | 1098 | static void |
1115 | ExpandWildcards(GNodeListNode *cln, GNode *pgn) | | 1099 | ExpandWildcards(GNodeListNode *cln, GNode *pgn) |
1116 | { | | 1100 | { |
| @@ -1545,88 +1529,88 @@ FindDepsArchive(GNode *gn, SrcList *slst | | | @@ -1545,88 +1529,88 @@ FindDepsArchive(GNode *gn, SrcList *slst |
1545 | /* | | 1529 | /* |
1546 | * Flag the member as such so we remember to look in the archive for | | 1530 | * Flag the member as such so we remember to look in the archive for |
1547 | * its modification time. The OP_JOIN | OP_MADE is needed because this | | 1531 | * its modification time. The OP_JOIN | OP_MADE is needed because this |
1548 | * target should never get made. | | 1532 | * target should never get made. |
1549 | */ | | 1533 | */ |
1550 | mem->type |= OP_MEMBER | OP_JOIN | OP_MADE; | | 1534 | mem->type |= OP_MEMBER | OP_JOIN | OP_MADE; |
1551 | } | | 1535 | } |
1552 | | | 1536 | |
1553 | static void | | 1537 | static void |
1554 | FindDepsRegularKnown(const char *name, size_t nameLen, GNode *gn, | | 1538 | FindDepsRegularKnown(const char *name, size_t nameLen, GNode *gn, |
1555 | SrcList *srcs, SrcList *targs) | | 1539 | SrcList *srcs, SrcList *targs) |
1556 | { | | 1540 | { |
1557 | SuffixListNode *ln; | | 1541 | SuffixListNode *ln; |
1558 | Src *targ; | | 1542 | Candidate *targ; |
1559 | char *pref; | | 1543 | char *pref; |
1560 | | | 1544 | |
1561 | for (ln = sufflist->first; ln != NULL; ln = ln->next) { | | 1545 | for (ln = sufflist->first; ln != NULL; ln = ln->next) { |
1562 | Suffix *suff = ln->datum; | | 1546 | Suffix *suff = ln->datum; |
1563 | if (!Suffix_IsSuffix(suff, nameLen, name + nameLen)) | | 1547 | if (!Suffix_IsSuffix(suff, nameLen, name + nameLen)) |
1564 | continue; | | 1548 | continue; |
1565 | | | 1549 | |
1566 | pref = bmake_strldup(name, (size_t)(nameLen - suff->nameLen)); | | 1550 | pref = bmake_strldup(name, (size_t)(nameLen - suff->nameLen)); |
1567 | targ = SrcNew(bmake_strdup(gn->name), pref, suff, NULL, gn); | | 1551 | targ = Candidate_New(bmake_strdup(gn->name), pref, suff, NULL, gn); |
1568 | | | 1552 | |
1569 | /* | | 1553 | /* |
1570 | * Add nodes from which the target can be made | | 1554 | * Add nodes from which the target can be made |
1571 | */ | | 1555 | */ |
1572 | AddLevel(srcs, targ); | | 1556 | AddLevel(srcs, targ); |
1573 | | | 1557 | |
1574 | /* | | 1558 | /* |
1575 | * Record the target so we can nuke it | | 1559 | * Record the target so we can nuke it |
1576 | */ | | 1560 | */ |
1577 | Lst_Append(targs, targ); | | 1561 | Lst_Append(targs, targ); |
1578 | } | | 1562 | } |
1579 | } | | 1563 | } |
1580 | | | 1564 | |
1581 | static void | | 1565 | static void |
1582 | FindDepsRegularUnknown(GNode *gn, const char *sopref, | | 1566 | FindDepsRegularUnknown(GNode *gn, const char *sopref, |
1583 | SrcList *srcs, SrcList *targs) | | 1567 | SrcList *srcs, SrcList *targs) |
1584 | { | | 1568 | { |
1585 | Src *targ; | | 1569 | Candidate *targ; |
1586 | | | 1570 | |
1587 | if (!Lst_IsEmpty(targs) || nullSuff == NULL) | | 1571 | if (!Lst_IsEmpty(targs) || nullSuff == NULL) |
1588 | return; | | 1572 | return; |
1589 | | | 1573 | |
1590 | SUFF_DEBUG1("\tNo known suffix on %s. Using .NULL suffix\n", gn->name); | | 1574 | SUFF_DEBUG1("\tNo known suffix on %s. Using .NULL suffix\n", gn->name); |
1591 | | | 1575 | |
1592 | targ = SrcNew(bmake_strdup(gn->name), bmake_strdup(sopref), | | 1576 | targ = Candidate_New(bmake_strdup(gn->name), bmake_strdup(sopref), |
1593 | nullSuff, NULL, gn); | | 1577 | nullSuff, NULL, gn); |
1594 | | | 1578 | |
1595 | /* | | 1579 | /* |
1596 | * Only use the default suffix rules if we don't have commands | | 1580 | * Only use the default suffix rules if we don't have commands |
1597 | * defined for this gnode; traditional make programs used to | | 1581 | * defined for this gnode; traditional make programs used to |
1598 | * not define suffix rules if the gnode had children but we | | 1582 | * not define suffix rules if the gnode had children but we |
1599 | * don't do this anymore. | | 1583 | * don't do this anymore. |
1600 | */ | | 1584 | */ |
1601 | if (Lst_IsEmpty(gn->commands)) | | 1585 | if (Lst_IsEmpty(gn->commands)) |
1602 | AddLevel(srcs, targ); | | 1586 | AddLevel(srcs, targ); |
1603 | else { | | 1587 | else { |
1604 | SUFF_DEBUG0("not "); | | 1588 | SUFF_DEBUG0("not "); |
1605 | } | | 1589 | } |
1606 | | | 1590 | |
1607 | SUFF_DEBUG0("adding suffix rules\n"); | | 1591 | SUFF_DEBUG0("adding suffix rules\n"); |
1608 | | | 1592 | |
1609 | Lst_Append(targs, targ); | | 1593 | Lst_Append(targs, targ); |
1610 | } | | 1594 | } |
1611 | | | 1595 | |
1612 | /* | | 1596 | /* |
1613 | * Deal with finding the thing on the default search path. We | | 1597 | * Deal with finding the thing on the default search path. We |
1614 | * always do that, not only if the node is only a source (not | | 1598 | * always do that, not only if the node is only a source (not |
1615 | * on the lhs of a dependency operator or [XXX] it has neither | | 1599 | * on the lhs of a dependency operator or [XXX] it has neither |
1616 | * children or commands) as the old pmake did. | | 1600 | * children or commands) as the old pmake did. |
1617 | */ | | 1601 | */ |
1618 | static void | | 1602 | static void |
1619 | FindDepsRegularPath(GNode *gn, Src *targ) | | 1603 | FindDepsRegularPath(GNode *gn, Candidate *targ) |
1620 | { | | 1604 | { |
1621 | if (gn->type & (OP_PHONY | OP_NOPATH)) | | 1605 | if (gn->type & (OP_PHONY | OP_NOPATH)) |
1622 | return; | | 1606 | return; |
1623 | | | 1607 | |
1624 | free(gn->path); | | 1608 | free(gn->path); |
1625 | gn->path = Dir_FindFile(gn->name, | | 1609 | gn->path = Dir_FindFile(gn->name, |
1626 | (targ == NULL ? dirSearchPath : | | 1610 | (targ == NULL ? dirSearchPath : |
1627 | targ->suff->searchPath)); | | 1611 | targ->suff->searchPath)); |
1628 | if (gn->path == NULL) | | 1612 | if (gn->path == NULL) |
1629 | return; | | 1613 | return; |
1630 | | | 1614 | |
1631 | Var_Set(TARGET, gn->path, gn); | | 1615 | Var_Set(TARGET, gn->path, gn); |
1632 | | | 1616 | |
| @@ -1672,30 +1656,30 @@ FindDepsRegularPath(GNode *gn, Src *targ | | | @@ -1672,30 +1656,30 @@ FindDepsRegularPath(GNode *gn, Src *targ |
1672 | * Input: | | 1656 | * Input: |
1673 | * gn Node for which to find sources | | 1657 | * gn Node for which to find sources |
1674 | * | | 1658 | * |
1675 | * Side Effects: | | 1659 | * Side Effects: |
1676 | * Same as Suff_FindDeps | | 1660 | * Same as Suff_FindDeps |
1677 | */ | | 1661 | */ |
1678 | static void | | 1662 | static void |
1679 | FindDepsRegular(GNode *gn, SrcList *slst) | | 1663 | FindDepsRegular(GNode *gn, SrcList *slst) |
1680 | { | | 1664 | { |
1681 | SrcList *srcs; /* List of sources at which to look */ | | 1665 | SrcList *srcs; /* List of sources at which to look */ |
1682 | SrcList *targs; /* List of targets to which things can be | | 1666 | SrcList *targs; /* List of targets to which things can be |
1683 | * transformed. They all have the same file, | | 1667 | * transformed. They all have the same file, |
1684 | * but different suff and pref fields */ | | 1668 | * but different suff and pref fields */ |
1685 | Src *bottom; /* Start of found transformation path */ | | 1669 | Candidate *bottom; /* Start of found transformation path */ |
1686 | Src *src; /* General Src pointer */ | | 1670 | Candidate *src; |
1687 | char *pref; /* Prefix to use */ | | 1671 | char *pref; /* Prefix to use */ |
1688 | Src *targ; /* General Src target pointer */ | | 1672 | Candidate *targ; |
1689 | | | 1673 | |
1690 | const char *name = gn->name; | | 1674 | const char *name = gn->name; |
1691 | size_t nameLen = strlen(name); | | 1675 | size_t nameLen = strlen(name); |
1692 | | | 1676 | |
1693 | /* | | 1677 | /* |
1694 | * Begin at the beginning... | | 1678 | * Begin at the beginning... |
1695 | */ | | 1679 | */ |
1696 | srcs = Lst_New(); | | 1680 | srcs = Lst_New(); |
1697 | targs = Lst_New(); | | 1681 | targs = Lst_New(); |
1698 | | | 1682 | |
1699 | /* | | 1683 | /* |
1700 | * We're caught in a catch-22 here. On the one hand, we want to use any | | 1684 | * We're caught in a catch-22 here. On the one hand, we want to use any |
1701 | * transformation implied by the target's sources, but we can't examine | | 1685 | * transformation implied by the target's sources, but we can't examine |
| @@ -1779,56 +1763,56 @@ sfnd_abort: | | | @@ -1779,56 +1763,56 @@ sfnd_abort: |
1779 | * the node's type field. | | 1763 | * the node's type field. |
1780 | */ | | 1764 | */ |
1781 | if (targ->suff->flags & SUFF_LIBRARY) | | 1765 | if (targ->suff->flags & SUFF_LIBRARY) |
1782 | gn->type |= OP_LIB; | | 1766 | gn->type |= OP_LIB; |
1783 | | | 1767 | |
1784 | /* | | 1768 | /* |
1785 | * Check for overriding transformation rule implied by sources | | 1769 | * Check for overriding transformation rule implied by sources |
1786 | */ | | 1770 | */ |
1787 | if (!Lst_IsEmpty(gn->children)) { | | 1771 | if (!Lst_IsEmpty(gn->children)) { |
1788 | src = FindCmds(targ, slst); | | 1772 | src = FindCmds(targ, slst); |
1789 | | | 1773 | |
1790 | if (src != NULL) { | | 1774 | if (src != NULL) { |
1791 | /* | | 1775 | /* |
1792 | * Free up all the Src structures in the transformation path | | 1776 | * Free up all the candidates in the transformation path, |
1793 | * up to, but not including, the parent node. | | 1777 | * up to but not including the parent node. |
1794 | */ | | 1778 | */ |
1795 | while (bottom != NULL && bottom->parent != NULL) { | | 1779 | while (bottom != NULL && bottom->parent != NULL) { |
1796 | if (Lst_FindDatum(slst, bottom) == NULL) | | 1780 | if (Lst_FindDatum(slst, bottom) == NULL) |
1797 | Lst_Append(slst, bottom); | | 1781 | Lst_Append(slst, bottom); |
1798 | bottom = bottom->parent; | | 1782 | bottom = bottom->parent; |
1799 | } | | 1783 | } |
1800 | bottom = src; | | 1784 | bottom = src; |
1801 | } | | 1785 | } |
1802 | } | | 1786 | } |
1803 | | | 1787 | |
1804 | if (bottom == NULL) { | | 1788 | if (bottom == NULL) { |
1805 | /* | | 1789 | /* |
1806 | * No idea from where it can come -- return now. | | 1790 | * No idea from where it can come -- return now. |
1807 | */ | | 1791 | */ |
1808 | goto sfnd_abort; | | 1792 | goto sfnd_abort; |
1809 | } | | 1793 | } |
1810 | | | 1794 | |
1811 | /* | | 1795 | /* |
1812 | * We now have a list of Src structures headed by 'bottom' and linked via | | 1796 | * We now have a list of candidates headed by 'bottom' and linked via |
1813 | * their 'parent' pointers. What we do next is create links between | | 1797 | * their 'parent' pointers. What we do next is create links between |
1814 | * source and target nodes (which may or may not have been created) | | 1798 | * source and target nodes (which may or may not have been created) |
1815 | * and set the necessary local variables in each target. The | | 1799 | * and set the necessary local variables in each target. |
1816 | * commands for each target are set from the commands of the | | 1800 | * |
| | | 1801 | * The commands for each target are set from the commands of the |
1817 | * transformation rule used to get from the src suffix to the targ | | 1802 | * transformation rule used to get from the src suffix to the targ |
1818 | * suffix. Note that this causes the commands list of the original | | 1803 | * suffix. Note that this causes the commands list of the original |
1819 | * node, gn, to be replaced by the commands of the final | | 1804 | * node, gn, to be replaced with the commands of the final |
1820 | * transformation rule. Also, the unmade field of gn is incremented. | | 1805 | * transformation rule. |
1821 | * Etc. | | | |
1822 | */ | | 1806 | */ |
1823 | if (bottom->node == NULL) | | 1807 | if (bottom->node == NULL) |
1824 | bottom->node = Targ_GetNode(bottom->file); | | 1808 | bottom->node = Targ_GetNode(bottom->file); |
1825 | | | 1809 | |
1826 | for (src = bottom; src->parent != NULL; src = src->parent) { | | 1810 | for (src = bottom; src->parent != NULL; src = src->parent) { |
1827 | targ = src->parent; | | 1811 | targ = src->parent; |
1828 | | | 1812 | |
1829 | Suffix_Reassign(&src->node->suffix, src->suff); | | 1813 | Suffix_Reassign(&src->node->suffix, src->suff); |
1830 | | | 1814 | |
1831 | if (targ->node == NULL) | | 1815 | if (targ->node == NULL) |
1832 | targ->node = Targ_GetNode(targ->file); | | 1816 | targ->node = Targ_GetNode(targ->file); |
1833 | | | 1817 | |
1834 | ApplyTransform(targ->node, src->node, | | 1818 | ApplyTransform(targ->node, src->node, |
| @@ -1842,27 +1826,27 @@ sfnd_abort: | | | @@ -1842,27 +1826,27 @@ sfnd_abort: |
1842 | * known). Note that the node can't have any sources that | | 1826 | * known). Note that the node can't have any sources that |
1843 | * need expanding, since SuffFindThem will stop on an existing | | 1827 | * need expanding, since SuffFindThem will stop on an existing |
1844 | * node, so all we need to do is set the standard variables. | | 1828 | * node, so all we need to do is set the standard variables. |
1845 | */ | | 1829 | */ |
1846 | targ->node->type |= OP_DEPS_FOUND; | | 1830 | targ->node->type |= OP_DEPS_FOUND; |
1847 | Var_Set(PREFIX, targ->pref, targ->node); | | 1831 | Var_Set(PREFIX, targ->pref, targ->node); |
1848 | Var_Set(TARGET, targ->node->name, targ->node); | | 1832 | Var_Set(TARGET, targ->node->name, targ->node); |
1849 | } | | 1833 | } |
1850 | } | | 1834 | } |
1851 | | | 1835 | |
1852 | Suffix_Reassign(&gn->suffix, src->suff); | | 1836 | Suffix_Reassign(&gn->suffix, src->suff); |
1853 | | | 1837 | |
1854 | /* | | 1838 | /* |
1855 | * Nuke the transformation path and the Src structures left over in the | | 1839 | * Nuke the transformation path and the candidates left over in the |
1856 | * two lists. | | 1840 | * two lists. |
1857 | */ | | 1841 | */ |
1858 | sfnd_return: | | 1842 | sfnd_return: |
1859 | if (bottom != NULL && Lst_FindDatum(slst, bottom) == NULL) | | 1843 | if (bottom != NULL && Lst_FindDatum(slst, bottom) == NULL) |
1860 | Lst_Append(slst, bottom); | | 1844 | Lst_Append(slst, bottom); |
1861 | | | 1845 | |
1862 | while (RemoveSrc(srcs) || RemoveSrc(targs)) | | 1846 | while (RemoveSrc(srcs) || RemoveSrc(targs)) |
1863 | continue; | | 1847 | continue; |
1864 | | | 1848 | |
1865 | Lst_MoveAll(slst, srcs); | | 1849 | Lst_MoveAll(slst, srcs); |
1866 | Lst_MoveAll(slst, targs); | | 1850 | Lst_MoveAll(slst, targs); |
1867 | } | | 1851 | } |
1868 | | | 1852 | |