luci.mk 6.8 KB

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