views:

228

answers:

3
target: dependencies
    command1
    command2

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.

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

Can you make valid Makefiles without tab characters?

+5  A: 

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.

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

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?”

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!

Alok
The issue with tabs is one of the first thing anyone using make learns - I've never found it to be a real problem.
anon
@Neil, Me neither: I never said I agreed with the UHH, I was just saying some people don't like it. :-)
Alok
+1  A: 

Not portably. Certain flavours of make absolutely require tab characters. Yet another reason for preferring tabs over spaces :-)

anon
+1  A: 

For anything but the most trivial/menial tasks, no.

Ignacio Vazquez-Abrams