Sat Nov 21 18:06:09 2020 UTC ()
make(1): document necessary condition in SuffUpdateTarget


(rillig)
diff -r1.262 -r1.263 src/usr.bin/make/suff.c

cvs diff -r1.262 -r1.263 src/usr.bin/make/suff.c (expand / switch to unified diff)

--- src/usr.bin/make/suff.c 2020/11/21 17:18:36 1.262
+++ src/usr.bin/make/suff.c 2020/11/21 18:06:09 1.263
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: suff.c,v 1.262 2020/11/21 17:18:36 rillig Exp $ */ 1/* $NetBSD: suff.c,v 1.263 2020/11/21 18:06:09 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" */
117MAKE_RCSID("$NetBSD: suff.c,v 1.262 2020/11/21 17:18:36 rillig Exp $"); 117MAKE_RCSID("$NetBSD: suff.c,v 1.263 2020/11/21 18:06:09 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
123typedef List SuffList; 123typedef List SuffList;
124typedef ListNode SuffListNode; 124typedef ListNode SuffListNode;
125 125
126typedef List SrcList; 126typedef List SrcList;
127typedef ListNode SrcListNode; 127typedef ListNode SrcListNode;
128 128
129static SuffList *sufflist; /* List of suffixes */ 129static SuffList *sufflist; /* List of suffixes */
130#ifdef CLEANUP 130#ifdef CLEANUP
@@ -657,37 +657,43 @@ SuffUpdateTarget(GNode *target, GNode ** @@ -657,37 +657,43 @@ SuffUpdateTarget(GNode *target, GNode **
657 Suff *srcSuff, *targSuff; 657 Suff *srcSuff, *targSuff;
658 char *ptr; 658 char *ptr;
659 659
660 if (*inout_main == NULL && *r && !(target->type & OP_NOTARGET)) { 660 if (*inout_main == NULL && *r && !(target->type & OP_NOTARGET)) {
661 *inout_main = target; 661 *inout_main = target;
662 Targ_SetMain(target); 662 Targ_SetMain(target);
663 return TRUE; 663 return TRUE;
664 } 664 }
665 665
666 if (target->type == OP_TRANSFORM) 666 if (target->type == OP_TRANSFORM)
667 return FALSE; 667 return FALSE;
668 668
669 /* 669 /*
670 * XXX: What is the purpose of the 'ptr == target->name' condition here? 
671 * In suff-rebuild.mk in the line '.SUFFIXES: .c .b .a', it prevents the 
672 * rule '.b.c' from being added again during Suff_AddSuffix(".b"). 
673 */ 
674 /* 
675 * XXX: What about a transformation ".cpp.c"? If ".c" is added as a new 670 * XXX: What about a transformation ".cpp.c"? If ".c" is added as a new
676 * suffix, it seems wrong that this transformation would be skipped just 671 * suffix, it seems wrong that this transformation would be skipped just
677 * because ".c" happens to be a prefix of ".cpp". 672 * because ".c" happens to be a prefix of ".cpp".
678 */ 673 */
679 if ((ptr = strstr(target->name, suff->name)) == NULL || 674 ptr = strstr(target->name, suff->name);
680 ptr == target->name) 675 if (ptr == NULL)
 676 return FALSE;
 677
 678 /*
 679 * XXX: In suff-rebuild.mk, in the line '.SUFFIXES: .c .b .a', this
 680 * condition prevents the rule '.b.c' from being added again during
 681 * Suff_AddSuffix(".b").
 682 *
 683 * XXX: Removing this paragraph makes suff-add-later.mk use massive
 684 * amounts of memory.
 685 */
 686 if (ptr == target->name)
681 return FALSE; 687 return FALSE;
682 688
683 if (SuffParseTransform(target->name, &srcSuff, &targSuff)) { 689 if (SuffParseTransform(target->name, &srcSuff, &targSuff)) {
684 if (*inout_main == target) { 690 if (*inout_main == target) {
685 *r = TRUE; 691 *r = TRUE;
686 *inout_main = NULL; 692 *inout_main = NULL;
687 Targ_SetMain(NULL); 693 Targ_SetMain(NULL);
688 } 694 }
689 Lst_Free(target->children); 695 Lst_Free(target->children);
690 target->children = Lst_New(); 696 target->children = Lst_New();
691 target->type = OP_TRANSFORM; 697 target->type = OP_TRANSFORM;
692 /* 698 /*
693 * link the two together in the proper relationship and order 699 * link the two together in the proper relationship and order