2
0

luci.mk 7.8 KB

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