skip to Main Content

I’m trying to take some source files, create some customised versions of those sources, then process those customised sources down to output files I can use. I’m using this make file. Note that this file is not fully complete, currently it only does the CSS* make, once that’s working I will add the PHP* make which is similar:

# root sources
CSSSOURCES =    $(wildcard *.scss)
PHPSOURCES =    $(wildcard *.phtml)

# partials, creates a configed source
CSSMSOURCES =   $(addprefix m.,$(CSSSOURCES:.scss=.m)) 
CSSDSOURCES =   $(addprefix d.,$(CSSSOURCES:.scss=.d)) 
PHPMSOURCES =   $(addprefix m.,$(PHPSOURCES:.phtml=.m)) 
PHPDSOURCES =   $(addprefix d.,$(PHPSOURCES:.phtml=.d))

# targets
CSSMTARGETS =   $(CSSMSOURCES:.m=.css)
CSSDTARGETS =   $(CSSDSOURCES:.d=.css)
PHPMTARGETS =   $(PHPMSOURCES:.m=.php)
PHPDTARGETS =   $(PHPDSOURCES:.d=.php)

# ensure no clash with built in rules
.SUFFIXES: .m .d .scss .css .phtml .php

all:    $(CSSMTARGETS)

%.m:    %.scss
    echo "%define MOBILE" | cat - $< >tmp
    mv tmp $@

%.d:    %.scss
    echo "%define DESKTOP" | cat - $< >tmp
    mv tmp $@

%.css:  %.m %d
    cat $< | mym1.pl >$@
    rm $<

.PHONY: test
test:
    @echo "sources - $(CSSSOURCES)"
    @echo "msources - $(CSSMSOURCES)"
    @echo "targets - $(CSSMTARGETS)"

Instead of creating the CSS targets I get this error:

make: *** No rule to make target 'm.page.css', needed by 'all'. Stop.

2

Answers


  1. make operates on file names; if there is no file named m.page.m and no file named m.page.d – which is what m.page.css depends on in accordance with your declared dependencies – then Make will conclude that it needs to create these. If it does not have any rules (built-in or by way of a recipe) to create those, the error message you get tells you pretty much exactly that.

    I’m guessing what you actually want is something like

    m.%: %
        echo "%define MOBILE" | cat - $< >$@
    
    d.%: %
        echo "%define DESKTOP" | cat - $< >$@
    

    This tells make how to create m.whatever and d.whatever from whatever; so it now knows how to create m.x.phtml from x.phtml and d.y.scss from y.scss etc.

    (Notice also how this avoids the separate mv of a static temporary file name, as discussed in comments.)

    %.css: %.scss
        mym1.pl <$< >$@
    %.php: %.phtml
        mym1.pl <$< >$@
    

    This tells make how to create m.z.css from m.z.scss, d.w.php from d.w.phtml, etc. I’m guessing here that mym1.pl can handle both cases.

    (Notice also the refactoring to avoid useless use of cat.)

    This does away with the somewhat mysterious .m and .d suffixes so you probably have to refactor the variables at the top of your Makefile.

    Login or Signup to reply.
  2. Instead of creating the CSS targets I get this error:

    make: *** No rule to make target 'm.page.css', needed by 'all'.  Stop.
    

    Your makefile provides exactly one rule by which m.page.css could be built or updated:

    %.css:  %.m %d
        cat $< | mym1.pl >$@
        rm $<
    

    In order for that rule to apply, however, both of the prerequisites, expressed as %.m and %d [sic] need to exist or be able to be built. There are problems with both.

    The former in this case represents a file m.page.m. This apparently does not already exist, but you have a rule by which it could be built from m.page.scss. Except you don’t have an m.page.scss or any rule to build one. The corresponding root source file is actually page.sccs.

    The latter prerequisite, %d, would have an analogous problem, but it doesn’t even get that far because you have omitted a period from the prerequisite name (should be %.d, not %d).

    The rule quoted above is moreover bogus because it designates two prerequisites but only uses one. That’s not inherently wrong, but it does not do anything useful to serve you here.

    Replacing your current pattern rules with these should help:

    m.%.m:    %.scss
        echo "%define MOBILE" | cat - $< >tmp
        mv tmp $@
    
    d.%.d:    %.scss
        echo "%define DESKTOP" | cat - $< >tmp
        mv tmp $@
    
    %.css:  %.m
        cat $< | mym1.pl >$@
        rm $<
    
    %.css:  %.d
        cat $< | mym1.pl >$@
        rm $<
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search