打电话给野牛-y而不被要求 [英] make calling bison -y without being asked to

查看:106
本文介绍了打电话给野牛-y而不被要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个叫做portugol的语法.文件名是基本的,但是我选择调用我的c程序portugol.c.

I have a grammar I'm writing, called portugol. The files names are basic, but I chose to call my c program portugol.c.

所以,基本上,我必须做:

So, basically, I have to do:

flex portugol.l      ==> lex.yy.c
bison -dy portugol.y ==> y.tab.c and y.tab.h
gcc y.tab.c lex.yy.c portugol.c -o portugol.bin -lm -ly  ==> portugol.bin

(我也有portugol.h,但这与问题无关)

(I also have portugol.h, but it is irrelevant to the problem)

很长一段时间以来,我一直在使用称为flexyagcc.sh的shell脚本来执行此操作.在此过程中没有错误.

For long time now, I'm using a shell script I called flexyagcc.sh that do this. No error in the process.

所以现在我决定学习makefile.

我面临的问题是,由于某种奇怪的原因,我调用的"bison -dy"后面跟着我没有写的命令:mv -f y.tab.c portugol.c

The problem I'm facing is that for some odd reason, "bison -dy" I called is followed by this command I didn't write: mv -f y.tab.c portugol.c

好吧,这破坏了我手工制作的源文件!

Well, this destroys my handmade source file!

我已经尽力了,但是无法摆脱这个"mv".

I've tried all I could, but could not get rid of this "mv".

我什至做了sleep并尝试过:

y.tab.c y.tab.h : portugol.y
    @echo --- bison -----------------------------------------------
    mv -f portugol.c ptg.c
    $(BISON) $(BFLAGS) portugol.y
    @echo --- bison sleeping --------------------------------------
    sleep 5
    -mv -f portugol.c y.tab.c
    -mv -f ptg.c portugol.c

但是令我惊讶的是,我得到了以下事件(按此顺序):

But for my surprise, I got the following events (in this order):

