tags:

views:

70

answers:

5

I have a directory "FS2" that contains the following files:

  • #ARGH#
  • this
  • that

I have a makefile with the following contents.

Template:sh= ls ./FS2/*
#all: $(Template)
        echo "Template is: $(Template)"
        touch all

When I run "clearmake -C sun" and the file "all" does not exist, I get the following output:

"Template is: ./FS2/#ARGH# ./FS2/that ./FS2/this"

Modifying either "this" or "that" does not cause "all" to be regenerated. When run with "-d" for debug, the "all" target is only dependent on the directory "./FS2", not the three files in the directory. I determined that when it expands "Template", the "#" gets treated as the beginning of a comment and the rest of the line is ignored!

The problem is caused by an editor that when killed leaves around files that begin with "#". If one of those files exists, then no modifications to files in the directory causes "all" to be regenerated.

Although, I do not want to make compilation dependent on whether a temporary file has been modified or not and will remove the file from the "Template" variable, I am still curious as to how to get this to work if I did want to treat the "#ARGH#" as a filename that the rule "all" is dependent on. Is this even possible?

+1  A: 

'#' is a valid Makefile comment char, so the second line is ignored by the make program.

Can you filter out (with grep) the files that start with # and process them separately?

florin
In this case, I can filter out the files beginning with "#", but I also think there must be a way to do this, if I couldn't.
Joshua Lee
+1  A: 

I'm not familiar with clearmake, but try replacing your template definition with

Template:sh= ls ./FS2/* | grep -v '#'

so that filenames containing # are not included in $(Template).

Dave Hinton
+3  A: 

I have a directory "FS2" that contains the following files: #ARGH# ...

Therein lies your problem. In my opinion, it is unwise using "funny" characters in filenames. Now I know that those characters are allowed but that doesn't make them a good idea (ASCII control characters like backspace are also allowed with similar annoying results).

I don't even like spaces in filenames, preferring instead SomethingLikeThis to show independent words in a file name, but at least the tools for handling spaces in many UNIX tools is known reasonably well.

My advice would be to rename the file if it was one of yours and save yourself some angst. But, since they're temporary files left around by an editor crash, delete them before your rules start running in the makefile. You probably shouldn't be rebuilding based on an editor temporary file anyway.

Or use a more targeted template like: Template:sh= ls ./FS2/[A-Za-z0-9]* to bypass those files altogether (that's an example only, you should ensure it doesn't faslely exclude files that should be included).

paxdiablo
Making your template more specific is the easiest way to go, even if you only change the `*` to `*.c` (or whatever file extension your source files use).
bta
A: 

If clearmake follows the same rules as GNU make, then you can also re-write your target using something like Template := $(wildcard *.c) which will be a little more intelligent about files with oddball names.

bta
There is a GNU mode in clearmake, but this had the same behavior when I tried it.
Joshua Lee
A: 

If I really want the file #ARGH# to contribute to whether the target all should be rebuilt as well as be included in the artifacts produced by the rule, the Makefile should be modified so that the line

Template:sh= ls ./FS2/*

is changed to

Template=./FS2/*
Template_files:sh= ls $(Template)

This works because $(Template) will be replaced by the literal string ./FS2/* after all and in the expansion of $(Template_files).

Clearmake (and GNU make) then use ./FS2/* as a pathname containing a wildcard when evaluating the dependencies, which expands in to the filenames ./FS2/#ARGH# ./FS2/that ./FS2/this and $(Template_files) can be used in the rules where a list of filenames is needed.

Joshua Lee