如何避免Makefile中重复的隐式规则?

发布于 2024-12-27 03:26:17 字数 769 浏览 0 评论 0原文

我正在开发一个Makefile自动生成软件(CodeMate),我想知道我是否可以避免为不同的文件编写隐式规则就足够了,但具有相同的操作:

%.o: %.F90
    @echo " Creating dependency $@"
    @echo $(seperator)
    @$(FORTRAN_COMPILER) -c $< $(OPTION) $(FORTRAN_FLAGS) $(INCLUDES)
%.o: %.f90
    @echo " Creating dependency $@"
    @echo $(seperator)
    @$(FORTRAN_COMPILER) -c $< $(OPTION) $(FORTRAN_FLAGS) $(INCLUDES)
%.o: %.F
    @echo " Creating dependency $@"
    @echo $(seperator)
    @$(FORTRAN_COMPILER) -c $< $(OPTION) $(FORTRAN_FLAGS) $(INCLUDES)
%.o: %.f
    @echo " Creating dependency $@"
    @echo $(seperator)
    @$(FORTRAN_COMPILER) -c $< $(OPTION) $(FORTRAN_FLAGS) $(INCLUDES)

这可以很好地工作,但有点难看。

谢谢!

I am working on a Makefile auto-generating software (CodeMate), and I would like to know if I can avoid to write the implicit rules for different file suffices but with the same operations as:

%.o: %.F90
    @echo " Creating dependency $@"
    @echo $(seperator)
    @$(FORTRAN_COMPILER) -c 
lt; $(OPTION) $(FORTRAN_FLAGS) $(INCLUDES)
%.o: %.f90
    @echo " Creating dependency $@"
    @echo $(seperator)
    @$(FORTRAN_COMPILER) -c 
lt; $(OPTION) $(FORTRAN_FLAGS) $(INCLUDES)
%.o: %.F
    @echo " Creating dependency $@"
    @echo $(seperator)
    @$(FORTRAN_COMPILER) -c 
lt; $(OPTION) $(FORTRAN_FLAGS) $(INCLUDES)
%.o: %.f
    @echo " Creating dependency $@"
    @echo $(seperator)
    @$(FORTRAN_COMPILER) -c 
lt; $(OPTION) $(FORTRAN_FLAGS) $(INCLUDES)

This can work well, but is a little ugly.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隔纱相望 2025-01-03 03:26:17

(未经测试:)

define f_rule
%.o: %.$(1)
    @echo " Creating dependency $@"
    @echo $(seperator)
    @$(FORTRAN_COMPILER) -c $< $(OPTION) $(FORTRAN_FLAGS) $(INCLUDES)
endef

F_EXTENSIONS := F90 f90 F f
$(foreach ext, $(F_EXTENSIONS), $(eval $(call f_rule,$(ext))))

(Untested:)

define f_rule
%.o: %.$(1)
    @echo " Creating dependency $@"
    @echo $(seperator)
    @$(FORTRAN_COMPILER) -c $< $(OPTION) $(FORTRAN_FLAGS) $(INCLUDES)
endef

F_EXTENSIONS := F90 f90 F f
$(foreach ext, $(F_EXTENSIONS), $(eval $(call f_rule,$(ext))))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文