3

I am using gnu make and in a Makefile I have, I see below rule. I want to add a similar rule with a recipe, but when I add a rule and its receipe on the next line by giving a tab or space for the recipe, I get make error.

dummy :
    @echo $(OBJS)

When i turned on the vim command :set list , i see:

dummy :$
^I@echo $(OBJS)$

What exactly are the characters before the recipe line(second line) which indent it from the start of line?

How do I enter them using keyboard (without having to copy paste the exisitng rule and then modifying it?

Where would I find information for various spaces/indents to be used in creating a Makefile from beginning, by hand(Not a automake/or other tool created makefile)?

3 Answers 3

9

Recipies in a makefile must be preceeded by a single standard tab character, nothing else.

^I is the representation of the tab character (see the table on the Wikipedia ASCII page), and therefore this should be correct.

So you should be able to enter it using Tab or Ctrl+I.
(assuming these are not remapped by the software)


Edit

On further investigation it looks like you can change the character required to preceed all recipe lines from a tab by setting the .RECIPEPREFIX special variable.

If this value has been defined in your makefile all recipes after the definition must use that character instead of a tab.

3
  • But when I do so with a TAB, for the recipe line, I keep getting a error when I do make , which says "Makefile:50: *** missing separator. Stop." at that line. Only when I copy some existing rule and use it, it goes through.
    – goldenmean
    Dec 21, 2010 at 12:07
  • @goldenmean Looking at the documentation and searching for "missing seperator" gives This means that make could not understand much of anything about the makefile line it just read. GNU make looks for various separators (:, =, recipe prefix characters, etc.) to indicate what kind of line it's parsing. This message means it couldn't find a valid one. - maybe you need to remove the space between the job name and the colon?
    – DMA57361
    Dec 21, 2010 at 12:11
  • @goldenmean - looking at the docs further it is apparently possibly to change the recipe prefix character from a tab by setting the .RECIPEPREFIX special variable - has these been defined in your makefile?
    – DMA57361
    Dec 21, 2010 at 12:21
2

After picking some pointers from answer given by DMA57361 above, and some more fiddling, i noticed that long time back in my .vimrc I had this command set expandtab (It expands tabs into spaces) and I use vim.

This was spoiling the Tab character which I was entering in my Makefile rules. Commenting that line in .vimrc helped and its working for me.

2

In light of the accepted answer: recipes must be preceded by a tab character, which is automatically replaced if set expandtab is enabled in your .vimrc. Overwriting your .RECIPEPREFIX is not recommended, as this breaks makefiles in codebases you downloaded. The naive approach is to simply remove set expandtab from your configuration, but you can get around this by adding the line

autocmd FileType make set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab.

This disables expandtab only when you're editing a makefile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.