base-files: add support for overlaying rootfs content
[openwrt/openwrt.git] / include / package-ipkg.mk
index b8c8cd6..e168eb3 100644 (file)
@@ -5,18 +5,25 @@
 # See /LICENSE for more information.
 #
 
-include $(INCLUDE_DIR)/feeds.mk
+ifndef DUMP
+  include $(INCLUDE_DIR)/feeds.mk
+endif
 
 # invoke ipkg-build with some default options
 IPKG_BUILD:= \
-  $(STAGING_DIR_HOST)/bin/ipkg-build -c -o 0 -g 0
+  $(SCRIPT_DIR)/ipkg-build -c -o 0 -g 0
 
 IPKG_STATE_DIR:=$(TARGET_DIR)/usr/lib/opkg
 
+# 1: package name
+# 2: variable name
+# 3: variable suffix
+# 4: file is a script
 define BuildIPKGVariable
 ifdef Package/$(1)/$(2)
   $$(IPKG_$(1)) : VAR_$(2)$(3)=$$(Package/$(1)/$(2))
-  $(1)_COMMANDS += echo "$$$$$(2)$(3)" > $(2)$(3);
+  $(call shexport,Package/$(1)/$(2))
+  $(1)_COMMANDS += echo "$$$$$$$$$(call shvar,Package/$(1)/$(2))" > $(2)$(3); $(if $(4),chmod 0755 $(2)$(3);)
 endif
 endef
 
@@ -62,7 +69,7 @@ ifneq ($(PKG_NAME),toolchain)
                                XARGS="$(XARGS)"; \
                        $(SCRIPT_DIR)/gen-dependencies.sh "$$(IDIR_$(1))"; \
                ) | while read FILE; do \
-                       grep -q "$$$$FILE" $(PKG_INFO_DIR)/$(1).provides || \
+                       grep -qxF "$$$$FILE" $(PKG_INFO_DIR)/$(1).provides || \
                                echo "$$$$FILE" >> $(PKG_INFO_DIR)/$(1).missing; \
                done; \
                if [ -f "$(PKG_INFO_DIR)/$(1).missing" ]; then \
@@ -89,27 +96,34 @@ ifeq ($(DUMP),)
     KEEP_$(1):=$(strip $(call Package/$(1)/conffiles))
 
     ifeq ($(BUILD_VARIANT),$$(if $$(VARIANT),$$(VARIANT),$(BUILD_VARIANT)))
+    do_install=
     ifdef Package/$(1)/install
+      do_install=yes
+    endif
+    ifdef Package/$(1)/install-overlay
+      do_install=yes
+    endif
+    ifdef do_install
       ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
         IPKGS += $(1)
         compile: $$(IPKG_$(1)) $(PKG_INFO_DIR)/$(1).provides $(STAGING_DIR_ROOT)/stamp/.$(1)_installed
         ifneq ($(ABI_VERSION),)
         compile: $(PKG_INFO_DIR)/$(1).version
         endif
+      else
+        $(if $(CONFIG_PACKAGE_$(1)),$$(info WARNING: skipping $(1) -- package not selected))
+      endif
 
-        ifeq ($(CONFIG_PACKAGE_$(1)),y)
-          .PHONY: $(PKG_INSTALL_STAMP).$(1)
-          compile: $(PKG_INSTALL_STAMP).$(1)
-          $(PKG_INSTALL_STAMP).$(1):
+      .PHONY: $(PKG_INSTALL_STAMP).$(1)
+      compile: $(PKG_INSTALL_STAMP).$(1)
+      $(PKG_INSTALL_STAMP).$(1):
                        if [ -f $(PKG_INSTALL_STAMP).clean ]; then \
                                rm -f \
                                        $(PKG_INSTALL_STAMP) \
                                        $(PKG_INSTALL_STAMP).clean; \
-                       fi; \
+                       fi
+      ifeq ($(CONFIG_PACKAGE_$(1)),y)
                        echo "$(1)" >> $(PKG_INSTALL_STAMP)
