0

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.

  • When you do "make abc.ext1", what do you want Make to do? Do you want it to build `abc.ext1`? Or `path/to/abc.ext1`? – Beta Apr 04 '13 at 14:54
  • path/to/abc.ext1 already exists and I don't want to build it. I want echo bla bla to get printed. Normally running make abc prints echo bla bla. –  Apr 04 '13 at 14:56
  • We can't give you a useful answer if you don't put in the effort to pose the question clearly. *What command are you using to invoke Make?* – Beta Apr 05 '13 at 16:41
  • Let me try to improve it. I am using "make path/to/abc.ext1" –  Apr 05 '13 at 16:44

3 Answers3

0

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
  • 92,819
  • 9
  • 109
  • 136
  • I tried this earlier and it wasn't working because conf file is inside a folder. Looks like / doesn't work in target, suggestion ? –  Apr 04 '13 at 14:18
  • If I use %.ext1: as my target it doesn't work. It says: make 'path/to/abc.ext1' update to date. –  Apr 04 '13 at 14:27
  • 2
    You need to edit your question to add in these details. Things like the fact that the file is in a different directory, etc. are absolutely critical to providing answers. As it is your question contains nowhere near enough information for us to answer it. You should show your makefile, cut/paste the command you type now and the output, then show the command you want to type and exactly what you want to happen when you type it. – MadScientist Apr 04 '13 at 18:14
  • I think as you pointed out the problem is full path. make path/to/abc.ext1 doesn't match %.ext1 –  Apr 05 '13 at 15:49
0

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?

Beta
  • 96,650
  • 16
  • 149
  • 150
0

Let me try to summarize what I have understood:

  1. The file path/to/abc.ext1 already exists.
  2. You already have make path/to/abc echoing bla bla without creating the file path/to/abc.
  3. You woud like 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.

adl
  • 15,627
  • 6
  • 51
  • 65
  • This does solve the problem mentioned in question. I have to work around make semantics because echo "bla bla" is lot more complicated and had recursive calls back to target. So, doing it using make semantics will need overhaul of build system. Thanks –  Apr 08 '13 at 14:38