你能制作没有制表符的有效 Makefile 吗? [英] Can you make valid Makefiles without tab characters?

查看:15
本文介绍了你能制作没有制表符的有效 Makefile 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

target: dependencies
    command1
    command2

在我的系统 (Mac OS X) 上,make 似乎要求 Makefile 在每个 command 行的内容之前有一个制表符,否则它会抛出一个语法错误.

On my system (Mac OS X), make seems to require that that Makefiles have a tab character preceding the the content of each command line, or it throws a syntax error.

在创建或编辑 Makefile 时这很烦人,因为我将编辑器设置为所有空间的所有时间.

This is an annoyance when creating or editing Makefiles because I have my editor set up to be all-spaces-all-the-time.

你能制作没有制表符的有效 Makefile 吗?

Can you make valid Makefiles without tab characters?

推荐答案

这是 make 的语法怪异/要求,与 Mac OS X 无关.不幸的是,您无能为力如果您打算使用 make,请执行此操作.

This is a syntax oddity/requirement of make, it has nothing to do with Mac OS X. Unfortunately, there's nothing you can do about it if you are going to use make.

编辑:GNU Make 现在支持自定义配方前缀.请参阅此答案.

Edit: GNU Make now supports a custom recipe prefix. See this answer.

你不是第一个不喜欢 make 的人.引用 Unix Haters 手册:

You are not the first one to dislike this aspect of make. To quote Unix Haters' Handbook:

Dennis 的 Makefile 的问题在于,他在添加注释行时,无意中在第 2 行开头的制表符之前插入了一个空格.制表符是 Makefile 语法中非常重要的一部分.所有命令行(在我们的示例中以 cc 开头的行)必须以制表符开头.在他进行更改后,第 2 行没有,因此出现错误.

The problem with Dennis’s Makefile is that when he added the comment line, he inadvertently inserted a space before the tab character at the beginning of line 2. The tab character is a very important part of the syntax of Makefiles. All command lines (the lines beginning with cc in our example) must start with tabs. After he made his change, line 2 didn’t, hence the error.

那又怎样?"你问:这有什么问题?"

"So what?" you ask, "What’s wrong with that?"

它本身并没有什么问题.只是当您考虑其他编程工具在 Unix 中如何工作时,使用制表符作为语法的一部分就像绿色贝雷帽中的那些 pungee 棒陷阱之一:来自堪萨斯州的可怜的孩子正走在约翰韦恩面前并且没有'看不到绊线.毕竟,堪萨斯州的玉米田没有绊线需要提防.哇!

There is nothing wrong with it, by itself. It’s just that when you consider how other programming tools work in Unix, using tabs as part of the syntax is like one of those pungee stick traps in The Green Berets: the poor kid from Kansas is walking point in front of John Wayne and doesn’t see the trip wire. After all, there are no trip wires to watch out for in Kansas corn fields. WHAM!

这篇关于你能制作没有制表符的有效 Makefile 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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