Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile circular dependency

Here is my Makefile:

.PHONY: all homework1
CFLAGS= -g -O0 -Wall -Werror -Wno-unused-function
LDFLAGS= -lm

all : homework1

homework1 : program.tab.o program.lex.o
%.o : %.c
    gcc -o$@ -c $(CFLAGS) $<
%.lex.c : %.lex %.tab.h
    flex -o$@ $<
%.tab.c %.tab.h : %.y
    bison --verbose -o$@ -d $<

Whenever I try to compile, I get the warning make: Circular program.lex <- program.lex.o dependency dropped. I don't see how program.lex is dependent on program.lex.o at all in the makefile. I see how the dependency tree is about 4 layers deep, but it doesn't look circular.

How can I improve my makefile?

like image 260
Mike Avatar asked Sep 09 '10 05:09

Mike


1 Answers

The trouble is that there is an implicit rule in Make (well, in GNUMake anyway) for linking a single object file to build en executable. Your makefile says nothing about how to build program.lex, so Make falls back on the implicit rule to build it from program.lex.o.

Since your your layout seems to depend on having program.lex to begin with, you can suppress the implicit rule by adding your own rule for program.lex (which does nothing):

program.lex:;
like image 66
Beta Avatar answered Sep 19 '22 18:09

Beta