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

查看:63
本文介绍了您可以制作没有制表符的有效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仇恨者手册:

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中的工作方式时,使用制表符作为语法的一部分就像是《绿色贝雷帽》中的那些橡皮筋陷阱一样:来自堪萨斯州的可怜孩子正站在约翰·韦恩的面前,而看不到跳闸线.毕竟,在堪萨斯州的玉米田里,没有绊脚石需要提防.哇!

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天全站免登陆