help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to deal with filenames with spaces and dollar signs?


From: Ken Smith
Subject: Re: How to deal with filenames with spaces and dollar signs?
Date: Wed, 8 Nov 2006 22:45:47 -0800

On 11/8/06, David Wuertele <address@hidden> wrote:
I'm making a makefile library that has to stand up to some chaotic file naming
schemes.  I need make to copy some files around, only when necessary, without
getting confused by filenames with spaces and special (ie make-meaningful)
characters.

One problem I have is that make chokes on spaces and $ characters.  For example,

I posted a partial solution to this problem from a previous thread
that may get you started.

 [1] http://lists.gnu.org/archive/html/help-make/2005-08/msg00095.html

It sounds like your situation may be more complicated than Java inner
classes.  However, aside from the solutions echoed here

 [2] 
http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query=spaces+in+filenames&submit=Search&idxname=help-make

to avoid any special characters in filenames, I can offer these tidbits.

- If you need to propogate a $ character through gmake to the shell,
remember that both will expand it.  In the post from [1], you may
notice an instance of $$$$.  I have seen it get as ridiculous or worse
when dealing with dollar signs that need to be armored against make
and shell processing. (eg. \$$\$$, etc.)

- Don't let make know about the filenames.  Have make generate
sentinel files with acceptable names and use shell constructs to
generate the filenames.  This is shown in the makefile included below.

- Once you figure out what you need to do to get make to deal with
your directory structure and can formalize it, it may make sense to
autogenerate the makefiles using some kind of preprocessing in order
to tie these difficulties up and deal with them in isolation.  (This
is its own ball of wax.)

The following is a modified version of your original makefile which
ostensibly does what you were trying to do.  It uses the sentinels
concept I mentioned in the tidbits above.  I think it sidesteps your
issue a bit because it sounds like you have extant files which you
would like to read into make variables and deal with using normal make
means.  That will be more difficult.  Please hit the list again if you
need more help.

 Ken

---GNUmakefile---
# You may need to remove newlines placed here by gmail, it should
# be 28 lines long.
SOURCE_DIR := source-dir
source-files = \
  $(SOURCE_DIR)/one \
  $(SOURCE_DIR)/two \
  $(SOURCE_DIR)/three/four \
  $(SOURCE_DIR)/three/5 \
  $(SOURCE_DIR)/three/6

.PHONY: all
all: $(source-files)


.PHONY: clean
clean:
        rm -rf $(SOURCE_DIR)

# make dirs
$(SOURCE_DIR): ; mkdir -p $@
$(SOURCE_DIR)/three: | $(SOURCE_DIR) ; mkdir -p $@

# make files
$(SOURCE_DIR)/one: | $(SOURCE_DIR) ; echo "one" > $@
$(SOURCE_DIR)/two: | $(SOURCE_DIR) ; echo "two" > $@
$(SOURCE_DIR)/three/four: | $(SOURCE_DIR)/three ; echo "four" > $@
$(SOURCE_DIR)/three/5: | $(SOURCE_DIR)/three ; echo "five" >
$(@D)/"file! with? \$$special characters in: its.name." ; touch $@
$(SOURCE_DIR)/three/6: | $(SOURCE_DIR)/three ; mkdir $(@D)/"directory!
with? \$$special characters in: its.name." ; echo "six" >
$(@D)/"directory! with? \$$special characters in: its.name."/six ;
touch $@




reply via email to

[Prev in Thread] Current Thread [Next in Thread]