luci.mk 6.9 KB

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