- rm -rf $(BUILD_DIR)/root
-
-$(curdir)/rootfs-prepare: $(TMP_DIR)/.build
- @if [ -d $(TOPDIR)/files ]; then \
- $(CP) $(TOPDIR)/files/. $(BUILD_DIR)/root; \
- fi
- @mkdir -p $(BUILD_DIR)/root/etc/rc.d
- @( \
- cd $(BUILD_DIR)/root; \
- for script in ./etc/init.d/*; do \
- grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
- IPKG_INSTROOT=$(BUILD_DIR)/root $(which bash) ./etc/rc.common $$script enable; \
- done || true \
- )
- @-find $(BUILD_DIR)/root -name CVS | $(XARGS) rm -rf
- @-find $(BUILD_DIR)/root -name .svn | $(XARGS) rm -rf
- @-find $(BUILD_DIR)/root -name '.#*' | $(XARGS) rm -f
+ rm -rf $(STAGING_DIR_ROOT)
+
+$(curdir)/merge:
+ rm -rf $(PACKAGE_DIR_ALL)
+ mkdir -p $(PACKAGE_DIR_ALL)
+ -$(foreach pdir,$(PACKAGE_SUBDIRS),$(if $(wildcard $(pdir)/*.ipk),ln -s $(pdir)/*.ipk $(PACKAGE_DIR_ALL);))
+
+$(curdir)/merge-index: $(curdir)/merge
+ (cd $(PACKAGE_DIR_ALL) && $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages; )
+
+ifndef SDK
+ $(curdir)/compile: $(curdir)/system/opkg/host/compile
+endif
+
+$(curdir)/install: $(TMP_DIR)/.build $(curdir)/merge $(if $(CONFIG_TARGET_PER_DEVICE_ROOTFS),$(curdir)/merge-index)
+ - find $(STAGING_DIR_ROOT) -type d | $(XARGS) chmod 0755
+ rm -rf $(TARGET_DIR) $(TARGET_DIR_ORIG)
+ [ -d $(TARGET_DIR)/tmp ] || mkdir -p $(TARGET_DIR)/tmp
+ $(call opkg,$(TARGET_DIR)) install \
+ $(call opkg_package_files,$(shell cat $(PACKAGE_INSTALL_FILES) 2>/dev/null))
+ @for file in $(PACKAGE_INSTALL_FILES); do \
+ [ -s $$file.flags ] || continue; \
+ for flag in `cat $$file.flags`; do \
+ $(call opkg,$(TARGET_DIR)) flag $$flag `cat $$file`; \
+ done; \
+ done || true
+ @-$(MAKE) package/preconfig
+
+ $(CP) $(TARGET_DIR) $(TARGET_DIR_ORIG)
+
+ $(call prepare_rootfs,$(TARGET_DIR))