LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   bison, flex and make problem (http://www.linuxquestions.org/questions/programming-9/bison-flex-and-make-problem-21295/)

ChimpFace9000 05-19-2002 01:10 AM

bison, flex and make problem
 
Im trying to get bison and flex to compile using my makefile, but i just cant get it to work. This is the makefile i use...

Code:

APP                := title
SRC_C                := main.c
OBJS                := $(SRC_C:.c=.o)
DEPS                := $(SRC_C:.c=.d)

CC                := gcc
CFLAGS                := -pipe
CPPFLAGS        := -Wall
TARGET_ARCH        :=
RM                := rm -f
ifdef RELEASE
        CFLAGS                += -s -O3
        TARGET_ARCH        += -march=i686
else
        CFLAGS                += -g
endif

LD                := $(CC)
LDFLAGS                := $(CFLAGS)
LDLIBS                :=

%.d        : %.c
        $(CC) $(CFLAGS) $(CPPFLAGS) -MM -o $@ $<

$(APP)        : $(OBJS)
        $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
-include $(DEPS)

clean:
        $(RM) $(APP)
        $(RM) $(OBJS)
        $(RM) $(DEPS)

If you know of anyway to incorporate bison and flex into this kind of makefile, please let me know.

kervin 05-19-2002 02:43 PM

what make is this? gnu? This does not look like a gnu make file to me.

is this windows? linux?

what do you mind compile? are you compiling bison/flex? or compiling a program that uses a flex generated lexer and a bison parser?

You're going to have to explain what you are doing.

ChimpFace9000 05-19-2002 05:25 PM

Oh sorry. Its a gnu make file for linux and im trying to compile a bison and flex grammer file. I just cant figure out how to fit it into the makefile, and get it to work right. My biggest problem is getting it to compile the bison file before the flex file so that it can use the .h file produced by bison.

kervin 05-19-2002 05:47 PM

Below is a simple makefile to compile a program called 'programmenu'. programmenu was a small floating gtk gui menu that used a XML grammer parser that was made with flex and bison.

The first target, 'all' is always the default target. That is the target that is built if none is specified.

note that I have a target called lex.yy.c. This is the lexer source that flex produces. There is also a target called lex.yy.o. Look at it's dependencies 'lex.yy.c' and 'y.tab.h'. 'y.tab.h' is generated by bison by default, and is needed for compiling the lexer source generated by flex.

I think you read the bison, flex manpages if you haven't already and look closely at the dependency tree in the makefile below.

CC = gcc
LDFLAGS = `gtk-config --libs`

INCLUDE =
CFLAGS = `gtk-config --cflags` -g -Wall

PROGRAM = programmenu

all: programmenu

programmenu: menu.o y.tab.o lex.yy.o tree.o
$(CC) $(LDFLAGS) menu.o y.tab.o lex.yy.o tree.o -o $(PROGRAM)

menu.o: y.tab.o
$(CC) $(CFLAGS) -c menu.c

y.tab.o: y.tab.c
$(CC) $(CFLAGS) -c y.tab.c

lex.yy.o: lex.yy.c y.tab.h
$(CC) $(CFLAGS) -Wno-unused -c lex.yy.c

tree.o: tree.c tree.h
$(CC) $(CFLAGS) -c tree.c

y.tab.c: menu.y
bison -ydv menu.y

y.tab.h: y.tab.c

lex.yy.c: menu.lex
flex -i menu.lex

run: $(PROGRAM)
./$(PROGRAM)

clean:
/bin/rm -f $(PROGRAM) *.o lex.yy.c y.tab.c y.tab.h y.output core

ChimpFace9000 05-19-2002 07:49 PM

My problem with the makefile in your post though is that you have to write out the dependencies yourself. In mine, for each file it will create a .d file with the dependencies in the file, then you just include the file, and it does all by itself. If i did it your way, it would be easy. But id like to fit it into mine.


All times are GMT -5. The time now is 01:12 PM.