-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
82 lines (65 loc) · 2.77 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
ifeq ($(V),)
Q = @
endif
PYTHON ?= python3
PY_COMPILE = $(Q)$(PYTHON) -m py_compile
pysrc_to_pyc = \
$(shell $(PYTHON) -c "from importlib.util import cache_from_source; \
print(cache_from_source('lsbtools/$(1)'))")
LSBTOOLS_PYC = $(call pysrc_to_pyc,lsbtools.py)
INSTALL_INITD_PYC = $(call pysrc_to_pyc,install_initd.py)
LSB_RELEASE_PYC = $(call pysrc_to_pyc,lsb_release.py)
REMOVE_INITD_PYC = $(call pysrc_to_pyc,remove_initd.py)
ALL_PYC = $(LSBTOOLS_PYC) $(INSTALL_INITD_PYC) $(LSBINSTALL_PYC) \
$(LSB_RELEASE_PYC) $(REMOVE_INITD_PYC)
ENTRY_POINT = install_initd.ent lsb_release.ent remove_initd.ent
PYLIB_DIR = $(shell $(PYTHON) -c "import sysconfig; \
print(sysconfig.get_path('purelib'))")
INIT ?= $(shell basename $(realpath /sbin/init))
.PHONY: all clean install
all: $(ALL_PYC) $(ENTRY_POINT)
clean: ; $(RM) $(ALL_PYC) $(ENTRY_POINT) python.shebang s-python-shebang
install: all
mkdir -pv $(DESTDIR)/$(PYLIB_DIR)
cp -av --no-preserve=ownership lsbtools \
-T $(DESTDIR)/$(PYLIB_DIR)/lsbtools
install -D -vm755 lsb_release.ent $(DESTDIR)/usr/bin/lsb_release
mkdir -pv $(DESTDIR)/usr/share/man/man1
install -vm644 man/lsb_release.1 $(DESTDIR)/usr/share/man/man1
if [[ "$(INIT)" != "systemd" ]]; then \
install -vdm 755 $(DESTDIR)/usr/sbin; \
for i in install_initd remove_initd; do \
install -D -vm755 $$i.ent $(DESTDIR)/usr/lib/lsb/$$i; \
rm -fv $(DESTDIR)/usr/sbin/$$i; \
ln -sv ../lib/lsb/$$i $(DESTDIR)/usr/sbin; \
done; \
mkdir -pv $(DESTDIR)/usr/share/man/man8; \
install -vm644 man/*.8 $(DESTDIR)/usr/share/man/man8; \
fi
$(LSBTOOLS_PYC): lsbtools/lsbtools.py
@echo '[PY_COMPILE] ' $@
$(PY_COMPILE) $<
$(INSTALL_INITD_PYC): lsbtools/install_initd.py
@echo '[PY_COMPILE] ' $@
$(PY_COMPILE) $<
$(LSB_RELEASE_PYC): lsbtools/lsb_release.py
@echo '[PY_COMPILE] ' $@
$(PY_COMPILE) $<
$(REMOVE_INITD_PYC): lsbtools/remove_initd.py
@echo '[PY_COMPILE] ' $@
$(PY_COMPILE) $<
%.ent: python.shebang
@echo '[GEN] ' $@
$(Q)cp $< $@
$(Q)echo "from lsbtools import $(patsubst %.ent,%,$@)" >> $@
python.shebang: s-python-shebang; @echo '[UPD] ' $@
.PHONY: s-python-shebang
s-python-shebang:
$(Q)$(PYTHON) -c \
"import sys,os;print('#!'+os.path.realpath(sys.executable))" \
> tmp-python.shebang
$(Q)if ! diff &> /dev/null tmp-python.shebang python.shebang; then \
mv tmp-python.shebang python.shebang; \
fi
$(Q)$(RM) tmp-python.shebang
$(Q)touch s-python-shebang