Merge pull request #5996 from janh/filterwin2k-description
[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 --verbose --no-abbrev --contains 2>/dev/null | \
117 sed -rne 's|^[^/]+/([^ ]+) [a-f0-9]{40} .+$$|\1|p' | head -n1)"; \
118 if [ "$$branch" != "master" ]; then \
119 variant="LuCI $$branch branch"; \
120 else \
121 variant="LuCI Master"; \
122 fi; \
123 fi; \
124 echo "$$variant" \
125 )))
126
127 include $(INCLUDE_DIR)/package.mk
128
129 # LUCI_SUBMENU: the submenu-item below the LuCI top-level menu inside OpoenWrt menuconfig
130 # usually one of the LUCI_MENU.* definitions
131 # LUCI_SUBMENU_DEFAULT: the regular SUBMENU defined by LUCI_TYPE or derrived from the packagename
132 # LUCI_SUBMENU_FORCED: manually forced value SUBMENU to set to by explicit definiton
133 # can be any string, "none" disables the creation of a submenu
134 # most usefull in combination with LUCI_CATEGORY, to make the package appear
135 # anywhere in the menu structure
136 LUCI_SUBMENU_DEFAULT=$(if $(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.app))
137 LUCI_SUBMENU=$(if $(LUCI_SUBMENU_FORCED),$(LUCI_SUBMENU_FORCED),$(LUCI_SUBMENU_DEFAULT))
138
139 define Package/$(PKG_NAME)
140 SECTION:=$(LUCI_SECTION)
141 CATEGORY:=$(LUCI_CATEGORY)
142 ifneq ($(LUCI_SUBMENU),none)
143 SUBMENU:=$(LUCI_SUBMENU)
144 endif
145 TITLE:=$(if $(LUCI_TITLE),$(LUCI_TITLE),LuCI $(LUCI_NAME) $(LUCI_TYPE))
146 DEPENDS:=$(LUCI_DEPENDS)
147 VERSION:=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))
148 $(if $(LUCI_EXTRA_DEPENDS),EXTRA_DEPENDS:=$(LUCI_EXTRA_DEPENDS))
149 $(if $(LUCI_PKGARCH),PKGARCH:=$(LUCI_PKGARCH))
150 $(if $(PKG_PROVIDES),PROVIDES:=$(PKG_PROVIDES))
151 URL:=$(LUCI_URL)
152 MAINTAINER:=$(LUCI_MAINTAINER)
153 endef
154
155 ifneq ($(LUCI_DESCRIPTION),)
156 define Package/$(PKG_NAME)/description
157 $(strip $(LUCI_DESCRIPTION))
158 endef
159 endif
160
161 define Build/Prepare
162 for d in luasrc htdocs root src; do \
163 if [ -d ./$$$$d ]; then \
164 mkdir -p $(PKG_BUILD_DIR)/$$$$d; \
165 $(CP) ./$$$$d/* $(PKG_BUILD_DIR)/$$$$d/; \
166 fi; \
167 done
168 $(call Build/Prepare/Default)
169 endef
170
171 define Build/Configure
172 endef
173
174 ifneq ($(wildcard ${CURDIR}/src/Makefile),)
175 MAKE_PATH := src/
176 MAKE_VARS += FPIC="$(FPIC)" LUCI_VERSION="$(PKG_SRC_VERSION)" LUCI_GITBRANCH="$(PKG_GITBRANCH)"
177
178 define Build/Compile
179 $(call Build/Compile/Default,clean compile)
180 endef
181 else
182 define Build/Compile
183 endef
184 endif
185
186 define Package/$(PKG_NAME)/install
187
188 ifneq ($(wildcard ${CURDIR}/luasrc),)
189 $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR)
190 cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/
191 $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm
192 $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true)
193 $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/)
194 endif
195 ifneq ($(wildcard ${CURDIR}/htdocs),)
196 $(INSTALL_DIR) $(1)$(HTDOCS)
197 cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/
198 $(if $(CONFIG_LUCI_JSMIN),$(call JsMin,$(1)$(HTDOCS)/),true)
199 $(if $(CONFIG_LUCI_CSSTIDY),$(call CssTidy,$(1)$(HTDOCS)/),true)
200 endif
201 ifneq ($(wildcard ${CURDIR}/root),)
202 $(INSTALL_DIR) $(1)/
203 cp -pR $(PKG_BUILD_DIR)/root/* $(1)/
204 endif
205 ifneq ($(wildcard ${CURDIR}/src),)
206 $(call Build/Install/Default)
207 $(CP) $(PKG_INSTALL_DIR)/* $(1)/
208 endif
209 endef
210
211 ifndef Package/$(PKG_NAME)/postinst
212 define Package/$(PKG_NAME)/postinst
213 [ -n "$${IPKG_INSTROOT}" ] || { \
214 rm -f /tmp/luci-indexcache
215 rm -rf /tmp/luci-modulecache/
216 killall -HUP rpcd 2>/dev/null
217 exit 0
218 }
219 endef
220 endif
221
222 # some generic macros that can be used by all packages
223 ifeq ($(LUCI_MINIFY_JS),1)
224 define SrcDiet
225 $(FIND) $(1) -type f -name '*.lua' | while read src; do \
226 if LUA_PATH="$(STAGING_DIR_HOSTPKG)/lib/lua/5.1/?.lua" luasrcdiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; \
227 then mv "$$$$src.o" "$$$$src"; fi; \
228 done
229 endef
230 else
231 define SrcDiet
232 $$(call MESSAGE,$$(LUCI_NAME) does not support Lua source minification)
233 endef
234 endif
235
236 ifeq ($(LUCI_MINIFY_JS),1)
237 define JsMin
238 $(FIND) $(1) -type f -name '*.js' | while read src; do \
239 if jsmin < "$$$$src" > "$$$$src.o"; \
240 then mv "$$$$src.o" "$$$$src"; fi; \
241 done
242 endef
243 else
244 define JsMin
245 $$(call MESSAGE,$$(LUCI_NAME) does not support JavaScript source minification)
246 endef
247 endif
248
249 ifeq ($(LUCI_MINIFY_CSS),1)
250 define CssTidy
251 $(FIND) $(1) -type f -name '*.css' | while read src; do \
252 if csstidy "$$$$src" --template=highest --remove_last_semicolon=true "$$$$src.o"; \
253 then mv "$$$$src.o" "$$$$src"; fi; \
254 done
255 endef
256 else
257 define CssTidy
258 $$(call MESSAGE,$$(LUCI_NAME) does not support CSS source minification)
259 endef
260 endif
261
262 define SubstituteVersion
263 $(FIND) $(1) -type f -name '*.htm' | while read src; do \
264 $(SED) 's/<%# *\([^ ]*\)PKG_VERSION *%>/\1$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))/g' \
265 -e 's/"\(<%= *\(media\|resource\) *%>[^"]*\.\(js\|css\)\)"/"\1?v=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))"/g' \
266 "$$$$src"; \
267 done
268 endef
269
270 # additional setting luci-base package
271 ifeq ($(PKG_NAME),luci-base)
272 define Package/luci-base/config
273 config LUCI_SRCDIET
274 bool "Minify Lua sources"
275 default n
276
277 config LUCI_JSMIN
278 bool "Minify JavaScript sources"
279 default y
280
281 config LUCI_CSSTIDY
282 bool "Minify CSS files"
283 default y
284
285 menu "Translations"$(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)),
286
287 config LUCI_LANG_$(lang)
288 tristate "$(shell echo '$(LUCI_LANG.$(lang))' | sed -e 's/^.* (\(.*\))$$/\1/') ($(lang))"))
289
290 endmenu
291 endef
292 endif
293
294
295 LUCI_BUILD_PACKAGES := $(PKG_NAME)
296
297 # 1: LuCI language code
298 # 2: BCP 47 language tag
299 define LuciTranslation
300 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)
301 SECTION:=luci
302 CATEGORY:=LuCI
303 TITLE:=$(PKG_NAME) - $(1) translation
304 HIDDEN:=1
305 DEFAULT:=LUCI_LANG_$(2)||(ALL&&m)
306 DEPENDS:=$(PKG_NAME)
307 VERSION:=$(PKG_PO_VERSION)
308 PKGARCH:=all
309 endef
310
311 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/description
312 Translation for $(PKG_NAME) - $(LUCI_LANG.$(2))
313 endef
314
315 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/install
316 $$(INSTALL_DIR) $$(1)/etc/uci-defaults
317 echo "uci set luci.languages.$(subst -,_,$(1))='$(LUCI_LANG.$(2))'; uci commit luci" \
318 > $$(1)/etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
319 $$(INSTALL_DIR) $$(1)$(LUCI_LIBRARYDIR)/i18n
320 $(foreach po,$(wildcard ${CURDIR}/po/$(2)/*.po), \
321 po2lmo $(po) \
322 $$(1)$(LUCI_LIBRARYDIR)/i18n/$(basename $(notdir $(po))).$(1).lmo;)
323 endef
324
325 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/postinst
326 [ -n "$$$${IPKG_INSTROOT}" ] || {
327 (. /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)) && rm -f /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
328 exit 0
329 }
330 endef
331
332 LUCI_BUILD_PACKAGES += luci-i18n-$(LUCI_BASENAME)-$(1)
333
334 endef
335
336 $(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)),$(eval $(call LuciTranslation,$(firstword $(LUCI_LC_ALIAS.$(lang)) $(lang)),$(lang)))))
337 $(foreach pkg,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(pkg))))