luci.mk 10 KB

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