luci.mk 11 KB

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