1
0

unpack.mk 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #
  2. # Copyright (C) 2006-2007 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. # unpacking files with +s may break on some platforms. this typically emits error code 2
  8. ifneq ($(HOST_OS),Linux)
  9. HOST_TAR:=trapret 2 $(TAR)
  10. else
  11. HOST_TAR:=$(TAR)
  12. endif
  13. TAR_CMD=$(HOST_TAR) -C $(1)/.. $(TAR_OPTIONS)
  14. UNZIP_CMD=unzip -d $(1)/.. $(DL_DIR)/$(PKG_SOURCE)
  15. ifeq ($(PKG_SOURCE),)
  16. PKG_UNPACK ?= true
  17. else
  18. ifeq ($(strip $(UNPACK_CMD)),)
  19. ifeq ($(strip $(PKG_CAT)),)
  20. # try to autodetect file type
  21. EXT:=$(call ext,$(PKG_SOURCE))
  22. EXT1:=$(EXT)
  23. ifeq ($(filter gz tgz,$(EXT)),$(EXT))
  24. EXT:=$(call ext,$(PKG_SOURCE:.$(EXT)=))
  25. DECOMPRESS_CMD:=gzip -dc $(DL_DIR)/$(PKG_SOURCE) |
  26. endif
  27. ifeq ($(filter bzip2 bz2 bz tbz2 tbz,$(EXT)),$(EXT))
  28. EXT:=$(call ext,$(PKG_SOURCE:.$(EXT)=))
  29. DECOMPRESS_CMD:=bzcat $(DL_DIR)/$(PKG_SOURCE) |
  30. endif
  31. ifeq ($(filter xz txz,$(EXT)),$(EXT))
  32. EXT:=$(call ext,$(PKG_SOURCE:.$(EXT)=))
  33. DECOMPRESS_CMD:=xzcat $(DL_DIR)/$(PKG_SOURCE) |
  34. endif
  35. ifeq ($(filter tgz tbz tbz2 txz,$(EXT1)),$(EXT1))
  36. EXT:=tar
  37. endif
  38. DECOMPRESS_CMD ?= cat $(DL_DIR)/$(PKG_SOURCE) |
  39. ifeq ($(EXT),tar)
  40. UNPACK_CMD=$(DECOMPRESS_CMD) $(TAR_CMD)
  41. endif
  42. ifeq ($(EXT),cpio)
  43. UNPACK_CMD=$(DECOMPRESS_CMD) (cd $(1)/..; cpio -i -d)
  44. endif
  45. ifeq ($(EXT),zip)
  46. UNPACK_CMD=$(UNZIP_CMD)
  47. endif
  48. endif
  49. # compatibility code for packages that set PKG_CAT
  50. ifeq ($(strip $(UNPACK_CMD)),)
  51. # use existing PKG_CAT
  52. UNPACK_CMD=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | $(TAR_CMD)
  53. ifeq ($(PKG_CAT),unzip)
  54. UNPACK_CMD=$(UNZIP_CMD)
  55. endif
  56. # replace zcat with $(ZCAT), because some system don't support it properly
  57. ifeq ($(PKG_CAT),zcat)
  58. UNPACK_CMD=gzip -dc $(DL_DIR)/$(PKG_SOURCE) | $(TAR_CMD)
  59. endif
  60. endif
  61. ifneq ($(strip $(CRLF_WORKAROUND)),)
  62. CRLF_CMD := && find $(PKG_BUILD_DIR) -type f -print0 | xargs -0 perl -pi -e 's!\r$$$$!!g'
  63. else
  64. CRLF_CMD :=
  65. endif
  66. endif
  67. ifdef PKG_BUILD_DIR
  68. PKG_UNPACK ?= $(SH_FUNC) $(call UNPACK_CMD,$(PKG_BUILD_DIR)) $(call CRLF_CMD,$(PKG_BUILD_DIR))
  69. endif
  70. ifdef HOST_BUILD_DIR
  71. HOST_UNPACK ?= $(SH_FUNC) $(call UNPACK_CMD,$(HOST_BUILD_DIR)) $(call CRLF_CMD,$(HOST_BUILD_DIR))
  72. endif
  73. endif # PKG_SOURCE