1
0

unpack.mk 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. endif
  57. ifdef PKG_BUILD_DIR
  58. PKG_UNPACK ?= $(SH_FUNC) $(call UNPACK_CMD,$(PKG_BUILD_DIR))
  59. endif
  60. ifdef HOST_BUILD_DIR
  61. HOST_UNPACK ?= $(SH_FUNC) $(call UNPACK_CMD,$(HOST_BUILD_DIR))
  62. endif
  63. endif # PKG_SOURCE