makefileprerequisites

My makefile only executes the first prerequisite?


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) ./$<                                                                                                                                                                                                             
        @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: $^            

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

Solution

  • 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) ./$<                                                                                                                                                                                                             
            @echo $(WG) --convert $(subst m4a,txt, $< ) $(subst m4a,wg, $< ) 
    

    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 $< will be the same file: foo.txt.

    You want to use a pattern rule:

    %.txt : %.m4a
            @echo $(WS) $(FLAGS) ./$<                                                                                                                                                                                                             
            @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,...)