Bug 236380

Summary: `auto.obj.mk` uses incorrect test for relative pathed `obj` directory.
Product: Base System Reporter: Duane <parakleta>
Component: miscAssignee: freebsd-bugs (Nobody) <bugs>
Status: New ---    
Severity: Affects Only Me    
Priority: ---    
Version: 11.2-STABLE   
Hardware: Any   
OS: Any   

Description Duane 2019-03-08 00:39:08 UTC
If using a Makefile with the following:

```
MK_AUTO_OBJ=yes
.include <auto.obj.mk>
```

the first time `make` is run results in an error starting with:

```
make: "/usr/share/mk/auto.obj.mk" line 61: could not use obj: .OBJDIR=
```

This error is generated by the following block of code:

```
.OBJDIR: ${__objdir}
.if ${.OBJDIR:tA} != ${__objdir:tA} && ${__objdir_made:Uno:M${__objdir}/*} != ""                                        
.error could not use ${__objdir}: .OBJDIR=${.OBJDIR}
.endif
```

The reason for this is that the use of the `.OBJDIR` target changes the current directory and thus if `__objdir` is a relative path then it can no longer be found.  The man page for `make` states that:

    ‘.OBJDIR’ may be modified in the makefile via the special
    target ‘.OBJDIR’.  In all cases, make will chdir(2) to
    the specified directory if it exists, and set ‘.OBJDIR’
    and ‘PWD’ to that directory before executing any targets.

I believe the solution is to convert `__objdir` to an absolute path after it has been created (and thus can be found) but before changing `.OBJDIR`.  That is, immediately before the block of code quoted above from line 59, add the following line:

```
__objdir:= ${__objdir:tA}
```

After this it is no longer necessary to use absolute paths in the following test so these can be removed.