开发者

nmake makefile, linking objects files in a subfolder

My makefile defines a link command:

prod_link = $(LINK) $(LINK_FLAGS) -o$(PROD_OUT) $(PROD_OBJS)

where $(PROD_OBJS) is a list of object files of the for开发者_高级运维m:

PROD_OBJS = objfile1.obj objfile2.obj objfile3.obj ... objfileN.obj

Now the makefile itself is at the root of my project directory. It gets messy to have object and listing files at the root, I'd like to put them in a subfolder.

Building and outputing the obj files to a subfolder works, I'm doing it with suffixes and inference:

.s.obj:
    $(ASSEMBLY) $(FLAGS) $*.s -o Objects\$*.obj

The problem is to pass the Objects folder to the link command.

I tried:

prod_link = $(LINK) $(LINK_FLAGS) -o$(PROD_OUT) Objects\$(PROD_OBJS)

but only the first file in the list of object files gets the folder's name.

How can I pass the Objects subfolder to all files of my list $(PROD_OBJS)?


EDIT

I tried also

PROD_OBJS = $(patsubst %.ss,Object\%.obj, $(PROD_SRC))

but got:

makefile(51) : fatal error U1000: syntax error : ')' missing in macro invocation
Stop.

This is quite strange...


nmake is not GNUMake, and is rather rubbish. See the NMAKE Reference for details.

As far as your problem goes (translating 1.o 2.o 3.o into d/1.o d/2/o d/3.o), try

OBJS= 1.o 2.o 3.o
# Looks wierd I know, but basically change ' ' to ' d/'
# (and it's not very robust!)
OBJS_WITH_PREFIX= d/$(OBJS: = d/)
!ERROR [$(OBJS_WITH_PREFIX)]

By the way, your pattern rule is lying to nmake. You say .s.obj:, which says "here is how to convert a .s file into a .obj," but then the commands you give actually create the object in a subfolder. You should have started the pattern rule with .s{Objects\}.obj:. See the docs for more details (Search Paths in Rules).


Very late to the party, but in case anyone else runs into the same problem:

This error

makefile(51) : fatal error U1000: syntax error : ')' missing in macro invocation
Stop.

is caused by the fact that the patsubst syntax doesn't seem to be supported by nmake. You can get around this by using the alternative syntax

$(var:suffix=replacement)

instead of

$(patsubst %suffix,%replacement,$(var))

(this is also valid in gnumake).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