make: Wildcard Pitfall
1
1 4.4.2 Pitfalls of Using Wildcards
1 ---------------------------------
1
1 Now here is an example of a naive way of using wildcard expansion, that
1 does not do what you would intend. Suppose you would like to say that
1 the executable file 'foo' is made from all the object files in the
1 directory, and you write this:
1
1 objects = *.o
1
1 foo : $(objects)
1 cc -o foo $(CFLAGS) $(objects)
1
1 The value of 'objects' is the actual string '*.o'. Wildcard expansion
1 happens in the rule for 'foo', so that each _existing_ '.o' file becomes
1 a prerequisite of 'foo' and will be recompiled if necessary.
1
1 But what if you delete all the '.o' files? When a wildcard matches
1 no files, it is left as it is, so then 'foo' will depend on the
1 oddly-named file '*.o'. Since no such file is likely to exist, 'make'
1 will give you an error saying it cannot figure out how to make '*.o'.
1 This is not what you want!
1
1 Actually it is possible to obtain the desired result with wildcard
1 expansion, but you need more sophisticated techniques, including the
11 'wildcard' function and string substitution. ⇒The Function
'wildcard' Wildcard Function.
1
1 Microsoft operating systems (MS-DOS and MS-Windows) use backslashes
1 to separate directories in pathnames, like so:
1
1 c:\foo\bar\baz.c
1
1 This is equivalent to the Unix-style 'c:/foo/bar/baz.c' (the 'c:'
1 part is the so-called drive letter). When 'make' runs on these systems,
1 it supports backslashes as well as the Unix-style forward slashes in
1 pathnames. However, this support does _not_ include the wildcard
1 expansion, where backslash is a quote character. Therefore, you _must_
1 use Unix-style slashes in these cases.
1