Bug 236380 - `auto.obj.mk` uses incorrect test for relative pathed `obj` directory.
Summary: `auto.obj.mk` uses incorrect test for relative pathed `obj` directory.
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 11.2-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2019-03-08 00:39 UTC by Duane
Modified: 2019-03-08 00:39 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Duane 2019-03-08 00:39:08 UTC
If using a Makefile with the following:

.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}

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.