[CRIU] [PATCH 2/6] lib Makefiles: integrate
Kir Kolyshkin
kir at openvz.org
Mon Feb 20 02:31:30 PST 2017
On 02/20/2017 02:13 AM, Dmitry Safonov wrote:
> her2017-02-20 6:13 GMT+03:00 Kir Kolyshkin <kir at openvz.org>:
>> Our whole system of Makefiles are integrated from top to bottom,
>> meaning:
>>
>> 1. The paths in sub-makefiles are relative to the top source dir.
>> 2. Sub-makefiles are executed via make $(build)=<SUBDIR> <TARGET>
>>
>> For some reason, makefiles under lib/ are the exclusion. Let's fix it.
>>
>> Side effect: you can now build any individual target under lib/,
>> for example, "make lib/c/libcriu.so" works.
>>
>> Signed-off-by: Kir Kolyshkin <kir at openvz.org>
>> ---
>> Makefile | 7 +++----
>> Makefile.install | 4 ++--
>> lib/Makefile | 54 +++++++++++++++++++++++---------------------------
>> lib/py/Makefile | 21 ++++++++++++--------
>> lib/py/images/Makefile | 19 +++++++++---------
>> scripts/crit-setup.py | 4 ++--
>> 6 files changed, 54 insertions(+), 55 deletions(-)
>>
>> diff --git a/Makefile b/Makefile
>> index 92e94eb..b1a455a 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -244,14 +244,12 @@ criu: $(criu-deps)
>> # (we might generate headers and such
>> # when building criu itself).
>> lib/%: criu .FORCE
>> - $(Q) $(MAKE) -C lib $@
>> + $(Q) $(MAKE) $(build)=lib $@
>> lib: criu
>> - $(Q) $(MAKE) -C lib all
>> + $(Q) $(MAKE) $(build)=lib all
>> .PHONY: lib
>>
>> subclean:
>> - $(call msg-clean, criu)
>> - $(Q) $(MAKE) -C lib clean
>> $(Q) $(MAKE) -C Documentation clean
>> $(Q) $(MAKE) $(build)=test/compel clean
>> $(Q) $(RM) .gitid
>> @@ -263,6 +261,7 @@ clean: subclean
>> $(Q) $(MAKE) $(build)=soccr $@
>> $(Q) $(MAKE) $(build)=compel $@
>> $(Q) $(MAKE) $(build)=compel/plugins $@
>> + $(Q) $(MAKE) $(build)=lib $@
>> .PHONY: clean
>>
>> # mrproper depends on clean in nmk
>> diff --git a/Makefile.install b/Makefile.install
>> index 9f27d3e..d756d97 100644
>> --- a/Makefile.install
>> +++ b/Makefile.install
>> @@ -29,7 +29,7 @@ install-man:
>> .PHONY: install-man
>>
>> install-lib: lib
>> - $(Q) $(MAKE) -C lib install
>> + $(Q) $(MAKE) $(build)=lib install
>> .PHONY: install-lib
>>
>> install-criu: criu
>> @@ -47,7 +47,7 @@ install: install-man install-lib install-criu install-compel
>>
>> uninstall:
>> $(Q) $(MAKE) -C Documentation $@
>> - $(Q) $(MAKE) -C lib $@
>> + $(Q) $(MAKE) $(build)=lib $@
>> $(Q) $(MAKE) -C criu $@
>> $(Q) $(MAKE) $(build)=compel $@
>> $(Q) $(MAKE) $(build)=compel/plugins $@
>> diff --git a/lib/Makefile b/lib/Makefile
>> index a4d9d87..084fee5 100644
>> --- a/lib/Makefile
>> +++ b/lib/Makefile
>> @@ -1,62 +1,58 @@
>> -include $(__nmk_dir)include.mk
>> -
>> CRIU_SO := libcriu.so
>> -UAPI_HEADERS := c/criu.h ../images/rpc.proto
>> +UAPI_HEADERS := lib/c/criu.h images/rpc.proto
>> PYTHON_BIN ?= python2
>>
>> #
>> # File to keep track of files installed by setup.py
>> -CRIT_SETUP_FILES := .crit-setup.files
>> +CRIT_SETUP_FILES := lib/.crit-setup.files
>> +
>> +all-y += lib-c lib-py
>>
>> #
>> # C language bindings.
>> -c/%: ../Makefile.versions
>> +lib/c/%: Makefile.versions
> Use the .FORCE, Kir.
> Otherwise your middle-top-makefile will think that target
> is up-to-date if it was once built. As it "to high" to know about
> dependencies.
Good catch, thanks! Will redo.
>> $(call msg-gen, $@)
>> - $(Q) $(MAKE) $(build)=c $@
>> + $(Q) $(MAKE) $(build)=lib/c $@
>>
>> cflags-so += $(CFLAGS) -rdynamic -Wl,-soname,$(CRIU_SO).$(CRIU_SO_VERSION_MAJOR)
>> ldflags-so += -lprotobuf-c
>> -c/$(CRIU_SO): c/built-in.o
>> +
>> +lib/c/$(CRIU_SO): lib/c/built-in.o
>> $(call msg-link, $@)
>> $(Q) $(CC) -shared $(cflags-so) -o $@ $^ $(ldflags-so) $(LDFLAGS)
>> -lib-c: c/$(CRIU_SO)
>> +lib-c: lib/c/$(CRIU_SO)
>> .PHONY: lib-c
>>
>> #
>> # Python bindings.
>> -lib-py:
>> +lib/py/%:
> ditto
>
>> $(call msg-gen, $@)
>> - $(Q) $(MAKE) -C py all
>> + $(Q) $(MAKE) $(build)=lib/py $@
>> +lib-py:
>> + $(Q) $(MAKE) $(build)=lib/py all
>> .PHONY: lib-py
>>
>> -all: lib-c lib-py
>> - @true
>> -.PHONY: all
>> -
>> -clean:
>> - $(call msg-clean, lib-c)
>> - $(Q) $(MAKE) $(build)=c $@
>> - $(Q) $(RM) c/$(CRIU_SO)
>> - $(Q) $(RM) c/criu.pc
>> - $(call msg-clean, lib-py)
>> - $(Q) $(MAKE) -C py $@
>> - $(Q) $(RM) -r build usr
>> -.PHONY: clean
>> +clean-lib:
>> + $(Q) $(MAKE) $(build)=lib/c clean
>> + $(Q) $(MAKE) $(build)=lib/py clean
>> +.PHONY: clean-lib
>> +clean: clean-lib
>> +cleanup-y += lib/c/$(CRIU_SO) lib/c/criu.pc
>>
>> -install: lib-c lib-py ../crit/crit c/criu.pc.in
>> - $(E) " INSTALL " $(CRIU_SO)
>> +install: lib-c lib-py crit/crit lib/c/criu.pc.in
>> + $(E) " INSTALL " lib
>> $(Q) mkdir -p $(DESTDIR)$(LIBDIR)
>> - $(Q) install -m 755 c/$(CRIU_SO) $(DESTDIR)$(LIBDIR)/$(CRIU_SO).$(CRIU_SO_VERSION_MAJOR).$(CRIU_SO_VERSION_MINOR)
>> + $(Q) install -m 755 lib/c/$(CRIU_SO) $(DESTDIR)$(LIBDIR)/$(CRIU_SO).$(CRIU_SO_VERSION_MAJOR).$(CRIU_SO_VERSION_MINOR)
>> $(Q) ln -fns $(CRIU_SO).$(CRIU_SO_VERSION_MAJOR).$(CRIU_SO_VERSION_MINOR) $(DESTDIR)$(LIBDIR)/$(CRIU_SO).$(CRIU_SO_VERSION_MAJOR)
>> $(Q) ln -fns $(CRIU_SO).$(CRIU_SO_VERSION_MAJOR).$(CRIU_SO_VERSION_MINOR) $(DESTDIR)$(LIBDIR)/$(CRIU_SO)
>> $(Q) mkdir -p $(DESTDIR)$(INCLUDEDIR)/criu/
>> $(Q) install -m 644 $(UAPI_HEADERS) $(DESTDIR)$(INCLUDEDIR)/criu/
>> $(E) " INSTALL " pkgconfig/criu.pc
>> $(Q) mkdir -p $(DESTDIR)$(LIBDIR)/pkgconfig
>> - $(Q) sed -e 's, at version@,$(CRIU_VERSION),' -e 's, at libdir@,$(LIBDIR),' -e 's, at includedir@,$(dir $(INCLUDEDIR)/criu/),' c/criu.pc.in > c/criu.pc
>> - $(Q) install -m 644 c/criu.pc $(DESTDIR)$(LIBDIR)/pkgconfig
>> + $(Q) sed -e 's, at version@,$(CRIU_VERSION),' -e 's, at libdir@,$(LIBDIR),' -e 's, at includedir@,$(dir $(INCLUDEDIR)/criu/),' lib/c/criu.pc.in > lib/c/criu.pc
>> + $(Q) install -m 644 lib/c/criu.pc $(DESTDIR)$(LIBDIR)/pkgconfig
>> $(E) " INSTALL " crit
>> - $(Q) $(PYTHON_BIN) ../scripts/crit-setup.py install --root=$(DESTDIR) --prefix=$(PREFIX) --record $(CRIT_SETUP_FILES)
>> + $(Q) $(PYTHON_BIN) scripts/crit-setup.py install --root=$(DESTDIR) --prefix=$(PREFIX) --record $(CRIT_SETUP_FILES)
>> .PHONY: install
>>
>> uninstall:
>> diff --git a/lib/py/Makefile b/lib/py/Makefile
>> index 9ef4fa4..59d54a2 100644
>> --- a/lib/py/Makefile
>> +++ b/lib/py/Makefile
>> @@ -1,13 +1,18 @@
>> -all: images rpc_pb2.py
>> +all-y += libpy-images rpc_pb2.py
>>
>> -.PHONY: all images clean
>> +$(obj)/images/%:
> ditto
>
>> + $(Q) $(MAKE) $(build)=$(obj)/images $@
>>
>> -images:
>> - $(Q) $(MAKE) -C images all
>> +libpy-images:
>> + $(Q) $(MAKE) $(build)=$(obj)/images all
>> +.PHONY: libpy-images
>>
>> rpc_pb2.py:
>> - $(Q) protoc -I=$(SRC_DIR)/images/ --python_out=./ $(SRC_DIR)/images/$(@:_pb2.py=.proto)
>> + $(Q) protoc -I=$(SRC_DIR)/images/ --python_out=$(obj) $(SRC_DIR)/images/$(@:_pb2.py=.proto)
>>
>> -clean:
>> - $(Q) $(MAKE) -C images clean
>> - $(Q) $(RM) rpc_pb2.py *.pyc
>> +cleanup-y += $(addprefix $(obj)/,rpc_pb2.py *.pyc)
>> +
>> +clean-lib-py:
>> + $(Q) $(MAKE) $(build)=$(obj)/images clean
>> +.PHONY: clean-lib-py
>> +clean: clean-lib-py
>> diff --git a/lib/py/images/Makefile b/lib/py/images/Makefile
>> index 8fad6d8..a5990c4 100644
>> --- a/lib/py/images/Makefile
>> +++ b/lib/py/images/Makefile
>> @@ -1,7 +1,4 @@
>> -include $(__nmk_dir)msg.mk
>> -all: pb.py images magic.py
>> -
>> -.PHONY: all images clean pb.py
>> +all-y += images magic.py 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))))
>> @@ -10,17 +7,19 @@ proto-py-modules := $(foreach m,$(proto),$(subst -,_,$(notdir $(m:.proto=_pb2)))
>> # 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)
>> + $(Q) protoc -I=$(SRC_DIR)/images -I=/usr/include/ --python_out=$(obj) $(proto)
>> +.PHONY: images
>>
>> magic.py: $(SRC_DIR)/scripts/magic-gen.py $(SRC_DIR)/criu/include/magic.h
>> $(call msg-gen, $@)
>> - $(Q) python $^ $@
>> + $(Q) python $^ $(obj)/$@
>>
>> pb.py: images
>> - $(Q) echo "# Autogenerated. Do not edit!" > $@
>> + $(Q) echo "# Autogenerated. Do not edit!" > $(obj)/$@
>> $(Q) for m in $(proto-py-modules); do \
>> - echo "from $$m import *" >> $@ ;\
>> + echo "from $$m import *" >> $(obj)/$@ ;\
>> done
>> +.PHONY: pb.py
>>
>> -clean:
>> - $(Q) $(RM) ./*_pb2.py ./*.pyc magic.py pb.py
>> +cleanup-y += $(addprefix $(obj)/,magic.py pb.py *.pyc)
>> +cleanup-y += $(call cleanify,$(addprefix $(obj)/,$(addsuffix .py,$(proto-py-modules))))
>> diff --git a/scripts/crit-setup.py b/scripts/crit-setup.py
>> index 74368da..60fef6a 100644
>> --- a/scripts/crit-setup.py
>> +++ b/scripts/crit-setup.py
>> @@ -6,7 +6,7 @@ setup(name = "crit",
>> author = "CRIU team",
>> author_email = "criu at openvz.org",
>> url = "https://github.com/xemul/criu",
>> - package_dir = {'pycriu': 'py'},
>> + package_dir = {'pycriu': 'lib/py'},
>> packages = ["pycriu", "pycriu.images"],
>> - scripts = ["../crit/crit"]
>> + scripts = ["crit/crit"]
>> )
>
More information about the CRIU
mailing list