NetBSD Problem Report #58229

From www@netbsd.org  Mon May  6 19:53:55 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id C96D11A9238
	for <gnats-bugs@gnats.NetBSD.org>; Mon,  6 May 2024 19:53:55 +0000 (UTC)
Message-Id: <20240506195354.98F381A923B@mollari.NetBSD.org>
Date: Mon,  6 May 2024 19:53:54 +0000 (UTC)
From: thorpej@me.com
Reply-To: thorpej@me.com
To: gnats-bugs@NetBSD.org
Subject: BSD make and GNU make differ in $< and $> handling in an annoying way
X-Send-Pr-Version: www-1.0

>Number:         58229
>Category:       toolchain
>Synopsis:       BSD make and GNU make differ in $< and $> handling in an annoying way
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 06 19:55:00 +0000 2024
>Last-Modified:  Wed May 08 19:45:01 +0000 2024
>Originator:     Jason Thorpe
>Release:        NetBSD 10.99.10
>Organization:
Just the BASICs
>Environment:
NetBSD the-ripe-vessel 10.99.10 NetBSD 10.99.10 (GENERIC) #68: Fri Nov 17 14:40:27 PST 2023  thorpej@the-ripe-vessel:/space/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
For the following Makefile snippet behaves differently in GNU make vs BSD make:

 ---- snip ----

OBJS=           tbvm.o
CLEANFILES=     $(OBJS) tbvm_program.h libtbvm.a
CFLAGS=         -Os -g -Wall -Wformat

all: libtbvm.a

tbvm.o: Makefile tbvm.c tbvm.h tbvm_opcodes.h tbvm_program.h

tbvm_program.h: tbvm_program.asm
        ../tbasm/tbasm -H $<

libtbvm.a: $(OBJS)
        rm -f $@
        ar -r $@ $(OBJS)
        ranlib $@

clean:
        -rm -f $(CLEANFILES)

 ---- snip ----

BSD make:

the-ripe-vessel:thorpej 51$ make tbvm_program.h
../tbasm/tbasm -H 
usage: tbasm [-o output.bin] input.asm
usage: tbasm -H[output.h] input.asm
*** Error code 1

Stop.
make: stopped in /home/thorpej/Github/thorpej/JTTB/tbvm
the-ripe-vessel:thorpej 52$ 


GNU make:

the-ripe-vessel:thorpej 52$ gmake tbvm_program.h
../tbasm/tbasm -H tbvm_program.asm
parsed 388 instructions (129 labels, 220 references)
program size: 1128 bytes
the-ripe-vessel:thorpej 53$ 


$< is ${.IMPSRC} in BSD make, and the behavior is documented:

           .IMPSRC       In suffix-transformation rules, the name/path of the
                         source from which the target is to be transformed
                         (the "implied" source); also known as `<'.  It is not
                         defined in explicit rules.

...but here's the annoying part: If I change to $> (${.ALLSRC}) it works in BSD make, but then fails in GNU make:

the-ripe-vessel:thorpej 57$ gmake
../tbasm/tbasm -H 
usage: tbasm [-o output.bin] input.asm
usage: tbasm -H[output.h] input.asm
gmake: *** [Makefile:10: tbvm_program.h] Error 1
the-ripe-vessel:thorpej 58$ 

>How-To-Repeat:
See above.
>Fix:
that would be nice.

>Audit-Trail:
From: Joseph Koshy <jkoshy@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: toolchain/58229: BSD make and GNU make differ in $< and $> handling
Date: Wed, 8 May 2024 20:44:22 +0100

 Does gmake support '$>'?

 For gmake v4.3 the manual (i.e., "info gmake") doesn't mention an
 automatic variable named '$>'.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.