以“#”开头的文件的 Makefile 问题

发布于 2024-08-23 03:12:28 字数 679 浏览 4 评论 0原文

我有一个目录“FS2”,其中包含以下文件:

  • ARGH

我有一个包含以下内容的 makefile

Template:sh= ls ./FS2/*
#all: $(Template)
        echo "Template is: $(Template)"
        touch all

当我运行“clearmake -C sun”并且文件“all”不存在时,我得到以下输出:

"Template is: ./FS2/#ARGH# ./FS2/that ./FS2/this"

修改“this”或“that”不会导致“all”重新生成。当使用“-d”进行调试时,“all”目标仅依赖于目录“./FS2”,而不依赖于该目录中的三个文件。我确定,当它展开“模板”时,“#”将被视为注释的开头,而该行的其余部分将被忽略!

该问题是由编辑器引起的,该编辑器在被杀死后会留下以“#”开头的文件。如果这些文件之一存在,则对目录中的文件的任何修改都不会导致“所有”重新生成。

虽然,我不想使编译依赖于临时文件是否已被修改,并且会从“Template”变量中删除该文件,但我仍然很好奇如果我确实想处理如何让它工作“#ARGH#”作为规则“all”所依赖的文件名。这可能吗?

I have a directory "FS2" that contains the following files:

  • ARGH

  • this
  • that

I have a makefile with the following contents.

Template:sh= ls ./FS2/*
#all: $(Template)
        echo "Template is: $(Template)"
        touch all

When I run "clearmake -C sun" and the file "all" does not exist, I get the following output:

"Template is: ./FS2/#ARGH# ./FS2/that ./FS2/this"

Modifying either "this" or "that" does not cause "all" to be regenerated. When run with "-d" for debug, the "all" target is only dependent on the directory "./FS2", not the three files in the directory. I determined that when it expands "Template", the "#" gets treated as the beginning of a comment and the rest of the line is ignored!

The problem is caused by an editor that when killed leaves around files that begin with "#". If one of those files exists, then no modifications to files in the directory causes "all" to be regenerated.

Although, I do not want to make compilation dependent on whether a temporary file has been modified or not and will remove the file from the "Template" variable, I am still curious as to how to get this to work if I did want to treat the "#ARGH#" as a filename that the rule "all" is dependent on. Is this even possible?

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

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

发布评论

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

评论(5

溺ぐ爱和你が 2024-08-30 03:12:29

我有一个目录“FS2”,其中包含以下文件:#ARGH# ...

这就是您的问题。在我看来,在文件名中使用“有趣”的字符是不明智的。现在我知道这些字符是允许的,但这并不意味着它们是一个好主意(也允许使用诸如退格键之类的 ASCII 控制字符,但会产生类似的烦人结果)。

我什至不喜欢文件名中的空格,更喜欢 SomethingLikeThis 在文件名中显示独立的单词,但至少许多 UNIX 工具中处理空格的工具是众所周知的。

我的建议是重命名该文件(如果它是您的文件之一),这样可以避免一些焦虑。但是,由于它们是编辑器崩溃时留下的临时文件,因此请在规则开始在 makefile 中运行之前删除它们。无论如何,您可能不应该基于编辑器临时文件进行重建。

或者使用更有针对性的模板,例如: Template:sh= ls ./FS2/[A-Za-z0-9]* 完全绕过这些文件(这只是一个示例,您应该确保它不会不要快速排除应该包含的文件)。

I have a directory "FS2" that contains the following files: #ARGH# ...

Therein lies your problem. In my opinion, it is unwise using "funny" characters in filenames. Now I know that those characters are allowed but that doesn't make them a good idea (ASCII control characters like backspace are also allowed with similar annoying results).

I don't even like spaces in filenames, preferring instead SomethingLikeThis to show independent words in a file name, but at least the tools for handling spaces in many UNIX tools is known reasonably well.

My advice would be to rename the file if it was one of yours and save yourself some angst. But, since they're temporary files left around by an editor crash, delete them before your rules start running in the makefile. You probably shouldn't be rebuilding based on an editor temporary file anyway.

Or use a more targeted template like: Template:sh= ls ./FS2/[A-Za-z0-9]* to bypass those files altogether (that's an example only, you should ensure it doesn't faslely exclude files that should be included).

つ低調成傷 2024-08-30 03:12:29

'#' 是有效的 Makefile 注释字符,因此第二行会被 make 程序忽略。

你能过滤掉(用grep)以#开头的文件并单独处理它们吗?

'#' is a valid Makefile comment char, so the second line is ignored by the make program.

Can you filter out (with grep) the files that start with # and process them separately?

夏雨凉 2024-08-30 03:12:29

我不熟悉clearmake,但尝试将模板定义替换为,

Template:sh= ls ./FS2/* | grep -v '#'

以便包含 # 的文件名不包含在 $(Template) 中。

I'm not familiar with clearmake, but try replacing your template definition with

Template:sh= ls ./FS2/* | grep -v '#'

so that filenames containing # are not included in $(Template).

戏蝶舞 2024-08-30 03:12:29

如果clearmake遵循与GNU make相同的规则,那么您还可以使用类似 Template := $(wildcard *.c) 的内容重写您的目标,这对于带有 oddball 的文件会更加智能名称。

If clearmake follows the same rules as GNU make, then you can also re-write your target using something like Template := $(wildcard *.c) which will be a little more intelligent about files with oddball names.

请你别敷衍 2024-08-30 03:12:29

如果我确实希望文件 #ARGH# 有助于确定目标 all 是否应该重建以及包含在规则生成的工件中,则 Makefile 应该是修改后,该行

Template:sh= ls ./FS2/*

更改为

Template=./FS2/*
Template_files:sh= ls $(Template)

This Works 因为 $(Template) 将在 all 之后被替换为文字字符串 ./FS2/*以及 $(Template_files) 的扩展。

然后,Clearmake(和 GNU make)在评估依赖项时使用 ./FS2/* 作为包含通配符的路径名,该路径名扩展为文件名 ./FS2/#ARGH# ./FS2 /that ./FS2/this$(Template_files) 可以在需要文件名列表的规则中使用。

If I really want the file #ARGH# to contribute to whether the target all should be rebuilt as well as be included in the artifacts produced by the rule, the Makefile should be modified so that the line

Template:sh= ls ./FS2/*

is changed to

Template=./FS2/*
Template_files:sh= ls $(Template)

This works because $(Template) will be replaced by the literal string ./FS2/* after all and in the expansion of $(Template_files).

Clearmake (and GNU make) then use ./FS2/* as a pathname containing a wildcard when evaluating the dependencies, which expands in to the filenames ./FS2/#ARGH# ./FS2/that ./FS2/this and $(Template_files) can be used in the rules where a list of filenames is needed.

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