[include] pass opkg offline root as command line arg, solves caching issues when...
[openwrt/svn-archive/archive.git] / include / package-ipkg.mk
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
8 # where to build (and put) .ipk packages
9 OPKG:= \
10 IPKG_TMP=$(TMP_DIR)/ipkg \
11 IPKG_INSTROOT=$(TARGET_DIR) \
12 IPKG_CONF_DIR=$(STAGING_DIR)/etc \
13 IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
14 $(STAGING_DIR_HOST)/bin/opkg \
15 -f $(STAGING_DIR)/etc/opkg.conf \
16 --offline-root $(TARGET_DIR) \
17 --force-depends \
18 --force-overwrite \
19 --force-run-hooks
20
21 # invoke ipkg-build with some default options
22 IPKG_BUILD:= \
23 ipkg-build -c -o 0 -g 0
24
25 IPKG_STATE_DIR:=$(TARGET_DIR)/usr/lib/opkg
26
27 define BuildIPKGVariable
28 $(call shexport,Package/$(1)/$(2))
29 $(1)_COMMANDS += $(SH_FUNC) var2file "$(call shvar,Package/$(1)/$(2))" $(2);
30 endef
31
32 PARENL :=(
33 PARENR :=)
34
35 dep_split=$(subst :,$(space),$(1))
36 dep_rem=$(subst !,,$(subst $(strip $(PARENL)),,$(subst $(strip $(PARENR)),,$(word 1,$(call dep_split,$(1))))))
37 dep_confvar=$(strip $(foreach cond,$(subst ||, ,$(call dep_rem,$(1))),$(CONFIG_$(cond))))
38 dep_pos=$(if $(call dep_confvar,$(1)),$(call dep_val,$(1)))
39 dep_neg=$(if $(call dep_confvar,$(1)),,$(call dep_val,$(1)))
40 dep_if=$(if $(findstring !,$(1)),$(call dep_neg,$(1)),$(call dep_pos,$(1)))
41 dep_val=$(word 2,$(call dep_split,$(1)))
42 strip_deps=$(strip $(subst +,,$(filter-out @%,$(1))))
43 filter_deps=$(foreach dep,$(call strip_deps,$(1)),$(if $(findstring :,$(dep)),$(call dep_if,$(dep)),$(dep)))
44
45 ifeq ($(DUMP),)
46 define BuildTarget/ipkg
47 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
48 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg-$(PKGARCH)/$(1)
49 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
50
51 ifeq ($(if $(VARIANT),$(BUILD_VARIANT)),$(VARIANT))
52 ifdef Package/$(1)/install
53 ifneq ($(CONFIG_PACKAGE_$(1))$(SDK)$(DEVELOPER),)
54 compile: $$(IPKG_$(1)) $(STAGING_DIR_ROOT)/stamp/.$(1)_installed
55
56 ifeq ($(CONFIG_PACKAGE_$(1)),y)
57 install: $$(INFO_$(1))
58 endif
59 else
60 compile: $(1)-disabled
61 $(1)-disabled:
62 @echo "WARNING: skipping $(1) -- package not selected"
63 endif
64 endif
65 endif
66
67 IDEPEND_$(1):=$$(call filter_deps,$$(DEPENDS))
68
69 $(eval $(call BuildIPKGVariable,$(1),conffiles))
70 $(eval $(call BuildIPKGVariable,$(1),preinst))
71 $(eval $(call BuildIPKGVariable,$(1),postinst))
72 $(eval $(call BuildIPKGVariable,$(1),prerm))
73 $(eval $(call BuildIPKGVariable,$(1),postrm))
74
75 $(STAGING_DIR_ROOT)/stamp/.$(1)_installed: $(STAMP_BUILT)
76 rm -rf $(STAGING_DIR_ROOT)/tmp-$(1)
77 mkdir -p $(STAGING_DIR_ROOT)/stamp $(STAGING_DIR_ROOT)/tmp-$(1)
78 $(call Package/$(1)/install,$(STAGING_DIR_ROOT)/tmp-$(1))
79 $(call Package/$(1)/install_lib,$(STAGING_DIR_ROOT)/tmp-$(1))
80 $(CP) $(STAGING_DIR_ROOT)/tmp-$(1)/. $(STAGING_DIR_ROOT)/
81 rm -rf $(STAGING_DIR_ROOT)/tmp-$(1)
82 touch $$@
83
84 $$(IPKG_$(1)): $(STAGING_DIR)/etc/opkg.conf $(STAMP_BUILT)
85 @rm -rf $(PACKAGE_DIR)/$(1)_* $$(IDIR_$(1))
86 mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL
87 $(call Package/$(1)/install,$$(IDIR_$(1)))
88 -find $$(IDIR_$(1)) -name 'CVS' -o -name '.svn' -o -name '.#*' | $(XARGS) rm -rf
89 $(RSTRIP) $$(IDIR_$(1))
90 SIZE=`cd $$(IDIR_$(1)); du -bs --exclude=./CONTROL . 2>/dev/null | cut -f1`; \
91 ( \
92 echo "Package: $(1)"; \
93 echo "Version: $(VERSION)"; \
94 DEPENDS='$(EXTRA_DEPENDS)'; \
95 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
96 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
97 done; \
98 echo "Depends: $$$$DEPENDS"; \
99 echo "Provides: $(PROVIDES)"; \
100 echo "Source: $(SOURCE)"; \
101 echo "Section: $(SECTION)"; \
102 echo "Priority: $(PRIORITY)"; \
103 echo "Maintainer: $(MAINTAINER)"; \
104 echo "Architecture: $(PKGARCH)"; \
105 echo "Installed-Size: $$$$SIZE"; \
106 echo -n "Description: "; $(SH_FUNC) getvar $(call shvar,Package/$(1)/description) | sed -e 's,^[[:space:]]*, ,g'; \
107 ) > $$(IDIR_$(1))/CONTROL/control
108 chmod 644 $$(IDIR_$(1))/CONTROL/control
109 (cd $$(IDIR_$(1))/CONTROL; \
110 $($(1)_COMMANDS) \
111 )
112 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
113 @[ -f $$(IPKG_$(1)) ]
114
115 $$(INFO_$(1)): $$(IPKG_$(1))
116 @[ -d $(TARGET_DIR)/tmp ] || mkdir -p $(TARGET_DIR)/tmp
117 $(OPKG) install $$(IPKG_$(1))
118
119 $(1)-clean:
120 rm -f $(PACKAGE_DIR)/$(1)_*
121
122 clean: $(1)-clean
123
124 endef
125
126 $(STAGING_DIR)/etc/opkg.conf:
127 mkdir -p $(STAGING_DIR)/etc
128 ( echo "dest root /" > $@; \
129 echo "arch all 100" >> $@; \
130 echo "arch $(PKGARCH) 200" >> $@ )
131
132 endif