unpack.mk 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS)
  14. UNZIP_CMD:=unzip -d $(PKG_BUILD_DIR)/.. $(DL_DIR)/$(PKG_SOURCE)
  15. ifeq ($(PKG_SOURCE),)
  16. PKG_UNPACK ?= true
  17. endif
  18. ifeq ($(strip $(PKG_UNPACK)),)
  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. UNPACK:=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. UNPACK:=bzcat $(DL_DIR)/$(PKG_SOURCE) |
  30. endif
  31. ifeq ($(filter tgz tbz tbz2,$(EXT1)),$(EXT1))
  32. EXT:=tar
  33. endif
  34. UNPACK ?= cat $(DL_DIR)/$(PKG_SOURCE) |
  35. ifeq ($(EXT),tar)
  36. PKG_UNPACK:=$(UNPACK) $(TAR_CMD)
  37. endif
  38. ifeq ($(EXT),cpio)
  39. PKG_UNPACK:=$(UNPACK) (cd $(PKG_BUILD_DIR)/..; cpio -i -d)
  40. endif
  41. ifeq ($(EXT),zip)
  42. PKG_UNPACK:=$(UNZIP_CMD)
  43. endif
  44. endif
  45. # compatibility code for packages that set PKG_CAT
  46. ifeq ($(strip $(PKG_UNPACK)),)
  47. # use existing PKG_CAT
  48. PKG_UNPACK:=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | $(TAR_CMD)
  49. ifeq ($(PKG_CAT),unzip)
  50. PKG_UNPACK:=$(UNZIP_CMD)
  51. endif
  52. # replace zcat with $(ZCAT), because some system don't support it properly
  53. ifeq ($(PKG_CAT),zcat)
  54. PKG_UNPACK:=gzip -dc $(DL_DIR)/$(PKG_SOURCE) | $(TAR_CMD)
  55. endif
  56. endif
  57. ifneq ($(strip $(CRLF_WORKAROUND)),)
  58. PKG_UNPACK += && find $(PKG_BUILD_DIR) -type f -print0 | xargs -0 perl -pi -e 's!\r$$$$!!g'
  59. endif
  60. endif