Makefile is using
.SUFFIXES: .ext1
.ext1:
echo bla bla
I have a configuration file path/to/abc.ext1 so make path/to/abc works fine.
I want make path/to/abc.ext1 to work as well. It would be great if I can reuse existing .ext1 target.
Makefile is using
.SUFFIXES: .ext1
.ext1:
echo bla bla
I have a configuration file path/to/abc.ext1 so make path/to/abc works fine.
I want make path/to/abc.ext1 to work as well. It would be great if I can reuse existing .ext1 target.
You can just add a rule for abc.ext1
, then running make abc.ext1
will work. Suffix rules are only searched if there is no explicit rule available.
If that doesn't work for your situation please explain your problem more clearly.
MadScientist's answer seems correct, but I think there's a miscommunication here.
If you have this rule:
%.ext1:
echo bla bla
and you make abc.ext1
, what happens?
Let me try to summarize what I have understood:
path/to/abc.ext1
already exists.make path/to/abc
echoing bla bla
without creating the file path/to/abc
.make path/to/abc.ext1
to behave like make path/to/abc
. In your current setup it does not work because path/to/abc.ext1
already exists, so make
has no reason to trigger a rule to "rebuild" it.In your case, you are not building any of the files abc
or abc.ext1
, so you should really tell make
that these are phony targets. (I assume you want make abc
to work even if abc
already exist and is newer than abc.ext1
, right?)
For a single file, you could have something like:
.PHONY: path/to/abc.ext1 path/to/abc
path/to/abc.ext1 path/to/abc:
@echo bla bla
This way, make path/to/abc.ext1
or make path/to/abc
will always run echo bla bla
regardless of the existence of path/to/abc.ext1
or path/to/abc
(make
will never check their existence).
Unfortunately, .PHONY
require an explicit list of targets. With GNU make you could compute that list of targets with $(wildcard...)
or if you need to recurse into subdirectories, with $(shell find...)
. For instance:
EXT1_FILES = $(shell find -type f -name '*.ext1' -print)
PHONY_TARGETS = $(EXT1_FILES) $(EXT1_FILES:.ext1=)
.PHONY: $(PHONY_TARGETS)
$(PHONY_TARGETS):
@echo bla bla
The $(EXT1_FILES:.ext1=)
just strips all .ext1
extensions from the filenames in $(EXT1_FILES)
.
If you have a very large tree, you will suffer from the $(shell find...)
invocation: it is runs every time your Makefile
is loaded by make
. If it's too slow, you could replace it by the explicit list of filename (maybe generated automatically).
Your question gives zero context, so it's hard to suggest more useful alternatives. It still feels like you are trying to abuse make
. When you state something like "make foo.ext1
should run some commands even if foo.ext1
exists", that's fishy. Can't you write a simple shell script that takes one argument, and does echo bla bla
whenever $1
or $1.ext1
exist? It would probably be a lot easier than trying to work around make
's semantics.