#
 
 include $(INCLUDE_DIR)/host.mk
+include $(INCLUDE_DIR)/unpack.mk
 
-ifneq ($(strip $(PKG_CAT)),)
-  ifeq ($(PKG_CAT),unzip)
-    UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
-  else
-    UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
-  endif
+ifneq ($(strip $(UNPACK)),)
   define Build/Prepare/Default
        $(UNPACK)
        @if [ -d ./patches ]; then \
 
                if $$TAR --version 2>&1 | grep 'GNU' >/dev/null; then \
                        echo "TAR_WILDCARDS:=--wildcards" >> $@; \
                fi; \
+               ZCAT=`which gzcat`; \
+               [ -n "$$ZCAT" -a -x "$$ZCAT" ] || ZCAT=`which zcat`; \
+               echo "ZCAT:=$$ZCAT" >> $@; \
        )
 
 
 
 include $(INCLUDE_DIR)/prereq.mk
 include $(INCLUDE_DIR)/host.mk
+include $(INCLUDE_DIR)/unpack.mk
 
 define shvar
 V_$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
   endif
 endef
 
-ifneq ($(strip $(PKG_CAT)),)
-  ifeq ($(PKG_CAT),unzip)
-    UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
-  else
-    UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
-  endif
+ifneq ($(strip $(PKG_UNPACK)),)
   define Build/Prepare/Default
        $(UNPACK)
        @if [ -d ./patches ]; then \
 
--- /dev/null
+ifeq ($(strip $(PKG_UNPACK)),)
+  ifneq ($(strip $(PKG_CAT)),)
+    # use existing PKG_CAT
+    UNPACK:=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
+    ifeq ($(PKG_CAT),unzip)
+      UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
+    endif
+    # replace zcat with $(ZCAT), because some system have it as gzcat
+    ifeq ($(PKG_CAT),zcat)
+      UNPACK:=$(ZCAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
+    endif
+  else
+    # try to autodetect file type
+  endif
+endif