blackFish
blackFish

Reputation: 105

makefile makes weird error

So I wrote a program to calculate Caesar cipher but I think it's not really matter - what matter is that when I'm trying to do make the compiler or who checks the syntax of my makefile is throw an error says :

make: *** No rule to make target 'clean.', needed by 'PHONY'. Stop.

In my directory I have 5 files:

main.c
ceasar.c
ceasar.h
parser.c
parser.h

and the makefile looks like:

PHONY : all clean.
CFLAGS = -c -g -Wall
CXXFLAGS = -o
CC = gcc
OBJECTS = main.o ceasar.o parser.o
EXTRA_SRCS = ceasear.h parser.h

all : ex1

ex1 : $(objects)
    $(CC) $(CXXFLAGS) ex1 $(objects)
%.o : %.c $(wildcard $(EXTRA_SRCS))
    $(CC) $(CFLAGS) $<

clean:  
    rm *.o

The makefile should clean the objects files when typed make clean and the line $(wildcard $(EXTRA_SRCS)) should checks if the c file has header file(parser and caeser, not main). I'm using ubuntu 15.10 and please help me :)

Upvotes: 0

Views: 205

Answers (1)

edwfr
edwfr

Reputation: 11

It's possible to specify fictitious target that has as purpose to execute a sequence of operations. These targets do not specify any dependency and must not appear as the first rule, to be carried out only if they are passed as arguments to make command explicitly. Fictitious target is not a file (the file does not exist) it is used to initiate the execution of the command in each case.

CFLAGS = -c -g -Wall
CXXFLAGS = -o
CC = gcc
OBJECTS = main.o ceasar.o parser.o
EXTRA_SRCS = ceasear.h parser.h

all : ex1

ex1 : $(objects)
$(CC) $(CXXFLAGS) ex1 $(objects)
%.o : %.c $(wildcard $(EXTRA_SRCS))
$(CC) $(CFLAGS) $<

.PHONY: clean

clean: rm *.o

Be careful because the fictitious target may be masked by existing files: if accidentally in the directory it creates a file called the same name of the fictitious target then, as the target has no dependencies, and the file already exists, that file does not need to be updated and then the command list will never be executed.

Upvotes: 1

Related Questions