luci.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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),$(if $(PKG_RELEASE),$(PKG_VERSION)-r$(PKG_RELEASE),$(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/$(LUCI_NAME))
  161. $(call Build/Prepare/Default)
  162. endef
  163. define Build/Configure
  164. endef
  165. ifneq ($(wildcard ${CURDIR}/src/Makefile),)
  166. MAKE_PATH := src/
  167. MAKE_VARS += FPIC="$(FPIC)" LUCI_VERSION="$(PKG_SRC_VERSION)" LUCI_GITBRANCH="$(PKG_GITBRANCH)"
  168. define Build/Compile
  169. $(call Build/Compile/Default,clean compile)
  170. endef
  171. else
  172. define Build/Compile
  173. endef
  174. endif
  175. define Package/$(PKG_NAME)/install
  176. ifneq ($(wildcard ${CURDIR}/luasrc),)
  177. $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR)
  178. cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/
  179. $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm
  180. $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true)
  181. $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/)
  182. endif
  183. ifneq ($(wildcard ${CURDIR}/ucode),)
  184. $(INSTALL_DIR) $(1)$(UCODE_LIBRARYDIR)
  185. cp -pR $(PKG_BUILD_DIR)/ucode/* $(1)$(UCODE_LIBRARYDIR)/
  186. $(call SubstituteVersion,$(1)$(UCODE_LIBRARYDIR)/)
  187. endif
  188. ifneq ($(wildcard ${CURDIR}/htdocs),)
  189. $(INSTALL_DIR) $(1)$(HTDOCS)
  190. cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/
  191. $(if $(CONFIG_LUCI_JSMIN),$(call JsMin,$(1)$(HTDOCS)/),true)
  192. $(if $(CONFIG_LUCI_CSSTIDY),$(call CssTidy,$(1)$(HTDOCS)/),true)
  193. endif
  194. ifneq ($(wildcard ${CURDIR}/root),)
  195. $(INSTALL_DIR) $(1)/
  196. cp -pR $(PKG_BUILD_DIR)/root/* $(1)/
  197. endif
  198. ifneq ($(wildcard ${CURDIR}/src),)
  199. $(call Build/Install/Default)
  200. $(CP) $(PKG_INSTALL_DIR)/* $(1)/
  201. endif
  202. endef
  203. ifndef Package/$(PKG_NAME)/postinst
  204. define Package/$(PKG_NAME)/postinst
  205. [ -n "$${IPKG_INSTROOT}" ] || { \
  206. rm -f /tmp/luci-indexcache.*
  207. rm -rf /tmp/luci-modulecache/
  208. killall -HUP rpcd 2>/dev/null
  209. exit 0
  210. }
  211. endef
  212. endif
  213. # some generic macros that can be used by all packages
  214. ifeq ($(LUCI_MINIFY_LUA),1)
  215. define SrcDiet
  216. $(FIND) $(1) -type f -name '*.lua' | while read src; do \
  217. if LUA_PATH="$(STAGING_DIR_HOSTPKG)/lib/lua/5.1/?.lua" luasrcdiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; \
  218. then mv "$$$$src.o" "$$$$src"; fi; \
  219. done
  220. endef
  221. else
  222. define SrcDiet
  223. $$(call MESSAGE,$$(LUCI_NAME) does not support Lua source minification)
  224. endef
  225. endif
  226. ifeq ($(LUCI_MINIFY_JS),1)
  227. define JsMin
  228. $(FIND) $(1) -type f -name '*.js' | while read src; do \
  229. if jsmin < "$$$$src" > "$$$$src.o"; \
  230. then mv "$$$$src.o" "$$$$src"; fi; \
  231. done
  232. endef
  233. else
  234. define JsMin
  235. $$(call MESSAGE,$$(LUCI_NAME) does not support JavaScript source minification)
  236. endef
  237. endif
  238. ifeq ($(LUCI_MINIFY_CSS),1)
  239. define CssTidy
  240. $(FIND) $(1) -type f -name '*.css' | while read src; do \
  241. if csstidy "$$$$src" --template=highest --remove_last_semicolon=true "$$$$src.o"; \
  242. then mv "$$$$src.o" "$$$$src"; fi; \
  243. done
  244. endef
  245. else
  246. define CssTidy
  247. $$(call MESSAGE,$$(LUCI_NAME) does not support CSS source minification)
  248. endef
  249. endif
  250. define SubstituteVersion
  251. $(FIND) $(1) -type f -name '*.htm' | while read src; do \
  252. $(SED) 's/<%# *\([^ ]*\)PKG_VERSION *%>/\1$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))/g' \
  253. -e 's/"\(<%= *\(media\|resource\) *%>[^"]*\.\(js\|css\)\)"/"\1?v=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))"/g' \
  254. "$$$$src"; \
  255. done; \
  256. $(FIND) $(1) -type f -name '*.ut' | while read src; do \
  257. $(SED) 's/{# *\([^ ]*\)PKG_VERSION *#}/\1$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))/g' \
  258. -e 's/"\({{ *\(media\|resource\) *}}[^"]*\.\(js\|css\)\)"/"\1?v=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))"/g' \
  259. "$$$$src"; \
  260. done
  261. endef
  262. # additional setting luci-base package
  263. ifeq ($(PKG_NAME),luci-base)
  264. define Package/luci-base/config
  265. config LUCI_SRCDIET
  266. bool "Minify Lua sources"
  267. default n
  268. config LUCI_JSMIN
  269. bool "Minify JavaScript sources"
  270. default y
  271. config LUCI_CSSTIDY
  272. bool "Minify CSS files"
  273. default y
  274. menu "Translations"$(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)),
  275. config LUCI_LANG_$(lang)
  276. tristate "$(shell echo '$(LUCI_LANG.$(lang))' | sed -e 's/^.* (\(.*\))$$/\1/') ($(lang))"))
  277. endmenu
  278. endef
  279. endif
  280. LUCI_BUILD_PACKAGES := $(PKG_NAME)
  281. # 1: LuCI language code
  282. # 2: BCP 47 language tag
  283. define LuciTranslation
  284. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)
  285. SECTION:=luci
  286. CATEGORY:=LuCI
  287. TITLE:=$(PKG_NAME) - $(1) translation
  288. HIDDEN:=1
  289. DEFAULT:=LUCI_LANG_$(2)||(ALL&&m)
  290. DEPENDS:=$(PKG_NAME)
  291. VERSION:=$(PKG_PO_VERSION)
  292. PKGARCH:=all
  293. endef
  294. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/description
  295. Translation for $(PKG_NAME) - $(LUCI_LANG.$(2))
  296. endef
  297. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/install
  298. $$(INSTALL_DIR) $$(1)/etc/uci-defaults
  299. echo "uci set luci.languages.$(subst -,_,$(1))='$(LUCI_LANG.$(2))'; uci commit luci" \
  300. > $$(1)/etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
  301. $$(INSTALL_DIR) $$(1)$(LUCI_LIBRARYDIR)/i18n
  302. $(foreach po,$(wildcard ${CURDIR}/po/$(2)/*.po), \
  303. po2lmo $(po) \
  304. $$(1)$(LUCI_LIBRARYDIR)/i18n/$(basename $(notdir $(po))).$(1).lmo;)
  305. endef
  306. LUCI_BUILD_PACKAGES += luci-i18n-$(LUCI_BASENAME)-$(1)
  307. endef
  308. $(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)),$(eval $(call LuciTranslation,$(firstword $(LUCI_LC_ALIAS.$(lang)) $(lang)),$(lang)))))
  309. $(foreach pkg,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(pkg))))