From nobody@FreeBSD.org  Fri Dec 23 16:09:24 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 672471065675
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 23 Dec 2011 16:09:24 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 558C68FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 23 Dec 2011 16:09:24 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id pBNG9OrL015950
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 23 Dec 2011 16:09:24 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id pBNG9OPd015949;
	Fri, 23 Dec 2011 16:09:24 GMT
	(envelope-from nobody)
Message-Id: <201112231609.pBNG9OPd015949@red.freebsd.org>
Date: Fri, 23 Dec 2011 16:09:24 GMT
From: "Tim &#268;as" <darkuranium@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Make forgets to chdir back to the original directory after finding an object dir
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         163567
>Category:       bin
>Synopsis:       make(1): add option to disable object directory
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Dec 23 16:10:10 UTC 2011
>Closed-Date:    
>Last-Modified:  Sun Jan 22 20:57:26 UTC 2012
>Originator:     Tim &#268;as
>Release:        9.0 RC3
>Organization:
n/a
>Environment:
FreeBSD tsibsd.tsi 9.0-RC3 FreeBSD 9.0-RC3 #0: Sun Dec  4 08:56:36 UTC 2011     root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
If the "make" utility finds an object dir, it changes to the path of the dir, but forgets to change back to the working directory.

A consequence of this is that portable makefiles do not work with BSD's implementation simply because there exists an "obj" directory in the tree.

This means that, say, trying to compile src/main.c actually invokes the compiler on (non-existing) obj/src/main.c.
>How-To-Repeat:
Run the following in a shell ('$' indicates a prompt):

$ rm -rf obj
$ echo -e "all:\n\tpwd" > Makefile
$ make
pwd
/path/to/dir
$ mkdir obj
$ make
pwd
/path/to/dir/obj

