luci.mk 6.2 KB

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