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
make
operates on file names; if there is no file namedm.page.m
and no file namedm.page.d
– which is whatm.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
This tells
make
how to createm.whatever
andd.whatever
fromwhatever
; so it now knows how to createm.x.phtml
fromx.phtml
andd.y.scss
fromy.scss
etc.(Notice also how this avoids the separate
mv
of a static temporary file name, as discussed in comments.)This tells
make
how to createm.z.css
fromm.z.scss
,d.w.php
fromd.w.phtml
, etc. I’m guessing here thatmym1.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 yourMakefile
.Your makefile provides exactly one rule by which
m.page.css
could be built or updated: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 fromm.page.scss
. Except you don’t have anm.page.scss
or any rule to build one. The corresponding root source file is actuallypage.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: