Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Oct 2013 09:43:04 +0200
From:      Johan Kuuse <kuuse@redantigua.com>
To:        "Simon J. Gerraty" <sjg@juniper.net>
Cc:        freebsd-doc@freebsd.org
Subject:   Re: FreeBSD Make question
Message-ID:  <CAGUU1d0DVRYO_GUryyJONbpTgxrsYFf=WeQkn63557stnpsaVQ@mail.gmail.com>
In-Reply-To: <20131024214923.CB0AF5807E@chaos.jnpr.net>
References:  <CAGUU1d1RQAuq=5rOczZnRnVo31Rh_xhYOnDP7-=ajVv4AnRwZA@mail.gmail.com> <alpine.GSO.1.10.1310241730590.4934@multics.mit.edu> <20131024214923.CB0AF5807E@chaos.jnpr.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Oct 24, 2013 at 11:49 PM, Simon J. Gerraty <sjg@juniper.net> wrote:

> >Simon: do we allow whitespace in target names in either fmake or bmake?
> >If so, what are the escaping rules?
>

Thanks Benjamin for the hints, I'll check out the -hackers list.


>
> Whether it is "allowed" or not, it isn't something I would consider
> doing.
>

Hi Simon,
I definitely agree that whitespaces shouldn't go into targets if it could
be avoided.

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. What if a path contains
whitespaces? (God forbid!)


>
> 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



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