luci.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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/librecmc/luci
  15. LUCI_MAINTAINER?=libreCMC LuCI community
  16. LUCI_MINIFY_LUA?=1
  17. LUCI_MINIFY_CSS?=1
  18. LUCI_MINIFY_JS?=1
  19. # Language code titles
  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_BR=Português do Brasil (Brazilian Portuguese)
  44. LUCI_LANG.pt=Português (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. # Submenu titles
  55. LUCI_MENU.col=1. Collections
  56. LUCI_MENU.mod=2. Modules
  57. LUCI_MENU.app=3. Applications
  58. LUCI_MENU.theme=4. Themes
  59. LUCI_MENU.proto=5. Protocols
  60. LUCI_MENU.lib=6. Libraries
  61. # Language aliases
  62. LUCI_LC_ALIAS.bn_BD=bn
  63. LUCI_LC_ALIAS.nb_NO=no
  64. LUCI_LC_ALIAS.pt_BR=pt-br
  65. LUCI_LC_ALIAS.zh_Hans=zh-cn
  66. LUCI_LC_ALIAS.zh_Hant=zh-tw
  67. # Default locations
  68. HTDOCS = /www
  69. LUA_LIBRARYDIR = /usr/lib/lua
  70. LUCI_LIBRARYDIR = $(LUA_LIBRARYDIR)/luci
  71. UCODE_LIBRARYDIR = /usr/share/ucode/luci
  72. # 1: everything expect po subdir or only po subdir
  73. define findrev
  74. $(shell \
  75. if git log -1 >/dev/null 2>/dev/null; then \
  76. set -- $$(git log -1 --format="%ct %h" --abbrev=7 -- $(if $(1),. ':(exclude)po',po)); \
  77. if [ -n "$$1" ]; then
  78. secs="$$(($$1 % 86400))"; \
  79. yday="$$(date --utc --date="@$$1" "+%y.%j")"; \
  80. printf 'git-%s.%05d-%s' "$$yday" "$$secs" "$$2"; \
  81. else \
  82. echo "unknown"; \
  83. fi; \
  84. else \
  85. ts=$$(find . -type f $(if $(1),-not) -path './po/*' -printf '%T@\n' 2>/dev/null | sort -rn | head -n1 | cut -d. -f1); \
  86. if [ -n "$$ts" ]; then \
  87. secs="$$(($$ts % 86400))"; \
  88. date="$$(date --utc --date="@$$ts" "+%y%m%d")"; \
  89. printf '%s.%05d' "$$date" "$$secs"; \
  90. else \
  91. echo "unknown"; \
  92. fi; \
  93. fi \
  94. )
  95. endef
  96. PKG_NAME?=$(LUCI_NAME)
  97. PKG_RELEASE?=1
  98. PKG_INSTALL:=$(if $(realpath src/Makefile),1)
  99. PKG_BUILD_DEPENDS += lua/host luci-base/host LUCI_CSSTIDY:csstidy/host LUCI_SRCDIET:luasrcdiet/host $(LUCI_BUILD_DEPENDS)
  100. PKG_CONFIG_DEPENDS += CONFIG_LUCI_SRCDIET CONFIG_LUCI_JSMIN CONFIG_LUCI_CSSTIDY
  101. PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
  102. PKG_PO_VERSION?=$(if $(DUMP),x,$(strip $(call findrev)))
  103. PKG_SRC_VERSION?=$(if $(DUMP),x,$(strip $(call findrev,1)))
  104. PKG_GITBRANCH?=$(if $(DUMP),x,$(strip $(shell \
  105. variant="LuCI"; \
  106. if git log -1 >/dev/null 2>/dev/null; then \
  107. branch=$$(git branch --format='%(refname:strip=3)' --remote --no-abbrev --contains 2>/dev/null | tail -n1); \
  108. branch=$${branch:-$$(git branch --format='%(refname:strip=2)' --no-abbrev --contains 2>/dev/null | tail -n1)}; \
  109. if [ "$$branch" != "master" ]; then \
  110. variant="LuCI $${branch:-unknown} branch"; \
  111. else \
  112. variant="LuCI Master"; \
  113. fi; \
  114. fi; \
  115. echo "$$variant" \
  116. )))
  117. include $(INCLUDE_DIR)/package.mk
  118. # LUCI_SUBMENU: the submenu-item below the LuCI top-level menu inside libreCMC menuconfig
  119. # usually one of the LUCI_MENU.* definitions
  120. # LUCI_SUBMENU_DEFAULT: the regular SUBMENU defined by LUCI_TYPE or derrived from the packagename
  121. # LUCI_SUBMENU_FORCED: manually forced value SUBMENU to set to by explicit definiton
  122. # can be any string, "none" disables the creation of a submenu
  123. # most usefull in combination with LUCI_CATEGORY, to make the package appear
  124. # anywhere in the menu structure
  125. LUCI_SUBMENU_DEFAULT=$(if $(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.app))
  126. LUCI_SUBMENU=$(if $(LUCI_SUBMENU_FORCED),$(LUCI_SUBMENU_FORCED),$(LUCI_SUBMENU_DEFAULT))
  127. ifneq ($(wildcard ${CURDIR}/luasrc/*),)
  128. ifneq ($(filter-out luci-lib-base luci-lua-runtime,$(PKG_NAME)),)
  129. LUCI_DEPENDS += +luci-lua-runtime
  130. endif
  131. endif
  132. define Package/$(PKG_NAME)
  133. SECTION:=$(LUCI_SECTION)
  134. CATEGORY:=$(LUCI_CATEGORY)
  135. ifneq ($(LUCI_SUBMENU),none)
  136. SUBMENU:=$(LUCI_SUBMENU)
  137. endif
  138. TITLE:=$(if $(LUCI_TITLE),$(LUCI_TITLE),LuCI $(LUCI_NAME) $(LUCI_TYPE))
  139. DEPENDS:=$(LUCI_DEPENDS)
  140. VERSION:=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))
  141. $(if $(LUCI_EXTRA_DEPENDS),EXTRA_DEPENDS:=$(LUCI_EXTRA_DEPENDS))
  142. $(if $(LUCI_PKGARCH),PKGARCH:=$(LUCI_PKGARCH))
  143. $(if $(PKG_PROVIDES),PROVIDES:=$(PKG_PROVIDES))
  144. URL:=$(LUCI_URL)
  145. MAINTAINER:=$(LUCI_MAINTAINER)
  146. endef
  147. ifneq ($(LUCI_DESCRIPTION),)
  148. define Package/$(PKG_NAME)/description
  149. $(strip $(LUCI_DESCRIPTION))
  150. endef
  151. endif
  152. define Build/Prepare
  153. for d in luasrc ucode htdocs root src; do \
  154. if [ -d ./$$$$d ]; then \
  155. mkdir -p $(PKG_BUILD_DIR)/$$$$d; \
  156. $(CP) ./$$$$d/* $(PKG_BUILD_DIR)/$$$$d/; \
  157. fi; \
  158. done
  159. $(call Build/Prepare/Default)
  160. endef
  161. define Build/Configure
  162. endef
  163. ifneq ($(wildcard ${CURDIR}/src/Makefile),)
  164. MAKE_PATH := src/
  165. MAKE_VARS += FPIC="$(FPIC)" LUCI_VERSION="$(PKG_SRC_VERSION)" LUCI_GITBRANCH="$(PKG_GITBRANCH)"
  166. define Build/Compile
  167. $(call Build/Compile/Default,clean compile)
  168. endef
  169. else
  170. define Build/Compile
  171. endef
  172. endif
  173. define Package/$(PKG_NAME)/install
  174. ifneq ($(wildcard ${CURDIR}/luasrc),)
  175. $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR)
  176. cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/
  177. $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm
  178. $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true)
  179. $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/)
  180. endif
  181. ifneq ($(wildcard ${CURDIR}/ucode),)
  182. $(INSTALL_DIR) $(1)$(UCODE_LIBRARYDIR)
  183. cp -pR $(PKG_BUILD_DIR)/ucode/* $(1)$(UCODE_LIBRARYDIR)/
  184. $(call SubstituteVersion,$(1)$(UCODE_LIBRARYDIR)/)
  185. endif
  186. ifneq ($(wildcard ${CURDIR}/htdocs),)
  187. $(INSTALL_DIR) $(1)$(HTDOCS)
  188. cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/
  189. $(if $(CONFIG_LUCI_JSMIN),$(call JsMin,$(1)$(HTDOCS)/),true)
  190. $(if $(CONFIG_LUCI_CSSTIDY),$(call CssTidy,$(1)$(HTDOCS)/),true)
  191. endif
  192. ifneq ($(wildcard ${CURDIR}/root),)
  193. $(INSTALL_DIR) $(1)/
  194. cp -pR $(PKG_BUILD_DIR)/root/* $(1)/
  195. endif
  196. ifneq ($(wildcard ${CURDIR}/src),)
  197. $(call Build/Install/Default)
  198. $(CP) $(PKG_INSTALL_DIR)/* $(1)/
  199. endif
  200. endef
  201. ifndef Package/$(PKG_NAME)/postinst
  202. define Package/$(PKG_NAME)/postinst
  203. [ -n "$${IPKG_INSTROOT}" ] || { \
  204. rm -f /tmp/luci-indexcache.*
  205. rm -rf /tmp/luci-modulecache/
  206. killall -HUP rpcd 2>/dev/null
  207. exit 0
  208. }
  209. endef
  210. endif
  211. # some generic macros that can be used by all packages
  212. ifeq ($(LUCI_MINIFY_LUA),1)
  213. define SrcDiet
  214. $(FIND) $(1) -type f -name '*.lua' | while read src; do \
  215. if LUA_PATH="$(STAGING_DIR_HOSTPKG)/lib/lua/5.1/?.lua" luasrcdiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; \
  216. then mv "$$$$src.o" "$$$$src"; fi; \
  217. done
  218. endef
  219. else
  220. define SrcDiet
  221. $$(call MESSAGE,$$(LUCI_NAME) does not support Lua source minification)
  222. endef
  223. endif
  224. ifeq ($(LUCI_MINIFY_JS),1)
  225. define JsMin
  226. $(FIND) $(1) -type f -name '*.js' | while read src; do \
  227. if python3 -m jsmin "$$$$src" > "$$$$src.o"; \
  228. then mv "$$$$src.o" "$$$$src"; fi; \
  229. done
  230. endef
  231. else
  232. define JsMin
  233. $$(call MESSAGE,$$(LUCI_NAME) does not support JavaScript source minification)
  234. endef
  235. endif
  236. ifeq ($(LUCI_MINIFY_CSS),1)
  237. define CssTidy
  238. $(FIND) $(1) -type f -name '*.css' | while read src; do \
  239. if csstidy "$$$$src" --template=highest --remove_last_semicolon=true "$$$$src.o"; \
  240. then mv "$$$$src.o" "$$$$src"; fi; \
  241. done
  242. endef
  243. else
  244. define CssTidy
  245. $$(call MESSAGE,$$(LUCI_NAME) does not support CSS source minification)
  246. endef
  247. endif
  248. define SubstituteVersion
  249. $(FIND) $(1) -type f -name '*.htm' | while read src; do \
  250. $(SED) 's/<%# *\([^ ]*\)PKG_VERSION *%>/\1$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))/g' \
  251. -e 's/"\(<%= *\(media\|resource\) *%>[^"]*\.\(js\|css\)\)"/"\1?v=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))"/g' \
  252. "$$$$src"; \
  253. done; \
  254. $(FIND) $(1) -type f -name '*.ut' | while read src; do \
  255. $(SED) 's/{# *\([^ ]*\)PKG_VERSION *#}/\1$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))/g' \
  256. -e 's/"\({{ *\(media\|resource\) *}}[^"]*\.\(js\|css\)\)"/"\1?v=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))"/g' \
  257. "$$$$src"; \
  258. done
  259. endef
  260. # additional setting luci-base package
  261. ifeq ($(PKG_NAME),luci-base)
  262. define Package/luci-base/config
  263. config LUCI_SRCDIET
  264. bool "Minify Lua sources"
  265. default n
  266. config LUCI_JSMIN
  267. bool "Minify JavaScript sources"
  268. default y
  269. config LUCI_CSSTIDY
  270. bool "Minify CSS files"
  271. default y
  272. menu "Translations"$(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)),
  273. config LUCI_LANG_$(lang)
  274. tristate "$(shell echo '$(LUCI_LANG.$(lang))' | sed -e 's/^.* (\(.*\))$$/\1/') ($(lang))"))
  275. endmenu
  276. endef
  277. endif
  278. LUCI_BUILD_PACKAGES := $(PKG_NAME)
  279. # 1: LuCI language code
  280. # 2: BCP 47 language tag
  281. define LuciTranslation
  282. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)
  283. SECTION:=luci
  284. CATEGORY:=LuCI
  285. TITLE:=$(PKG_NAME) - $(1) translation
  286. HIDDEN:=1
  287. DEFAULT:=LUCI_LANG_$(2)||(ALL&&m)
  288. DEPENDS:=$(PKG_NAME)
  289. VERSION:=$(PKG_PO_VERSION)
  290. PKGARCH:=all
  291. endef
  292. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/description
  293. Translation for $(PKG_NAME) - $(LUCI_LANG.$(2))
  294. endef
  295. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/install
  296. $$(INSTALL_DIR) $$(1)/etc/uci-defaults
  297. echo "uci set luci.languages.$(subst -,_,$(1))='$(LUCI_LANG.$(2))'; uci commit luci" \
  298. > $$(1)/etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
  299. $$(INSTALL_DIR) $$(1)$(LUCI_LIBRARYDIR)/i18n
  300. $(foreach po,$(wildcard ${CURDIR}/po/$(2)/*.po), \
  301. po2lmo $(po) \
  302. $$(1)$(LUCI_LIBRARYDIR)/i18n/$(basename $(notdir $(po))).$(1).lmo;)
  303. endef
  304. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/postinst
  305. [ -n "$$$${IPKG_INSTROOT}" ] || {
  306. (. /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)) && rm -f /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
  307. exit 0
  308. }
  309. endef
  310. LUCI_BUILD_PACKAGES += luci-i18n-$(LUCI_BASENAME)-$(1)
  311. endef
  312. $(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)),$(eval $(call LuciTranslation,$(firstword $(LUCI_LC_ALIAS.$(lang)) $(lang)),$(lang)))))
  313. $(foreach pkg,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(pkg))))