简体   繁体   English

Makefile命令修改

[英]Makefile command modification

I would like to modify a Makefile command: 我想修改一个Makefile命令:

-rm -f $(OBJS)
-rm -f $(OBJS:.o=.mod)

The first removes all filenames.o and the second removes all filenames.mod. 第一个删除所有filenames.o,第二个删除所有filenames.mod。 However, I would like to modify the second such that I get: mod_filenames.mod, ie, add the string "mod_". 但是,我想修改第二个,这样我得到:mod_filenames.mod,即添加字符串“ mod_”。

I tried: -rm -f mod_$(OBJS:.o=.mod), but this only affected the first file in the list. 我试过:-rm -f mod _ $(OBJS:.o = .mod),但这仅影响列表中的第一个文件。 But I'm jet guessing here. 但是我在这里猜测。 If anyone could suggest a wide site where such programming is explained, I would grateful. 如果有人能建议一个广泛的站点解释此类编程,我将不胜感激。

GNU Make Manual . GNU Make手册

There is also GNU Make Unleased book and GNU Make Standard Library . 还有GNU Make Unleased书GNU Make标准库

See 8.3 Functions for File Names of the manual, you can use $(addprefix ...) (there are other ways) to get: 请参见手册的8.3文件名功能 ,可以使用$(addprefix ...) (还有其他方法)获取:

-rm -f $(OBJS)
-rm -f $(addprefix mod_,$(OBJS:.o=.mod))

It would be even better to use $(RM) (it's usually rm -f ): 最好使用$(RM) (通常是rm -f ):

-$(RM) $(OBJS)
-$(RM) $(addprefix mod_,$(OBJS:.o=.mod))

The GNU make manual describes all these things. GNU make手册描述了所有这些内容。

You can use patterns to get what you want: 您可以使用模式来获取所需的内容:

-rm -f $(OBJS:%.o=mod_%.mod)

Writing $(OBJS:.o=.mod) is just shorthand for $(OBJS:%.o=%.mod) . 编写$(OBJS:.o=.mod)只是$(OBJS:%.o=%.mod)简写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM