build: clean up redundant touching of the package install info file
[openwrt/staging/chunkeey.git] / include / package.mk
index 37cea1448df8339f9eb2d325bbac70b04dc537ad..bf308bb5c076aa8f01eeb8638bdd60103abb273a 100644 (file)
@@ -37,7 +37,6 @@ endif
 
 include $(INCLUDE_DIR)/hardening.mk
 include $(INCLUDE_DIR)/prereq.mk
-include $(INCLUDE_DIR)/host.mk
 include $(INCLUDE_DIR)/unpack.mk
 include $(INCLUDE_DIR)/depends.mk
 
@@ -57,7 +56,7 @@ ifneq ($(PREV_STAMP_PREPARED),)
   STAMP_PREPARED:=$(PREV_STAMP_PREPARED)
   CONFIG_AUTOREBUILD:=
 else
-  STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))$(call confvar,$(PKG_PREPARED_DEPENDS)))
+  STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))_$(call confvar,CONFIG_AUTOREMOVE $(PKG_PREPARED_DEPENDS)))
 endif
 STAMP_CONFIGURED=$(PKG_BUILD_DIR)/.configured$(if $(DUMP),,_$(call confvar,$(PKG_CONFIG_DEPENDS)))
 STAMP_CONFIGURED_WILDCARD=$(PKG_BUILD_DIR)/.configured_*
@@ -96,6 +95,8 @@ include $(INCLUDE_DIR)/package-ipkg.mk
 include $(INCLUDE_DIR)/package-bin.mk
 include $(INCLUDE_DIR)/autotools.mk
 
+_pkg_target:=$(if $(QUILT),,.)
+
 override MAKEFLAGS=
 CONFIG_SITE:=$(INCLUDE_DIR)/site/$(ARCH)
 CUR_MAKEFILE:=$(filter-out Makefile,$(firstword $(MAKEFILE_LIST)))
@@ -154,6 +155,7 @@ define Build/CoreTargets
   $(STAMP_PREPARED): $(STAMP_PREPARED_DEPENDS)
        @-rm -rf $(PKG_BUILD_DIR)
        @mkdir -p $(PKG_BUILD_DIR)
+       touch $$@_check
        $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
        $(Build/Prepare)
        $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
@@ -170,6 +172,8 @@ define Build/CoreTargets
 
   $(call Build/Exports,$(STAMP_BUILT))
   $(STAMP_BUILT): $(STAMP_CONFIGURED) $(STAMP_BUILT_DEPENDS)
+       rm -f $$@
+       touch $$@_check
        $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
        $(Build/Compile)
        $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
@@ -204,13 +208,20 @@ define Build/CoreTargets
        touch $$@
 
   ifdef Build/InstallDev
-    .compile: $(STAMP_INSTALLED)
+    $(_pkg_target)compile: $(STAMP_INSTALLED)
   endif
 
-  .prepare: $(STAMP_PREPARED)
-  .configure: $(STAMP_CONFIGURED)
-  .dist: $(STAMP_CONFIGURED)
-  .distcheck: $(STAMP_CONFIGURED)
+  $(_pkg_target)prepare: $(STAMP_PREPARED)
+  $(_pkg_target)configure: $(STAMP_CONFIGURED)
+  $(_pkg_target)dist: $(STAMP_CONFIGURED)
+  $(_pkg_target)distcheck: $(STAMP_CONFIGURED)
+
+  ifneq ($(CONFIG_AUTOREMOVE),)
+    compile:
+               -touch $(PKG_BUILD_DIR)/.autoremove 2>/dev/null >/dev/null
+               $(FIND) $(PKG_BUILD_DIR) -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' -and -not -name '.pkgdir' | \
+                       $(XARGS) rm -rf
+  endif
 endef
 
 define Build/DefaultTargets
@@ -282,22 +293,26 @@ Build/DistCheck=$(call Build/DistCheck/Default,)
 .PHONY: prepare-package-install
 prepare-package-install:
        @mkdir -p $(PKG_INFO_DIR)
-       @touch $(PKG_INSTALL_STAMP).clean
+       @rm -f $(PKG_INSTALL_STAMP)
        @echo "$(filter-out essential nonshared,$(PKG_FLAGS))" > $(PKG_INSTALL_STAMP).flags
 
 $(PACKAGE_DIR):
        mkdir -p $@
 
-compile: prepare-package-install
+compile:
 .install: .compile
 install: compile
 
-clean: FORCE
+force-clean-build: FORCE
+       rm -rf $(PKG_BUILD_DIR)
+
+clean-build: $(if $(wildcard $(PKG_BUILD_DIR)/.autoremove),force-clean-build)
+
+clean: force-clean-build
        $(CleanStaging)
        $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
        $(Build/Clean)
        rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
-       rm -rf $(PKG_BUILD_DIR)
 
 dist:
        $(Build/Dist)