Make complains “missing separator (did you mean TAB?)”

compilingmake

While trying to install the som_pak-3.1-NAcMoS.tar.gz file, I've used the below commands:

$ tar xvf som_pak-3.1-NAcMoS.tar.gz
$ cd som_pak-3.1
$ cp makefile.unix makefile
$ make
$ cd ..
$ ln -s som_pak-3.1 $NACMOS_HOME/som_pak

But while executing the make command I'm getting the following error:

* missing separator (did you mean TAB instead of 8 spaces?). Stop.

  • Can anybody tell me the reason for the error?
  • Is there any packages need to include with this?

Best Answer

The error you're encountering:

*** missing separator (did you mean TAB instead of 8 spaces?). Stop.

Means that the makefile contains spaces instead of Tab's. The make utility is notoriously picky about the use of Space instead of Tab. So it's likely that the makefile contains Space at the beginning of rule stanzas within the file.

Example

Let's say I have the following 3 .c files:

hello.c
char *
hello() 
{
  return "Hello";
}
world.c
char *
world() 
{
  return "world";
}
main.c:
#include <stdio.h>

/* Prototypes. */
char *hello();
char *world();

int
main(int argc, char *argv[]) 
{
    printf("%s, %s!\n", hello(), world());
    return 0;
}    

Say I have the following Makefile:

# The executable 'helloworld' depends on all 3 object files
helloworld: main.o hello.o world.o
        cc -o helloworld main.o hello.o world.o # Line starts with TAB!

# Build main.o (only requires main.c to exist)
main.o: main.c
        cc -c main.c # Line starts with TAB!

# Build hello.o (only requires hello.c to exist)
hello.o: hello.c
        cc -c hello.c # Line starts with TAB!

# Build world.o (only requires world.c to exist)
world.o: world.c
        cc -c world.c # Line starts with TAB!

#  Remove object files, executables (UNIX/Windows), Emacs backup files, 
#+ and core files
clean:
        rm -rf  *.o helloworld *~ *.core core # Line starts with TAB!

Now we try to build a target

When I run it against the target helloworld:

$ make helloworld
makefile:3: *** missing separator (did you mean TAB instead of 8 spaces?).  Stop.

Look familiar?

Fixing the issue

You can fix this by changing the Spaces to actual Tab characters. I used vim to repair my file. Simply open it:

$ vim makefile

And then run this command within:

:%s/^[ ]\+/^I/

NOTE: ^I is a special character. Typing ^ followed by I will be interpreted differently compared to Ctrl+V-Ctrl+I.

This will substitute all the lines that begin with 1 or more Spaces with an actual Tab.

Now when I rerun my helloworld target:

$ make helloworld
cc -c main.c # Line starts with TAB!
cc -c hello.c # Line starts with TAB!
cc -c world.c # Line starts with TAB!
cc -o helloworld main.o hello.o world.o # Line starts with TAB!

References

Related Question