Smith Dwayne
Smith Dwayne

Reputation: 2807

Makefile with Bison and Lex

I am doing a simple Interpreter using bison and lex. This is my make file content.

#
# makefile for ccalc
#
OBJS += mylang.o SM.o lex.o parse.o

# rules
%.c: %.y
    bison -o $(@:%.o=%.d) $<

%.c: %.l
    flex -o$(@:%.o=%.d) -i $<

# dependencies
mylang: mylang.yy.tab.c lex.c $(OBJS)
    @echo g++ -Os -std=c++0x -omylang $(OBJS)
    @g++ -Os -std=c++0x  -omylang $(OBJS)
    @echo ' '

# source
mylang.o: mylang.cpp

SM.o: SM.cpp SM.h

lex.o: lex.c

parse.o: mylang.yy.tab.c

mylang.yy.tab.c: mylang.yy

lex.c: mylang.ll

When run this make file, The command running as

g++    -c -o SM.o SM.cpp

But I want to run as,

g++ -Os -std=c++0x -c -o SM.o SM.cpp

What Should I change in my make file to run with c++0x Compiler Version.

Upvotes: 1

Views: 1263

Answers (1)

jofel
jofel

Reputation: 3405

Set CXXFLAGS flags accordingly:

CXXFLAGS="-Os -std=c++0"

make uses internal defaults rule to compile c++ files to .o files. You can display them with make -p.

The rules in your case are

COMPILE.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
COMPILE.cpp = $(COMPILE.cc)

%.o: %.cpp
    #  recipe to execute (built-in):
    $(COMPILE.cpp) $(OUTPUT_OPTION) $<

Upvotes: 3

Related Questions