criu/lib/Makefile
Radostin Stoyanov 376f3d1800 crit: add requirements.txt for pip>=20.1
When building with pip version 20.0.2 or older, the pip install
command creates a temporary directory and copies all files from
./crit. This results in the following error message:

    ModuleNotFoundError: No module named 'pycriu'

This error appears because the symlink 'pycriu' uses a relative path
that becomes invalid '../lib/py/'.

The '--no-build-isolation' option for pip install is needed to enable
the use of pre-installed dependencies (e.g., protobuf) during build.

The '--ignore-installed' option for pip is needed to avoid an error when
crit is already installed. For example, crit is installed in the GitHub
CI environment as part of the criu OBS package as a dependency for
podman.

Distributions such as Arch Linux have adopted an externally managed
python installation in compliance with PEP 668 [1] that prevents pip
from breaking the system by either installing packages to the system or
locally in the home folder. The '--break-system-packages' [2] option
allows pip to modify an externally managed Python installation.

[1] https://peps.python.org/pep-0668/
[2] https://pip.pypa.io/en/stable/cli/pip_uninstall/

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
2023-10-22 13:29:25 -07:00

97 lines
3.7 KiB
Makefile

CRIU_SO := libcriu.so
CRIU_A := libcriu.a
UAPI_HEADERS := lib/c/criu.h images/rpc.proto images/rpc.pb-c.h criu/include/version.h
all-y += lib-c lib-a lib-py
PYTHON_EXTERNALLY_MANAGED := $(shell $(PYTHON) -c 'import os, sysconfig; print(int(os.path.isfile(os.path.join(sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED"))))')
PIP_BREAK_SYSTEM_PACKAGES := 0
#
# C language bindings.
lib/c/Makefile: ;
lib/c/%: .FORCE
$(Q) $(MAKE) $(build)=lib/c $@
cflags-so += $(CFLAGS) -rdynamic -Wl,-soname,$(CRIU_SO).$(CRIU_SO_VERSION_MAJOR)
ldflags-so += -lprotobuf-c
lib/c/$(CRIU_SO): lib/c/built-in.o
$(call msg-link, $@)
$(Q) $(CC) -shared $(cflags-so) -o $@ $^ $(ldflags-so) $(LDFLAGS)
lib/c/$(CRIU_A): lib/c/built-in.o
$(call msg-link, $@)
$(Q) $(AR) rcs $@ $^
lib-c: lib/c/$(CRIU_SO)
lib-a: lib/c/$(CRIU_A)
.PHONY: lib-c lib-a
#
# Python bindings.
lib/py/Makefile: ;
lib/py/%: .FORCE
$(call msg-gen, $@)
$(Q) $(MAKE) $(build)=lib/py $@
lib-py:
$(Q) $(MAKE) $(build)=lib/py all
.PHONY: lib-py
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_A) lib/c/criu.pc
mrproper: clean
install: lib-c lib-a lib-py lib/c/criu.pc.in
$(E) " INSTALL " lib
$(Q) mkdir -p $(DESTDIR)$(LIBDIR)
$(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) install -m 755 lib/c/$(CRIU_A) $(DESTDIR)$(LIBDIR)/$(CRIU_A)
$(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,@version@,$(CRIU_VERSION),' -e 's,@libdir@,$(LIBDIR),' -e 's,@includedir@,$(dir $(INCLUDEDIR)/criu/),' lib/c/criu.pc.in > lib/c/criu.pc
$(Q) install -m 644 lib/c/criu.pc $(DESTDIR)$(LIBDIR)/pkgconfig
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP INSTALL crit: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make install"
else
$(E) " INSTALL " crit
$(Q) $(PYTHON) -m pip install -r ./crit/requirements.txt
$(Q) $(PYTHON) -m pip install --no-build-isolation --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
endif
else
$(E) " INSTALL " crit
$(Q) $(PYTHON) -m pip install -r ./crit/requirements.txt
$(Q) $(PYTHON) -m pip install --no-build-isolation --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
endif
.PHONY: install
uninstall:
$(E) " UNINSTALL" $(CRIU_SO)
$(Q) $(RM) $(addprefix $(DESTDIR)$(LIBDIR)/,$(CRIU_SO).$(CRIU_SO_VERSION_MAJOR))
$(Q) $(RM) $(addprefix $(DESTDIR)$(LIBDIR)/,$(CRIU_SO))
$(Q) $(RM) $(addprefix $(DESTDIR)$(LIBDIR)/,$(CRIU_A))
$(Q) $(RM) $(addprefix $(DESTDIR)$(LIBDIR)/,$(CRIU_SO).$(CRIU_SO_VERSION_MAJOR).$(CRIU_SO_VERSION_MINOR))
$(Q) $(RM) $(addprefix $(DESTDIR)$(INCLUDEDIR)/criu/,$(notdir $(UAPI_HEADERS)))
$(E) " UNINSTALL" pkgconfig/criu.pc
$(Q) $(RM) $(addprefix $(DESTDIR)$(LIBDIR)/pkgconfig/,criu.pc)
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP UNINSTALL crit: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make uninstall"
else
$(E) " UNINSTALL" crit
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
endif
else
$(E) " UNINSTALL" crit
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
endif
.PHONY: uninstall