823

This is my makefile:

all:ll

ll:ll.c   
  gcc  -c  -Wall -Werror -02 c.c ll.c  -o  ll  $@  $<

clean :
  \rm -fr ll

When I try to make clean or make make, I get this error:

:makefile:4: *** missing separator.  Stop.

How can I fix it?

Greg
  • 9,068
  • 6
  • 49
  • 91
Rahul Reddy
  • 12,613
  • 10
  • 22
  • 21
  • 9
    You can use .RECIPEPREFIX to change the character make uses. See: https://www.gnu.org/software/make/manual/html_node/Special-Variables.html#Special-Variables – aseq Dec 01 '16 at 09:30
  • 5
    How was this not closed as a duplicate??? Possible duplicate of [Make error: missing separator](https://stackoverflow.com/questions/920413/make-error-missing-separator) – jww Aug 24 '17 at 16:32
  • 1
    In the mcedit "Options -> General" make shure that "Fake half tabs" do not have "X" in square brackets before that option. – Jovan Ružić Mar 21 '19 at 03:53
  • In vim, use: ```Ctrl+V + Tab``` – matthewpark319 Dec 03 '21 at 04:21

19 Answers19

1592

make defines a tab is required to start each recipe. All actions of every rule are identified by tabs. If you prefer to prefix your recipes with a character other than tab, you can set the .RECIPEPREFIX variable to an alternate character.

To check, I use the command cat -e -t -v makefile_name.

It shows the presence of tabs with ^I and line endings with $. Both are vital to ensure that dependencies end properly and tabs mark the action for the rules so that they are easily identifiable to the make utility.

Example:

Kaizen ~/so_test $ cat -e -t -v  mk.t
all:ll$      ## here the $ is end of line ...                   
$
ll:ll.c   $
^Igcc  -c  -Wall -Werror -02 c.c ll.c  -o  ll  $@  $<$ 
## the ^I above means a tab was there before the action part, so this line is ok .
 $
clean :$
   \rm -fr ll$
## see here there is no ^I which means , tab is not present .... 
## in this case you need to open the file again and edit/ensure a tab 
## starts the action part
Efren
  • 4,003
  • 4
  • 33
  • 75
Nitin4873
  • 16,804
  • 1
  • 13
  • 15
  • 44
    "cat -e -t -v makefile_name" is the best thing. Ever. I kept staring at the screen, seeing what looked like a tab, totally missing that it is the ONE LINE in the entire file which used spaces instead of a hard tab. – arinmorf Feb 01 '15 at 15:44
  • When copy/pasting from one makefile to another using the vi (or vim) editor be sure not to accidentally grab the ~ (tilde) line indicating end of file. A real ~ looks like a vi marker and will cause the "*** missing separator. Stop." error. This may seem obvious but when it happens accidentally it's far from evident. See [my blog commentary](http://skycoast.us/pscott/archives/000071.html) for more information. – Scott Feb 26 '16 at 01:11
  • 4
    `-v` option for `cat` command is redundant here because `-e` means `-vE` and `-t` means `-vT`. – xxks-kkk Apr 25 '16 at 10:38
  • 1
    It's no more "stupid" than Python needing whitespace for control flow, or C needing identifiers made up of certain characters, or English needing vowels. It's just a rule. – paxdiablo Feb 01 '18 at 01:47
  • Perhaps it has changed at some point, but using 4 spaces works just as well. – Juha Untinen Mar 03 '19 at 17:43
  • 2
    @JuhaUntinen no, it has never changed and no, it does not work just as well. – MadScientist Apr 19 '19 at 22:52
  • be aware that Make is also temperamental when it comes to syntax and whitespace. I managed to fix this error by putting a space between `ifeq` and the `(` in my Makefile. plenty of ways to stump a beginner – Crazy Redd Jan 19 '20 at 20:25
  • `cat -e -t -v Makefile` can be substituted with `cat -A Makefile` which is equivalent to `cat -vET Makefile` – abmblob Feb 16 '20 at 07:36
  • Be aware that as of GNU make 3.82 (released in 2010), you can use `.RECIPEPREFIX` to redefine the recipe introduction character to use something different than TAB. See https://www.gnu.org/software/make/manual/html_node/Special-Variables.html#index-_002eRECIPEPREFIX-_0028change-the-recipe-prefix-character_0029 – MadScientist May 11 '20 at 13:48
  • If you are using vim, and are using expandtab to insert spaces when you hit tab key, then in insert mode use Ctrl+v followed by Tab to enter actual tab character. – Peaceful Aug 08 '21 at 17:33
  • Just to be clear, you don't have to eyeball the entire file to find "the one line" that uses spaces instead of a TAB. Make tells you _exactly_ which line is the problem. An error like `Makefile:4: *** missing separator` means the problem is on line 4 of the file `Makefile`. – MadScientist Jan 05 '22 at 18:30
118

On VS Code, just click the "Space: 4" on the downright corner and change it to tab when editing your Makefile.

Alan
  • 1,582
  • 1
  • 13
  • 11
  • VS Code recognised that my 'common.mk' file, extracted from a no-suffix 'Makefile' was a make file, and highlighted it correctly - but quietly started indenting with spaces instead of tabs. – Francis Norton Jan 08 '18 at 18:28
  • 5
    This worked when I selected "Convert Indentation to Tabs" – abk Nov 22 '21 at 02:42
  • 2
    It worked with "Convert Indentation to Tabs" – Varun Mar 09 '23 at 17:48
60

By default, you should always write command after a Tab and not white space. This can be changed to another character with .RECIPEPREFIX variable.

This applies to gcc line (line #4) in your case. You need to insert tab before gcc.

Also replace \rm -fr ll with rm -fr ll. Insert tabs before this command too.

Efren
  • 4,003
  • 4
  • 33
  • 75
Denny Mathew
  • 1,072
  • 9
  • 13
  • 4
    To be very clear, there must be a hard TAB character as the first character in each logical recipe line. After the TAB, you can add any kind of whitespace you want. – MadScientist Jun 05 '13 at 12:47
  • should the tabspace be equal to 2 or 4? in /.vimrc set tabstop = 2 or 4? – Rahul Reddy Jun 05 '13 at 17:52
  • 4
    @RahulReddy how an editor displays a tab has nothing to do with whether there is or is not a tab character in the configuration. – xaxxon May 14 '18 at 11:14
21

TLDR;

makefile syntax can be quirky
if you want a line of code to be interpreted as make code it must only be indented with spaces.
if you want a line of code to be interpreted as bash code it must only be indented with tabs

sometask:
  ifeq ($FOO,bar)  // this is make code. only spaces
    echo "foobar"  // this is bash code. only tabs
  endif            // again, this is make code. only spaces

technically its the leading indentation that dictates the interpreter.

WeezyKrush
  • 464
  • 5
  • 11
20

The solution for PyCharm would be to install a Makefile support plugin:

  1. Open Preferences (cmd + ,)
  2. Go to Plugins -> Marketplace
  3. Search for Makefile support, install and restart the IDE.

This should fix the problem and provide a syntax for a makefile.

Tomasz Bartkowiak
  • 12,154
  • 4
  • 57
  • 62
  • This also helps in GoLand – Vizjerei Jan 30 '20 at 08:38
  • I find IDE real matters. Tab edition is not supported in pycharm. When I change to ATOM, TAB input works. – Moonlight Knight Feb 12 '20 at 10:33
  • 1
    If your IDE is automatically indenting with spaces, you might be able to enter a unicode tab with \u09 which on some desktop environments for Linux can be done with Ctrl+Shift+U then typing '09'. " ". It isn't very fun though. – szmoore Oct 04 '21 at 09:51
16

Using .editorconfig to fix the tabs automagically:

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab
Daniel W.
  • 31,164
  • 13
  • 93
  • 151
11

When you created a Makefile in VSCode, You should set the Tab Size: 4enter image description here.

hesam rajaei
  • 320
  • 3
  • 8
9

Its pretty old question but still I would like say about one more option using vi/vim editor to visualize the tabs. If you have vi/vim installed then open a Makefile (e.g. vim Makefile) and enter :set list. This will show number of tabs inserted as below,

 %-linux: force$
^I@if [ "$(GCC_VERSION)" = "2.96" ] ; then \$
^I^Iecho ===== Generating build tree for legacy $@ architecture =====; \$
^I^I$(CONFIGURE) $(CWD) $@ legacy; \$
^Ielse \$
^I^Iecho ===== Generating build tree for $@ architecture =====; \$
^I^I$(CONFIGURE) $(CWD) $@; \$
^Ifi$
^Icd build-$@;make$
Panch
  • 1,097
  • 3
  • 12
  • 43
8

You started line 4 with "space,space" instead of "tab" - nothing else.

Petr Kosvanec
  • 115
  • 1
  • 7
4

The key point was "HARD TAB"

  1. Check whether you used TAB instead of whitespace
  2. Check your .vimrc for set tabstop=X
Daniel W.
  • 31,164
  • 13
  • 93
  • 151
wlsherica
  • 557
  • 1
  • 5
  • 10
4

If anyone of you are using a product from Intellij, the solution for this it's the following:

  1. Go to Preferences > Editor > Code Style
  2. here you need to select the file type related to your problem. But most probably you need to select Other File Types.
  3. In the tab opened mark the checkbox for Use tab character and be careful, Tab size and Indent values must be 4.
3

Try with the following command.

perl -pi -e 's/^ */\t/' Makefile

Arshid KV
  • 9,631
  • 3
  • 35
  • 36
2

If you are using mcedit for makefile edit. you have to see the following mark. enter image description here

X zheng
  • 1,731
  • 1
  • 17
  • 25
2

If you are here searching how to make the tabs and new lines you added understandable by vim you have to first enable tab in vim.

You can do it using :set noet i.e. (to switch from spaces to TAB) before you make your tab additions.

With this command your tabs will look like the other ones (i.e. ^I) and *** missing separator. Stop. error from make will go away :)

after you make changes you can switch back with :set et

Yonas Kassa
  • 3,362
  • 1
  • 18
  • 27
2

Do yourself a favour and make this a permanent member of your .editorconfig, if your editor/IDE supports it (it probably does!)

[Makefile]
indent_style = tab
Jan Klan
  • 667
  • 6
  • 16
1

This is because tab is replaced by spaces. To disable this feature go to

gedit->edit->preferences->editor

and remove check for

"replace tab with space"

Mansuro
  • 4,558
  • 4
  • 36
  • 76
Shrinivas Patgar
  • 91
  • 1
  • 3
  • 8
0

If you are editing your Makefile in eclipse:

Windows-> Preferences->General->Editor->Text Editors->Show Whitespace Characters -> Apply

Or use the shortcut shown below.

Tab will be represented by gray ">>" and Space will be represented by gray "." as in figure below.

enter image description here

Rose
  • 2,792
  • 4
  • 28
  • 42
0

If someone ever comes across this issue with

*** missing separator.  Stop.

during the build, they should double-check their file system path to the sources, it should not contain special characters like "#"

e.g. path

/home/user/#my_sources/

might be invalid

  • Could you please give more details? – Fahima Mokhtari Jun 03 '22 at 09:44
  • The issue generally happens when you use spaces in place of Tab. In most editors there will be a setting to change the Tab to spaces conversion. That need's to be disabled or one can use notepad++ or sublime text to replace all spaces before rules with tabs. – Amandeep Singh Jul 19 '22 at 15:01
  • I'm not sure what you guys mean and what details you want. My answer is related to the path to the sources, in my case, the problem was that the file system path contained the special character "#" and the problem was not related to the content of the sources itself and there was no mention of that potential problem in other answers. The problem with spaces is already elaborated on in other answers. –  Lonedone Jul 21 '22 at 08:08
0

For me 2023 only this worked. enter image description here

After this everything worked fine.

Michael Nelles
  • 5,426
  • 8
  • 41
  • 57