0

I am new to make. Suppose I have a makefile which has atarget, the target will kick off different compile command base on the version: From version 1.x.x to version 3.x.x, it will kick off command 1. While version 4.x.x or above, it will kick off command 2.

run-%: %.txt
   <if %.txt is in between 1.x.x and 3.x.x, kick off command 1 with %.txt as input>
   <else kick off command 2 with %x.txt as input>

User will run it like this:

make run-2.2.0

Does make provide some sort of pattern matching?

Kintarō
  • 2,947
  • 10
  • 48
  • 75
  • Also take a look at [this answer](https://stackoverflow.com/questions/3728372/version-number-comparison-inside-makefile/60206580#60206580) – Vroomfondel Apr 09 '20 at 17:48

1 Answers1

0

There is nothing like glob's [1-3] if that's what you mean by "pattern matching". All you can do is write multiple rules unfortunately:

run-1.%: 1.%.txt
    <command1>
run-2.%: 2.%.txt
    <command1>
run-3.%: 3.%.txt
    <command1>

run-%: %.txt
    <command2>
MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • You can potentially simplify this various ways: assign `COMMAND1 = ` then use `$(COMMAND1)` in the three recipes to reduce duplication. If you wanted to get very fancy you could use `eval` to avoid writing the rule multiple times but if there are really only three "old versions" it's probably simpler to read and understand to just write it out three times. – MadScientist Apr 08 '20 at 14:25