简体   繁体   English

与野牛和Lex的Makefile

[英]Makefile with Bison and Lex

I am doing a simple Interpreter using bison and lex. 我正在使用bison和lex做一个简单的解释器。 This is my make file content. 这是我的make文件内容。

#
# 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 运行此make文件时,命令运行为

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. 我应该在make文件中进行哪些更改才能与c ++ 0x编译器版本一起运行。

Set CXXFLAGS flags accordingly: 相应地设置CXXFLAGS标志:

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

make uses internal defaults rule to compile c++ files to .o files. make使用内部默认规则将c ++文件编译为.o文件。 You can display them with make -p . 您可以使用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) $<

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM