include $(__nmk_dir)msg.mk
all: pb.py images magic.py

.PHONY: all images clean pb.py

proto := $(filter-out $(SRC_DIR)/images/rpc.proto, $(sort $(wildcard $(SRC_DIR)/images/*.proto)))
proto-py-modules := $(foreach m,$(proto),$(subst -,_,$(notdir $(m:.proto=_pb2))))

# We don't need rpc_pb2.py here, as it is not related to the images.
# Unfortunately, we can't drop ugly _pb2 suffixes here, because
# some _pb2 files depend on others _pb2 files.
images:
	$(Q) protoc -I=$(SRC_DIR)/images -I=/usr/include/ --python_out=./ $(proto)

magic.py: $(SRC_DIR)/scripts/magic-gen.py $(SRC_DIR)/criu/include/magic.h
	$(call msg-gen, $@)
	$(Q) python $^ $@

pb.py: images
	$(Q) echo "# Autogenerated. Do not edit!" > $@
	$(Q) for m in $(proto-py-modules); do \
		echo "from $$m import *" >> $@ ;\
	done

clean:
	$(Q) $(RM) ./*_pb2.py ./*.pyc magic.py pb.py
