nmake appending to variables

对着背影说爱祢 提交于 2021-02-07 12:23:17

问题


  • Utility: NMake
  • Platform : Windows 7

I have the following Makefile

FILE = $(shell) *.c
FILE += $(shell) *.cpp

exec:
    @echo $(FILE)

This works perfectly fine with make. This throws up the following error with nmake

makefile(2) : fatal error U1036: syntax error : too many names to left of '='
Stop.

What could be the reason?

Without the line

FILE += $(shell) *.cpp

nmake works perfectly fine.


回答1:


The += syntax is a GNU Make extension that was pioneered in Sun's make in the late 80s. It is not part of the syntax for POSIX standard make, or the original AT&T make.

If you use extensions, you get caught when you switch to a system that doesn't support them. You either have to rework things (hard) or stick with the original system.


One way to modify the file to work with nmake is probably:

FILE1 = $(shell) *.c
FILE2 = $(shell) *.cpp
FILE  = $(FILE1) $(FILE2)

exec:
    @echo $(FILE)

Or, given that the macro shell is not defined, even:

FILE1 = *.c
FILE2 = *.cpp
FILE  = $(FILE1) $(FILE2)

exec:
    @echo $(FILE)



回答2:


Instead of

FILE = $(shell) *.c
FILE += $(shell) *.cpp

you must use

FILE = $(shell) *.c
FILE = $(shell) *.cpp $(FILE)

The expansion strategy is different from nmake and make. nmake expands all before starting evaluating the rules while make does it just in times when needed and because this gives problems it has the two flavours of expansion as described in the info pages.

I personally like nmake's way better. And by the way, use "jom" instead of "nmake".



来源:https://stackoverflow.com/questions/9848207/nmake-appending-to-variables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!