+# where to build (and put) .ipk packages
+OPKG:= \
+ IPKG_NO_SCRIPT=1 \
+ IPKG_TMP=$(TMP_DIR)/ipkg \
+ IPKG_INSTROOT=$(TARGET_DIR) \
+ IPKG_CONF_DIR=$(STAGING_DIR)/etc \
+ IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
+ $(XARGS) $(STAGING_DIR_HOST)/bin/opkg \
+ --offline-root $(TARGET_DIR) \
+ --force-depends \
+ --force-overwrite \
+ --force-postinstall \
+ --force-maintainer \
+ --add-dest root:/ \
+ --add-arch all:100 \
+ --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200
+
+PACKAGE_INSTALL_FILES:= \
+ $(foreach pkg,$(sort $(package-y)), \
+ $(foreach variant, \
+ $(if $(strip $(package/$(pkg)/variants)), \
+ $(package/$(pkg)/variants), \
+ $(if $(package/$(pkg)/default-variant), \
+ $(package/$(pkg)/default-variant), \
+ default \
+ ) \
+ ), \
+ $(PKG_INFO_DIR)/$(lastword $(subst /,$(space),$(pkg))).$(variant).install \
+ ) \
+ )
+
+$(curdir)/cleanup: $(TMP_DIR)/.build
+ rm -rf $(STAGING_DIR_ROOT)
+
+$(curdir)/install: $(TMP_DIR)/.build $(curdir)/system/opkg/host/install
+ - find $(STAGING_DIR_ROOT) -type d | $(XARGS) chmod 0755
+ rm -rf $(TARGET_DIR)
+ [ -d $(TARGET_DIR)/tmp ] || mkdir -p $(TARGET_DIR)/tmp
+ @$(FIND) `sed -e 's|.*|$(PACKAGE_DIR)$(if $(CONFIG_PER_FEED_REPO),/*)/&_*.ipk|' $(PACKAGE_INSTALL_FILES)` | sort -u | $(OPKG) install
+ @for file in $(PACKAGE_INSTALL_FILES); do \
+ [ -s $$file.flags ] || continue; \
+ for flag in `cat $$file.flags`; do \
+ $(OPKG) flag $$flag < $$file; \
+ done; \
+ done || true
+ @-$(MAKE) package/preconfig