luci.mk 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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.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" --abbrev=7); \
  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 branch --remote --verbose --no-abbrev --contains 2>/dev/null | \
  67. sed -rne 's|^[^/]+/([^ ]+) [a-f0-9]{40} .+$$|\1|p' | head -n1)"; \
  68. if [ "$$branch" != "master" ]; then \
  69. variant="LuCI $$branch branch"; \
  70. else \
  71. variant="LuCI Master"; \
  72. fi; \
  73. fi; \
  74. echo "$$variant" \
  75. )))
  76. PKG_RELEASE?=1
  77. PKG_INSTALL:=$(if $(realpath src/Makefile),1)
  78. PKG_BUILD_DEPENDS += lua/host luci-base/host $(LUCI_BUILD_DEPENDS)
  79. PKG_CONFIG_DEPENDS += CONFIG_LUCI_SRCDIET
  80. PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
  81. include $(INCLUDE_DIR)/package.mk
  82. define Package/$(PKG_NAME)
  83. SECTION:=luci
  84. CATEGORY:=LuCI
  85. SUBMENU:=$(if $(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.app))
  86. TITLE:=$(if $(LUCI_TITLE),$(LUCI_TITLE),LuCI $(LUCI_NAME) $(LUCI_TYPE))
  87. DEPENDS:=$(LUCI_DEPENDS)
  88. $(if $(LUCI_PKGARCH),PKGARCH:=$(LUCI_PKGARCH))
  89. endef
  90. ifneq ($(LUCI_DESCRIPTION),)
  91. define Package/$(PKG_NAME)/description
  92. $(strip $(LUCI_DESCRIPTION))
  93. endef
  94. endif
  95. # Language selection for luci-base
  96. ifeq ($(PKG_NAME),luci-base)
  97. define Package/luci-base/config
  98. config LUCI_SRCDIET
  99. bool "Minify Lua sources"
  100. default n
  101. menu "Translations"$(foreach lang,$(LUCI_LANGUAGES),
  102. config LUCI_LANG_$(lang)
  103. tristate "$(shell echo '$(LUCI_LANG.$(lang))' | sed -e 's/^.* (\(.*\))$$/\1/') ($(lang))")
  104. endmenu
  105. endef
  106. endif
  107. define Build/Prepare
  108. for d in luasrc htdocs root src; do \
  109. if [ -d ./$$$$d ]; then \
  110. mkdir -p $(PKG_BUILD_DIR)/$$$$d; \
  111. $(CP) ./$$$$d/* $(PKG_BUILD_DIR)/$$$$d/; \
  112. fi; \
  113. done
  114. $(call Build/Prepare/Default)
  115. endef
  116. define Build/Configure
  117. endef
  118. ifneq ($(wildcard ${CURDIR}/src/Makefile),)
  119. MAKE_PATH := src/
  120. MAKE_VARS += FPIC="$(FPIC)" LUCI_VERSION="$(PKG_VERSION)" LUCI_GITBRANCH="$(PKG_GITBRANCH)"
  121. define Build/Compile
  122. $(call Build/Compile/Default,clean compile)
  123. endef
  124. else
  125. define Build/Compile
  126. endef
  127. endif
  128. HTDOCS = /www
  129. LUA_LIBRARYDIR = /usr/lib/lua
  130. LUCI_LIBRARYDIR = $(LUA_LIBRARYDIR)/luci
  131. define SrcDiet
  132. $(FIND) $(1) -type f -name '*.lua' | while read src; do \
  133. if LuaSrcDiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; \
  134. then mv "$$$$src.o" "$$$$src"; fi; \
  135. done
  136. endef
  137. define SubstituteVersion
  138. $(FIND) $(1) -type f -name '*.htm' | while read src; do \
  139. $(SED) 's/<%# *\([^ ]*\)PKG_VERSION *%>/\1$(PKG_VERSION)/g' \
  140. -e 's/"\(<%= *\(media\|resource\) *%>[^"]*\.\(js\|css\)\)"/"\1?v=$(PKG_VERSION)"/g' \
  141. "$$$$src"; \
  142. done
  143. endef
  144. define Package/$(PKG_NAME)/install
  145. if [ -d $(PKG_BUILD_DIR)/luasrc ]; then \
  146. $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR); \
  147. cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/; \
  148. $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm; \
  149. $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true); \
  150. $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/); \
  151. else true; fi
  152. if [ -d $(PKG_BUILD_DIR)/htdocs ]; then \
  153. $(INSTALL_DIR) $(1)$(HTDOCS); \
  154. cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/; \
  155. else true; fi
  156. if [ -d $(PKG_BUILD_DIR)/root ]; then \
  157. $(INSTALL_DIR) $(1)/; \
  158. cp -pR $(PKG_BUILD_DIR)/root/* $(1)/; \
  159. else true; fi
  160. if [ -d $(PKG_BUILD_DIR)/src ]; then \
  161. $(call Build/Install/Default) \
  162. $(CP) $(PKG_INSTALL_DIR)/* $(1)/; \
  163. else true; fi
  164. endef
  165. ifneq ($(LUCI_DEFAULTS),)
  166. define Package/$(PKG_NAME)/postinst
  167. [ -n "$${IPKG_INSTROOT}" ] || {$(foreach script,$(LUCI_DEFAULTS),
  168. (. /etc/uci-defaults/$(script)) && rm -f /etc/uci-defaults/$(script))
  169. exit 0
  170. }
  171. endef
  172. endif
  173. LUCI_BUILD_PACKAGES := $(PKG_NAME)
  174. define LuciTranslation
  175. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)
  176. SECTION:=luci
  177. CATEGORY:=LuCI
  178. TITLE:=$(PKG_NAME) - $(1) translation
  179. HIDDEN:=1
  180. DEFAULT:=LUCI_LANG_$(1)||(ALL&&m)
  181. DEPENDS:=$(PKG_NAME)
  182. PKGARCH:=all
  183. endef
  184. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/description
  185. Translation for $(PKG_NAME) - $(LUCI_LANG.$(1))
  186. endef
  187. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/install
  188. $$(INSTALL_DIR) $$(1)/etc/uci-defaults
  189. echo "uci set luci.languages.$(subst -,_,$(1))='$(LUCI_LANG.$(1))'; uci commit luci" \
  190. > $$(1)/etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
  191. $$(INSTALL_DIR) $$(1)$(LUCI_LIBRARYDIR)/i18n
  192. $(foreach po,$(wildcard ${CURDIR}/po/$(1)/*.po), \
  193. po2lmo $(po) \
  194. $$(1)$(LUCI_LIBRARYDIR)/i18n/$(basename $(notdir $(po))).$(1).lmo;)
  195. endef
  196. define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/postinst
  197. [ -n "$$$${IPKG_INSTROOT}" ] || {
  198. (. /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)) && rm -f /etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1)
  199. exit 0
  200. }
  201. endef
  202. LUCI_BUILD_PACKAGES += luci-i18n-$(LUCI_BASENAME)-$(1)
  203. endef
  204. $(foreach lang,$(LUCI_LANGUAGES),$(eval $(call LuciTranslation,$(lang))))
  205. $(foreach pkg,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(pkg))))