Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Mar 2012 21:20:04 +0000
From:      Chris Rees <utisoft@gmail.com>
To:        John Baldwin <jhb@freebsd.org>
Cc:        Doug Barton <dougb@freebsd.org>, svn-src-all@freebsd.org, Dimitry Andric <dim@freebsd.org>, src-committers@freebsd.org, Bruce Evans <brde@optusnet.com.au>, svn-src-head@freebsd.org
Subject:   Re: svn commit: r233052 - head/share/mk
Message-ID:  <CADLo839Ef3bu_14AdexOWapOacFLk3MM9HK-oNLmtA52Cc9C6w@mail.gmail.com>
In-Reply-To: <201203201019.40486.jhb@freebsd.org>
References:  <201203162319.q2GNJjx5039482@svn.freebsd.org> <4F678B03.8050307@FreeBSD.org> <4F67A7A9.50003@FreeBSD.org> <201203201019.40486.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 20 March 2012 14:19, John Baldwin <jhb@freebsd.org> wrote:
> On Monday, March 19, 2012 5:39:53 pm Doug Barton wrote:
>> On 3/19/2012 12:37 PM, Dimitry Andric wrote:
>> > It would be much nicer to be able to write:
>> >
>> > .if defined(FOO)
>> > =A0 .if defined(BAR)
>> > =A0 =A0 CFLAGS+=3D =A0 =A0 =A0 =A0-DFOO_BAR
>> > =A0 .endif
>> > .endif
>>
>> Take a look at /usr/ports/Mk/bsd.port.mk for how this can be done.
>
> Hmm, do yoo have a specific example? =A0The bits in I see in bsd.port.mk =
suffer
> from the limitation Dimitry raises, e.g.:
>
> .if defined(OPTIONS)
> # include OPTIONSFILE first if exists
> . =A0 =A0 =A0 if exists(${OPTIONSFILE}) && !make(rmconfig)
> . =A0 =A0 =A0 include "${OPTIONSFILE}"
> . =A0 =A0 =A0 endif
> . =A0 =A0 =A0 if exists(${OPTIONSFILE}.local)
> . =A0 =A0 =A0 include "${OPTIONSFILE}.local"
> . =A0 =A0 =A0 endif
> WITHOUT:=3D
> WITH:=3D
> . =A0 =A0 =A0 if defined(OPTIONS)
> REALOPTIONS=3D${OPTIONS:C/".*"//g}
> . =A0 =A0 =A0 for O in ${REALOPTIONS}
> RO:=3D${O}
> . =A0 =A0 =A0 if ${RO:L} =3D=3D off
> WITHOUT:=3D =A0 =A0 =A0 ${WITHOUT} ${OPT}
> . =A0 =A0 =A0 endif
> . =A0 =A0 =A0 if ${RO:L} =3D=3D on
> WITH:=3D =A0 =A0 =A0 =A0 =A0${WITH} ${OPT}
> . =A0 =A0 =A0 endif
> OPT:=3D${RO}
> . =A0 =A0 =A0 endfor
> . =A0 =A0 =A0 endif
>
> That is, all the lines that don't start with a . are not indented, and
> even this indentation is rather horrible (it doesn't nest, and it
> has the odd structure of 'if defined(OPTIONS) { if defined(OPTIONS) {} }'=
.

I don't see how it's any more horrible than the kernel style's rules
on indented #ifs (though I can see the reasoning for that)

It's an unfortunate consequence of the fact that any line starting
with whitespace must be a shell command-- from before Makefiles were
allowed conditionals etc.

It's got to be an improvement on:

.if defined(ONE)
.if !defined(TWO)
.for one in two three four
.if ${VAR} =3D=3D ${one}
.if defined(VERBOSE)
.warning VAR =3D one
.endif
.endif
.endfor
.elif ${VAR} =3D=3D four
.if defined(VERBOSE)
.warning VAR =3D four
.endif
.else
.warning VAR is not four, and VERBOSE is ignored
.endif    # XXXX Which one is this for??
.endif

which is what a lot of the Makefiles look like... debugging if-less
endifs etc is infinitely easier if we indent, however horrible it
looks.

We shouldn't be *trying* to make Makefiles hard to read ;)

Chris



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CADLo839Ef3bu_14AdexOWapOacFLk3MM9HK-oNLmtA52Cc9C6w>