makefileaspell

Makefile for checking spelling


I am trying to configure a makefile so that I can use aspell in it to check a folder of .mb files. I am not sure how to configure it but I tried this:

spellcheck-en:
    for f in src/docs/en/*.md; do aspell --lang=en check $f; done

The thing is, the makefile is not reading the $f so when I run 'make spellcheck-en' I get this:

Error: You must specify a file name.
Error: You must specify a file name.
Error: You must specify a file name.
Error: You must specify a file name.
Error: You must specify a file name.
make: *** [Makefile:29: spellcheck-en] Error 255

However, running this: "for f in src/docs/en/*.md; do aspell --lang=en check $f; done" on the terminal is not an issue. Is there another way to indicate $f in a makefile?

Thank you.


Solution

  • This answer is not about your issues which have been fixed in the comments. Your Makefile, while working after you'll replace $f by $$f, is not better than the equivalent shell script. It has 2 main drawbacks:

    The following solves these two drawbacks:

    # File Makefile
    MDDIR   := src/docs/en
    OKDIR   := .ok
    MDFILES := $(wildcard $(MDDIR)/*.md)
    OKFILES := $(patsubst $(MDDIR)/%.md,$(OKDIR)/%,$(MDFILES))
    
    .PHONY: spellcheck-en
    spellcheck-en: $(OKFILES)
    
    $(OKDIR)/%: $(MDDIR)/%.md | $(OKDIR)
        aspell --lang=en check $<
        touch $@
    
    $(OKDIR):
        mkdir -p $@
    
    .PHONY: clean
    clean:
        rm -rf $(OKDIR)
    

    If you now run:

    make -j8 spellcheck-en
    

    or just (because being the first target spellcheck-en is the default goal):

    make -j8
    

    You'll check only the files that changed since the last check and you'll run these checks in parallel with up to 8 jobs at a time.

    Explanations:

    All these are well explained in the GNU make manual.