1
0

luci.mk 7.0 KB

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