0

I have a makefile already written and all the libraries as I need, can anybody redact it correctly with the right tabulations and structure:

# Macros
CC = gcc
COMP_FLAG = -std=c99 -Wall -pedantic-errors -Werror -DNDEBUG
LIB_FLAG = -L. -lmtm
# Main target
tests: memcache_test my_set_test cache_test user_test

# Targets make <file>
user_test: user_test.o user.o
$(CC) user_test.o user.o $(LIB_FLAG) -o $@

memcache_test: memcache_test.o memcache.o user.o cache.o
$(CC) memcache_test.o memcache.o user.o cache.o $(LIB_FLAG) -o $@ 

cache_test: cache_test.o cache.o
$(CC) cache_test.o cache.o $(LIB_FLAG) -o $@

my_set_test: my_set_test.o my_set.o
$(CC) my_set_test.o my_set.o -o $@


# Targets make <file>_test.o
user_test.o: tests/user_test.c user.h tests/test_utilities.h map.h set.h 
$(CC) -c $(COMP_FLAG) $(LIB_FLAG) tests/$*.c 

memcache_test.o: tests/memcache_test.c tests/test_utilities.h memcache.h map.h cache.h set.h list.h
$(CC) -c $(COMP_FLAG) $(LIB_FLAG) tests/$*.c

cache_test.o: tests/cache_test.c cache.h tests/test_utilities.h set.h 
$(CC) -c $(COMP_FLAG) $(LIB_FLAG) tests/$*.c

my_set_test.o: my_set/my_set_test.c tests/test_utilities.h my_set/my_set.h
$(CC) -c $(COMP_FLAG) $(LIB_FLAG) my_set/$*.c

# Targets make <file>.o
memcache.o: memcache.c memcache.h map.h cache.h list.h set.h user.h
$(CC) -c $(COMP_FLAG) $(LIB_FLAG) $*.c

user.o: user.c user.h set.h map.h
$(CC) -c $(COMP_FLAG) $(LIB_FLAG) $*.c

cache.o: cache.c cache.h set.h
$(CC) -c $(COMP_FLAG) $(LIB_FLAG) $*.c

my_set.o: my_set/my_set.c my_set/my_set.h 
$(CC) -c $(COMP_FLAG) my_set/$*.c

# Target runs all test files
run: run_my_set_test run_cache_test run_memcache_test run_user_test

run_clean: clean run

run_my_set_test: my_set_test
./my_set_test

run_cache_test: cache_test
./cache_test

run_memcache_test: memcache_test
./memcache_test

run_user_test: user_test
./user_test

# Target remove all <*_test> and <*.o> files
clean: clean_o clean_test

clean_test:
rm -f *_test
clean_o:
rm -f *.o

When I try to run it, it says:

***** missing separator. Stop.

I don't know how and where to put the separators.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ilya.K.
  • 291
  • 1
  • 13
  • 1
    `make` will want tab characters for the *action* part (or whatever it's called). – trojanfoe Dec 27 '15 at 19:10
  • What does this means? As I understand I need to tabulate it correctfully, but I dont know how to do it. That's why I'm asking for somebody to write it correctfully. Am I wrong? – Ilya.K. Dec 27 '15 at 19:11
  • 2
    Well I think it's better if you understand what the format should be rather than coming here for someone to do your work for you. There should be many articles about Makefiles out there on the net. – trojanfoe Dec 27 '15 at 19:47
  • 1
    Possible duplicate of [Make error: missing separator](http://stackoverflow.com/questions/920413/make-error-missing-separator) – Etan Reisner Dec 27 '15 at 22:50

1 Answers1

0

Each rule in the makefile is a line with a colon (':'), followed by optional lines that are commands. Each command must begin with a tab:

user_test: user_test.o user.o
    $(CC) user_test.o user.o $(LIB_FLAG) -o $@

Is that sufficient explanation?

Beta
  • 96,650
  • 16
  • 149
  • 150