Hi,
Can you use $(FOO-BAR) in Makefile? It's not portable in POSIX [1]
"Applications shall select macro names from the set of characters
consisting solely of periods, underscores, digits, and alphabetics
from the portable character set"
And the Autoconf manual too says that it's not portable [2].
But Paul Eggert found a number of such Makefile macro names in Emacs [3],
which have apparently not been hurting for years.
Prompted by this, I've tested the support for Makefile macro names with
dashes in
- GNU make,
- dmake 4.12,
- smake 1.2.1,
- the vendor 'make' in
- MacOS X,
- FreeBSD 6.4,
- OpenBSD 4.4,
- NetBSD 5.0,
- AIX 5.1,
- HP-UX 10.20,
- IRIX 6.5 (also pmake, smake),
- OSF/1 5.1,
- Solaris 2.6 (also dmake),
and found that all support it. The test was this Makefile:
================== Makefile ===================
FOO-BAR = yellow_dog
FOO_BAR = green_cat
all : $(FOO-BAR)
$(FOO-BAR) : greet_dog
$(FOO_BAR) : greet_cat
greet_dog:
echo hello my dog
greet_cat:
echo hello my cat
================================================
So I think it's time to update the Autoconf documentation by adding a
sentence. Here's a proposed patch.
[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html
[2]
http://www.gnu.org/software/autoconf/manual/html_node/Special-Chars-in-Names.html
[3] http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg01031.html
2011-01-28 Bruno Haible <[email protected]>
doc: Don't discourage dashes in Makefile macro names.
* doc/autoconf.texi (Special Chars in Names): Mention that dashes in
Makefile macro names are supported.
--- doc/autoconf.texi.orig Fri Jan 28 12:34:38 2011
+++ doc/autoconf.texi Fri Jan 28 12:26:49 2011
@@ -19183,10 +19183,12 @@
@section Special Characters in Make Macro Names
Posix limits macro names to nonempty strings containing only
-ASCII letters and digits, @samp{.}, and @samp{_}. Many
-@command{make} implementations allow a wider variety of characters, but
-portable makefiles should avoid them. It is portable to start a name
-with a special character, e.g., @samp{$(.FOO)}.
+ASCII letters and digits, @samp{.}, and @samp{_}. Although Posix does
+not allow dashes @samp{-} in names, all known current @command{make}
+implementations support them. Many @command{make} implementations allow
+a wider variety of characters, but portable makefiles should avoid them.
+It is portable to start a name with a special character, e.g.,
+@samp{$(.FOO)}.
Some ancient @command{make} implementations don't support leading
underscores in macro names. An example is NEWS-OS 4.2R.