2
0

luci.mk 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. # Language code titles
  13. LUCI_LANG.bg=български (Bulgarian)
  14. LUCI_LANG.ca=Català (Catalan)
  15. LUCI_LANG.cs=Čeština (Czech)
  16. LUCI_LANG.de=Deutsch (German)
  17. LUCI_LANG.el=Ελληνικά (Greek)
  18. LUCI_LANG.en=English
  19. LUCI_LANG.es=Español (Spanish)
  20. LUCI_LANG.fr=Français (French)
  21. LUCI_LANG.he=עִבְרִית (Hebrew)
  22. LUCI_LANG.hi=हिंदी (Hindi)
  23. LUCI_LANG.hu=Magyar (Hungarian)
  24. LUCI_LANG.it=Italiano (Italian)
  25. LUCI_LANG.ja=日本語 (Japanese)
  26. LUCI_LANG.ko=한국어 (Korean)
  27. LUCI_LANG.mr=Marāṭhī (Marathi)
  28. LUCI_LANG.ms=Bahasa Melayu (Malay)
  29. LUCI_LANG.nb_NO=Norsk (Norwegian)
  30. LUCI_LANG.pl=Polski (Polish)
  31. LUCI_LANG.pt_BR=Português do Brasil (Brazialian Portuguese)
  32. LUCI_LANG.pt=Português (Portuguese)
  33. LUCI_LANG.ro=Română (Romanian)
  34. LUCI_LANG.ru=Русский (Russian)
  35. LUCI_LANG.sk=Slovenčina (Slovak)
  36. LUCI_LANG.sv=Svenska (Swedish)
  37. LUCI_LANG.tr=Türkçe (Turkish)
  38. LUCI_LANG.uk=Українська (Ukrainian)
  39. LUCI_LANG.vi=Tiếng Việt (Vietnamese)
  40. LUCI_LANG.zh_Hans=中文 (Chinese)
  41. LUCI_LANG.zh_Hant=臺灣華語 (Taiwanese)
  42. # Submenu titles
  43. LUCI_MENU.col=1. Collections
  44. LUCI_MENU.mod=2. Modules
  45. LUCI_MENU.app=3. Applications
  46. LUCI_MENU.theme=4. Themes
  47. LUCI_MENU.proto=5. Protocols
  48. LUCI_MENU.lib=6. Libraries
  49. # Language aliases
  50. LUCI_LC_ALIAS.nb_NO=no
  51. LUCI_LC_ALIAS.pt_BR=pt-br
  52. LUCI_LC_ALIAS.zh_Hans=zh-cn
  53. LUCI_LC_ALIAS.zh_Hant=zh-tw
  54. PKG_NAME?=$(LUCI_NAME)
  55. PKG_VERSION?=$(if $(DUMP),x,$(strip $(shell \
  56. if svn info >/dev/null 2>/dev/null; then \
  57. revision="svn-r$$(LC_ALL=C svn info | sed -ne 's/^Revision: //p')"; \
  58. elif git log -1 >/dev/null 2>/dev/null; then \
  59. revision="svn-r$$(LC_ALL=C git log -1 | sed -ne 's/.*git-svn-id: .*@\([0-9]\+\) .*/\1/p')"; \
  60. if [ "$$revision" = "svn-r" ]; then \
  61. set -- $$(git log -1 --format="%ct %h" --abbrev=7); \
  62. secs="$$(($$1 % 86400))"; \
  63. yday="$$(date --utc --date="@$$1" "+%y.%j")"; \
  64. revision="$$(printf 'git-%s.%05d-%s' "$$yday" "$$secs" "$$2")"; \
  65. fi; \
  66. else \
  67. revision="unknown"; \
  68. fi; \
  69. echo "$$revision" \
  70. )))
  71. PKG_GITBRANCH?=$(if $(DUMP),x,$(strip $(shell \
  72. variant="LuCI"; \
  73. if git log -1 >/dev/null 2>/dev/null; then \
  74. branch="$$(git branch --remote --verbose --no-abbrev --contains 2>/dev/null | \
  75. sed -rne 's|^[^/]+/([^ ]+) [a-f0-9]{40} .+$$|\1|p' | head -n1)"; \
  76. if [ "$$branch" != "master" ]; then \
  77. variant="LuCI $$branch branch"; \
  78. else \
  79. variant="LuCI Master"; \
  80. fi; \
  81. fi; \
  82. echo "$$variant" \
  83. )))
  84. PKG_RELEASE?=1
  85. PKG_INSTALL:=$(if $(realpath src/Makefile),1)
  86. PKG_BUILD_DEPENDS += lua/host luci-base/host LUCI_CSSTIDY:csstidy/host LUCI_SRCDIET:luasrcdiet/host $(LUCI_BUILD_DEPENDS)
  87. PKG_CONFIG_DEPENDS += CONFIG_LUCI_SRCDIET CONFIG_LUCI_JSMIN CONFIG_LUCI_CSSTIDY
  88. PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
  89. include $(INCLUDE_DIR)/package.mk
  90. define Package/$(PKG_NAME)
  91. SECTION:=luci
  92. CATEGORY:=LuCI
  93. SUBMENU:=$(if $(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.app))
  94. TITLE:=$(if $(LUCI_TITLE),$(LUCI_TITLE),LuCI $(LUCI_NAME) $(LUCI_TYPE))
  95. DEPENDS:=$(LUCI_DEPENDS)
  96. $(if $(LUCI_EXTRA_DEPENDS),EXTRA_DEPENDS:=$(LUCI_EXTRA_DEPENDS))
  97. $(if $(LUCI_PKGARCH),PKGARCH:=$(LUCI_PKGARCH))
  98. endef
  99. ifneq ($(LUCI_DESCRIPTION),)
  100. define Package/$(PKG_NAME)/description
  101. $(strip $(LUCI_DESCRIPTION))
  102. endef
  103. endif
  104. # Language selection for luci-base
  105. ifeq ($(PKG_NAME),luci-base)
  106. define Package/luci-base/config
  107. config LUCI_SRCDIET
  108. bool "Minify Lua sources"
  109. default n
  110. config LUCI_JSMIN
  111. bool "Minify JavaScript sources"
  112. default y
  113. config LUCI_CSSTIDY
  114. bool "Minify CSS files"
  115. default y
  116. menu "Translations"$(foreach lang,$(LUCI_LANGUAGES),
  117. config LUCI_LANG_$(lang)
  118. tristate "$(shell echo '$(LUCI_LANG.$(lang))' | sed -e 's/^.* (\(.*\))$$/\1/') ($(lang))")
  119. endmenu
  120. endef
  121. endif
  122. define Build/Prepare
  123. for d in luasrc htdocs root src; do \
  124. if [ -d ./$$$$d ]; then \
  125. mkdir -p $(PKG_BUILD_DIR)/$$$$d; \
  126. $(CP) ./$$$$d/* $(PKG_BUILD_DIR)/$$$$d/; \
  127. fi; \
  128. done
  129. $(call Build/Prepare/Default)
  130. endef
  131. define Build/Configure
  132. endef
  133. ifneq ($(wildcard ${CURDIR}/src/Makefile),)
  134. MAKE_PATH := src/
  135. MAKE_VARS += FPIC="$(FPIC)" LUCI_VERSION="$(PKG_VERSION)" LUCI_GITBRANCH="$(PKG_GITBRANCH)"
  136. define Build/Compile
  137. $(call Build/Compile/Default,clean compile)
  138. endef
  139. else
  140. define Build/Compile
  141. endef
  142. endif
  143. HTDOCS = /www
  144. LUA_LIBRARYDIR = /usr/lib/lua
  145. LUCI_LIBRARYDIR = $(LUA_LIBRARYDIR)/luci
  146. define SrcDiet
  147. $(FIND) $(1) -type f -name '*.lua' | while read src; do \
  148. if LUA_PATH="$(STAGING_DIR_HOSTPKG)/lib/lua/5.1/?.lua" luasrcdiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; \
  149. then mv "$$$$src.o" "$$$$src"; fi; \
  150. done
  151. endef
  152. define JsMin
  153. $(FIND) $(1) -type f -name '*.js' | while read src; do \
  154. if jsmin < "$$$$src" > "$$$$src.o"; \
  155. then mv "$$$$src.o" "$$$$src"; fi; \
  156. done
  157. endef
  158. define CssTidy
  159. $(FIND) $(1) -type f -name '*.css' | while read src; do \
  160. if csstidy "$$$$src" --template=highest --remove_last_semicolon=true "$$$$src.o"; \
  161. then mv "$$$$src.o" "$$$$src"; fi; \
  162. done
  163. endef
  164. define SubstituteVersion
  165. $(FIND) $(1) -type f -name '*.htm' | while read src; do \
  166. $(SED) 's/<%# *\([^ ]*\)PKG_VERSION *%>/\1$(PKG_VERSION)/g' \
  167. -e 's/"\(<%= *\(media\|resource\) *%>[^"]*\.\(js\|css\)\)"/"\1?v=$(PKG_VERSION)"/g' \
  168. "$$$$src"; \
  169. done
  170. endef
  171. define Package/$(PKG_NAME)/install
  172. if [ -d $(PKG_BUILD_DIR)/luasrc ]; then \
  173. $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR); \
  174. cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/; \
  175. $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm; \
  176. $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true); \
  177. $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/); \
  178. else true; fi
  179. if [ -d $(PKG_BUILD_DIR)/htdocs ]; then \
  180. $(INSTALL_DIR) $(1)$(HTDOCS); \
  181. cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/; \
  182. $(if $(CONFIG_LUCI_JSMIN),$(call JsMin,$(1)$(HTDOCS)/),true); \
  183. $(if $(CONFIG_LUCI_CSSTIDY),$(call CssTidy,$(1)$(HTDOCS)/),true); \
  184. else true; fi
  185. if [ -d $(PKG_BUILD_DIR)/root ]; then \
  186. $(INSTALL_DIR) $(1)/; \
  187. cp -pR $(PKG_BUILD_DIR)/root/* $(1)/; \
  188. else true; fi
  189. if [ -d $(PKG_BUILD_DIR)/src ]; then \
  190. $(call Build/Install/Default) \
  191. $(CP) $(PKG_INSTALL_DIR)/* $(1)/; \
  192. else true; fi
  193. endef
  194. ifneq ($(LUCI_DEFAULTS),)
  195. define Package/$(PKG_NAME)/postinst
  196. [ -n "$${IPKG_INSTROOT}" ] || {$(foreach script,$(LUCI_DEFAULTS),
  197. (. /etc/uci-defaults/$(script)) && rm -f /etc/uci-defaults/$(script))
  198. rm -f /tmp/luci-indexcache
  199. exit 0
  200. }
  201. endef
  202. endif
  203. LUCI_BUILD_PACKAGES := $(PKG_NAME)
  204. # 1: LuCI language code
  205. # 2: BCP 47 language tag
  206. define LuciTranslation
  207. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)
  208. SECTION:=luci
  209. CATEGORY:=LuCI
  210. TITLE:=$(PKG_NAME) - $(1) translation
  211. HIDDEN:=1
  212. DEFAULT:=LUCI_LANG_$(2)||(ALL&&m)
  213. DEPENDS:=$(PKG_NAME)
  214. PKGARCH:=all
  215. endef
  216. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/description
  217. Translation for $(PKG_NAME) - $(LUCI_LANG.$(2))
  218. endef
  219. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/install
  220. $$(INSTALL_DIR) $$(1)/etc/uci-defaults
  221. echo "uci set luci.languages.$(subst -,_,$(1))='$(LUCI_LANG.$(2))'; uci commit luci" \
  222. > $$(1)/etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
  223. $$(INSTALL_DIR) $$(1)$(LUCI_LIBRARYDIR)/i18n
  224. $(foreach po,$(wildcard ${CURDIR}/po/$(2)/*.po), \
  225. po2lmo $(po) \
  226. $$(1)$(LUCI_LIBRARYDIR)/i18n/$(basename $(notdir $(po))).$(1).lmo;)
  227. endef
  228. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/postinst
  229. [ -n "$$$${IPKG_INSTROOT}" ] || {
  230. (. /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)) && rm -f /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
  231. exit 0
  232. }
  233. endef
  234. LUCI_BUILD_PACKAGES += luci-i18n-$(LUCI_BASENAME)-$(1)
  235. endef
  236. $(foreach lang,$(LUCI_LANGUAGES),$(eval $(call LuciTranslation,$(firstword $(LUCI_LC_ALIAS.$(lang)) $(lang)),$(lang))))
  237. $(foreach pkg,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(pkg))))