将GNUMake与包含空格的文件名一起使用的最可靠方法是什么? [英] What is the most reliable way of using GNUMake with filenames containing spaces?

查看:85
本文介绍了将GNUMake与包含空格的文件名一起使用的最可靠方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用GNUMake运行基于规则的Makefile,该文件在目录结构中(在Windows文件系统上)构建一组C文件.

I want to use GNUMake to run a rule-based makefile which builds a set of C files in a directory structure (on a Windows file system).

根目录,一些子目录和一些文件包含空格.

The root directory, some sub-directories and some files contain spaces.

示例文件:"C:\Documents and Settings\<username>\My Documents\Test Dir\Build Me.c"

当文件路径包含空格时,GNUMake不会真正起作用.我已经读过解决此问题的可能方法(从文件名中删除空格,使用8.3格式,用?\\替换空格等),但没有一个是完美的(或者是吗? )

GNUMake doesn't really work when the file paths contain spaces. I've read about the possible ways of working around this issue (removing the spaces from my filenames, using the 8.3 format, substituting spaces with ? or \\ etc.) but none of them are perfect (or are they?)

有解决这个问题的灵丹妙药吗?

Is there a silver bullet that will solve this problem?

顺便说一句,我坚持使用GNUMake,不能使用其他制作工具.

推荐答案

最简单的方法确实是修复文件名.

The easiest thing is indeed to fix the file names.

但是,如果失败,请编写命令以在文件名两边加上双引号.最简单,最安全的方法是将所有文件名放入宏.诀窍在于,您必须转义双引号,否则Make会自己吃光双引号.

Failing that, though, write your commands to put double quotes around the file names. The easiest and safest thing is to put all the file names into macros; the trick there is that you have to escape the double quotes, which Make is otherwise going to want to eat up itself.

所以: FN ="\" C:\ My Documents \ myfiles.c \" FN2 ="C:\ My Documents \ myfile2.c"

So: FN="\"C:\My Documents\myfiles.c\"" FN2="C:\My Documents\myfile2.c"

或使用 $(CC)$(CFLAGS)"$(FN2)"

or use $(CC) $(CFLAGS) "$(FN2)"

这里的技巧是用echo回显您的命令行

The trick here is to echo your command line with echo

echo $(CC) $(CFLAGS) "$(FN2)"

或使用make -d获取make尝试执行的操作的所有详细信息.

or use make -d to get all the details of what make is trying to do.

您可能需要对此稍加修改,特别是您可能需要将转义符加倍

You may need to hack about with this a bit, in particular, you may need to double up the escapes

这篇关于将GNUMake与包含空格的文件名一起使用的最可靠方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