3

I'm trying to modify an existing makefile.am to include a rule to convert the *.rc extension into a resource file. Here's as far as I can currently get.

mytarget_SOURCES += ico.rc

.rc.o:
    windres -i $< $@

As is described here: http://www.gnu.org/software/automake/manual/html_node/Suffixes.html In the generated makefile, ico.rc is added to the sources, and ico.o is added to the objects (so that's good I guess).

At the end of the makefile a this .rc.o rule is literally pasted, but I am doubting that should be the case, right? The .rc.o is supposed to be an automake rule, but it isn't a good make rule for creating the ico.o file, is it?

When make is run, it remakes the makefile and then goes on to complain on there being no rule to make ico.o. windres, or whatever I put there (e.g. an echo) is never run. I've tried googling, but information is scarce, and most I've been able to find is copies of the link I gave above. What am I doing wrong?

MicroVirus
  • 5,324
  • 2
  • 28
  • 53

1 Answers1

2

Automake simply copies make rules into the generated Makefile verbatim. So as long as what you write is valid makefile syntax, it's OK.

What you have there is part of a valid implicit suffix rule in make. However, you're missing that you need to define .rc as a valid suffix (the .o is part of the built-in suffix list so you don't have to add it, unless you just want to be complete).

Add this to your Makefile.am as well:

.SUFFIXES: .rc

See http://www.gnu.org/software/make/manual/html_node/Suffix-Rules.html for more details.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • Automake complained that I should use `SUFFIXES = `, so I tried that. Still same old, it expects ico.o, but make doesn't know how to build it. I tried adding a make rule `%.o: %.rc ...` but doesn't help :( – MicroVirus Jan 13 '14 at 18:17
  • Turns out I went full retard and deleted ico.rc, somewhere along my frustrations, and that was the source of my errors... – MicroVirus Jan 13 '14 at 18:32
  • Using `%.rc : %.o` is OK if you are OK with requiring GNU make. Automake can generate makefiles which are very widely portable across implementations of POSIX make, but if you use GNU make only features like pattern rules then the output is restricted to GNU make as well. – MadScientist Jan 13 '14 at 18:36
  • To get automake to add the ico.o to the list of objects, I need to use the suffix rule. Thansk for your help – MicroVirus Jan 13 '14 at 18:46
  • 1
    What I was trying to say was that you can EITHER use the pattern rule and restrict yourself to GNU make, OR you can use the suffix rule and add `.rc` to SUFFIXES and be portable across different make versions. If you use pattern rules you don't need to change SUFFIXES, but this construct is not understood by automake so it will be passed through into your makefile as-is, and it's up to the make program (GNU make) to parse it for you. – MadScientist Jan 13 '14 at 18:49
  • Ok, I understand what you are saying. If one goes for the pattern rule then one could in principal add dependencies to the build rule, which would be nice in my situation (as it actually depends on a header version.h). How does one then tell automake to add the object that comes out of the custom build rule to the list of objects passed to the linker? The suffix rule works, but is very limited, in that one can't add dependencies, other than the implied rc->o – MicroVirus Jan 13 '14 at 22:59
  • 1
    Sure you can add dependencies. You don't have to list all the dependencies in the rule itself (in fact, with suffix and pattern rules you _can't_ unless all the matching targets have the same prerequisites which is pretty rare). Just add a new prerequisite line, like `foo.o : version.h`. No commands, just prerequisites. – MadScientist Jan 14 '14 at 00:52
  • As for adding telling automake anything, you don't have to do that. Just list the source file normally. Make will handle the implicit rule lookup. – MadScientist Jan 14 '14 at 00:53