FreeBSD Make question

Simon J. Gerraty sjg at juniper.net
Fri Oct 25 18:33:10 UTC 2013


On Fri, 25 Oct 2013 09:43:04 +0200, Johan Kuuse writes:
>The background is that I'm trying to create a system of nonrecursive
>Makefiles, where all paths must be absolute.
>This implies using absolute paths as target names. 

This works fine - my dirdeps.mk uses absolute paths of directories (plus
added attributes) as targets

>What if a path contains whitespaces? (God forbid!)

You lose.  Ideally you throw an error.

.error "Sorry ${USER}, I cannot let you do that"

Alternatively you could try substituting the spaces with glob chars.
That may cause more trouble than it fixes.

fixing make to handle this would not be trivial.






>
>>
>> What is the problem we are trying to solve?
>>
>>
>Problem described above, below goes a sample Makefile, trying several ways
>to escaping whitespaces in target names.
>
>The Makefile:
>
>Makefile.freebsd-questions
>--------
># MY_TARGET=/home/joe/directory name with spaces/hello.c
># MY_SECOND_TARGET=/home/joe/directory name with spaces/world.c
>
># MY_TARGET='/home/joe/directory name with spaces/hello.c'
># MY_SECOND_TARGET='/home/joe/directory name with spaces/world.c'
>
># MY_TARGET="/home/joe/directory name with spaces/hello.c"
># MY_SECOND_TARGET="/home/joe/directory name with spaces/world.c"
>
>MY_TARGET=/home/joe/directory\ name\ with\ spaces/hello.c
>MY_SECOND_TARGET=/home/joe/directory\ name\ with\ spaces/world.c
>
>all: ${MY_TARGET} ${MY_SECOND_TARGET}
>@echo This is Make version $(MAKE_VERSION)
>
>${MY_TARGET}:
>    @echo $@
>
>${MY_SECOND_TARGET}:
>    @echo $@
>--------
>
>The output:
>
>FreeBSD Make:
>make -f Makefile.freebsd-questions
>--------
>"Makefile.freebsd-questions", line 20: warning: duplicate script for target
>"/home/joe/directory\" ignored
>"Makefile.freebsd-questions", line 20: warning: duplicate script for target
>"name\" ignored
>"Makefile.freebsd-questions", line 20: warning: duplicate script for target
>"with\" ignored
>/home/joe/directory\
>name\
>with\
>spaces/hello.c
>spaces/world.c
>This is Make version 9201120530
>--------
>
>GNU Make:
>gmake -f Makefile.freebsd-questions
>--------
>/home/joe/directory name with spaces/hello.c
>/home/joe/directory name with spaces/world.c
>This is Make version 3.82
>--------
>
>
>The only possible workaround I have found so far with FreeBSD Make, is
>to substitute whitespaces with another character in the target
>variables, for example '+', (i.e.
>/home/joe/directory+name+with+spaces/hello.c) and using the modified
>variable as the target name. In the target rule, the variable
>substitution then has to be "reversed" to obtain the "real" target
>name:
>
># MY_TARGET=/home/joe/directory name with spaces/hello.c#
>MY_TARGET_PLUS != echo "$(MY_TARGET)" | sed -e 's/ /+/g'
>
>
>${MY_TARGET_PLUS}:    @echo "${@:C/\+/ /g}"
>
>Using this ugly hack, the warnings disappears in the example above, but it
>doesn't really resolve the problem, as MY_TARGET_PLUS will always be a
>non-existing target. So using this hack, targets will always be
>executed/rebuilt, even if MY_TARGET is up to date.
>Best regards, Johan Kuuse
>
>--047d7b6d91d485fa2504e98be68f
>Content-Type: text/html; charset="ISO-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
><div dir=3D"ltr"><br><div class=3D"gmail_extra"><div class=3D"gmail_quote">=
>On Thu, Oct 24, 2013 at 11:49 PM, Simon J. Gerraty <span dir=3D"ltr"><<a=
> href=3D"mailto:sjg at juniper.net" target=3D"_blank">sjg at juniper.net</a>><=
>/span> wrote:<br>
><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
>left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
>adding-left:1ex"><div class=3D"im">>Simon: do we allow whitespace in tar=
>get names in either fmake or bmake?<br>
>
>>If so, what are the escaping rules?<br></div></blockquote><div><br></di=
>v><div>Thanks Benjamin for the hints, I'll check out the -hackers list.=
></div><div>=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0=
>px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);borde=
>r-left-style:solid;padding-left:1ex">
><div class=3D"im">
><br>
></div>Whether it is "allowed" or not, it isn't something I wo=
>uld consider<br>
>doing.<br></blockquote><div><br></div><div>Hi Simon,</div><div>I definitely=
> agree that whitespaces shouldn't go into targets if it could be avoide=
>d.</div><div><br></div><div>The background is that I'm trying to create=
> a system of nonrecursive Makefiles, where all paths must be absolute.</div=
>>
><div>This implies using absolute paths as target names. What if a path cont=
>ains whitespaces? (God forbid!)</div><div>=A0<br></div><blockquote class=3D=
>"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;borde=
>r-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
>
><br>
>What is the problem we are trying to solve?<br>
><br></blockquote><div><br></div><div>Problem described above, below goes a =
>sample Makefile, trying several ways to escaping whitespaces in target name=
>s.</div><div><br></div><div>The Makefile:=A0</div></div></div><div class=3D=
>"gmail_extra">
><pre id=3D"text-2" class=3D"" style=3D"font-size:1.4em;margin-left:10px;col=
>or:rgb(0,0,0)">Makefile.freebsd-questions<br>--------<br># MY_TARGET=3D/hom=
>e/joe/directory name with spaces/hello.c<br># MY_SECOND_TARGET=3D/home/joe/=
>directory name with spaces/world.c<br>
> <br># MY_TARGET=3D'/home/joe/directory name with spaces/hello.c'<b=
>r># MY_SECOND_TARGET=3D'/home/joe/directory name with spaces/world.c&#3=
>9;<br> <br># MY_TARGET=3D"/home/joe/directory name with spaces/hello.c=
>"<br>
># MY_SECOND_TARGET=3D"/home/joe/directory name with spaces/world.c&quo=
>t;<br> <br>MY_TARGET=3D/home/joe/directory\ name\ with\ spaces/hello.c<br>M=
>Y_SECOND_TARGET=3D/home/joe/directory\ name\ with\ spaces/world.c<br> <br>a=
>ll: ${MY_TARGET} ${MY_SECOND_TARGET}<br>
>@echo This is Make version $(MAKE_VERSION)<br> <br>${MY_TARGET}:<br>    @ec=
>ho $@<br> <br>${MY_SECOND_TARGET}:<br>    @echo $@<br>--------<br><br></pre=
>><pre id=3D"text-2" class=3D"" style=3D"font-size:1.4em;margin-left:10px;co=
>lor:rgb(0,0,0)">
><span style=3D"font-family:arial;font-size:small;color:rgb(34,34,34)">The o=
>utput:=A0</span> <br> <br>FreeBSD Make:<br>make -f Makefile.freebsd-questio=
>ns<br>--------<br>"Makefile.freebsd-questions", line 20: warning:=
> duplicate script for target<br>
>"/home/joe/directory\" ignored<br>"Makefile.freebsd-question=
>s", line 20: warning: duplicate script for target<br>"name\"=
> ignored<br>"Makefile.freebsd-questions", line 20: warning: dupli=
>cate script for target<br>
>"with\" ignored<br>/home/joe/directory\<br>name\<br>with\<br>spac=
>es/hello.c<br>spaces/world.c<br>This is Make version 9201120530<br>--------=
><br> <br>GNU Make:<br>gmake -f Makefile.freebsd-questions<br>--------<br>
>/home/joe/directory name with spaces/hello.c<br>/home/joe/directory name wi=
>th spaces/world.c<br>This is Make version 3.82<br>--------<br>=A0</pre><pre=
> id=3D"text-2" class=3D"" style=3D"margin-left:10px"><span style=3D"color:r=
>gb(34,34,34);font-size:small;font-family:arial">The only possible workaroun=
>d I have found so far with FreeBSD Make, is </span><span style=3D"color:rgb=
>(34,34,34);font-family:arial">to substitute whitespaces with another charac=
>ter in the target variables, for example '+', (i.e.</span><span sty=
>le=3D"color:rgb(34,34,34);font-family:arial">=A0</span><span style=3D"color=
>:rgb(0,0,0);font-family:arial">/home/joe/directory+name+with+spaces/hello.c=
>) </span><span style=3D"color:rgb(34,34,34);font-family:arial">and using th=
>e modified variable as the target name. In the target rule, the variable su=
>bstitution then has to be "reversed" to obtain the "real&quo=
>t; target name:</span><div style=3D"color:rgb(0,0,0)">
><span style=3D"color:rgb(34,34,34);font-family:arial"><br></span></div><pre=
> id=3D"text-2" class=3D"" style=3D"margin-left:10px"><font color=3D"#000000=
>"># MY_TARGET=3D/home/joe/directory name with spaces/hello.c
></font><span style=3D"color:rgb(0,0,0);font-family:arial"># MY_TARGET_PLUS =
>!=3D echo "$(</span><span style=3D"color:rgb(0,0,0);font-family:arial"=
>>MY_TARGET)"=A0</span><font color=3D"#000000" face=3D"arial">|</font><=
>span style=3D"color:rgb(0,0,0);font-family:arial"> sed -e 's/ /+/g'=
></span></pre>
><pre id=3D"text-2" class=3D"" style=3D"color:rgb(0,0,0);margin-left:10px"><=
>span style=3D"font-family:arial">
>${MY_TARGET_PLUS}:
></span><span style=3D"font-family:arial">    @echo "$</span><span styl=
>e=3D"font-family:arial">{</span><span style=3D"font-family:arial">@:C/</spa=
>n><span style=3D"font-family:arial">\+</span><span style=3D"font-family:ari=
>al">/ /g</span><span style=3D"font-family:arial">}</span><span style=3D"fon=
>t-family:arial">"</span><span style=3D"font-family:arial"><br>
></span><span style=3D"font-family:arial">
></span></pre><span style=3D"color:rgb(34,34,34);font-family:arial">Using th=
>is ugly hack, the warnings disappears in the example above, but it doesn&#3=
>9;t really resolve the problem, as </span><span style=3D"color:rgb(0,0,0);f=
>ont-family:arial">MY_TARGET_PLUS </span><span style=3D"font-family:arial">w=
>ill always be a non-existing target. So using this hack, targets will alway=
>s be executed/rebuilt, even if </span><span style=3D"color:rgb(0,0,0);font-=
>family:arial">MY_TARGET is up to date.</span><span style=3D"font-family:ari=
>al"><br>
></span><span style=3D"color:rgb(34,34,34);font-family:arial">
>Best regards,
></span><span style=3D"font-family:arial">Johan Kuuse</span></pre></div></di=
>v>
>
>--047d7b6d91d485fa2504e98be68f--



More information about the freebsd-doc mailing list