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