svn commit: r233052 - head/share/mk

Chris Rees utisoft at gmail.com
Tue Mar 20 21:20:44 UTC 2012


On 20 March 2012 14:19, John Baldwin <jhb at 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)
>> >   .if defined(BAR)
>> >     CFLAGS+=        -DFOO_BAR
>> >   .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?  The bits in I see in bsd.port.mk suffer
> from the limitation Dimitry raises, e.g.:
>
> .if defined(OPTIONS)
> # include OPTIONSFILE first if exists
> .       if exists(${OPTIONSFILE}) && !make(rmconfig)
> .       include "${OPTIONSFILE}"
> .       endif
> .       if exists(${OPTIONSFILE}.local)
> .       include "${OPTIONSFILE}.local"
> .       endif
> WITHOUT:=
> WITH:=
> .       if defined(OPTIONS)
> REALOPTIONS=${OPTIONS:C/".*"//g}
> .       for O in ${REALOPTIONS}
> RO:=${O}
> .       if ${RO:L} == off
> WITHOUT:=       ${WITHOUT} ${OPT}
> .       endif
> .       if ${RO:L} == on
> WITH:=          ${WITH} ${OPT}
> .       endif
> OPT:=${RO}
> .       endfor
> .       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} == ${one}
.if defined(VERBOSE)
.warning VAR = one
.endif
.endif
.endfor
.elif ${VAR} == four
.if defined(VERBOSE)
.warning VAR = 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


More information about the svn-src-all mailing list