2 # Copyright (C) 2008-2015 The LuCI Team <luci@lists.subsignal.org>
4 # This is free software, licensed under the Apache License, Version 2.0 .
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)
14 # Language code titles
15 LUCI_LANG.bg=български (Bulgarian)
16 LUCI_LANG.bn_BD=বাংলা (Bengali)
17 LUCI_LANG.ca=Català (Catalan)
18 LUCI_LANG.cs=Čeština (Czech)
19 LUCI_LANG.de=Deutsch (German)
20 LUCI_LANG.el=Ελληνικά (Greek)
22 LUCI_LANG.es=Español (Spanish)
23 LUCI_LANG.fr=Français (French)
24 LUCI_LANG.he=עִבְרִית (Hebrew)
25 LUCI_LANG.hi=हिंदी (Hindi)
26 LUCI_LANG.hu=Magyar (Hungarian)
27 LUCI_LANG.it=Italiano (Italian)
28 LUCI_LANG.ja=日本語 (Japanese)
29 LUCI_LANG.ko=한국어 (Korean)
30 LUCI_LANG.mr=Marāṭhī (Marathi)
31 LUCI_LANG.ms=Bahasa Melayu (Malay)
32 LUCI_LANG.nb_NO=Norsk (Norwegian)
33 LUCI_LANG.pl=Polski (Polish)
34 LUCI_LANG.pt_BR=Português do Brasil (Brazilian Portuguese)
35 LUCI_LANG.pt=Português (Portuguese)
36 LUCI_LANG.ro=Română (Romanian)
37 LUCI_LANG.ru=Русский (Russian)
38 LUCI_LANG.sk=Slovenčina (Slovak)
39 LUCI_LANG.sv=Svenska (Swedish)
40 LUCI_LANG.tr=Türkçe (Turkish)
41 LUCI_LANG.uk=Українська (Ukrainian)
42 LUCI_LANG.vi=Tiếng Việt (Vietnamese)
43 LUCI_LANG.zh_Hans=简体中文 (Chinese Simplified)
44 LUCI_LANG.zh_Hant=繁體中文 (Chinese Traditional)
47 LUCI_MENU.col=1. Collections
48 LUCI_MENU.mod=2. Modules
49 LUCI_MENU.app=3. Applications
50 LUCI_MENU.theme=4. Themes
51 LUCI_MENU.proto=5. Protocols
52 LUCI_MENU.lib=6. Libraries
55 LUCI_LC_ALIAS.bn_BD=bn
56 LUCI_LC_ALIAS.nb_NO=no
57 LUCI_LC_ALIAS.pt_BR=pt-br
58 LUCI_LC_ALIAS.zh_Hans=zh-cn
59 LUCI_LC_ALIAS.zh_Hant=zh-tw
62 PKG_NAME?=$(LUCI_NAME)
65 # 1: everything expect po subdir or only po subdir
68 if git log -1 >/dev/null 2>/dev/null; then \
69 set -- $$(git log -1 --format="%ct %h" --abbrev=7 -- $(if $(1),. ':(exclude)po',po)); \
71 secs="$$(($$1 % 86400))"; \
72 yday="$$(date --utc --date="@$$1" "+%y.%j")"; \
73 printf 'git-%s.%05d-%s' "$$yday" "$$secs" "$$2"; \
78 ts=$$(find . -type f $(if $(1),-not) -path './po/*' -printf '%T@\n' 2>/dev/null | sort -rn | head -n1 | cut -d. -f1); \
79 if [ -n "$$ts" ]; then \
80 secs="$$(($$ts % 86400))"; \
81 date="$$(date --utc --date="@$$ts" "+%y%m%d")"; \
82 printf '%s.%05d' "$$date" "$$secs"; \
90 PKG_PO_VERSION?=$(if $(DUMP),x,$(strip $(call findrev)))
91 PKG_SRC_VERSION?=$(if $(DUMP),x,$(strip $(call findrev,1)))
93 PKG_GITBRANCH?=$(if $(DUMP),x,$(strip $(shell \
95 if git log -1 >/dev/null 2>/dev/null; then \
96 branch="$$(git branch --remote --verbose --no-abbrev --contains 2>/dev/null | \
97 sed -rne 's|^[^/]+/([^ ]+) [a-f0-9]{40} .+$$|\1|p' | head -n1)"; \
98 if [ "$$branch" != "master" ]; then \
99 variant="LuCI $$branch branch"; \
101 variant="LuCI Master"; \
108 PKG_INSTALL:=$(if $(realpath src/Makefile),1)
109 PKG_BUILD_DEPENDS += lua/host luci-base/host LUCI_CSSTIDY:csstidy/host LUCI_SRCDIET:luasrcdiet/host $(LUCI_BUILD_DEPENDS)
110 PKG_CONFIG_DEPENDS += CONFIG_LUCI_SRCDIET CONFIG_LUCI_JSMIN CONFIG_LUCI_CSSTIDY
112 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
114 include $(INCLUDE_DIR)/package.mk
116 define Package/$(PKG_NAME)
119 SUBMENU:=$(if $(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.app))
120 TITLE:=$(if $(LUCI_TITLE),$(LUCI_TITLE),LuCI $(LUCI_NAME) $(LUCI_TYPE))
121 DEPENDS:=$(LUCI_DEPENDS)
122 VERSION:=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))
123 $(if $(LUCI_EXTRA_DEPENDS),EXTRA_DEPENDS:=$(LUCI_EXTRA_DEPENDS))
124 $(if $(LUCI_PKGARCH),PKGARCH:=$(LUCI_PKGARCH))
127 ifneq ($(LUCI_DESCRIPTION),)
128 define Package/$(PKG_NAME)/description
129 $(strip $(LUCI_DESCRIPTION))
133 # Language selection for luci-base
134 ifeq ($(PKG_NAME),luci-base)
135 define Package/luci-base/config
137 bool "Minify Lua sources"
141 bool "Minify JavaScript sources"
145 bool "Minify CSS files"
148 menu "Translations"$(foreach lang,$(LUCI_LANGUAGES),
150 config LUCI_LANG_$(lang)
151 tristate "$(shell echo '$(LUCI_LANG.$(lang))' | sed -e 's/^.* (\(.*\))$$/\1/') ($(lang))")
158 for d in luasrc htdocs root src; do \
159 if [ -d ./$$$$d ]; then \
160 mkdir -p $(PKG_BUILD_DIR)/$$$$d; \
161 $(CP) ./$$$$d/* $(PKG_BUILD_DIR)/$$$$d/; \
164 $(call Build/Prepare/Default)
167 define Build/Configure
170 ifneq ($(wildcard ${CURDIR}/src/Makefile),)
172 MAKE_VARS += FPIC="$(FPIC)" LUCI_VERSION="$(PKG_SRC_VERSION)" LUCI_GITBRANCH="$(PKG_GITBRANCH)"
175 $(call Build/Compile/Default,clean compile)
183 LUA_LIBRARYDIR = /usr/lib/lua
184 LUCI_LIBRARYDIR = $(LUA_LIBRARYDIR)/luci
187 $(FIND) $(1) -type f -name '*.lua' | while read src; do \
188 if LUA_PATH="$(STAGING_DIR_HOSTPKG)/lib/lua/5.1/?.lua" luasrcdiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; \
189 then mv "$$$$src.o" "$$$$src"; fi; \
194 $(FIND) $(1) -type f -name '*.js' | while read src; do \
195 if jsmin < "$$$$src" > "$$$$src.o"; \
196 then mv "$$$$src.o" "$$$$src"; fi; \
201 $(FIND) $(1) -type f -name '*.css' | while read src; do \
202 if csstidy "$$$$src" --template=highest --remove_last_semicolon=true "$$$$src.o"; \
203 then mv "$$$$src.o" "$$$$src"; fi; \
207 define SubstituteVersion
208 $(FIND) $(1) -type f -name '*.htm' | while read src; do \
209 $(SED) 's/<%# *\([^ ]*\)PKG_VERSION *%>/\1$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))/g' \
210 -e 's/"\(<%= *\(media\|resource\) *%>[^"]*\.\(js\|css\)\)"/"\1?v=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))"/g' \
215 define Package/$(PKG_NAME)/install
216 if [ -d $(PKG_BUILD_DIR)/luasrc ]; then \
217 $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR); \
218 cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/; \
219 $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm; \
220 $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true); \
221 $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/); \
223 if [ -d $(PKG_BUILD_DIR)/htdocs ]; then \
224 $(INSTALL_DIR) $(1)$(HTDOCS); \
225 cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/; \
226 $(if $(CONFIG_LUCI_JSMIN),$(call JsMin,$(1)$(HTDOCS)/),true); \
227 $(if $(CONFIG_LUCI_CSSTIDY),$(call CssTidy,$(1)$(HTDOCS)/),true); \
229 if [ -d $(PKG_BUILD_DIR)/root ]; then \
230 $(INSTALL_DIR) $(1)/; \
231 cp -pR $(PKG_BUILD_DIR)/root/* $(1)/; \
233 if [ -d $(PKG_BUILD_DIR)/src ]; then \
234 $(call Build/Install/Default) \
235 $(CP) $(PKG_INSTALL_DIR)/* $(1)/; \
239 ifndef Package/$(PKG_NAME)/postinst
240 define Package/$(PKG_NAME)/postinst
241 [ -n "$${IPKG_INSTROOT}" ] || {$(foreach script,$(LUCI_DEFAULTS),
242 (. /etc/uci-defaults/$(script)) && rm -f /etc/uci-defaults/$(script))
243 rm -f /tmp/luci-indexcache
244 rm -rf /tmp/luci-modulecache/
245 killall -HUP rpcd 2>/dev/null
252 LUCI_BUILD_PACKAGES := $(PKG_NAME)
254 # 1: LuCI language code
255 # 2: BCP 47 language tag
256 define LuciTranslation
257 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)
260 TITLE:=$(PKG_NAME) - $(1) translation
262 DEFAULT:=LUCI_LANG_$(2)||(ALL&&m)
264 VERSION:=$(PKG_PO_VERSION)
268 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/description
269 Translation for $(PKG_NAME) - $(LUCI_LANG.$(2))
272 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/install
273 $$(INSTALL_DIR) $$(1)/etc/uci-defaults
274 echo "uci set luci.languages.$(subst -,_,$(1))='$(LUCI_LANG.$(2))'; uci commit luci" \
275 > $$(1)/etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
276 $$(INSTALL_DIR) $$(1)$(LUCI_LIBRARYDIR)/i18n
277 $(foreach po,$(wildcard ${CURDIR}/po/$(2)/*.po), \
279 $$(1)$(LUCI_LIBRARYDIR)/i18n/$(basename $(notdir $(po))).$(1).lmo;)
282 define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/postinst
283 [ -n "$$$${IPKG_INSTROOT}" ] || {
284 (. /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)) && rm -f /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
289 LUCI_BUILD_PACKAGES += luci-i18n-$(LUCI_BASENAME)-$(1)
293 $(foreach lang,$(LUCI_LANGUAGES),$(eval $(call LuciTranslation,$(firstword $(LUCI_LC_ALIAS.$(lang)) $(lang)),$(lang))))
294 $(foreach pkg,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(pkg))))