-   Programming (
-   -   bison, flex and make problem (

ChimpFace9000 05-19-2002 02: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...


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
        CFLAGS                += -s -O3
        TARGET_ARCH        += -march=i686
        CFLAGS                += -g

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

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

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

        $(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 03: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 06: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 06: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 ''. '' 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`

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

PROGRAM = programmenu

all: programmenu

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

$(CC) $(CFLAGS) -c menu.c
$(CC) $(CFLAGS) -c

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

tree.o: tree.c tree.h
$(CC) $(CFLAGS) -c tree.c menu.y
bison -ydv menu.y

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

run: $(PROGRAM)

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

ChimpFace9000 05-19-2002 08: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 09:33 PM.