Reputation: 24806
I need to generate a .c
and .h
from a Google Protocol Buffer spec .proto
in my build.
Currently I followed the approach of manually recording the dependencies to my generated .h
file. That is, I added several:
somefilethatincludesthegenerated.$(OBJEXT): mygenerated.h
and that together with my rules to build mygenerated.h
and mygenerated.c
works. I know about BUILT_SOURCES
but that only works for make all
not for make mytarget
.
So I wanted to explore the possibility of generating the sources from configure
instead, as described in the Automake manual.
The AC_CONFIG_FILES
would allow me to generate mygenerated.h
from a mygenerated.h.in
but really this file is not meant to be generated from a template. The files are to be generated by using an external tool called protoc
. In my Makefile.am
file the rule to build the generated sources is:
mygenerated.c mygenerated.c: myprotofile.proto
$(PROTOC) --proto_path=$(srcdir) --c_out=$(builddir) $^
How can achieve something similar from within configure
itself?. What I'm after is to build the generated sources always, and before any other target (BUILT_SOURCES
will not work for targets other than all
, check
, and some others)
Upvotes: 0
Views: 498
Reputation: 24806
I suceeded using AC_CONFIG_COMMANDS
instead of AC_CONFIG_FILES
.
So to run protoc
(or protoc-c
like in this case) from configure
add the following to configure.ac
:
AC_CONFIG_COMMANDS([src/mygenerated.h],
[protoc-c --proto_path=src --c_out=src src/myprotofile.proto])
Then when you run ./configure
you will see a
config.status: executing src/mygenerated.h commands
Note that if you modify the .proto
file you need to rerun ./configure
. This is a drawback of the "generate sources from configure" approach.
Upvotes: 2