如何在Gnu Make文件中全局运行一些命令

编程入门 行业动态 更新时间:2024-10-28 15:20:05
本文介绍了如何在Gnu Make文件中全局运行一些命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个gnu Makefile,它通过环境变量收集版本信息.现在,我想在使用gnumake语法构建任何目标之前全局执行操作".作为伪代码,这意味着:

I have a gnu Makefile that collects version information through environment variables. Now, I want to do "something" globally before any target is built using the gnumake syntax. As pseudo code, this means:

  • 存在指定文件时,将其删除
  • 遍历字符串数组并将其值放入指定的文件

我尝试过:

$(shell if exist $(subst /,\,$(products)filenames.h) del /F/Q $(subst /,\,$(products)filenames.h)) $(foreach Item, $(EnvFilenames), @echo $(Item) >> $(subst /,\,$(products)filenames.h))

这给了我一个错误:

C:\temp\Makefile.mak:72: *** missing separator. Stop.

其中第72行是$(shell ...行.如果我将其放在define部分:

where Line 72 is the $(shell ... line. If I put this in a define section:

define foobar $(shell if exist $(subst /,\,$(products)filenames.h) del /F/Q $(subst /,\,$(products)filenames.h)) $(foreach Item, $(EnvFilenames), @echo $(Item) >> $(subst /,\,$(products)filenames.h)) endef

并将其称为目标,它可以正常运行:

and call this for a target, it runs fine:

$(products)$test.o : test.c $(commons) $(call foobar) $(cc) $(cflags_m) test.c -o$@

并执行应有的操作...但是,只要我想从另一个define内部调用它,它就会再次失败,并缺少分隔符.

and does what it should... but as soon as I want to call it from inside of another define, it fails again with a missing seperator.

这是什么意思,我该如何解决?

What does it mean and how can I fix it?

编译是在Win32平台上进行的,不必是多平台的.

Compilation takes place on a Win32 platform and does not have to be multi-platform.

推荐答案

如果每个Make调用足够一次,则可以将其放入全局分配中.

If once per Make invocation is sufficient, you could put it in a global assignment.

# Ignore the value, calling for side effects IGNORE := $(shell commands with side effects)

我会建议不要使用这种黑客,但我可以想象一下可能会派上用场的情况.

I would recommend against this hack, but I can imagine situations where it might come in handy.

更多推荐

如何在Gnu Make文件中全局运行一些命令

本文发布于:2023-05-27 19:34:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/300603.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:全局   命令   文件   如何在   Gnu

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!