suff.c (250773) | suff.c (250837) |
---|---|
1/* $NetBSD: suff.c,v 1.69 2011/09/29 23:38:04 sjg Exp $ */ | 1/* $NetBSD: suff.c,v 1.70 2013/05/18 13:13:34 sjg Exp $ */ |
2 3/* 4 * Copyright (c) 1988, 1989, 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Adam de Boor. 9 * --- 54 unchanged lines hidden (view full) --- 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 68 * SUCH DAMAGE. 69 */ 70 71#ifndef MAKE_NATIVE | 2 3/* 4 * Copyright (c) 1988, 1989, 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Adam de Boor. 9 * --- 54 unchanged lines hidden (view full) --- 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 68 * SUCH DAMAGE. 69 */ 70 71#ifndef MAKE_NATIVE |
72static char rcsid[] = "$NetBSD: suff.c,v 1.69 2011/09/29 23:38:04 sjg Exp $"; | 72static char rcsid[] = "$NetBSD: suff.c,v 1.70 2013/05/18 13:13:34 sjg Exp $"; |
73#else 74#include <sys/cdefs.h> 75#ifndef lint 76#if 0 77static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; 78#else | 73#else 74#include <sys/cdefs.h> 75#ifndef lint 76#if 0 77static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; 78#else |
79__RCSID("$NetBSD: suff.c,v 1.69 2011/09/29 23:38:04 sjg Exp $"); | 79__RCSID("$NetBSD: suff.c,v 1.70 2013/05/18 13:13:34 sjg Exp $"); |
80#endif 81#endif /* not lint */ 82#endif 83 84/*- 85 * suff.c -- 86 * Functions to maintain suffix lists and find implicit dependents 87 * using suffix transformation rules --- 1970 unchanged lines hidden (view full) --- 2058 * children, then look for any overriding transformations they imply. 2059 * Should we find one, we discard the one we found before. 2060 */ 2061 bottom = NULL; 2062 targ = NULL; 2063 2064 if (!(gn->type & OP_PHONY)) { 2065 | 80#endif 81#endif /* not lint */ 82#endif 83 84/*- 85 * suff.c -- 86 * Functions to maintain suffix lists and find implicit dependents 87 * using suffix transformation rules --- 1970 unchanged lines hidden (view full) --- 2058 * children, then look for any overriding transformations they imply. 2059 * Should we find one, we discard the one we found before. 2060 */ 2061 bottom = NULL; 2062 targ = NULL; 2063 2064 if (!(gn->type & OP_PHONY)) { 2065 |
2066 while (ln != NULL) { | 2066 while (ln != NULL) { 2067 /* 2068 * Look for next possible suffix... 2069 */ 2070 ln = Lst_FindFrom(sufflist, ln, &sd, SuffSuffIsSuffixP); 2071 2072 if (ln != NULL) { 2073 int prefLen; /* Length of the prefix */ 2074 2075 /* 2076 * Allocate a Src structure to which things can be transformed 2077 */ 2078 targ = bmake_malloc(sizeof(Src)); 2079 targ->file = bmake_strdup(gn->name); 2080 targ->suff = (Suff *)Lst_Datum(ln); 2081 targ->suff->refCount++; 2082 targ->node = gn; 2083 targ->parent = NULL; 2084 targ->children = 0; 2085#ifdef DEBUG_SRC 2086 targ->cp = Lst_Init(FALSE); 2087#endif 2088 2089 /* 2090 * Allocate room for the prefix, whose end is found by 2091 * subtracting the length of the suffix from 2092 * the end of the name. 2093 */ 2094 prefLen = (eoname - targ->suff->nameLen) - sopref; 2095 targ->pref = bmake_malloc(prefLen + 1); 2096 memcpy(targ->pref, sopref, prefLen); 2097 targ->pref[prefLen] = '\0'; 2098 2099 /* 2100 * Add nodes from which the target can be made 2101 */ 2102 SuffAddLevel(srcs, targ); 2103 2104 /* 2105 * Record the target so we can nuke it 2106 */ 2107 (void)Lst_AtEnd(targs, targ); 2108 2109 /* 2110 * Search from this suffix's successor... 2111 */ 2112 ln = Lst_Succ(ln); 2113 } 2114 } 2115 |
2067 /* | 2116 /* |
2068 * Look for next possible suffix... | 2117 * Handle target of unknown suffix... |
2069 */ | 2118 */ |
2070 ln = Lst_FindFrom(sufflist, ln, &sd, SuffSuffIsSuffixP); | 2119 if (Lst_IsEmpty(targs) && suffNull != NULL) { 2120 if (DEBUG(SUFF)) { 2121 fprintf(debug_file, "\tNo known suffix on %s. Using .NULL suffix\n", gn->name); 2122 } |
2071 | 2123 |
2072 if (ln != NULL) { 2073 int prefLen; /* Length of the prefix */ 2074 2075 /* 2076 * Allocate a Src structure to which things can be transformed 2077 */ | |
2078 targ = bmake_malloc(sizeof(Src)); 2079 targ->file = bmake_strdup(gn->name); | 2124 targ = bmake_malloc(sizeof(Src)); 2125 targ->file = bmake_strdup(gn->name); |
2080 targ->suff = (Suff *)Lst_Datum(ln); | 2126 targ->suff = suffNull; |
2081 targ->suff->refCount++; 2082 targ->node = gn; 2083 targ->parent = NULL; 2084 targ->children = 0; | 2127 targ->suff->refCount++; 2128 targ->node = gn; 2129 targ->parent = NULL; 2130 targ->children = 0; |
2131 targ->pref = bmake_strdup(sopref); |
|
2085#ifdef DEBUG_SRC 2086 targ->cp = Lst_Init(FALSE); 2087#endif 2088 2089 /* | 2132#ifdef DEBUG_SRC 2133 targ->cp = Lst_Init(FALSE); 2134#endif 2135 2136 /* |
2090 * Allocate room for the prefix, whose end is found by subtracting 2091 * the length of the suffix from the end of the name. | 2137 * Only use the default suffix rules if we don't have commands 2138 * defined for this gnode; traditional make programs used to 2139 * not define suffix rules if the gnode had children but we 2140 * don't do this anymore. |
2092 */ | 2141 */ |
2093 prefLen = (eoname - targ->suff->nameLen) - sopref; 2094 targ->pref = bmake_malloc(prefLen + 1); 2095 memcpy(targ->pref, sopref, prefLen); 2096 targ->pref[prefLen] = '\0'; | 2142 if (Lst_IsEmpty(gn->commands)) 2143 SuffAddLevel(srcs, targ); 2144 else { 2145 if (DEBUG(SUFF)) 2146 fprintf(debug_file, "not "); 2147 } |
2097 | 2148 |
2098 /* 2099 * Add nodes from which the target can be made 2100 */ 2101 SuffAddLevel(srcs, targ); | 2149 if (DEBUG(SUFF)) 2150 fprintf(debug_file, "adding suffix rules\n"); |
2102 | 2151 |
2103 /* 2104 * Record the target so we can nuke it 2105 */ | |
2106 (void)Lst_AtEnd(targs, targ); | 2152 (void)Lst_AtEnd(targs, targ); |
2107 2108 /* 2109 * Search from this suffix's successor... 2110 */ 2111 ln = Lst_Succ(ln); | |
2112 } | 2153 } |
2113 } | |
2114 | 2154 |
2115 /* 2116 * Handle target of unknown suffix... 2117 */ 2118 if (Lst_IsEmpty(targs) && suffNull != NULL) { 2119 if (DEBUG(SUFF)) { 2120 fprintf(debug_file, "\tNo known suffix on %s. Using .NULL suffix\n", gn->name); 2121 } 2122 2123 targ = bmake_malloc(sizeof(Src)); 2124 targ->file = bmake_strdup(gn->name); 2125 targ->suff = suffNull; 2126 targ->suff->refCount++; 2127 targ->node = gn; 2128 targ->parent = NULL; 2129 targ->children = 0; 2130 targ->pref = bmake_strdup(sopref); 2131#ifdef DEBUG_SRC 2132 targ->cp = Lst_Init(FALSE); 2133#endif 2134 | |
2135 /* | 2155 /* |
2136 * Only use the default suffix rules if we don't have commands 2137 * defined for this gnode; traditional make programs used to 2138 * not define suffix rules if the gnode had children but we 2139 * don't do this anymore. | 2156 * Using the list of possible sources built up from the target 2157 * suffix(es), try and find an existing file/target that matches. |
2140 */ | 2158 */ |
2141 if (Lst_IsEmpty(gn->commands)) 2142 SuffAddLevel(srcs, targ); 2143 else { 2144 if (DEBUG(SUFF)) 2145 fprintf(debug_file, "not "); 2146 } | 2159 bottom = SuffFindThem(srcs, slst); |
2147 | 2160 |
2148 if (DEBUG(SUFF)) 2149 fprintf(debug_file, "adding suffix rules\n"); 2150 2151 (void)Lst_AtEnd(targs, targ); 2152 } 2153 2154 /* 2155 * Using the list of possible sources built up from the target suffix(es), 2156 * try and find an existing file/target that matches. 2157 */ 2158 bottom = SuffFindThem(srcs, slst); 2159 2160 if (bottom == NULL) { 2161 /* 2162 * No known transformations -- use the first suffix found for setting 2163 * the local variables. 2164 */ 2165 if (!Lst_IsEmpty(targs)) { 2166 targ = (Src *)Lst_Datum(Lst_First(targs)); | 2161 if (bottom == NULL) { 2162 /* 2163 * No known transformations -- use the first suffix found 2164 * for setting the local variables. 2165 */ 2166 if (!Lst_IsEmpty(targs)) { 2167 targ = (Src *)Lst_Datum(Lst_First(targs)); 2168 } else { 2169 targ = NULL; 2170 } |
2167 } else { | 2171 } else { |
2168 targ = NULL; | 2172 /* 2173 * Work up the transformation path to find the suffix of the 2174 * target to which the transformation was made. 2175 */ 2176 for (targ = bottom; targ->parent != NULL; targ = targ->parent) 2177 continue; |
2169 } | 2178 } |
2170 } else { 2171 /* 2172 * Work up the transformation path to find the suffix of the 2173 * target to which the transformation was made. 2174 */ 2175 for (targ = bottom; targ->parent != NULL; targ = targ->parent) 2176 continue; | |
2177 } | 2179 } |
2178 } | |
2179 2180 Var_Set(TARGET, gn->path ? gn->path : gn->name, gn, 0); 2181 2182 pref = (targ != NULL) ? targ->pref : gn->name; 2183 Var_Set(PREFIX, pref, gn, 0); 2184 2185 /* 2186 * Now we've got the important local variables set, expand any sources --- 467 unchanged lines hidden --- | 2180 2181 Var_Set(TARGET, gn->path ? gn->path : gn->name, gn, 0); 2182 2183 pref = (targ != NULL) ? targ->pref : gn->name; 2184 Var_Set(PREFIX, pref, gn, 0); 2185 2186 /* 2187 * Now we've got the important local variables set, expand any sources --- 467 unchanged lines hidden --- |