forked from turnkeylinux/tklbam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
96 lines (73 loc) · 2.33 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# standard Python project Makefile
progname = $(shell awk '/^Source/ {print $$2}' debian/control)
name=
prefix = /usr/local
PATH_BIN = $(prefix)/bin
PATH_INSTALL_LIB = $(prefix)/lib/$(progname)
PATH_DIST := $(progname)-$$(autoversion HEAD)
SHELL = /bin/bash
all: help
debug:
$(foreach v, $V, $(warning $v = $($v)))
@true
dist:
-mkdir -p $(PATH_DIST)
cp -a .git $(PATH_DIST)
cd $(PATH_DIST) && git-checkout --force HEAD
tar jcvf $(PATH_DIST).tar.bz2 $(PATH_DIST)
rm -rf $(PATH_DIST)
docs:
$(MAKE) -C docs
help:
@echo '=== Targets:'
@echo 'install [ prefix=path/to/usr ] # default: prefix=$(value prefix)'
@echo 'uninstall [ prefix=path/to/usr ]'
@echo 'docs'
@echo
@echo 'clean'
# DRY macros
debbuild=debian/$(shell awk '/^Package/ {print $$2}' debian/control)
truepath = $(shell echo $1 | sed -e 's|^$(debbuild)||')
libpath = $(call truepath,$(PATH_INSTALL_LIB))/$$(basename $1)
subcommand = $(progname)-$$(echo $1 | sed 's|.*/||; s/^cmd_//; s/_/-/g; s/.py$$//')
echo-do = echo $1; $1
# first argument: code we execute if there is just one executable module
# second argument: code we execute if there is more than on executable module
define with-py-executables
@modules=$$(find -maxdepth 1 -type f -name 'cmd_*.py' -perm -100); \
modules_len=$$(echo $$modules | wc -w); \
if [ $$modules_len = 1 ]; then \
module=$$modules; \
$(call echo-do, $1); \
elif [ $$modules_len -gt 1 ]; then \
for module in $$modules; do \
$(call echo-do, $2); \
done; \
fi;
endef
install: docs
@echo
@echo \*\* CONFIG: prefix = $(prefix) \*\*
@echo
install -d $(PATH_BIN) $(PATH_INSTALL_LIB)
cp *.py $(PATH_INSTALL_LIB)
install -d $(PATH_INSTALL_LIB)/cmd_internals
cp cmd_internals/*.py $(PATH_INSTALL_LIB)/cmd_internals
$(call with-py-executables, \
ln -fs $(call libpath, $$module) $(PATH_BIN)/$(progname), \
ln -fs $(call libpath, $$module) $(PATH_BIN)/$(call subcommand, $$module))
ln -fs $(call libpath, cmd.py) $(PATH_BIN)/$(progname)
uninstall:
rm -rf $(PATH_INSTALL_LIB)
$(call with-py-executables, \
rm -f $(PATH_BIN)/$(progname), \
rm -f $(PATH_BIN)/$(call subcommand, $$module))
clean:
$(MAKE) -C docs clean
rm -f {,*/}*.pyc {,*/}*.pyo
@emptydirs=$$(find -type d -empty); \
if [ "$$emptydirs" ]; then \
echo rmdir $$emptydirs; \
rmdir $$emptydirs; \
fi
.PHONY: all debug dist docs help install uninstall clean