-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
95 lines (74 loc) · 3.16 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
# 2012.10.09 - Giuseppe Sucameli
# This makefile can be used with each pyQGIS plugin.
#
# It searches all the .ui and .qrc files recursively in the current directory
# tree, then it compiles the files it has found according to the following
# schema:
# <srcdir>/<relpath>/<filename>.ui -> <outdir>/<relpath>/<filename>_ui.py
# <srcdir>/<relpath>/<filename>.qrc -> <outdir>/<relpath>/<filename>_rc.py
#
# Use SRCDIR and OUTDIR to override source and/or destination directories.
# macros to generate the output filename from the input filename
ui_in2outname=$(patsubst %.ui,%_ui.py,$(1))
rc_in2outname=$(patsubst %.qrc,%_rc.py,$(1))
# source directory: it's current dir if not specified
SRCDIR?=$(CURDIR)
SRC_DIR:=$(abspath $(SRCDIR))
# the source dir must exist (use realpath to check it)
ifeq ($(realpath $(SRCDIR)),)
abort:
@echo ">>> ERROR: The source dir \"$(SRC_DIR)\" doesn't exist."
endif
# source folder name, used to create the plugin package
PLUGIN_NAME?=$(notdir $(SRC_DIR))
# output directory: it's current dir if not specified
OUTDIR?=$(CURDIR)
OUT_DIR:=$(abspath $(OUTDIR))
# macro to make a recursive wildcard search:
# $1 is the directory tree the search starts from, $2 is the pattern
rwildcard=$(foreach d,$(wildcard $(1)*),$(call rwildcard,$(d)/,$(2))$(filter $(subst *,%,$(2)),$(d)))
# macro to replace $(SRC_DIR) with $(OUT_DIR) in the argument $1
in2outdir=$(patsubst $(SRC_DIR)%,$(OUT_DIR)%,$(1))
# macro to convert the .ui file paths $(1) to the generated .py file paths
ui_in2out=$(foreach f,$(1),$(call in2outdir,$(dir $(f)))$(call ui_in2outname,$(notdir $(f))))
# macro to convert the .qrc file paths $(1) to the generated .py file paths
rc_in2out=$(foreach f,$(1),$(call in2outdir,$(dir $(f)))$(call rc_in2outname,$(notdir $(f))))
# path to the .py files generated by pyuic4 from the .ui files
UI_SOURCES:=$(call rwildcard,$(SRC_DIR),*.ui)
UI_FILES:=$(call ui_in2out,$(UI_SOURCES))
# path to the .py files generated by pyrcc4 from the .qrc files
RC_SOURCES:=$(call rwildcard,$(SRC_DIR),*.qrc)
RC_FILES:=$(call rc_in2out,$(RC_SOURCES))
# rule template to compile .ui files
define UI_template
$(call ui_in2out,$(1)): $(1)
pyuic4 -o $$@ $$<
endef
# for each directory containing .ui files create a rule to compile them
UI_DIRS:=$(sort $(dir $(UI_SOURCES)))
$(foreach d,$(UI_DIRS),$(eval $(call UI_template,$(d)%.ui)))
# rule template to compile .qrc files
define RC_template
$(call rc_in2out,$(1)): $(1)
pyrcc4 -o $$@ $$<
endef
# for each directory containing .qrc files create a rule to compile them
RC_DIRS:=$(sort $(dir $(RC_SOURCES)))
$(foreach d,$(RC_DIRS),$(eval $(call RC_template,$(d)%.qrc)))
all: copyfiles ui rc
ui: $(UI_FILES)
rc: $(RC_FILES)
copyfiles:
ifneq ($(SRC_DIR),$(OUT_DIR))
mkdir -p $(OUT_DIR)
cp -rf $(SRC_DIR)/* $(OUT_DIR)
endif
clean:
rm -rf $(UI_FILES) $(RC_FILES)
# rule to generate a zip package containing all the stuff in the output directory
package: all
@cd $(OUT_DIR)/../ && \
rm -f $(PLUGIN_NAME).zip && \
zip -qr $(PLUGIN_NAME).zip $(PLUGIN_NAME) -x \*.svn* -x \*.pyc -x \*~ -x \*entries\* -x \*.git\* -x \*.skip\* -x \*.settings\* -x \*.project\*
@echo ">>> DONE: Package \"$(abspath $(OUT_DIR)/../)/$(PLUGIN_NAME).zip\" created."
@cd $(CURDIR)