我的 makefile 只执行第一个先决条件?

huangapple go评论40阅读模式
英文:

My makefile only executes the first prerequisite?

问题

当我运行make时,它正确地执行第一个先决条件".m4a"文件,但然后停止不继续。我已经检查过,$(OBJ) 似乎包含了所有的文件,所以我不明白为什么它停止?

.SUFFIXES : .txt .m4a
SOURCES := $(wildcard  *.m4a)
OBJ := $(subst m4a,txt,$(SOURCES))
WS = whisper
WG = wordgrinder

FLAGS = --device cuda:1 --model small
.PHONY: test clean imported

all : $(OBJ)

$(OBJ): $(SOURCES)
        @echo $(WS) $(FLAGS) ./$<
        @echo $(WG) --convert $(subst m4a,txt, $< ) $(subst m4a,wg, $< )

clean :
        rm *~ *.json  *.srt  *.tsv  *.vtt

imported:
        mv odt/*.odt odt/imported/

test: $(SOURCES)
        @echo $(OBJ)
        @echo PREREQUISITES: $^

编辑:添加了makemake test的输出

make
whisper --device cuda:1 --model small ./Nigel_00001.m4a
wordgrinder --convert Nigel_00001.txt Nigel_00001.wg
whisper --device cuda:1 --model small ./Nigel_00001.m4a
wordgrinder --convert Nigel_00001.txt Nigel_00001.wg
make test
Nigel_00001.txt Olivier_00001.txt
PREREQUISITES: Nigel_00001.m4a Olivier_00001.m4a
英文:

When I run make, it correctly does the first prerequisite ".m4a" file, but then it stops and doesn't proceed. I've checked and the $(OBJ) does seem to have all the files in there, so I can't understand why it stops?

.SUFFIXES : .txt .m4a                                                                                                                                                                                                                         
SOURCES := $(wildcard  *.m4a)                                                                                                                                                                                                                 
OBJ := $(subst m4a,txt,$(SOURCES))                                                                                                                                                                                                            
WS = whisper                                                                                                                                                                                                                                  
WG = wordgrinder                                                                                                                                                                                                                              
                                                                                                                                                                                                                                              
FLAGS = --device cuda:1 --model small                                                                                                                                                                                                         
.PHONY: test clean imported                                                                                                                                                                                                                   
                                                                                                                                                                                                                                              
all : $(OBJ)                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                              
$(OBJ): $(SOURCES)                                                                                                                                                                                                                            
        @echo $(WS) $(FLAGS) ./$&lt;                                                                                                                                                                                                             
        @echo $(WG) --convert $(subst m4a,txt, $&lt; ) $(subst m4a,wg, $&lt; )                                                                                                                                                                      
                                                                                                                                                                                                                                              
clean :                                                                                                                                                                                                                                       
        rm *~ *.json  *.srt  *.tsv  *.vtt                                                                                                                                                                                                     
                                                                                                                                                                                                                                              
imported:                                                                                                                                                                                                                                     
        mv odt/*.odt odt/imported/                                                                                                                                                                                                            
                                                                                                                                                                                                                                              
test: $(SOURCES)                                                                                                                                                                                                                              
        @echo $(OBJ)                                                                                                                                                                                                                          
        @echo PREREQUISITES: $^            

EDIT: Added the output of make and make test

make
whisper --device cuda:1 --model small ./Nigel_00001.m4a
wordgrinder --convert Nigel_00001.txt Nigel_00001.wg
whisper --device cuda:1 --model small ./Nigel_00001.m4a
wordgrinder --convert Nigel_00001.txt Nigel_00001.wg
make test
Nigel_00001.txt Olivier_00001.txt
PREREQUISITES: Nigel_00001.m4a Olivier_00001.m4a

答案1

得分: 0

You've told Make to use the first prerequisite - that's what $< means.

It looks like you wanted a pattern rule, perhaps this:

%.txt: %.m4a                                                                                                                                                                                                                    
        $(WS) $(FLAGS) $<                                                                                                                                                                                                             
        $(WG) --convert $@ $(subst m4a,wg, $< )      

Or perhaps even a pair of pattern rules:

%.wg: %.m4a                                                                                                                                                                                                                    
        $(WS) $(FLAGS) $<                     

%.txt: %.wg                                                                                                                                                                    
        $(WG) --convert $@ $<
英文:

You've told Make to use the first prerequisite - that's what $&lt; means.

It looks like you wanted a pattern rule, perhaps this:

%.txt: %.m4a                                                                                                                                                                                                                    
        $(WS) $(FLAGS) $&lt;                                                                                                                                                                                                             
        $(WG) --convert $@ $(subst m4a,wg, $&lt; )      

Or perhaps even a pair of pattern rules:

%.wg: %.m4a                                                                                                                                                                                                                    
        $(WS) $(FLAGS) $&lt;                     

%.txt: %.wg                                                                                                                                                                    
        $(WG) --convert $@ $&lt;

答案2

得分: 0

这是您要翻译的部分:

It would be very helpful if you showed (cut and paste) the output you see, in your question. I&#39;m pretty sure that it&#39;s not the case it only runs one instance of the recipe. Instead I think what happens is that it runs the commands once for each source file but it always uses the same filename.

That&#39;s because this rule is wrong:

$(OBJ): $(SOURCES)                                                                                                                                                                                                                            
        @echo $(WS) $(FLAGS) ./$&lt;                                                                                                                                                                                                             
        @echo $(WG) --convert $(subst m4a,txt, $&lt; ) $(subst m4a,wg, $&lt; ) 

After expansion the first line is (giving some sample filenames):

foo.m4a bar.m4a baz.m4a : foo.txt bar.txt baz.txt

You appear to want make to do something like take the first target and match it up with the first prerequisite, the second target matched up with the second prerequisite, etc. but that&#39;s not how make works. The recipe above is identical to writing this:

foo.m4a : foo.txt bar.txt baz.txt                                                                                                                                                                                                                            
        ...
bar.m4a : foo.txt bar.txt baz.txt                                                                                                                                                                                                                            
        ...
bar.m4a : foo.txt bar.txt baz.txt                                                                                                                                                                                                                            
        ...

You can see that this isn&#39;t what you want, because for every recipe the value of `$&lt;` will be the same file: `foo.txt`.

You want to use a pattern rule:

%.txt : %.m4a
        @echo $(WS) $(FLAGS) ./$&lt;                                                                                                                                                                                                             
        @echo $(WG) --convert $@ $*.wg

Also just a note, you shouldn&#39;t be using `subst` here. That will substitute _all_ instances of that string. So if your file is `from4all.m4a` then `$(subst m4a,txt,...)` will give you `frotxtll.txt` which is wrong. You should be using `patsubst`: `$(patsubst %.m4a,%.txt,...)`
英文:

It would be very helpful if you showed (cut and paste) the output you see, in your question. I'm pretty sure that it's not the case it only runs one instance of the recipe. Instead I think what happens is that it runs the commands once for each source file but it always uses the same filename.

That's because this rule is wrong:

$(OBJ): $(SOURCES)                                                                                                                                                                                                                            
        @echo $(WS) $(FLAGS) ./$&lt;                                                                                                                                                                                                             
        @echo $(WG) --convert $(subst m4a,txt, $&lt; ) $(subst m4a,wg, $&lt; ) 

After expansion the first line is (giving some sample filenames):

foo.m4a bar.m4a baz.m4a : foo.txt bar.txt baz.txt

You appear to want make to do something like take the first target and match it up with the first prerequisite, the second target matched up with the second prerequisite, etc. but that's not how make works. The recipe above is identical to writing this:

foo.m4a : foo.txt bar.txt baz.txt                                                                                                                                                                                                                            
        ...
bar.m4a : foo.txt bar.txt baz.txt                                                                                                                                                                                                                            
        ...
bar.m4a : foo.txt bar.txt baz.txt                                                                                                                                                                                                                            
        ...

You can see that this isn't what you want, because for every recipe the value of $&lt; will be the same file: foo.txt.

You want to use a pattern rule:

%.txt : %.m4a
        @echo $(WS) $(FLAGS) ./$&lt;                                                                                                                                                                                                             
        @echo $(WG) --convert $@ $*.wg

Also just a note, you shouldn't be using subst here. That will substitute all instances of that string. So if your file is from4all.m4a then $(subst m4a,txt,...) will give you frotxtll.txt which is wrong. You should be using patsubst: $(patsubst %.m4a,%.txt,...)

huangapple
  • 本文由 发表于 2023年6月8日 22:01:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76432667.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定