Minor cleanups
[quicknote] / Makefile
1 PROJECT_NAME=quicknote
2 PROJECT_VERSION=0.7.8
3 SOURCE_PATH=src
4 SOURCE=$(shell find $(SOURCE_PATH) -iname "*.py")
5 LOCALE_PATH=locale
6 LOCALE_FILES=$(shell find $(LOCALE_PATH) -iname "*.mo")
7 PROGRAM=$(SOURCE_PATH)/$(PROJECT_NAME).py
8 OBJ=$(SOURCE:.py=.pyc)
9 BUILD_PATH=./builddeb/
10
11 TEXT_DOMAIN=$(PROJECT_NAME)
12 POTFILES=$(wildcard src/quicknoteclasses/*.py)
13
14 UNIT_TEST=nosetests --with-doctest -w .
15 SYNTAX_TEST=support/test_syntax.py
16 STYLE_TEST=../../Python/tools/pep8.py --ignore=W191,E501
17 LINT_RC=./support/pylint.rc
18 LINT=pylint --rcfile=$(LINT_RC)
19 PROFILE_GEN=python -m cProfile -o .profile
20 PROFILE_VIEW=python -m pstats .profile
21 TODO_FINDER=support/todo.py
22 CTAGS=ctags-exuberant
23
24 .PHONY: all run profile debug test lint tags todo clean distclean install update_po build_mo
25
26 all: test
27
28 run: $(OBJ)
29         $(PROGRAM)
30
31 profile: $(OBJ)
32         $(PROFILE_GEN) $(PROGRAM)
33         $(PROFILE_VIEW)
34
35 debug: $(OBJ)
36         $(DEBUGGER) $(PROGRAM)
37
38 test: $(OBJ)
39         $(UNIT_TEST)
40
41 package: clean $(OBJ) all
42         dpkg-buildpackage -rfakeroot 
43         dpkg -i ../$(PROJECT_NAME)_$(PROJECT_VERSION)_all.deb
44
45 update_po: po/templates.pot
46         @for lang in $(basename $(notdir $(wildcard po/*.po))); do \
47                 msgmerge -U --strict --no-wrap po/$$lang.po po/templates.pot; \
48         done
49
50 po/templates.pot: $(POTFILES)
51         xgettext --language=Python --strict --no-wrap --output=$@ $(POTFILES)
52
53 build_mo:
54         @for lang in $(basename $(notdir $(wildcard po/*.po))); do \
55                 mkdir -p locale/$$lang/LC_MESSAGES; \
56                 msgfmt --statistics -c -o locale/$$lang/LC_MESSAGES/$(TEXT_DOMAIN).mo po/$$lang.po; \
57         done
58
59 build: $(OBJ) build_mo
60         rm -Rf $(BUILD_PATH)
61         mkdir $(BUILD_PATH)
62         cp $(PROGRAM)  $(BUILD_PATH)
63         cp src/constants.py $(BUILD_PATH)
64         $(foreach file, $(DATA), cp $(file) $(BUILD_PATH)/$(subst /,-,$(file)) ; )
65         $(foreach file, $(SOURCE), cp $(file) $(BUILD_PATH)/$(subst /,-,$(file)) ; )
66         $(foreach file, $(OBJ), cp $(file) $(BUILD_PATH)/$(subst /,-,$(file)) ; )
67         $(foreach file, $(LOCALE_FILES), cp $(file) $(BUILD_PATH)/$(subst /,-,$(file)) ; )
68         cp data/$(PROJECT_NAME).desktop $(BUILD_PATH)
69         cp data/$(PROJECT_NAME).service $(BUILD_PATH)
70         cp data/low/$(PROJECT_NAME).png $(BUILD_PATH)/26x26-$(PROJECT_NAME).png
71         cp data/40/$(PROJECT_NAME).png $(BUILD_PATH)/40x40-$(PROJECT_NAME).png
72         cp data/48/$(PROJECT_NAME).png $(BUILD_PATH)/48x48-$(PROJECT_NAME).png
73         cp data/scale/$(PROJECT_NAME).png $(BUILD_PATH)/scale-$(PROJECT_NAME).png
74         cp support/builddeb.py $(BUILD_PATH)
75         cp support/fake_py2deb.py $(BUILD_PATH)
76
77 lint: $(OBJ)
78         $(foreach file, $(SOURCE), $(LINT) $(file) ; )
79
80 tags: $(TAG_FILE) 
81
82 todo: $(TODO_FILE)
83
84 clean:
85         rm -rf ./locale
86         rm -Rf $(OBJ)
87         rm -Rf $(BUILD_PATH)
88         rm -Rf $(TODO_FILE)
89
90 distclean:
91         rm -Rf $(OBJ)
92         rm -Rf $(BUILD_PATH)
93         rm -Rf $(TAG_FILE)
94         find $(SOURCE_PATH) -name "*.*~" | xargs rm -f
95         find $(SOURCE_PATH) -name "*.swp" | xargs rm -f
96         find $(SOURCE_PATH) -name "*.bak" | xargs rm -f
97         find $(SOURCE_PATH) -name ".*.swp" | xargs rm -f
98
99 $(TAG_FILE): $(OBJ)
100         mkdir -p $(dir $(TAG_FILE))
101         $(CTAGS) -o $(TAG_FILE) $(SOURCE)
102
103 $(TODO_FILE): $(SOURCE)
104         @- $(TODO_FINDER) $(SOURCE) > $(TODO_FILE)
105
106 %.pyc: %.py
107         $(SYNTAX_TEST) $<
108
109 #Makefile Debugging
110 #Target to print any variable, can be added to the dependencies of any other target
111 #Userfule flags for make, -d, -p, -n
112 print-%: ; @$(error $* is $($*) ($(value $*)) (from $(origin $*)))