1
0

unpack.mk 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Copyright (C) 2006-2020 OpenWrt.org
  4. HOST_TAR:=$(TAR)
  5. TAR_CMD=$(HOST_TAR) -C $(1)/.. $(TAR_OPTIONS)
  6. UNZIP_CMD=unzip -q -d $(1)/.. $(DL_DIR)/$(PKG_SOURCE)
  7. ifeq ($(PKG_SOURCE),)
  8. PKG_UNPACK ?= true
  9. else
  10. ifeq ($(strip $(UNPACK_CMD)),)
  11. ifeq ($(strip $(PKG_CAT)),)
  12. # try to autodetect file type
  13. EXT:=$(call ext,$(PKG_SOURCE))
  14. EXT1:=$(EXT)
  15. ifeq ($(filter gz tgz,$(EXT)),$(EXT))
  16. EXT:=$(call ext,$(PKG_SOURCE:.$(EXT)=))
  17. DECOMPRESS_CMD:=$(STAGING_DIR_HOST)/bin/libdeflate-gzip -dc $(DL_DIR)/$(PKG_SOURCE) |
  18. endif
  19. ifeq ($(filter bzip2 bz2 bz tbz2 tbz,$(EXT)),$(EXT))
  20. EXT:=$(call ext,$(PKG_SOURCE:.$(EXT)=))
  21. DECOMPRESS_CMD:=bzcat $(DL_DIR)/$(PKG_SOURCE) |
  22. endif
  23. ifeq ($(filter xz txz,$(EXT)),$(EXT))
  24. EXT:=$(call ext,$(PKG_SOURCE:.$(EXT)=))
  25. DECOMPRESS_CMD:=xzcat $(DL_DIR)/$(PKG_SOURCE) |
  26. endif
  27. ifeq (zst,$(EXT))
  28. EXT:=$(call ext,$(PKG_SOURCE:.$(EXT)=))
  29. DECOMPRESS_CMD:=zstdcat $(DL_DIR)/$(PKG_SOURCE) |
  30. endif
  31. ifeq ($(filter tgz tbz tbz2 txz,$(EXT1)),$(EXT1))
  32. EXT:=tar
  33. endif
  34. DECOMPRESS_CMD ?= cat $(DL_DIR)/$(PKG_SOURCE) |
  35. ifeq ($(EXT),tar)
  36. UNPACK_CMD=$(DECOMPRESS_CMD) $(TAR_CMD)
  37. endif
  38. ifeq ($(EXT),cpio)
  39. UNPACK_CMD=$(DECOMPRESS_CMD) (cd $(1)/..; $(STAGING_DIR_HOST)/bin/cpio -i -d)
  40. endif
  41. ifeq ($(EXT),zip)
  42. UNPACK_CMD=$(UNZIP_CMD)
  43. endif
  44. endif
  45. # compatibility code for packages that set PKG_CAT
  46. ifeq ($(strip $(UNPACK_CMD)),)
  47. # use existing PKG_CAT
  48. UNPACK_CMD=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | $(TAR_CMD)
  49. ifeq ($(PKG_CAT),unzip)
  50. UNPACK_CMD=$(UNZIP_CMD)
  51. endif
  52. # replace zcat with $(ZCAT), because some system don't support it properly
  53. ifeq ($(PKG_CAT),zcat)
  54. UNPACK_CMD=$(STAGING_DIR_HOST)/bin/libdeflate-gzip -dc $(DL_DIR)/$(PKG_SOURCE) | $(TAR_CMD)
  55. endif
  56. endif
  57. endif
  58. ifdef PKG_BUILD_DIR
  59. PKG_UNPACK ?= $(SH_FUNC) $(call UNPACK_CMD,$(PKG_BUILD_DIR))
  60. endif
  61. ifdef HOST_BUILD_DIR
  62. HOST_UNPACK ?= $(SH_FUNC) $(call UNPACK_CMD,$(HOST_BUILD_DIR))
  63. endif
  64. endif # PKG_SOURCE