I'd like to use automatic dependency generation with files generated from flex
and bison
.
Right now, I'm doing this:
CSRC=$(wildcard *.c)
OSRC=grammar.y scanner.l
OUTPUT_DIR="../bin"
SOLIDC_OBJS=solid_ast.o solid_strbuf.o solid_strlit.o solidc.o
SOLIDL_OBJS=solidl.o solid_ast.o solid_strbuf.o
CFLAGS += -MD -MP
CC=clang
BISON=bison
FLEX=flex
MKDIR=mkdir -p
all: solidc
solidc: setup $(SOLIDC_OBJS)
$(BISON) -vd grammar.y
$(FLEX) --header-file=scanner.yy.h -o scanner.yy.c scanner.l
$(CC) -o $(OUTPUT_DIR)/$@ $(SOLIDC_OBJS) scanner.yy.o grammar.tab.o
setup:
@$(MKDIR) $(OUTPUT_DIR)
run:
$(OUTPUT_DIR)/$(OUTPUT_NAME)
clean:
$(RM) $(wildcard $(OUTPUT_DIR)/*) $(wildcard *.o) $(wildcard *.d) \
$(wildcard scanner.yy.*) $(wildcard grammar.tab.*) \
$(wildcard grammar.output)
-include $(SRC:%.c=%.d) scanner.yy.d grammar.tab.d
But this doesn't work because scanner.yy.d
and grammar.tab.d
never get a chance to be generated.
What's the best way to work around this?
Please note that this question is actually not the same as GNU make: Generating automatic dependencies with generated header files, because I'm using the "less efficient"
-include
method rather thansef
, in addition to lots of other things.