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