luci-lua-runtime: dispatcher.lua: re-add post_on() dispatch action
[project/luci.git] / luci.mk
diff --git a/luci.mk b/luci.mk
index 4c69a5e3bb80de9ea86772190a018fb7cff95207..53c5130681cc9d1642075387f4711948f8cae0e2 100644 (file)
--- a/luci.mk
+++ b/luci.mk
@@ -14,6 +14,9 @@ LUCI_SECTION?=luci
 LUCI_CATEGORY?=LuCI
 LUCI_URL?=https://github.com/openwrt/luci
 LUCI_MAINTAINER?=OpenWrt LuCI community
+LUCI_MINIFY_LUA?=1
+LUCI_MINIFY_CSS?=1
+LUCI_MINIFY_JS?=1
 
 # Language code titles
 LUCI_LANG.ar=العربية (Arabic)
@@ -24,7 +27,6 @@ LUCI_LANG.cs=Čeština (Czech)
 LUCI_LANG.da=Dansk (Danish)
 LUCI_LANG.de=Deutsch (German)
 LUCI_LANG.el=Ελληνικά (Greek)
-LUCI_LANG.en=English
 LUCI_LANG.es=Español (Spanish)
 LUCI_LANG.fi=Suomi (Finnish)
 LUCI_LANG.fr=Français (French)
@@ -34,6 +36,7 @@ LUCI_LANG.hu=Magyar (Hungarian)
 LUCI_LANG.it=Italiano (Italian)
 LUCI_LANG.ja=日本語 (Japanese)
 LUCI_LANG.ko=한국어 (Korean)
+LUCI_LANG.lt=Lietuvių (Lithuanian)
 LUCI_LANG.mr=Marāṭhī (Marathi)
 LUCI_LANG.ms=Bahasa Melayu (Malay)
 LUCI_LANG.nb_NO=Norsk (Norwegian)
@@ -70,6 +73,7 @@ LUCI_LC_ALIAS.zh_Hant=zh-tw
 HTDOCS = /www
 LUA_LIBRARYDIR = /usr/lib/lua
 LUCI_LIBRARYDIR = $(LUA_LIBRARYDIR)/luci
+UCODE_LIBRARYDIR = /usr/share/ucode/luci
 
 
 # 1: everything expect po subdir or only po subdir
