Debian Codegraph @

Makefile

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 # This makefile contains all recipes to build and manage the FreeDict
2 # tools, including the API. It also provides targets to build a release archive
3 # with the latest tools included.
4
5 FREEDICT_TOOLS ?= .
6 include $(FREEDICT_TOOLS)/mk/config.mk
7
8 VERSION = 0.4
9 PREFIX ?= usr
10 DESTDIR ?=
11 INSTALLDIR ?= $(abspath $(DESTDIR)/$(PREFIX)/share/freedict)
12
13 dirs = api JMdict lib mk xquery xsl/inc
14 TARGET_INSTALL_DIRS = $(addprefix $(INSTALLDIR)/tools/, $(dirs))
15
16
17 api: #! generate the api with information about all dictionaries and their downloads at the configured api path
18 api:
19 $(call mount_or_reuse); \
20 $(call exc_pyscript,fd_api) || sleep 1; \
21 $(call umount_or_keep)
22 @$(MAKE) -C $(FREEDICT_TOOLS) --no-print-directory api-validation
23
24 # allow retrieval of API path from Makefile and from rule below
25 get_api_path=$(call exc_pyscript,fd_file_mgr,-a) | tr -d '\n'
26 api-path: #! print the output directory to the generated API file (read from configuration) (trailing newline is removed)
27 @$(call get_api_path)
28
29 api-validation: #! validate the freedict-database.xml against its RNG schema
30 xmllint --noout --relaxng freedict-database.rng $(shell $(call get_api_path))/freedict-database.xml
31
32
33
34
35 mount: #! mount or synchronize FreeDict releases / generated dictionaries
36 $(call exc_pyscript,fd_file_mgr,-m)
37
38 need-update: #! queries for unreleased dictionaries or for those with newer source changes
39 @$(call mount_or_reuse); \
40 $(call exc_pyscript,fd_api,-n)\
41 || sleep 1; \
42 $(call umount_or_keep)
43
44 umount: #! runs umount / clean up actions for unmounting remote volumes (if SSH is used)
45 @$(call exc_pyscript,fd_file_mgr,-u)
46
47 $(BUILD_DIR)/freedict-tools-$(VERSION).tar.bz2: Makefile* *.pl
48 ifeq ($(wildcard $(BUILD_DIR)),)
49 mkdir -p $(BUILD_DIR)
50 endif
51 tar --totals --exclude="*/.svn/*" --exclude="*/.*" \
52 --exclude="*/charlint*" --exclude="*/UnicodeData.txt" \
53 --exclude="*/ergane/jet4/*" \
54 --exclude="*/ergane/unzip/*" \
55 --exclude="*/ergane/zip/*" \
56 --exclude="*/__pycache__/*" \
57 -cvjf $@ ../tools
58
59 install-deps: #! probe current operating system to install build prerequisites for dictionary development
60 echo -n "Do you want to use unison or sshfs? Enter one of them or nothing: "; \
61 read ACCESS_METHOD; \
62 if command -v apt-get; then \
63 sudo apt-get install unzip tar xsltproc libxml-libxml-perl python3 $$ACCESS_METHOD; \
64 elif command -v pacman; then \
65 if [ `uname -o` = 'GNU/Linux' ]; then \
66 sudo pacman -S unzip tar libxslt libxml-perl python $$ACCESS_METHOD; \
67 else \
68 echo "Sorry, but it seems you're not running pacman on GNU/Linux. There's currently no installation rule for this platform."; \
69 fi; \
70 else \
71 echo "Unknown platform. Feel free to report the corresponding packages to us."; \
72 fi
73
74
75 # This helps to express \n as a special variable to Make; it **needs** two
76 # newlines within the define
77 define newline
78
79
80 endef
81
82 # This may not contain apostrophes
83 define VENV_HELP
84 A virtual environment is a local copy of all Python utilities, scripts and
85 libraries for Python development. With a virtual environment, you do not need to
86 install all the FreeDict scripts globally in your system, but you are of course
87 free to do so. The mk_venv command will make sure that the virtual environment
88 is created at the correct place; use "P=/some/path" to specify the path.
89 Example:
90 make mk_venv P=../fd-venv
91 NOTE: If you have not pkg-config on your system, you need to manually set the
92 environment variable ICU_VERSION to the version of libicu on your system.
93 This is due to some internal restructuring of the libicu library that we
94 depend on.
95 After installation, you will be asked whether the virtual environment should be
96 added to the FreeDict configuration. This is generally a good idea, because this
97 means that the FreeDict build system will take care of all the required steps.
98 endef
99
100 mk_venv-help:
101 echo -e '$(subst $(newline),\n,${VENV_HELP})'
102
103 mk_venv: #! initialise a new (Python) virtual environment; use mk_venv-help for detailled help
104 @if [ "${P}" = '' ]; then \
105 echo Need to give a path with P=, e.g. "make mk_venv P=/some/dir"; \
106 exit 222; fi
107 @if ! command -v virtualenv &> /dev/null; then \
108 echo '`virtualenv` not found, please install it and try again.'; exit 10; \
109 fi
110 @virtualenv -q -p $(PYTHON) ${P}
111 @if [ -z "$(ICU_VERSION)" ]; then \
112 if ! command -v pkg-config; then \
113 echo "Environment variable ICU_VERSION unset and 'pkg-config' not found."; \
114 echo "Please set ICU_VERSION to the version of libicu installed on your system."; \
115 exit 127; \
116 fi; \
117 export ICU_VERSION=`pkg-config --modversion icu-i18n`; \
118 fi; \
119 source ${P}/bin/activate; pip install -r requirements.txt
120 @if [ "$(FREEDICTRC)" = "" ]; then \
121 echo "You don't have a FreeDict configuration yet. Please create one, "; \
122 echo 'as described in the chapter "Build System" of the FreeDict HOWTO';\
123 echo "from the Wiki";fi
124 if ! [ -f $(FREEDICTRC) ]; then \
125 NO_CONF=1; \
126 elif ! grep virtual_env < $(FREEDICTRC) &> /dev/null; then \
127 NO_CONF=1; \
128 else NO_CONF=0; \
129 fi; \
130 if [ $$NO_CONF -eq 1 ]; then \
131 echo -n "Do you want to add the virtual_env to the FreeDict configuration? [y|n] "; \
132 read CHOICE;\
133 if [ "$$CHOICE" = "y" ]; then \
134 mkdir -p $(dir $(FREEDICTRC));\
135 touch $(FREEDICTRC);\
136 PATH=$(abspath ${P}); \
137 if ! grep -r '[DEFAULT]' $(FREEDICTRC) &> /dev/null; then \
138 echo >> $(FREEDICTRC);\
139 echo '[DEFAULT]' >> $(FREEDICTRC); \
140 echo "virtual_env = $$PATH" >> $(FREEDICTRC) ;\
141 else \
142 sed -i 's|\[DEFAULT\]|[DEFAULT]\nvirtual_env = '$$PATH'|' $(FREEDICTRC); \
143 fi; \
144 echo done; \
145 fi; \
146 fi
147
148 # NOTE: the directories below HAVE to be on one line
149 INSTALL_DIRS := api api/generator api/file_manager api/generator/apigen mk xquery xsl/inc
150 INSTALL_PATHS := $(wildcard api/*.py api/generator/*.py api/generator/apigen/*.py api/file_manager/*.py \
151 freedict-database.rng \
152 mk/*.mk xsl/inc/* \
153 xquery/* xsl/tei2c5.xsl)
154 install: #! install the tools to $$DESTDIR/$PREFIX/share/freedict (default /usr/local/share/freedict)
155 install:
156 @echo Creating directories in $(INSTALLDIR)…
157 @set -e; for d in $(INSTALL_DIRS); do \
158 install -d $(INSTALLDIR)/$$d; \
159 done
160 @echo Copying files to $(INSTALLDIR)…
161 @set -e; for f in $(INSTALL_PATHS); do \
162 if [ -f $$f ]; then \
163 install -m 644 $$f $(INSTALLDIR)/$$f; \
164 fi \
165 done
166
167
168
169
170 release: #! build a release tarball in $$BUILD_DIR, ../build by default
171 release: $(BUILD_DIR)/freedict-tools-$(VERSION).tar.bz2
172
173 release-path: #! print the output directory to which releases are deployed (read from configuration); trailing newline is removed
174 @$(call exc_pyscript,fd_file_mgr,-r) | tr -d '\n'
175
176 .PHONY: release install api all mount umount api-validation