suff.c (143959) | suff.c (144020) |
---|---|
1/*- 2 * Copyright (c) 1988, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1989 by Berkeley Softworks 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Adam de Boor. --- 25 unchanged lines hidden (view full) --- 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)suff.c 8.4 (Berkeley) 3/21/94 39 */ 40 41#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1988, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1989 by Berkeley Softworks 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Adam de Boor. --- 25 unchanged lines hidden (view full) --- 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)suff.c 8.4 (Berkeley) 3/21/94 39 */ 40 41#include <sys/cdefs.h> |
42__FBSDID("$FreeBSD: head/usr.bin/make/suff.c 143959 2005-03-22 07:50:40Z harti $"); | 42__FBSDID("$FreeBSD: head/usr.bin/make/suff.c 144020 2005-03-23 12:56:15Z harti $"); |
43 44/*- 45 * suff.c -- 46 * Functions to maintain suffix lists and find implicit dependents 47 * using suffix transformation rules 48 * 49 * Interface: 50 * Suff_Init Initialize all things to do with suffixes. --- 34 unchanged lines hidden (view full) --- 85 * any file that doesn't have a known one. 86 * 87 * Suff_FindDeps Find implicit sources for and the location of 88 * a target based on its suffix. Returns the 89 * bottom-most node added to the graph or NULL 90 * if the target had no implicit sources. 91 */ 92 | 43 44/*- 45 * suff.c -- 46 * Functions to maintain suffix lists and find implicit dependents 47 * using suffix transformation rules 48 * 49 * Interface: 50 * Suff_Init Initialize all things to do with suffixes. --- 34 unchanged lines hidden (view full) --- 85 * any file that doesn't have a known one. 86 * 87 * Suff_FindDeps Find implicit sources for and the location of 88 * a target based on its suffix. Returns the 89 * bottom-most node added to the graph or NULL 90 * if the target had no implicit sources. 91 */ 92 |
93#include <sys/queue.h> |
|
93#include <assert.h> 94#include <string.h> 95#include <stdlib.h> 96 97#include "arch.h" 98#include "buf.h" 99#include "config.h" 100#include "dir.h" --- 28 unchanged lines hidden (view full) --- 129 */ 130typedef struct Suff { 131 char *name; /* The suffix itself */ 132 int nameLen; /* Length of the suffix */ 133 short flags; /* Type of suffix */ 134#define SUFF_INCLUDE 0x01 /* One which is #include'd */ 135#define SUFF_LIBRARY 0x02 /* One which contains a library */ 136#define SUFF_NULL 0x04 /* The empty suffix */ | 94#include <assert.h> 95#include <string.h> 96#include <stdlib.h> 97 98#include "arch.h" 99#include "buf.h" 100#include "config.h" 101#include "dir.h" --- 28 unchanged lines hidden (view full) --- 130 */ 131typedef struct Suff { 132 char *name; /* The suffix itself */ 133 int nameLen; /* Length of the suffix */ 134 short flags; /* Type of suffix */ 135#define SUFF_INCLUDE 0x01 /* One which is #include'd */ 136#define SUFF_LIBRARY 0x02 /* One which contains a library */ 137#define SUFF_NULL 0x04 /* The empty suffix */ |
137 Lst searchPath; /* Path for files with this suffix */ | 138 struct Path searchPath; /* Path for files with this suffix */ |
138 int sNum; /* The suffix number */ 139 int refCount; /* Reference count of list membership */ 140 Lst parents; /* Suffixes we have a transformation to */ 141 Lst children; /* Suffixes we have a transformation from */ 142 Lst ref; /* List of lists this suffix is referenced */ 143} Suff; 144 145/* --- 545 unchanged lines hidden (view full) --- 691 * Already known 692 */ 693 return; 694 695 s = emalloc(sizeof(Suff)); 696 697 s->name = estrdup(str); 698 s->nameLen = strlen(s->name); | 139 int sNum; /* The suffix number */ 140 int refCount; /* Reference count of list membership */ 141 Lst parents; /* Suffixes we have a transformation to */ 142 Lst children; /* Suffixes we have a transformation from */ 143 Lst ref; /* List of lists this suffix is referenced */ 144} Suff; 145 146/* --- 545 unchanged lines hidden (view full) --- 692 * Already known 693 */ 694 return; 695 696 s = emalloc(sizeof(Suff)); 697 698 s->name = estrdup(str); 699 s->nameLen = strlen(s->name); |
699 Lst_Init(&s->searchPath); | 700 TAILQ_INIT(&s->searchPath); |
700 Lst_Init(&s->children); 701 Lst_Init(&s->parents); 702 Lst_Init(&s->ref); 703 s->sNum = sNum++; 704 s->flags = 0; 705 s->refCount = 0; 706 707 Lst_AtEnd(&sufflist, s); --- 14 unchanged lines hidden (view full) --- 722 * Results: 723 * The searchPath for the desired suffix or NULL if the suffix isn't 724 * defined. 725 * 726 * Side Effects: 727 * None 728 *----------------------------------------------------------------------- 729 */ | 701 Lst_Init(&s->children); 702 Lst_Init(&s->parents); 703 Lst_Init(&s->ref); 704 s->sNum = sNum++; 705 s->flags = 0; 706 s->refCount = 0; 707 708 Lst_AtEnd(&sufflist, s); --- 14 unchanged lines hidden (view full) --- 723 * Results: 724 * The searchPath for the desired suffix or NULL if the suffix isn't 725 * defined. 726 * 727 * Side Effects: 728 * None 729 *----------------------------------------------------------------------- 730 */ |
730Lst * | 731struct Path * |
731Suff_GetPath(char *sname) 732{ 733 Suff *s; 734 735 s = SuffSuffFind(sname); 736 if (s == NULL) 737 return (NULL); 738 return (&s->searchPath); --- 18 unchanged lines hidden (view full) --- 757 *----------------------------------------------------------------------- 758 */ 759void 760Suff_DoPaths(void) 761{ 762 Suff *s; 763 LstNode *ln; 764 char *ptr; | 732Suff_GetPath(char *sname) 733{ 734 Suff *s; 735 736 s = SuffSuffFind(sname); 737 if (s == NULL) 738 return (NULL); 739 return (&s->searchPath); --- 18 unchanged lines hidden (view full) --- 758 *----------------------------------------------------------------------- 759 */ 760void 761Suff_DoPaths(void) 762{ 763 Suff *s; 764 LstNode *ln; 765 char *ptr; |
765 Lst inIncludes; /* Cumulative .INCLUDES path */ 766 Lst inLibs; /* Cumulative .LIBS path */ | 766 struct Path inIncludes; /* Cumulative .INCLUDES path */ 767 struct Path inLibs; /* Cumulative .LIBS path */ |
767 | 768 |
768 Lst_Init(&inIncludes); 769 Lst_Init(&inLibs); | 769 TAILQ_INIT(&inIncludes); 770 TAILQ_INIT(&inLibs); |
770 771 for (ln = Lst_First(&sufflist); ln != NULL; ln = Lst_Succ(ln)) { 772 s = Lst_Datum(ln); | 771 772 for (ln = Lst_First(&sufflist); ln != NULL; ln = Lst_Succ(ln)) { 773 s = Lst_Datum(ln); |
773 if (!Lst_IsEmpty(&s->searchPath)) { | |
774#ifdef INCLUDES | 774#ifdef INCLUDES |
775 if (s->flags & SUFF_INCLUDE) { 776 Dir_Concat(&inIncludes, &s->searchPath); 777 } | 775 if (s->flags & SUFF_INCLUDE) { 776 Path_Concat(&inIncludes, &s->searchPath); 777 } |
778#endif /* INCLUDES */ 779#ifdef LIBRARIES | 778#endif /* INCLUDES */ 779#ifdef LIBRARIES |
780 if (s->flags & SUFF_LIBRARY) { 781 Dir_Concat(&inLibs, &s->searchPath); 782 } 783#endif /* LIBRARIES */ 784 Dir_Concat(&s->searchPath, &dirSearchPath); 785 } else { 786 Lst_Destroy(&s->searchPath, Dir_Destroy); 787 Lst_Duplicate(&s->searchPath, &dirSearchPath, 788 Dir_CopyDir); | 780 if (s->flags & SUFF_LIBRARY) { 781 Path_Concat(&inLibs, &s->searchPath); |
789 } | 782 } |
783#endif /* LIBRARIES */ 784 Path_Concat(&s->searchPath, &dirSearchPath); |
|
790 } 791 | 785 } 786 |
792 Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", &inIncludes), 793 VAR_GLOBAL); | 787 ptr = Path_MakeFlags("-I", &inIncludes); 788 Var_Set(".INCLUDES", ptr, VAR_GLOBAL); |
794 free(ptr); | 789 free(ptr); |
795 Var_Set(".LIBS", ptr = Dir_MakeFlags("-L", &inLibs), 796 VAR_GLOBAL); | 790 791 ptr = Path_MakeFlags("-L", &inLibs); 792 Var_Set(".LIBS", ptr, VAR_GLOBAL); |
797 free(ptr); 798 | 793 free(ptr); 794 |
799 Lst_Destroy(&inIncludes, Dir_Destroy); 800 Lst_Destroy(&inLibs, Dir_Destroy); | 795 Path_Clear(&inIncludes); 796 Path_Clear(&inLibs); |
801} 802 803/*- 804 *----------------------------------------------------------------------- 805 * Suff_AddInclude -- 806 * Add the given suffix as a type of file which gets included. 807 * Called from the parse module when a .INCLUDES line is parsed. 808 * The suffix must have already been defined. --- 227 unchanged lines hidden (view full) --- 1036 if (Targ_FindNode(s->file, TARG_NOCREATE) != NULL) { 1037#ifdef DEBUG_SRC 1038 printf("remove %p from %p\n", s, srcs); 1039#endif 1040 rs = s; 1041 break; 1042 } 1043 | 797} 798 799/*- 800 *----------------------------------------------------------------------- 801 * Suff_AddInclude -- 802 * Add the given suffix as a type of file which gets included. 803 * Called from the parse module when a .INCLUDES line is parsed. 804 * The suffix must have already been defined. --- 227 unchanged lines hidden (view full) --- 1032 if (Targ_FindNode(s->file, TARG_NOCREATE) != NULL) { 1033#ifdef DEBUG_SRC 1034 printf("remove %p from %p\n", s, srcs); 1035#endif 1036 rs = s; 1037 break; 1038 } 1039 |
1044 if ((ptr = Dir_FindFile(s->file, | 1040 if ((ptr = Path_FindFile(s->file, |
1045 &s->suff->searchPath)) != NULL) { 1046 rs = s; 1047#ifdef DEBUG_SRC 1048 printf("remove %p from %p\n", s, srcs); 1049#endif 1050 free(ptr); 1051 break; 1052 } --- 189 unchanged lines hidden (view full) --- 1242 * expansions. 1243 */ 1244static void 1245SuffExpandWildcards(GNode *child, Lst *members) 1246{ 1247 char *cp; 1248 Lst exp; /* List of expansions */ 1249 LstNode *ln; | 1041 &s->suff->searchPath)) != NULL) { 1042 rs = s; 1043#ifdef DEBUG_SRC 1044 printf("remove %p from %p\n", s, srcs); 1045#endif 1046 free(ptr); 1047 break; 1048 } --- 189 unchanged lines hidden (view full) --- 1238 * expansions. 1239 */ 1240static void 1241SuffExpandWildcards(GNode *child, Lst *members) 1242{ 1243 char *cp; 1244 Lst exp; /* List of expansions */ 1245 LstNode *ln; |
1250 Lst *path; /* Search path along which to expand */ | 1246 struct Path *path; /* Search path along which to expand */ |
1251 1252 Lst_Init(members); 1253 1254 /* 1255 * Find a path along which to expand the word. 1256 * 1257 * If the word has a known suffix, use that path. 1258 * If it has no known suffix and we're allowed to use the null --- 18 unchanged lines hidden (view full) --- 1277 */ 1278 path = &dirSearchPath; 1279 } 1280 1281 /* 1282 * Expand the word along the chosen path 1283 */ 1284 Lst_Init(&exp); | 1247 1248 Lst_Init(members); 1249 1250 /* 1251 * Find a path along which to expand the word. 1252 * 1253 * If the word has a known suffix, use that path. 1254 * If it has no known suffix and we're allowed to use the null --- 18 unchanged lines hidden (view full) --- 1273 */ 1274 path = &dirSearchPath; 1275 } 1276 1277 /* 1278 * Expand the word along the chosen path 1279 */ 1280 Lst_Init(&exp); |
1285 Dir_Expand(child->name, path, &exp); | 1281 Path_Expand(child->name, path, &exp); |
1286 1287 while (!Lst_IsEmpty(&exp)) { 1288 /* 1289 * Fetch next expansion off the list and find its GNode 1290 */ 1291 cp = Lst_DeQueue(&exp); 1292 1293 DEBUGF(SUFF, ("%s...", cp)); --- 513 unchanged lines hidden (view full) --- 1807 sfnd_abort: 1808 /* 1809 * Deal with finding the thing on the default search path if the 1810 * node is only a source (not on the lhs of a dependency 1811 * operator or [XXX] it has neither children or commands). 1812 */ 1813 if (OP_NOP(gn->type) || (Lst_IsEmpty(&gn->children) && 1814 Lst_IsEmpty(&gn->commands))) { | 1282 1283 while (!Lst_IsEmpty(&exp)) { 1284 /* 1285 * Fetch next expansion off the list and find its GNode 1286 */ 1287 cp = Lst_DeQueue(&exp); 1288 1289 DEBUGF(SUFF, ("%s...", cp)); --- 513 unchanged lines hidden (view full) --- 1803 sfnd_abort: 1804 /* 1805 * Deal with finding the thing on the default search path if the 1806 * node is only a source (not on the lhs of a dependency 1807 * operator or [XXX] it has neither children or commands). 1808 */ 1809 if (OP_NOP(gn->type) || (Lst_IsEmpty(&gn->children) && 1810 Lst_IsEmpty(&gn->commands))) { |
1815 gn->path = Dir_FindFile(gn->name, | 1811 gn->path = Path_FindFile(gn->name, |
1816 (targ == NULL ? &dirSearchPath : 1817 &targ->suff->searchPath)); 1818 if (gn->path != NULL) { 1819 char *ptr; 1820 Var_Set(TARGET, gn->path, gn); 1821 1822 if (targ != NULL) { 1823 /* --- 320 unchanged lines hidden (view full) --- 2144 * Create null suffix for single-suffix rules (POSIX). The thing doesn't 2145 * actually go on the suffix list or everyone will think that's its 2146 * suffix. 2147 */ 2148 emptySuff = suffNull = emalloc(sizeof(Suff)); 2149 2150 suffNull->name = estrdup(""); 2151 suffNull->nameLen = 0; | 1812 (targ == NULL ? &dirSearchPath : 1813 &targ->suff->searchPath)); 1814 if (gn->path != NULL) { 1815 char *ptr; 1816 Var_Set(TARGET, gn->path, gn); 1817 1818 if (targ != NULL) { 1819 /* --- 320 unchanged lines hidden (view full) --- 2140 * Create null suffix for single-suffix rules (POSIX). The thing doesn't 2141 * actually go on the suffix list or everyone will think that's its 2142 * suffix. 2143 */ 2144 emptySuff = suffNull = emalloc(sizeof(Suff)); 2145 2146 suffNull->name = estrdup(""); 2147 suffNull->nameLen = 0; |
2152 Lst_Init(&suffNull->searchPath); 2153 Dir_Concat(&suffNull->searchPath, &dirSearchPath); | 2148 TAILQ_INIT(&suffNull->searchPath); 2149 Path_Concat(&suffNull->searchPath, &dirSearchPath); |
2154 Lst_Init(&suffNull->children); 2155 Lst_Init(&suffNull->parents); 2156 Lst_Init(&suffNull->ref); 2157 suffNull->sNum = sNum++; 2158 suffNull->flags = SUFF_NULL; 2159 suffNull->refCount = 1; 2160} 2161 --- 28 unchanged lines hidden (view full) --- 2190 LST_FOREACH(tln, &s->parents) 2191 printf("`%s' ", ((const Suff *)Lst_Datum(tln))->name); 2192 2193 printf("\n#\tFrom: "); 2194 LST_FOREACH(tln, &s->children) 2195 printf("`%s' ", ((const Suff *)Lst_Datum(tln))->name); 2196 2197 printf("\n#\tSearch Path: "); | 2150 Lst_Init(&suffNull->children); 2151 Lst_Init(&suffNull->parents); 2152 Lst_Init(&suffNull->ref); 2153 suffNull->sNum = sNum++; 2154 suffNull->flags = SUFF_NULL; 2155 suffNull->refCount = 1; 2156} 2157 --- 28 unchanged lines hidden (view full) --- 2186 LST_FOREACH(tln, &s->parents) 2187 printf("`%s' ", ((const Suff *)Lst_Datum(tln))->name); 2188 2189 printf("\n#\tFrom: "); 2190 LST_FOREACH(tln, &s->children) 2191 printf("`%s' ", ((const Suff *)Lst_Datum(tln))->name); 2192 2193 printf("\n#\tSearch Path: "); |
2198 Dir_PrintPath(&s->searchPath); | 2194 Path_Print(&s->searchPath); |
2199 2200 printf("\n"); 2201 } 2202 2203 printf("#*** Transformations:\n"); 2204 LST_FOREACH(ln, &transforms) { 2205 gn = Lst_Datum(ln); 2206 printf("%-16s: ", gn->name); 2207 Targ_PrintType(gn->type); 2208 printf("\n"); 2209 LST_FOREACH(tln, &gn->commands) 2210 printf("\t%s\n", (const char *)Lst_Datum(tln)); 2211 printf("\n"); 2212 } 2213} | 2195 2196 printf("\n"); 2197 } 2198 2199 printf("#*** Transformations:\n"); 2200 LST_FOREACH(ln, &transforms) { 2201 gn = Lst_Datum(ln); 2202 printf("%-16s: ", gn->name); 2203 Targ_PrintType(gn->type); 2204 printf("\n"); 2205 LST_FOREACH(tln, &gn->commands) 2206 printf("\t%s\n", (const char *)Lst_Datum(tln)); 2207 printf("\n"); 2208 } 2209} |