The effect is the same if "pwd" is replaced with \$\$PWD (which generates "$$PWD" instead of "pwd" in the makefile.
>Fix:
The problem is that chdir_verify_path does not change the directory back on success.

In the file /usr/src/usr.bin/make/main.c, change the function chdir_verify_path() - right before "return (obpath)", add:

chdir(curdir);

(plus checks to see if this went fine).


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Sat Dec 24 02:33:16 UTC 2011 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=163567 
State-Changed-From-To: open->closed 
State-Changed-By: eadler 
State-Changed-When: Mon Dec 26 01:08:32 UTC 2011 
State-Changed-Why:  
per jilles comments this will not be changed 

http://www.freebsd.org/cgi/query-pr.cgi?pr=163567 

From: Eitan Adler <lists@eitanadler.com>
To: bug-followup@freebsd.org, darkuranium@gmail.com
Cc:  
Subject: Re: bin/163567: make(1) forgets to chdir back to the original
 directory after finding an object dir
Date: Sun, 25 Dec 2011 20:07:09 -0500

 ---------- Forwarded message ----------
 From: Jilles Tjoelker <jilles@stack.nl>
 Date: Sun, Dec 25, 2011 at 5:31 PM
 
 I think this will break object directories. As hinted at by the function
 name, make is supposed to change to the object directory and run the
 compiler etc. from there passing absolute pathnames to the source files.
 There appears to be no other chdir() call to perform this function
 (except if .MAKEFILEDEPS is in effect).
 
 I have not tried it but it seems like that if buildworld will still work
 at all it will put compilation results in the wrong place.
 
 Besides, the objection seems against obj/ and obj.${MACHINE}/ being used
 as object directories. If one of these subdirectories exist, make will
 enter separate source&object directories mode and various restrictions
 apply (source files must be referenced via a variable like $<, via the
 .PATH or VPATH mechanism or be prefixed with ${.CURDIR}/).
 
 -- 
 Eitan Adler

From: Tim Cas <darkuranium@gmail.com>
To: bug-followup@FreeBSD.org, darkuranium@gmail.com
Cc:  
Subject: Re: bin/163567: make(1) forgets to chdir back to the original
 directory after finding an object dir
Date: Mon, 26 Dec 2011 13:10:12 +0100

 --20cf301af4750b948004b4fda62e
 Content-Type: text/plain; charset=ISO-8859-1
 
 The objection is definately not against using object directories, but
 against leaving the current directory as the obj dir. The problem is that
 having an "obj" dir makes things like the following not work with BSD make:
 
 gcc -o obj/whatever.o -c src/whatever.c
 
 That "src/whatever.c" part is problematic as GCC will look inside of
 /obj/src instead of /src.
 
 --20cf301af4750b948004b4fda62e
 Content-Type: text/html; charset=ISO-8859-1
 
 The objection is definately not against using object directories, but against leaving the current directory as the obj dir. The problem is that having an &quot;obj&quot; dir makes things like the following not work with BSD make:<br>
 <br>gcc -o obj/whatever.o -c src/whatever.c<br><br>That &quot;src/whatever.c&quot; part is problematic as GCC will look inside of /obj/src instead of /src.<br>
 
 --20cf301af4750b948004b4fda62e--
State-Changed-From-To: closed->open 
State-Changed-By: eadler 
State-Changed-When: Sun Jan 8 17:52:16 UTC 2012 
State-Changed-Why:  
jilles may want to look at this objection 


Responsible-Changed-From-To: eadler->jilles 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Sun Jan 8 17:52:16 UTC 2012 
Responsible-Changed-Why:  
jilles may want to look at this objection 

http://www.freebsd.org/cgi/query-pr.cgi?pr=163567 

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, darkuranium@gmail.com
Cc:  
Subject: Re: bin/163567: make(1) forgets to chdir back to the original
 directory after finding an object dir
Date: Sun, 8 Jan 2012 23:26:11 +0100

 Tim Cas wrote:
 > The objection is definately not against using object directories, but
 > against leaving the current directory as the obj dir. The problem is
 > that having an "obj" dir makes things like the following not work with
 > BSD make:
 
 > gcc -o obj/whatever.o -c src/whatever.c
 
 > That "src/whatever.c" part is problematic as GCC will look inside of
 > /obj/src instead of /src.
 
 The FreeBSD build system (/usr/share/mk/bsd.*) depends on object
 directories working this way, so the only way to fix your problem
 without modifying your Makefiles would be to disable ./obj as an object
 directory. This will not break buildworld, buildkernel and the like but
 may break ad hoc compilations of single directories (e.g., I created a
 ~/src/git/freebsd/bin/sh/obj to hold object files when just compiling
 sh).
 
 It looks like NetBSD make (bmake) works the same way.
 
 Apparently, in FreeBSD and NetBSD make the directory obj is just
 reserved for their particular way of separate source and object
 directories. (The way supported by some autotools-using packages is
 different.)
 
 Personally, I am not interested in changing make to allow arbitrary use
 of the directory obj, except perhaps in .POSIX mode (but who uses
 that?).
 
 -- 
 Jilles Tjoelker

From: Tim Cas <darkuranium@gmail.com>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/163567: make(1) forgets to chdir back to the original
 directory after finding an object dir
Date: Sun, 8 Jan 2012 23:34:06 +0100

 --20cf303f648840c10a04b60be109
 Content-Type: text/plain; charset=ISO-8859-1
 
 Hmm, I suppose I'll need to add in a hack for this, like "if $pwd | grep
 '/obj$'; then cd ..; fi".
 
 Maybe adding a flag would be an option, since there probably are other
 Makefiles out there where the authors did not anticipate this; though of
 course, gmake could be used in such a case instead.
 
 On 8 January 2012 23:26, Jilles Tjoelker <jilles@stack.nl> wrote:
 
 > Tim Cas wrote:
 > > The objection is definately not against using object directories, but
 > > against leaving the current directory as the obj dir. The problem is
 > > that having an "obj" dir makes things like the following not work with
 > > BSD make:
 >
 > > gcc -o obj/whatever.o -c src/whatever.c
 >
 > > That "src/whatever.c" part is problematic as GCC will look inside of
 > > /obj/src instead of /src.
 >
 > The FreeBSD build system (/usr/share/mk/bsd.*) depends on object
 > directories working this way, so the only way to fix your problem
 > without modifying your Makefiles would be to disable ./obj as an object
 > directory. This will not break buildworld, buildkernel and the like but
 > may break ad hoc compilations of single directories (e.g., I created a
 > ~/src/git/freebsd/bin/sh/obj to hold object files when just compiling
 > sh).
 >
 > It looks like NetBSD make (bmake) works the same way.
 >
 > Apparently, in FreeBSD and NetBSD make the directory obj is just
 > reserved for their particular way of separate source and object
 > directories. (The way supported by some autotools-using packages is
 > different.)
 >
 > Personally, I am not interested in changing make to allow arbitrary use
 > of the directory obj, except perhaps in .POSIX mode (but who uses
 > that?).
 >
 > --
 > Jilles Tjoelker
 >
 
 --20cf303f648840c10a04b60be109
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 Hmm, I suppose I&#39;ll need to add in a hack for this, like &quot;if $pwd =
 | grep &#39;/obj$&#39;; then cd ..; fi&quot;.<br><br>Maybe adding a flag wo=
 uld be an option, since there probably are other Makefiles out there where =
 the authors did not anticipate this; though of course, gmake could be used =
 in such a case instead.<br>
 <br><div class=3D"gmail_quote">On 8 January 2012 23:26, Jilles Tjoelker <sp=
 an dir=3D"ltr">&lt;<a href=3D"mailto:jilles@stack.nl">jilles@stack.nl</a>&g=
 t;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
  .8ex;border-left:1px #ccc solid;padding-left:1ex">
 Tim Cas wrote:<br>
 &gt; The objection is definately not against using object directories, but<=
 br>
 &gt; against leaving the current directory as the obj dir. The problem is<b=
 r>
 &gt; that having an &quot;obj&quot; dir makes things like the following not=
  work with<br>
 &gt; BSD make:<br>
 <br>
 &gt; gcc -o obj/whatever.o -c src/whatever.c<br>
 <br>
 &gt; That &quot;src/whatever.c&quot; part is problematic as GCC will look i=
 nside of<br>
 &gt; /obj/src instead of /src.<br>
 <br>
 The FreeBSD build system (/usr/share/mk/bsd.*) depends on object<br>
 directories working this way, so the only way to fix your problem<br>
 without modifying your Makefiles would be to disable ./obj as an object<br>
 directory. This will not break buildworld, buildkernel and the like but<br>
 may break ad hoc compilations of single directories (e.g., I created a<br>
 ~/src/git/freebsd/bin/sh/obj to hold object files when just compiling<br>
 sh).<br>
 <br>
 It looks like NetBSD make (bmake) works the same way.<br>
 <br>
 Apparently, in FreeBSD and NetBSD make the directory obj is just<br>
 reserved for their particular way of separate source and object<br>
 directories. (The way supported by some autotools-using packages is<br>
 different.)<br>
 <br>
 Personally, I am not interested in changing make to allow arbitrary use<br>
 of the directory obj, except perhaps in .POSIX mode (but who uses<br>
 that?).<br>
 <span class=3D"HOEnZb"><font color=3D"#888888"><br>
 --<br>
 Jilles Tjoelker<br>
 </font></span></blockquote></div><br>
 
 --20cf303f648840c10a04b60be109--
Responsible-Changed-From-To: jilles->freebsd-bugs 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Sun Jan 22 20:55:08 UTC 2012 
Responsible-Changed-Why:  
There may be some use in adding an option to disable object directories, 
but I am not interested in doing it. 

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