luci.mk: adjust path of purged index cache files
[project/luci.git] / luci.mk
1 #
2 # Copyright (C) 2008-2015 The LuCI Team <luci@lists.subsignal.org>
3 #
4 # This is free software, licensed under the Apache License, Version 2.0 .
5 #
6
7 LUCI_NAME?=$(notdir ${CURDIR})
8 LUCI_TYPE?=$(word 2,$(subst -, ,$(LUCI_NAME)))
9 LUCI_BASENAME?=$(patsubst luci-$(LUCI_TYPE)-%,%,$(LUCI_NAME))
10 LUCI_LANGUAGES:=$(sort $(filter-out templates,$(notdir $(wildcard ${CURDIR}/po/*))))
11 LUCI_DEFAULTS:=$(notdir $(wildcard ${CURDIR}/root/etc/uci-defaults/*))
12 LUCI_PKGARCH?=$(if $(realpath src/Makefile),,all)
13 LUCI_SECTION?=luci
14 LUCI_CATEGORY?=LuCI
15 LUCI_URL?=https://github.com/openwrt/luci
16 LUCI_MAINTAINER?=OpenWrt LuCI community
17 LUCI_MINIFY_LUA?=1
18 LUCI_MINIFY_CSS?=1
19 LUCI_MINIFY_JS?=1
20
21 # Language code titles
22 LUCI_LANG.ar=العربية (Arabic)
23 LUCI_LANG.bg=български (Bulgarian)
24 LUCI_LANG.bn_BD=বাংলা (Bengali)
25 LUCI_LANG.ca=Català (Catalan)
26 LUCI_LANG.cs=Čeština (Czech)
27 LUCI_LANG.da=Dansk (Danish)
28 LUCI_LANG.de=Deutsch (German)
29 LUCI_LANG.el=Ελληνικά (Greek)
30 LUCI_LANG.es=Español (Spanish)
31 LUCI_LANG.fi=Suomi (Finnish)
32 LUCI_LANG.fr=Français (French)
33 LUCI_LANG.he=עִבְרִית (Hebrew)
34 LUCI_LANG.hi=हिंदी (Hindi)
35 LUCI_LANG.hu=Magyar (Hungarian)
36 LUCI_LANG.it=Italiano (Italian)
37 LUCI_LANG.ja=日本語 (Japanese)
38 LUCI_LANG.ko=한국어 (Korean)
39 LUCI_LANG.mr=Marāṭhī (Marathi)
40 LUCI_LANG.ms=Bahasa Melayu (Malay)
41 LUCI_LANG.nb_NO=Norsk (Norwegian)
42 LUCI_LANG.nl=Nederlands (Dutch)
43 LUCI_LANG.pl=Polski (Polish)
44 LUCI_LANG.pt_BR=Português do Brasil (Brazilian Portuguese)
45 LUCI_LANG.pt=Português (Portuguese)
46 LUCI_LANG.ro=Română (Romanian)
47 LUCI_LANG.ru=Русский (Russian)
48 LUCI_LANG.sk=Slovenčina (Slovak)
49 LUCI_LANG.sv=Svenska (Swedish)
50 LUCI_LANG.tr=Türkçe (Turkish)
51 LUCI_LANG.uk=Українська (Ukrainian)
52 LUCI_LANG.vi=Tiếng Việt (Vietnamese)
53 LUCI_LANG.zh_Hans=简体中文 (Chinese Simplified)
54 LUCI_LANG.zh_Hant=繁體中文 (Chinese Traditional)
55
56 # Submenu titles
57 LUCI_MENU.col=1. Collections
58 LUCI_MENU.mod=2. Modules
59 LUCI_MENU.app=3. Applications
60 LUCI_MENU.theme=4. Themes
61 LUCI_MENU.proto=5. Protocols
62 LUCI_MENU.lib=6. Libraries
63
64 # Language aliases
65 LUCI_LC_ALIAS.bn_BD=bn
66 LUCI_LC_ALIAS.nb_NO=no
67 LUCI_LC_ALIAS.pt_BR=pt-br
68 LUCI_LC_ALIAS.zh_Hans=zh-cn
69 LUCI_LC_ALIAS.zh_Hant=zh-tw
70
71 # Default locations
72 HTDOCS = /www
73 LUA_LIBRARYDIR = /usr/lib/lua
74 LUCI_LIBRARYDIR = $(LUA_LIBRARYDIR)/luci
75
76
77 # 1: everything expect po subdir or only po subdir
78 define findrev
79 $(shell \
80 if git log -1 >/dev/null 2>/dev/null; then \
81 set -- $$(git log -1 --format="%ct %h" --abbrev=7 -- $(if $(1),. ':(exclude)po',po)); \
82 if [ -n "$$1" ]; then
83 secs="$$(($$1 % 86400))"; \
84 yday="$$(date --utc --date="@$$1" "+%y.%j")"; \
85 printf 'git-%s.%05d-%s' "$$yday" "$$secs" "$$2"; \
86 else \
87 echo "unknown"; \
88 fi; \
89 else \
90 ts=$$(find . -type f $(if $(1),-not) -path './po/*' -printf '%T@\n' 2>/dev/null | sort -rn | head -n1 | cut -d. -f1); \
91 if [ -n "$$ts" ]; then \
92 secs="$$(($$ts % 86400))"; \
93 date="$$(date --utc --date="@$$ts" "+%y%m%d")"; \
94 printf '%s.%05d' "$$date" "$$secs"; \
95 else \
96 echo "unknown"; \
97 fi; \
98 fi \
99 )
100 endef
101
102 PKG_NAME?=$(LUCI_NAME)
103 PKG_RELEASE?=1
104 PKG_INSTALL:=$(if $(realpath src/Makefile),1)
105 PKG_BUILD_DEPENDS += lua/host luci-base/host LUCI_CSSTIDY:csstidy/host LUCI_SRCDIET:luasrcdiet/host $(LUCI_BUILD_DEPENDS)
106 PKG_CONFIG_DEPENDS += CONFIG_LUCI_SRCDIET CONFIG_LUCI_JSMIN CONFIG_LUCI_CSSTIDY
107
108 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
109
110 PKG_PO_VERSION?=$(if $(DUMP),x,$(strip $(call findrev)))
111 PKG_SRC_VERSION?=$(if $(DUMP),x,$(strip $(call findrev,1)))
112
113 PKG_GITBRANCH?=$(if $(DUMP),x,$(strip $(shell \
114 variant="LuCI"; \
115 if git log -1 >/dev/null 2>/dev/null; then \
116 branch=$$(git branch --remote --no-abbrev --contains 2>/dev/null | tail -n1); \
117 branch=$${branch:-$$(git branch --no-abbrev --contains 2>/dev/null)}; \
118 branch=$${branch#? }; branch=$${branch#*/}; \
119 if [ "$$branch" != "master" ]; then \
120 variant="LuCI $${branch:-unknown} branch"; \
121 else \
122 variant="LuCI Master"; \
123 fi; \
124 fi; \
125 echo "$$variant" \
126 )))
127
128 include $(INCLUDE_DIR)/package.mk
129
130 # LUCI_SUBMENU: the submenu-item below the LuCI top-level menu inside OpenWrt menuconfig
131 # usually one of the LUCI_MENU.* definitions
132 # LUCI_SUBMENU_DEFAULT: the regular SUBMENU defined by LUCI_TYPE or derrived from the packagename
133 # LUCI_SUBMENU_FORCED: manually forced value SUBMENU to set to by explicit definiton
134 # can be any string, "none" disables the creation of a submenu
135 # most usefull in combination with LUCI_CATEGORY, to make the package appear
136 # anywhere in the menu structure
137 LUCI_SUBMENU_DEFAULT=$(if $(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.app))
138 LUCI_SUBMENU=$(if $(LUCI_SUBMENU_FORCED),$(LUCI_SUBMENU_FORCED),$(LUCI_SUBMENU_DEFAULT))
139
140 define Package/$(PKG_NAME)
141 SECTION:=$(LUCI_SECTION)
142 CATEGORY:=$(LUCI_CATEGORY)
143 ifneq ($(LUCI_SUBMENU),none)
144 SUBMENU:=$(LUCI_SUBMENU)
145 endif
146 TITLE:=$(if $(LUCI_TITLE),$(LUCI_TITLE),LuCI $(LUCI_NAME) $(LUCI_TYPE))
147 DEPENDS:=$(LUCI_DEPENDS)
148 VERSION:=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))
149 $(if $(LUCI_EXTRA_DEPENDS),EXTRA_DEPENDS:=$(LUCI_EXTRA_DEPENDS))
150 $(if $(LUCI_PKGARCH),PKGARCH:=$(LUCI_PKGARCH))
151 $(if $(PKG_PROVIDES),PROVIDES:=$(PKG_PROVIDES))
152 URL:=$(LUCI_URL)
153 MAINTAINER:=$(LUCI_MAINTAINER)
154 endef
155
156 ifneq ($(LUCI_DESCRIPTION),)
157 define Package/$(PKG_NAME)/description
158 $(strip $(LUCI_DESCRIPTION))
159 endef
160 endif
161
162 define Build/Prepare
163 for d in luasrc htdocs root src; do \
164 if [ -d ./$$$$d ]; then \
165 mkdir -p $(PKG_BUILD_DIR)/$$$$d; \
166 $(CP) ./$$$$d/* $(PKG_BUILD_DIR)/$$$$d/; \
167 fi; \
168 done
169 $(call Build/Prepare/Default)
170 endef
171
172 define Build/Configure
173 endef
174
175 ifneq ($(wildcard ${CURDIR}/src/Makefile),)
176 MAKE_PATH := src/
177 MAKE_VARS += FPIC="$(FPIC)" LUCI_VERSION="$(PKG_SRC_VERSION)" LUCI_GITBRANCH="$(PKG_GITBRANCH)"
178
179 define Build/Compile
180 $(call Build/Compile/Default,clean compile)
181 endef
182 else
183 define Build/Compile
184 endef
185 endif
186
187 define Package/$(PKG_NAME)/install
188
189 ifneq ($(wildcard ${CURDIR}/luasrc),)
190 $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR)
191 cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/
192 $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm
193 $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true)
194 $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/)
195 endif
196 ifneq ($(wildcard ${CURDIR}/htdocs),)
197 $(INSTALL_DIR) $(1)$(HTDOCS)
198 cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/
199 $(if $(CONFIG_LUCI_JSMIN),$(call JsMin,$(1)$(HTDOCS)/),true)
200 $(if $(CONFIG_LUCI_CSSTIDY),$(call CssTidy,$(1)$(HTDOCS)/),true)
201 endif
202 ifneq ($(wildcard ${CURDIR}/root),)
203 $(INSTALL_DIR) $(1)/
204 cp -pR $(PKG_BUILD_DIR)/root/* $(1)/
205 endif
206 ifneq ($(wildcard ${CURDIR}/src),)
207 $(call Build/Install/Default)
208 $(CP) $(PKG_INSTALL_DIR)/* $(1)/
209 endif
210 endef
211
212 ifndef Package/$(PKG_NAME)/postinst
213 define Package/$(PKG_NAME)/postinst
214 [ -n "$${IPKG_INSTROOT}" ] || { \
215 rm -f /tmp/luci-indexcache.*
216 rm -rf /tmp/luci-modulecache/
217 killall -HUP rpcd 2>/dev/null
218 exit 0
219 }
220 endef
221 endif
222
223 # some generic macros that can be used by all packages
224 ifeq ($(LUCI_MINIFY_LUA),1)
225 define SrcDiet
226 $(FIND) $(1) -type f -name '*.lua' | while read src; do \
227 if LUA_PATH="$(STAGING_DIR_HOSTPKG)/lib/lua/5.1/?.lua" luasrcdiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; \
228 then mv "$$$$src.o" "$$$$src"; fi; \
229 done
230 endef
231 else
232 define SrcDiet
233 $$(call MESSAGE,$$(LUCI_NAME) does not support Lua source minification)
234 endef
235 endif
236
237 ifeq ($(LUCI_MINIFY_JS),1)
238 define JsMin
239 $(FIND) $(1) -type f -name '*.js' | while read src; do \
240 if jsmin < "$$$$src" > "$$$$src.o"; \
241 then mv "$$$$src.o" "$$$$src"; fi; \
242 done
243 endef
244 else
245 define JsMin
246 $$(call MESSAGE,$$(LUCI_NAME) does not support JavaScript source minification)
247 endef
248 endif
249
250 ifeq ($(LUCI_MINIFY_CSS),1)
251 define CssTidy
252 $(FIND) $(1) -type f -name '*.css' | while read src; do \
253 if csstidy "$$$$src" --template=highest --remove_last_semicolon=true "$$$$src.o"; \
254 then mv "$$$$src.o" "$$$$src"; fi; \
255 done
256 endef
257 else
258 define CssTidy
259 $$(call MESSAGE,$$(LUCI_NAME) does not support CSS source minification)
260 endef
261 endif
262
263 define SubstituteVersion
264 $(FIND) $(1) -type f -name '*.htm' | while read src; do \
265 $(SED) 's/<%# *\([^ ]*\)PKG_VERSION *%>/\1$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))/g' \
266 -e 's/"\(<%= *\(media\|resource\) *%>[^"]*\.\(js\|css\)\)"/"\1?v=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))"/g' \
267 "$$$$src"; \
268 done
269 endef
270
271 # additional setting luci-base package
272 ifeq ($(PKG_NAME),luci-base)
273 define Package/luci-base/config
274 config LUCI_SRCDIET
275 bool "Minify Lua sources"
276 default n
277
278 config LUCI_JSMIN
279 bool "Minify JavaScript sources"
280 default y
281
282 config LUCI_CSSTIDY
283 bool "Minify CSS files"
284 default y
285
286 menu "Translations"$(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)),
287
288 config LUCI_LANG_$(lang)
289 tristate "$(shell echo '$(LUCI_LANG.$(lang))' | sed -e 's/^.* (\(.*\))$$/\1/') ($(lang))"))
290
291 endmenu
292 endef
293 endif
294
295
296 LUCI_BUILD_PACKAGES := $(PKG_NAME)
297
298 # 1: LuCI language code
299 # 2: BCP 47 language tag
300 define LuciTranslation
301 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)
302 SECTION:=luci
303 CATEGORY:=LuCI
304 TITLE:=$(PKG_NAME) - $(1) translation
305 HIDDEN:=1
306 DEFAULT:=LUCI_LANG_$(2)||(ALL&&m)
307 DEPENDS:=$(PKG_NAME)
308 VERSION:=$(PKG_PO_VERSION)
309 PKGARCH:=all
310 endef
311
312 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/description
313 Translation for $(PKG_NAME) - $(LUCI_LANG.$(2))
314 endef
315
316 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/install
317 $$(INSTALL_DIR) $$(1)/etc/uci-defaults
318 echo "uci set luci.languages.$(subst -,_,$(1))='$(LUCI_LANG.$(2))'; uci commit luci" \
319 > $$(1)/etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
320 $$(INSTALL_DIR) $$(1)$(LUCI_LIBRARYDIR)/i18n
321 $(foreach po,$(wildcard ${CURDIR}/po/$(2)/*.po), \
322 po2lmo $(po) \
323 $$(1)$(LUCI_LIBRARYDIR)/i18n/$(basename $(notdir $(po))).$(1).lmo;)
324 endef
325
326 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/postinst
327 [ -n "$$$${IPKG_INSTROOT}" ] || {
328 (. /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)) && rm -f /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
329 exit 0
330 }
331 endef
332
333 LUCI_BUILD_PACKAGES += luci-i18n-$(LUCI_BASENAME)-$(1)
334
335 endef
336
337 $(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)),$(eval $(call LuciTranslation,$(firstword $(LUCI_LC_ALIAS.$(lang)) $(lang)),$(lang)))))
338 $(foreach pkg,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(pkg))))