1
0

unpack.mk 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. HOST_TAR:=$(TAR)
  8. TAR_CMD=$(HOST_TAR) -C $(1)/.. $(TAR_OPTIONS)
  9. UNZIP_CMD=unzip -q -d $(1)/.. $(DL_DIR)/$(PKG_SOURCE)
  10. ifeq ($(PKG_SOURCE),)
  11. PKG_UNPACK ?= true
  12. else
  13. ifeq ($(strip $(UNPACK_CMD)),)
  14. ifeq ($(strip $(PKG_CAT)),)
  15. # try to autodetect file type
  16. EXT:=$(call ext,$(PKG_SOURCE))
  17. EXT1:=$(EXT)
  18. ifeq ($(filter gz tgz,$(EXT)),$(EXT))
  19. EXT:=$(call ext,$(PKG_SOURCE:.$(EXT)=))
  20. DECOMPRESS_CMD:=gzip -dc $(DL_DIR)/$(PKG_SOURCE) |
  21. endif
  22. ifeq ($(filter bzip2 bz2 bz tbz2 tbz,$(EXT)),$(EXT))
  23. EXT:=$(call ext,$(PKG_SOURCE:.$(EXT)=))
  24. DECOMPRESS_CMD:=bzcat $(DL_DIR)/$(PKG_SOURCE) |
  25. endif
  26. ifeq ($(filter xz txz,$(EXT)),$(EXT))
  27. EXT:=$(call ext,$(PKG_SOURCE:.$(EXT)=))
  28. DECOMPRESS_CMD:=xzcat $(DL_DIR)/$(PKG_SOURCE) |
  29. endif
  30. ifeq ($(filter tgz tbz tbz2 txz,$(EXT1)),$(EXT1))
  31. EXT:=tar
  32. endif
  33. DECOMPRESS_CMD ?= cat $(DL_DIR)/$(PKG_SOURCE) |
  34. ifeq ($(EXT),tar)
  35. UNPACK_CMD=$(DECOMPRESS_CMD) $(TAR_CMD)
  36. endif
  37. ifeq ($(EXT),cpio)
  38. UNPACK_CMD=$(DECOMPRESS_CMD) (cd $(1)/..; cpio -i -d)
  39. endif
  40. ifeq ($(EXT),zip)
  41. UNPACK_CMD=$(UNZIP_CMD)
  42. endif
  43. endif
  44. # compatibility code for packages that set PKG_CAT
  45. ifeq ($(strip $(UNPACK_CMD)),)
  46. # use existing PKG_CAT
  47. UNPACK_CMD=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | $(TAR_CMD)
  48. ifeq ($(PKG_CAT),unzip)
  49. UNPACK_CMD=$(UNZIP_CMD)
  50. endif
  51. # replace zcat with $(ZCAT), because some system don't support it properly
  52. ifeq ($(PKG_CAT),zcat)
  53. UNPACK_CMD=gzip -dc $(DL_DIR)/$(PKG_SOURCE) | $(TAR_CMD)
  54. endif
  55. endif
  56. ifneq ($(strip $(CRLF_WORKAROUND)),)
  57. CRLF_CMD := && find $(PKG_BUILD_DIR) -type f -print0 | xargs -0 perl -pi -e 's!\r$$$$!!g'
  58. else
  59. CRLF_CMD :=
  60. endif
  61. endif
  62. ifdef PKG_BUILD_DIR
  63. PKG_UNPACK ?= $(SH_FUNC) $(call UNPACK_CMD,$(PKG_BUILD_DIR)) $(call CRLF_CMD,$(PKG_BUILD_DIR))
  64. endif
  65. ifdef HOST_BUILD_DIR
  66. HOST_UNPACK ?= $(SH_FUNC) $(call UNPACK_CMD,$(HOST_BUILD_DIR)) $(call CRLF_CMD,$(HOST_BUILD_DIR))
  67. endif
  68. endif # PKG_SOURCE