Bug 155000 - make(1) doesn't handle .POSIX: correctly
Summary: make(1) doesn't handle .POSIX: correctly
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-24 11:30 UTC by Colin Percival
Modified: 2018-05-20 23:52 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Colin Percival freebsd_committer freebsd_triage 2011-02-24 11:30:07 UTC
make(1) doesn't handle .POSIX: correctly.  It sucks in sys.mk before it
reads the Makefile, and sys.mk has several instances of
.if defined(%POSIX)
to switch between POSIX and non-POSIX mode; because sys.mk is processed
first, there is no opportunity for a .POSIX: directive to take effect.

Fix: 

Before processing sys.mk, main() should "taste" the Makefile by looking
for .POSIX.  This is required to appear on the first non-comment line of
the Makefile, so we don't need to actually parse the Makefile in order
to check for this.
How-To-Repeat: $ echo .POSIX: > Makefile
$ make -V CC
(prints "cc"; it should print "c89".)
Comment 1 Bruce Evans freebsd_committer freebsd_triage 2011-02-24 22:35:30 UTC
On Thu, 24 Feb 2011, Colin Percival wrote:

>> Description:
>
> make(1) doesn't handle .POSIX: correctly.  It sucks in sys.mk before it
> reads the Makefile, and sys.mk has several instances of
> .if defined(%POSIX)
> to switch between POSIX and non-POSIX mode; because sys.mk is processed
> first, there is no opportunity for a .POSIX: directive to take effect.
>
>> How-To-Repeat:
> $ echo .POSIX: > Makefile
> $ make -V CC
> (prints "cc"; it should print "c89".)

Except that there is the opportunity to set %POSIX using make -D.  This
might be enough in practice.  The namespace pollution avoidance is
too perfect -- there seems to be no way to set %POSIX or .POSIX in the
environment.

Bruce
Comment 2 Colin Percival freebsd_committer freebsd_triage 2011-02-24 23:41:51 UTC
On 02/24/11 14:35, Bruce Evans wrote:
> Except that there is the opportunity to set %POSIX using make -D.  This
> might be enough in practice.  The namespace pollution avoidance is
> too perfect -- there seems to be no way to set %POSIX or .POSIX in the
> environment.

Is this relevant?  POSIX says that the Right Way to demand POSIX mode is
to put .POSIX on the first non-comment line of the Makefile; our %POSIX
variable is a red herring as far as POSIX is concerned.

-- 
Colin Percival
Security Officer, FreeBSD | freebsd.org | The power to serve
Founder / author, Tarsnap | tarsnap.com | Online backups for the truly paranoid
Comment 3 Bruce Evans freebsd_committer freebsd_triage 2011-02-25 02:13:09 UTC
On Thu, 24 Feb 2011, Colin Percival wrote:

> On 02/24/11 14:35, Bruce Evans wrote:
>> Except that there is the opportunity to set %POSIX using make -D.  This
>> might be enough in practice.  The namespace pollution avoidance is
>> too perfect -- there seems to be no way to set %POSIX or .POSIX in the
>> environment.
>
> Is this relevant?  POSIX says that the Right Way to demand POSIX mode is
> to put .POSIX on the first non-comment line of the Makefile; our %POSIX
> variable is a red herring as far as POSIX is concerned.

It allows A Way.

Of course you should fix make(1) to support the POSIX way if this is
not too hard.  If make can see .POSIX before including sys.mk, then
it could alternatively include a POSIX-sys.mk instead.  This would be
cleaner than the ifdefs in sys.mk, and would inhibit breakage of the
POSIX case by putting things like CTF in its rules.

Bruce
Comment 4 Eitan Adler freebsd_committer freebsd_triage 2011-02-25 17:27:19 UTC
This is just a pointer to bin/11114 filed on a similar issue

-- 
Eitan Adler
Comment 5 Simon J. Gerraty freebsd_committer freebsd_triage 2014-06-04 22:18:39 UTC
Perhaps all the stuff in sys.mk which is %POSIX dependent should be moved 
somewhere that is read after Makefile.
Of course no guarantee that a posix compliant makefile will include anything
Comment 6 Simon J. Gerraty freebsd_committer freebsd_triage 2017-06-10 17:10:20 UTC
The issue isn't make(1) but rather share/mk
As noted share/mk/sys.mk does not know .POSIX is desired up front.

Two workarounds would be simple enough

1/ make -DWITH_POSIX_MK and sys.mk could do .POSIX: itself.

2/ add a posix/sys.mk which could set .POSIX: and then include ../sys.mk 
   for this one you'd need to make -m .../share/mk/posix
Comment 7 Simon J. Gerraty freebsd_committer freebsd_triage 2017-06-10 17:11:48 UTC
(In reply to Colin Percival from comment #2)
If you really want to limit yourself to POSIX use make -r
Comment 8 Colin Percival freebsd_committer freebsd_triage 2017-06-10 17:37:36 UTC
You're missing the point.  If the first line of Makefile is ".POSIX:" then make is supposed to operate in POSIX mode.  The fact that you can get POSIX mode in other ways is irrelevant to whether we satisfy this requirement.
Comment 9 Eitan Adler freebsd_committer freebsd_triage 2018-05-20 23:52:35 UTC
For bugs matching the following conditions:
- Status == In Progress
- Assignee == "bugs@FreeBSD.org"
- Last Modified Year <= 2017

Do
- Set Status to "Open"