$ make all o=pequeno
--- bison -----------------------------------------------
mv -f portugol.c ptg.c
bison -dy portugol.y
--- bison sleeping --------------------------------------
sleep 5
mv -f portugol.c y.tab.c
mv: cannot stat `portugol.c': No such file or directory
make: [y.tab.c] Error 1 (ignored)
mv -f ptg.c portugol.c
bison -dy portugol.y 
mv -f y.tab.c portugol.c

惊奇! mv命令是最后一个!不管我做什么.我创建了其他规则,只是为了使它最后发生(或首先欺骗递归过程).决不!我还使用了指令:.NOTPARALLEL.没办法.

Surprise! The mv command is the last one! No matter what I do. I created other rules, just to make it happen last (or first to trick the recursive process). No way! I also used the directive: .NOTPARALLEL. No way.

我也在同一行中尝试了所有方法,以确保它们以给定的顺序执行:

I also tried all in the same line, to be sure they execute in the given order:

mv -f portugol.c ptg.c && $(BISON) $(BFLAGS) portugol.y && sleep 5 && mv -f portugol.c y.tab.c && mv -f ptg.c portugol.c

没有成功.

好吧,在我放弃之前,我决定使用标准的野牛输出.因此,我将拥有:

Well, before I gave up, I decided to use the standard bison output. So, I would have:

flex portugol.l         ==> lex.yy.c
bison -d portugol.y     ==> portugol.tab.c and y.tab.h
gcc portugol.tab.c lex.yy.c portugol.c -o portugol.bin -lm -ly  ==> portugol.bin

但是我仍然得到这个:

--- bison -----------------------------------------------
bison -d portugol.y
bison -y portugol.y 
mv -f y.tab.c portugol.c

我也试图在野牛之前chmod -w和之后的+w.

I also tried to chmod -w before and +w after bison, no way.

目前,我的想法不多了.

For now, I run out of ideas.

有什么方法可以防止叫第二只野牛吗?还是调用mv命令?还是欺骗它以不覆盖我的文件portugol.c?

Is there a way to prevent make to call the second bison? Or to call the mv command? Or to trick it to not overwrite my file portugol.c?

谢谢! 贝科

PS-已编辑.使用:

PS- Edited. Using:

 Ubuntu 10.04.2 LTS
 GNU Make 3.81

PPS.编辑.小错别字.

PPS. Edited. Minor typos.

PPPS.编辑.回答伊势紫藤:

PPPS. Edited. Answering Ise wisteria:

感谢您的回答.我已经将您的makefile保存为makefile2并尝试过.我从品牌得到的答案是:

Thanks for your answer. I've saved your makefile as makefile2 and tried. The answer I got from the make is:

$ make -f makefile2
bison -dy portugol.y
yacc  portugol.y 
mv -f y.tab.c portugol.c
gcc y.tab.c lex.yy.c portugol.c -o portugol.bin -lm -ly
gcc: y.tab.c: No such file or directory
make: *** [portugol.bin] Error 1

我还注意到,今天"第二次野牛呼叫不是野牛呼叫,而是yacc呼叫.也许我们在这里谈论一些环境变量?它也随着我的makefile改变:

I also noted that "today" the second bison call is not a bison call, but a yacc call. Maybe we are talking about some environment variable here? It also changes with my makefile:

$ make all o=pequeno
--- bison -----------------------------------------------
bison --defines=y.tab.h --output=y.tab.c portugol.y
--- flex ------------------------------------------------
flex  portugol.l
yacc  portugol.y 
mv -f y.tab.c portugol.c

PPPPS.回答Beta.您的建议有效.我叫make y.tab.c并得到一个简单的结果:

PPPPS. Answering Beta. Your advice works. I called make y.tab.c and got a simple:

$ make y.tab.c
--- bison -----------------------------------------------
bison --defines=y.tab.h --output=y.tab.c portugol.y
$

这是我完整的文件:

# Compila o compilador Portugol usando lex e yacc,
# e opcionalmente gera o .asm.c e o .bin
# a partir do fonte .ptg usando o novo compilador gerado.
#
#/*
#    arquivo: makefile
#    Autor: Ruben Carlo Benante
#    Email: ***@beco.cc
#    Data: 23/04/2009
#    Modificado: 22/03/2011
#    Versao: Portugol v3q
#*/
#
# Exemplo:
# ./flexyagcc portugol teste
#
# inicia os seguintes processos:
#      flex portugol.l                                          (gera lex.yy.c)
#      bison -dy portugol.y                                     (gera yy.tab.c e yy.tab.h)
#      gcc y.tab.c lex.yy.c portugol.c -o portugol.bin -lm -ly  (gera portugol.bin)
#
# inicia opcionalmente (ultimas linhas descomentadas):
#      portugol.bin teste.ptg teste.asm.c                (gera teste.asm.c)
#      gcc -x c teste.asm.c -o teste.bin -lm             (gera teste.bin)
#
#
# entrada:
#          portugol.l (arquivo em linguagem lex, analisador lexico)
#          portugol.y (arquivo em linguagem yacc, analisador sintatico)
#          portugol.c (arquivo em linguagem c, gerador de codigo)
# entrada opcional:
#          teste.ptg  (arquivo em linguagem portugol)
#
# saida:
#        lex.yy.c (saida do lex, em linguagem c)
#        y.tab.c  (saida do yacc, em linguagem c)
#        y.tab.h  (saida do yacc, definicoes da linguagem portugol)
#        portugol.bin (saida do gcc, arquivo executavel, finalmente o compilador portugol)
# saida opcional:
#        teste.asm.c   (saida do compilador portugol, arquivo em codigo de quadruplas)
#        teste.bin     (saida do gcc, arquivo executavel, o fonte .ptg em binario)
#
###################################### 
LEX     = flex
BISON = bison
BFLAGS  = --defines=y.tab.h --output=y.tab.c
CC = gcc
#CFLAGS = -g0 -O3 -Wall
CFLAGS = -g0
OBJS = y.tab.o lex.yy.o portugol.o
#OBJS = portugol.tab.o lex.yy.o portugol.o
DEPS =  portugol.h y.tab.h
SOURCES = y.tab.c lex.yy.c portugol.c
#SOURCES = portugol.tab.c lex.yy.c portugol.c

.PHONY : clean cleanall cleanptg run all makebug teste

.NOTPARALLEL :

#portugol.bin : lex.yy.c y.tab.c y.tab.h portugol.c portugol.h
portugol.bin : $(SOURCES) $(DEPS) $(OBJS)
    @echo --- gcc portugol ----------------------------------------
    $(CC) $(CFLAGS) $(OBJS) -o portugol.bin -lm -ly
#   gcc lex.yy.c y.tab.c portugol.c -o portugol.bin -lm -ly
#   $(CC) $(CFLAGS) $(SOURCES) -o portugol.bin -lm -ly

%.o : %.c
    @echo --- gcc objects -----------------------------------------
    $(CC) $(CFLAGS) -c $< -o $@

#portugol.tab.c y.tab.h : portugol.y
y.tab.c y.tab.h : portugol.y
    @echo --- bison -----------------------------------------------
    $(BISON) $(BFLAGS) portugol.y
#   @echo --- bison y.tab.c ---------------------------------------
#   mv -f portugol.c ptg.c
#   sleep 3
#   -mv -f portugol.c y.tab.c
#   -mv -f ptg.c portugol.c

lex.yy.c : portugol.l
    @echo --- flex ------------------------------------------------
    $(LEX) $(LFLAGS) portugol.l

teste :
    @echo --- testing ---------------------------------------------
    @echo $(o)

#Portugol -----------

%.asm.c : %.ptg portugol.bin
    @echo --- portugol --------------------------------------------
    ./portugol.bin $< $@

%.bin : %.asm.c
    @echo --- gcc asm ---------------------------------------------
    $(CC) -x c $< -o $@ -lm

run : $(o).bin
    @echo --- running! --------------------------------------------
    ./$(o).bin

all : $(o).bin

clean:
    -rm lex.yy.c y.tab.c y.tab.h *.o portugol.bin portugol.tab.c

cleanall:
    -rm lex.yy.c y.tab.c y.tab.h *.o *.bin

cleanasm:
    -rm *.asm.c

VPS.重要的编辑更新.请注意可能出现的实际问题:

VPS. Important edit update. Attention for a possible indication of the real problem:

我将名称portugol.y更改为portugol.syn,问题已停止!

I changed the name portugol.y to portugol.syn and the problem has stoped!

--- bison -----------------------------------------------
bison --defines=y.tab.h --output=y.tab.c portugol.syn
---------------------------------------------------------

那是怎么回事?在我看来,这表明make对文件".y"具有一些默认评估,现在我们需要回答这个问题,找出其根源以及如何禁用它.非常感谢.

How is that? This indicates, in my opinion, that make has some default evaluation for files ".y" and now we need, to answer this question, to find out the root of this, and how to disable it. Thanks very much.

推荐答案

问题是make具有用于从.y和.l文件构建.c文件的内置规则,而正是这些内置规则被触发并导致您的悲伤.

The problem is that make has built-in rules for building .c files from .y and .l files, and it is these builtin rules that are getting triggered and causing you grief.

使用GNU make,您可以通过用空白规则覆盖这些内置规则来禁用它们.放

With GNU make, you can disable these builtin rules by overriding them with blank rules. Put

%.c: %.y
%.c: %.l

在您的makefile中的某个位置,您的问题应该消失了.

in your makefile somewhere and your problems should go away.

您可以通过运行make -p -f /dev/null

这篇关于打电话给野牛-y而不被要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