-        endif
-      else
-        $$(info WARNING: skipping $(1) -- package not selected)
       endif
     endif
     endif
@@ -121,11 +135,12 @@ ifeq ($(DUMP),)
     $(FixupReverseDependencies)
 
     $(eval $(call BuildIPKGVariable,$(1),conffiles))
-    $(eval $(call BuildIPKGVariable,$(1),preinst))
-    $(eval $(call BuildIPKGVariable,$(1),postinst,-pkg))
-    $(eval $(call BuildIPKGVariable,$(1),prerm,-pkg))
-    $(eval $(call BuildIPKGVariable,$(1),postrm))
+    $(eval $(call BuildIPKGVariable,$(1),preinst,,1))
+    $(eval $(call BuildIPKGVariable,$(1),postinst,-pkg,1))
+    $(eval $(call BuildIPKGVariable,$(1),prerm,-pkg,1))
+    $(eval $(call BuildIPKGVariable,$(1),postrm,,1))
 
+    $(STAGING_DIR_ROOT)/stamp/.$(1)_installed : export PATH=$$(TARGET_PATH_PKG)
     $(STAGING_DIR_ROOT)/stamp/.$(1)_installed: $(STAMP_BUILT)
        rm -rf $(STAGING_DIR_ROOT)/tmp-$(1)
        mkdir -p $(STAGING_DIR_ROOT)/stamp $(STAGING_DIR_ROOT)/tmp-$(1)
@@ -149,7 +164,7 @@ Package: $(1)
 Version: $(VERSION)
 $$(call addfield,Depends,$$(Package/$(1)/DEPENDS)
 )$$(call addfield,Conflicts,$$(call mergelist,$(CONFLICTS))
-)$$(call addfield,Provides,$(PROVIDES)
+)$$(call addfield,Provides,$$(call mergelist,$(PROVIDES))
 )$$(call addfield,Source,$(SOURCE)
 )$$(call addfield,License,$$(PKG_LICENSE)
 )$$(call addfield,LicenseFiles,$$(PKG_LICENSE_FILES)
@@ -165,10 +180,13 @@ $(_endef)
     $(PKG_INFO_DIR)/$(1).provides: $$(IPKG_$(1))
     $$(IPKG_$(1)) : export CONTROL=$$(Package/$(1)/CONTROL)
     $$(IPKG_$(1)) : export DESCRIPTION=$$(Package/$(1)/description)
+    $$(IPKG_$(1)) : export PATH=$$(TARGET_PATH_PKG)
     $$(IPKG_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-ipkg.mk
-       @rm -rf $$(PDIR_$(1))/$(1)_* $$(IDIR_$(1))
+       @rm -rf $$(IDIR_$(1)) $$(call opkg_package_files,$(1))
        mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR)
        $(call Package/$(1)/install,$$(IDIR_$(1)))
+       $(if $(Package/$(1)/install-overlay),mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/rootfs-overlay)
+       $(call Package/$(1)/install-overlay,$$(IDIR_$(1))/rootfs-overlay)
        -find $$(IDIR_$(1)) -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| $(XARGS) rm -rf
        @( \
                find $$(IDIR_$(1)) -name lib\*.so\* -or -name \*.ko | awk -F/ '{ print $$$$NF }'; \
@@ -199,7 +217,7 @@ $(_endef)
                        echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
                        echo "default_prerm \$$$$0 \$$$$@"; \
                ) > prerm; \
-               chmod 0755 prerm; \
+               chmod 0755 postinst prerm; \
                $($(1)_COMMANDS) \
        )
 
@@ -221,7 +239,7 @@ $(_endef)
        @[ -f $$(IPKG_$(1)) ]
 
     $(1)-clean:
-       rm -f $$(PDIR_$(1))/$(1)_*
+       $$(if $$(call opkg_package_files,$(1)),rm -f $$(call opkg_package_files,$(1)))
 
     clean: $(1)-clean