From mark@thuvia.demon.co.uk  Wed Dec 12 10:28:59 2001
Return-Path: <mark@thuvia.demon.co.uk>
Received: from thuvia.demon.co.uk (thuvia.demon.co.uk [193.237.34.248])
	by hub.freebsd.org (Postfix) with ESMTP id B1D0037B419
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Dec 2001 10:28:53 -0800 (PST)
Received: from dotar-sojat.thuvia.org (dotar-sojat.thuvia.org [10.0.0.4])
	by phaidor.thuvia.org (8.11.6/8.11.6) with ESMTP id fBCISok03453
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Dec 2001 18:28:50 GMT
	(envelope-from mark@thuvia.demon.co.uk)
Received: (from mark@localhost)
	by dotar-sojat.thuvia.org (8.11.6/8.11.6) id fBCIWgR15816;
	Wed, 12 Dec 2001 18:32:42 GMT
	(envelope-from mark)
Message-Id: <200112121832.fBCIWgR15816@dotar-sojat.thuvia.org>
Date: Wed, 12 Dec 2001 18:32:42 GMT
From: Mark Valentine <mark@thuvia.demon.co.uk>
Reply-To: Mark Valentine <mark@thuvia.demon.co.uk>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] make(1) System V include behaviour differs
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         32759
>Category:       bin
>Synopsis:       [PATCH] make(1) System V include behaviour differs
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    jmallett
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 12 10:30:00 PST 2001
>Closed-Date:    Wed Jun 04 07:11:12 CDT 2003
>Last-Modified:  Thu Jun 05 05:49:18 PDT 2003
>Originator:     Mark Valentine
>Release:        FreeBSD 4.4-STABLE i386
>Organization:
>Environment:
System: FreeBSD dotar-sojat.thuvia.org 4.4-STABLE FreeBSD 4.4-STABLE #1: Thu Nov 29 19:15:44 GMT 2001 root@dejah-thoris.thuvia.org:/usr/obj/usr/src/sys/GENERIC i386


>Description:
	make(1) looks first for files "included" using the System V syntax
	relative to the directory of the including makefile.

	Sun's make and GNU make both look relative to the current directory.
>How-To-Repeat:
	$ cd /tmp
	$ cat >test.mk
	include t/foo.mk
	$ mkdir t
	$ cat >t/foo.mk
	include bar.mk
	$ cat >t/bar.mk
	all::
		@echo Not OK
	$ cat >bar.mk
	all::
		@echo OK
	$ make -f test.mk
	Not OK
	$ gmake -f test.mk
	OK

>Fix:
The following patch has been lightly tested.

Index: usr.bin/make/parse.c
===================================================================
RCS file: /usr/cvs/src/usr.bin/make/parse.c,v
retrieving revision 1.22
diff -u -r1.22 parse.c
--- usr.bin/make/parse.c	28 Aug 1999 01:03:35 -0000	1.22
+++ usr.bin/make/parse.c	11 Dec 2001 19:46:31 -0000
@@ -1830,7 +1830,6 @@
     char          *fullname;	/* full pathname of file */
     IFile         *oldFile;	/* state associated with current file */
     char          *cp;		/* current position in file spec */
-    char	  *prefEnd;
 
     /*
      * Skip over whitespace
@@ -1862,42 +1861,12 @@
 
     /*
      * Now we know the file's name, we attempt to find the durn thing.
-     * A return of NULL indicates the file don't exist.
-     *
-     * Include files are first searched for relative to the including
-     * file's location. We don't want to cd there, of course, so we
-     * just tack on the old file's leading path components and call
-     * Dir_FindFile to see if we can locate the beast.
-     * XXX - this *does* search in the current directory, right?
+     * Search for it first on the -I search path, then on the .PATH
+     * search path, if not found in a -I directory.
      */
-
-    prefEnd = strrchr (fname, '/');
-    if (prefEnd != (char *)NULL) {
-	char  	*newName;
-
-	*prefEnd = '\0';
-	newName = str_concat (fname, file, STR_ADDSLASH);
-	fullname = Dir_FindFile (newName, parseIncPath);
-	if (fullname == (char *)NULL) {
-	    fullname = Dir_FindFile(newName, dirSearchPath);
-	}
-	free (newName);
-	*prefEnd = '/';
-    } else {
-	fullname = (char *)NULL;
-    }
-
+    fullname = Dir_FindFile (file, parseIncPath);
     if (fullname == (char *)NULL) {
-	/*
-	 * System makefile or makefile wasn't found in same directory as
-	 * included makefile. Search for it first on the -I search path,
-	 * then on the .PATH search path, if not found in a -I directory.
-	 * XXX: Suffix specific?
-	 */
-	fullname = Dir_FindFile (file, parseIncPath);
-	if (fullname == (char *)NULL) {
-	    fullname = Dir_FindFile(file, dirSearchPath);
-	}
+        fullname = Dir_FindFile(file, dirSearchPath);
     }
 
     if (fullname == (char *)NULL) {
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->will 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Sun Dec 30 04:29:51 PST 2001 
Responsible-Changed-Why:  
Will, are you still looking after BSD make? 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32759 
Responsible-Changed-From-To: will->freebsd-bugs 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Mon Dec 31 01:08:31 PST 2001 
Responsible-Changed-Why:  
Will's no longer interested in BSD make. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32759 

From: "Matthew Emmerton" <matt@gsicomp.on.ca>
To: <freebsd-gnats-submit@FreeBSD.org>, <mark@thuvia.demon.co.uk>
Cc:  
Subject: Re: bin/32759: [PATCH] make(1) System V include behaviour differs
Date: Sun, 13 Jan 2002 00:36:09 -0500

 This looks fine.
 
 --
 Matt Emmerton
 
Responsible-Changed-From-To: freebsd-bugs->jmallett 
Responsible-Changed-By: jmallett 
Responsible-Changed-When: Fri Jul 26 14:41:18 PDT 2002 
Responsible-Changed-Why:  
I'll take responsibility for this... 

http://www.freebsd.org/cgi/query-pr.cgi?pr=32759 
State-Changed-From-To: open->patched 
State-Changed-By: jmallett 
State-Changed-When: Tue Oct 22 18:58:13 PDT 2002 
State-Changed-Why:  
Committed to -CURRENT, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=32759 
State-Changed-From-To: patched->closed 
State-Changed-By: jmallett 
State-Changed-When: 4 Jun 2003 07:10:32 CDT 
State-Changed-Why:  
Change will not be MFC'd, it seems. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=32759 
>Unformatted:
