2
0

luci.mk 9.8 KB

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