protocol buffers - Makefile generic rule where target and prerequisite names differ -
i'm trying hybrid c/java build infrastructure making heavy use of protocol buffers set work correctly. while ant doing final java build, there lot of jni prerequisites being done in autoconf/make prior this, , ant being called makefile.
here's snippet of i'm trying working:
protodir = ../server/protos proto_source = file_1.proto file_2.proto built_sources = $(proto_source:.proto=.java) # tell make proto files vpath %.proto $(protodir) # build java proto files src/appname/proto/%.java: %.proto protoc --java_out=src/ --proto_path=`dirname $<` $<
the problem? protoc java removes underscores in file names, , hence %.java , %.proto file names don't match. build end working, rebuilds proto files (and hence depends on proto files) every time make called.
how can make %.java , %.proto can differ, or possible?
ok, found way using eval , defined macro.
protodir = ../server/protos protogendir = src/appname/proto/ proto_source = file_1.proto file_2.proto built_sources = $(subst _,,$(addprefix $(protogendir), $(proto_source:.proto=.java))) # tell make proto files vpath %.proto $(protodir) # build java proto files define buildproto $(subst _,,$(addprefix $(protogendir), $(protoname:.proto=.java))): $(protoname) protoc --java_out=src/ --proto_path=`dirname $$<` $$< endef $(foreach protoname,$(proto_source),$(eval $(buildproto)))
inspired by: http://make.mad-scientist.net/the-eval-function/
Comments
Post a Comment