LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 05-19-2002, 02:10 AM   #1
ChimpFace9000
Member
 
Registered: Jul 2001
Location: So. Cal.
Distribution: Slackware 8.1
Posts: 55

Rep: Reputation: 15
Post 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.
 
Old 05-19-2002, 03:43 PM   #2
kervin
Member
 
Registered: Jan 2002
Location: Melbourne, FL.
Distribution: redhat
Posts: 168

Rep: Reputation: 30
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.
 
Old 05-19-2002, 06:25 PM   #3
ChimpFace9000
Member
 
Registered: Jul 2001
Location: So. Cal.
Distribution: Slackware 8.1
Posts: 55

Original Poster
Rep: Reputation: 15
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.
 
Old 05-19-2002, 06:47 PM   #4
kervin
Member
 
Registered: Jan 2002
Location: Melbourne, FL.
Distribution: redhat
Posts: 168

Rep: Reputation: 30
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
 
Old 05-19-2002, 08:49 PM   #5
ChimpFace9000
Member
 
Registered: Jul 2001
Location: So. Cal.
Distribution: Slackware 8.1
Posts: 55

Original Poster
Rep: Reputation: 15
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
installing bison and flex rameshsena Linux - Software 10 06-21-2010 12:33 PM
bison / flex zaman Programming 1 08-16-2005 11:19 AM
Problem with binutils first pass / bison & flex installation peristaltic Linux From Scratch 3 03-20-2005 11:17 AM
Flex make problem MattZ3 Mandriva 1 02-25-2005 12:34 AM
[flex & bison] Why does my rule fail from line 2? chuanyung Programming 0 07-30-2004 05:21 AM


All times are GMT -5. The time now is 04:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration