gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Tabs on Makefile: what for?

#103311 - Izhido - Wed Sep 20, 2006 10:06 pm

Hi!

I wanted to tell you about something odd that happened to me when developing vc2mkfil. At the very beginning, I built an application that created an exact copy of the /examples/nds/templates/arm9/Makefile present on devkitPro; character by character, line by line. No modifications of any kind, just a copy of an existing, functional makefile. I ran the tool, and invoked "make" with that file. Just imagine my surprise when "make" printed the following:

Code:

Makefile:102: ***** missing separator. Stop.


WTF??? I went and checked, line by line, the original makefile against the generated one... no visible differences... it should work!!! Then, after a while, it hit me: The files were not really the same, since I replaced all TABs with 3-spaces (three ' '(20H) blank spaces). The line being mentioned reads like this:

Code:

$(BUILD):
    @[ -d $@ ] || mkdir -p $@             <----- Line 102


The thing here is, if I replace the tabs preceding each line where each target's commands are specified, with blank spaces, then "make" refuses to accept the file, arguing there's a "missing separator". (???) Shouldn't a blank space be considered a valid separator? Or am I missing something here?

I must admit I'm not an expert on "make" builds, but... isn't that behavior odd? What do you think about it? Is there a reasonable explanation for this? I'd like very much to know... :)

#103314 - Sausage Boy - Wed Sep 20, 2006 10:28 pm

Makefiles have been working like that since like, more than a hundred years ago. Deal with it.
_________________
"no offense, but this is the gayest game ever"

#103315 - Cearn - Wed Sep 20, 2006 10:29 pm

As annoying as it is, this is the standard behaviour for makefiles. See this here manual page. As for why it has to be a tab, I'd like to know that one myself. Also nice is how escaped linebreaks cannot have whitespace after the backslash. A line ending in "\" is fine, one ending in "\ " isn't.

#103317 - Izhido - Wed Sep 20, 2006 10:47 pm

Hehe. Figures.

BTW, thanks for the link, Cearn. Very helpful. And, Sausage Boy, OK, I promise I'll live with it :).

#103601 - cloak - Fri Sep 22, 2006 11:39 pm

Cearn wrote:
Also nice is how escaped linebreaks cannot have whitespace after the backslash. A line ending in "\" is fine, one ending in "\ " isn't.


Makes sense when you think about it from a programming perspective. You are esentially escaping the \n of the file (think \\n) which ignores the newline. Once there is whitespace after you get something like \ \n. How can you distinguish if this should be an end of line or continuation?

-Cloak

#103606 - Izhido - Fri Sep 22, 2006 11:53 pm

Um... while (from a programming point of view) this is correct, the thing is, makefiles are usually created by people, not machines, and for us, it's too easy to put spaces, tabs, comments, or whatever, into these files, just to "pretify" them, or making them more understandable for another people. After all, C/C++ let us do this... so, why makefiles (the things one uses to compile C/C++ programs) shouldn't? Just my 2 cents ....

#103813 - tepples - Sun Sep 24, 2006 7:40 pm

Izhido wrote:
makefiles are usually created by people, not machines, and for us, it's too easy to put spaces, tabs, comments, or whatever, into these files, just to "pretify" them, or making them more understandable for another people. After all, C/C++ let us do this... so, why makefiles (the things one uses to compile C/C++ programs) shouldn't?

Python, classic Fortran, and older assembly languages are whitespace sensitive.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#103937 - Izhido - Mon Sep 25, 2006 3:26 pm

... and let's not forget BASIC and all it's Visual- children :)

#103958 - tepples - Mon Sep 25, 2006 6:00 pm

BASIC has never been whitespace sensitive. Every Do is terminated by a Loop, every For has a Next, every If has an End If, much like in Pascal.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#103966 - Izhido - Mon Sep 25, 2006 6:46 pm

... yet, Visual Basic 6.0/.NET 2002/.NET 2003/2005 requires that, when you wish to continue a line, you write " _" (a blank space followed by an underscore followed ONLY by Enter, no whitespace/comment), or else it wont compile.

#103970 - sajiimori - Mon Sep 25, 2006 7:23 pm

Yeah, newlines are included in the traditional definition of "whitespace."

Agreed that the 'make' pseudo-language sucks horribly. It's what you get when you don't plan ahead, and you consistently make the wrong decisions at every step in development.

#154482 - gauauu - Wed Apr 16, 2008 9:49 pm

To bring back from the dead:

Cearn wrote:
As for why it has to be a tab, I'd like to know that one myself.


I just read ESR's The Art of Unix Programming which has a quote from the creator of make:

Quote:

Why the tab in column 1? Yacc was new, Lex was brand new. I hadn't tried either, so I figured this would be a good excuse to learn. After getting myself snarled up with my first stab at Lex, I just did something simple with the pattern newline-tab. It worked, it stayed. And then a few weeks later I had a user population of about a dozen, most of them friends, and I didn't want to screw up my embedded base. The rest, sadly, is history.

-- Stuart Feldman

#154485 - Dominik - Wed Apr 16, 2008 10:58 pm

gauauu wrote:
I just read ESR's The Art of Unix Programming which has a quote from the creator of make:

Quote:

Why the tab in column 1? Yacc was new, Lex was brand new. I hadn't tried either, so I figured this would be a good excuse to learn. After getting myself snarled up with my first stab at Lex, I just did something simple with the pattern newline-tab. It worked, it stayed. And then a few weeks later I had a user population of about a dozen, most of them friends, and I didn't want to screw up my embedded base. The rest, sadly, is history.

-- Stuart Feldman


*lol* Thanks for the quote. Made it worthwhile for me that I clicked on this thread in the first place. :)