luci.mk 7.9 KB

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