unpack.mk 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ext=$(word $(words $(subst ., ,$(1))),$(subst ., ,$(1)))
  2. # unpacking files with +s may break on some platforms. this typically emits error code 2
  3. ifneq ($(HOST_OS),Linux)
  4. HOST_TAR:=trapret 2 $(TAR)
  5. else
  6. HOST_TAR:=$(TAR)
  7. endif
  8. TAR_CMD:=$(HOST_TAR) -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS)
  9. UNZIP_CMD:=unzip -d $(PKG_BUILD_DIR)/.. $(DL_DIR)/$(PKG_SOURCE)
  10. ifeq ($(PKG_SOURCE),)
  11. PKG_UNPACK ?= true
  12. endif
  13. ifeq ($(strip $(PKG_UNPACK)),)
  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. UNPACK:=$(ZCAT) $(DL_DIR)/$(PKG_SOURCE) |
  21. endif
  22. ifeq ($(filter bzip2 bz2 bz tbz2 tbz,$(EXT)),$(EXT))
  23. EXT:=$(call ext,$(PKG_SOURCE:.$(EXT)=))
  24. UNPACK:=bzcat $(DL_DIR)/$(PKG_SOURCE) |
  25. endif
  26. ifeq ($(filter tgz tbz tbz2,$(EXT1)),$(EXT1))
  27. EXT:=tar
  28. endif
  29. UNPACK ?= cat $(DL_DIR)/$(PKG_SOURCE) |
  30. ifeq ($(EXT),tar)
  31. PKG_UNPACK:=$(UNPACK) $(TAR_CMD)
  32. endif
  33. ifeq ($(EXT),cpio)
  34. PKG_UNPACK:=$(UNPACK) (cd $(PKG_BUILD_DIR)/..; cpio -i -d)
  35. endif
  36. ifeq ($(EXT),zip)
  37. PKG_UNPACK:=$(UNZIP_CMD)
  38. endif
  39. endif
  40. # compatibility code for packages that set PKG_CAT
  41. ifeq ($(strip $(PKG_UNPACK)),)
  42. # use existing PKG_CAT
  43. PKG_UNPACK:=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | $(TAR_CMD)
  44. ifeq ($(PKG_CAT),unzip)
  45. PKG_UNPACK:=$(UNZIP_CMD)
  46. endif
  47. # replace zcat with $(ZCAT), because some system have it as gzcat
  48. ifeq ($(PKG_CAT),zcat)
  49. PKG_UNPACK:=$(ZCAT) $(DL_DIR)/$(PKG_SOURCE) | $(TAR_CMD)
  50. endif
  51. endif
  52. ifneq ($(strip $(CRLF_WORKAROUND)),)
  53. PKG_UNPACK += && find $(PKG_BUILD_DIR) -type f -print0 | xargs -0 perl -pi -e 's!\r$$$$!!g'
  54. endif
  55. endif