@@ -111,10 +115,10 @@ PKG_SRC_VERSION?=$(if $(DUMP),x,$(strip $(call findrev,1)))
 PKG_GITBRANCH?=$(if $(DUMP),x,$(strip $(shell \
        variant="LuCI"; \
        if git log -1 >/dev/null 2>/dev/null; then \
-               branch="$$(git branch --remote --verbose --no-abbrev --contains 2>/dev/null | \
-                       sed -rne 's|^[^/]+/([^ ]+) [a-f0-9]{40} .+$$|\1|p' | head -n1)"; \
+               branch=$$(git branch --format='%(refname:strip=3)' --remote --no-abbrev --contains 2>/dev/null | tail -n1); \
+               branch=$${branch:-$$(git branch --format='%(refname:strip=2)' --no-abbrev --contains 2>/dev/null | tail -n1)}; \
                if [ "$$branch" != "master" ]; then \
-                       variant="LuCI $$branch branch"; \
+                       variant="LuCI $${branch:-unknown} branch"; \
                else \
                        variant="LuCI Master"; \
                fi; \
@@ -124,16 +128,22 @@ PKG_GITBRANCH?=$(if $(DUMP),x,$(strip $(shell \
 
 include $(INCLUDE_DIR)/package.mk
 
-# LUCI_SUBMENU: the submenu-item below the LuCI top-level menu inside OpoenWrt menuconfig
+# LUCI_SUBMENU: the submenu-item below the LuCI top-level menu inside OpenWrt menuconfig
 #               usually one of the LUCI_MENU.* definitions
 # LUCI_SUBMENU_DEFAULT: the regular SUBMENU defined by LUCI_TYPE or derrived from the packagename
 # LUCI_SUBMENU_FORCED: manually forced value SUBMENU to set to by explicit definiton
-#                      can be any string, "none" disables the creation of a submenu 
+#                      can be any string, "none" disables the creation of a submenu
 #                      most usefull in combination with LUCI_CATEGORY, to make the package appear
 #                      anywhere in the menu structure
 LUCI_SUBMENU_DEFAULT=$(if $(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.app))
 LUCI_SUBMENU=$(if $(LUCI_SUBMENU_FORCED),$(LUCI_SUBMENU_FORCED),$(LUCI_SUBMENU_DEFAULT))
 
+ifneq ($(wildcard ${CURDIR}/luasrc/*),)
+ ifneq ($(filter-out luci-lib-base luci-lua-runtime,$(PKG_NAME)),)
+  LUCI_DEPENDS += +luci-lua-runtime
+ endif
+endif
+
 define Package/$(PKG_NAME)
   SECTION:=$(LUCI_SECTION)
   CATEGORY:=$(LUCI_CATEGORY)
@@ -157,7 +167,7 @@ ifneq ($(LUCI_DESCRIPTION),)
 endif
 
 define Build/Prepare
-       for d in luasrc htdocs root src; do \
+       for d in luasrc ucode htdocs root src; do \
          if [ -d ./$$$$d ]; then \
            mkdir -p $(PKG_BUILD_DIR)/$$$$d; \
                $(CP) ./$$$$d/* $(PKG_BUILD_DIR)/$$$$d/; \
@@ -182,33 +192,39 @@ else
 endif
 
 define Package/$(PKG_NAME)/install
-       if [ -d $(PKG_BUILD_DIR)/luasrc ]; then \
-         $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR); \
-         cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/; \
-         $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm; \
-         $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true); \
-         $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/); \
-       else true; fi
-       if [ -d $(PKG_BUILD_DIR)/htdocs ]; then \
-         $(INSTALL_DIR) $(1)$(HTDOCS); \
-         cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/; \
-         $(if $(CONFIG_LUCI_JSMIN),$(call JsMin,$(1)$(HTDOCS)/),true); \
-         $(if $(CONFIG_LUCI_CSSTIDY),$(call CssTidy,$(1)$(HTDOCS)/),true); \
-       else true; fi
-       if [ -d $(PKG_BUILD_DIR)/root ]; then \
-         $(INSTALL_DIR) $(1)/; \
-         cp -pR $(PKG_BUILD_DIR)/root/* $(1)/; \
-       else true; fi
-       if [ -d $(PKG_BUILD_DIR)/src ]; then \
-         $(call Build/Install/Default) \
-         $(CP) $(PKG_INSTALL_DIR)/* $(1)/; \
-       else true; fi
+
+ ifneq ($(wildcard ${CURDIR}/luasrc),)
+       $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR)
+       cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/
+       $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm
+       $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true)
+       $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/)
+ endif
+ ifneq ($(wildcard ${CURDIR}/ucode),)
+         $(INSTALL_DIR) $(1)$(UCODE_LIBRARYDIR)
+         cp -pR $(PKG_BUILD_DIR)/ucode/* $(1)$(UCODE_LIBRARYDIR)/
+         $(call SubstituteVersion,$(1)$(UCODE_LIBRARYDIR)/)
+ endif
+ ifneq ($(wildcard ${CURDIR}/htdocs),)
+       $(INSTALL_DIR) $(1)$(HTDOCS)
+       cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/
+       $(if $(CONFIG_LUCI_JSMIN),$(call JsMin,$(1)$(HTDOCS)/),true)
+       $(if $(CONFIG_LUCI_CSSTIDY),$(call CssTidy,$(1)$(HTDOCS)/),true)
+ endif
+ ifneq ($(wildcard ${CURDIR}/root),)
+       $(INSTALL_DIR) $(1)/
+       cp -pR $(PKG_BUILD_DIR)/root/* $(1)/
+ endif
+ ifneq ($(wildcard ${CURDIR}/src),)
+       $(call Build/Install/Default)
+       $(CP) $(PKG_INSTALL_DIR)/* $(1)/
+ endif
 endef
 
 ifndef Package/$(PKG_NAME)/postinst
 define Package/$(PKG_NAME)/postinst
 [ -n "$${IPKG_INSTROOT}" ] || { \
-       rm -f /tmp/luci-indexcache
+       rm -f /tmp/luci-indexcache.*
        rm -rf /tmp/luci-modulecache/
        killall -HUP rpcd 2>/dev/null
        exit 0
@@ -217,32 +233,55 @@ endef
 endif
 
 # some generic macros that can be used by all packages
-define SrcDiet
+ifeq ($(LUCI_MINIFY_LUA),1)
+  define SrcDiet
        $(FIND) $(1) -type f -name '*.lua' | while read src; do \
                if LUA_PATH="$(STAGING_DIR_HOSTPKG)/lib/lua/5.1/?.lua" luasrcdiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; \
                then mv "$$$$src.o" "$$$$src"; fi; \
        done
-endef
+  endef
+else
+  define SrcDiet
+       $$(call MESSAGE,$$(LUCI_NAME) does not support Lua source minification)
+  endef
+endif
 
-define JsMin
+ifeq ($(LUCI_MINIFY_JS),1)
+  define JsMin
        $(FIND) $(1) -type f -name '*.js' | while read src; do \
                if jsmin < "$$$$src" > "$$$$src.o"; \
                then mv "$$$$src.o" "$$$$src"; fi; \
        done
-endef
+  endef
+else
+  define JsMin
+       $$(call MESSAGE,$$(LUCI_NAME) does not support JavaScript source minification)
+  endef
+endif
 
-define CssTidy
+ifeq ($(LUCI_MINIFY_CSS),1)
+  define CssTidy
        $(FIND) $(1) -type f -name '*.css' | while read src; do \
                if csstidy "$$$$src" --template=highest --remove_last_semicolon=true "$$$$src.o"; \
                then mv "$$$$src.o" "$$$$src"; fi; \
        done
-endef
+  endef
+else
+  define CssTidy
+       $$(call MESSAGE,$$(LUCI_NAME) does not support CSS source minification)
+  endef
+endif
 
 define SubstituteVersion
        $(FIND) $(1) -type f -name '*.htm' | while read src; do \
                $(SED) 's/<%# *\([^ ]*\)PKG_VERSION *%>/\1$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))/g' \
                    -e 's/"\(<%= *\(media\|resource\) *%>[^"]*\.\(js\|css\)\)"/"\1?v=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))"/g' \
                        "$$$$src"; \
+       done; \
+       $(FIND) $(1) -type f -name '*.ut' | while read src; do \
+               $(SED) 's/{# *\([^ ]*\)PKG_VERSION *#}/\1$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))/g' \
+                   -e 's/"\({{ *\(media\|resource\) *}}[^"]*\.\(js\|css\)\)"/"\1?v=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))"/g' \
+                       "$$$$src"; \
        done
 endef
 
@@ -258,13 +297,13 @@ ifeq ($(PKG_NAME),luci-base)
        default y
 
    config LUCI_CSSTIDY
-        bool "Minify CSS files"
-        default y
+       bool "Minify CSS files"
+       default y
 
-   menu "Translations"$(foreach lang,$(LUCI_LANGUAGES),
+   menu "Translations"$(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)),
 
      config LUCI_LANG_$(lang)
-          tristate "$(shell echo '$(LUCI_LANG.$(lang))' | sed -e 's/^.* (\(.*\))$$/\1/') ($(lang))")
+          tristate "$(shell echo '$(LUCI_LANG.$(lang))' | sed -e 's/^.* (\(.*\))$$/\1/') ($(lang))"))
 
    endmenu
  endef
@@ -312,5 +351,5 @@ define LuciTranslation
 
 endef
 
-$(foreach lang,$(LUCI_LANGUAGES),$(eval $(call LuciTranslation,$(firstword $(LUCI_LC_ALIAS.$(lang)) $(lang)),$(lang))))
+$(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)),$(eval $(call LuciTranslation,$(firstword $(LUCI_LC_ALIAS.$(lang)) $(lang)),$(lang)))))
 $(foreach pkg,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(pkg))))