fix unnecessary package rebuild
[openwrt/openwrt.git] / openwrt / include / package.mk
index 43f175890008626f9a968ead2b9e36a8dd68d9b6..069e28b84f34a8681cb7df1fe55f4fc2a9050df7 100644 (file)
@@ -15,15 +15,11 @@ include $(INCLUDE_DIR)/prereq.mk
 define Build/DefaultTargets
   ifeq ($(DUMP),)
     ifeq ($(CONFIG_AUTOREBUILD),y)
-      ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR))
-       $$(warning package has changed, need to rebuild $(subst $(TOPDIR)/,,$(PKG_BUILD_DIR)))
+      _INFO:=
+      ifneq ($(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR))
+        _INFO+=$(subst $(TOPDIR)/,,$(PKG_BUILD_DIR))
         $(PKG_BUILD_DIR)/.prepared: package-clean
       endif
-
-      ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install $(IPKG_$(1)) $(PKG_BUILD_DIR)),$(IPKG_$(1)))
-       $$(warning $(subst $(TOPDIR)/,,$(PKG_BUILD_DIR)) has changed, need to rebuild $(subst $(TOPDIR)/,,$(IPKG_$(1))))
-        $(PKG_BUILD_DIR)/.built: package-rebuild
-      endif
     endif
   endif
 
@@ -42,6 +38,10 @@ define Build/DefaultTargets
        touch $$@
 
   ifdef Build/InstallDev
+    ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed $(PKG_BUILD_DIR)),$(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed)
+      $(PKG_BUILD_DIR)/.built: package-rebuild
+    endif
+
     $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
        mkdir -p $(STAGING_DIR)/stampfiles
        $(call Build/InstallDev)
@@ -89,6 +89,14 @@ define Package/Default
   DESCRIPTION:=
 endef
 
+define BuildDescription
+  ifneq ($(DESCRIPTION),)
+    DESCRIPTION:=$(TITLE)\\ $(DESCRIPTION)
+  else
+    DESCRIPTION:=$(TITLE)
+  endif
+endef
+
 define BuildIPKGVariable
   pkg_$(subst .,_,$(subst -,_,$(1)))_$(2) = $$(Package/$(1)/$(2))
   export pkg_$(subst .,_,$(subst -,_,$(1))_$(2))
@@ -98,21 +106,14 @@ endef
 define BuildPackage
   $(eval $(call Package/Default))
   $(eval $(call Package/$(1)))
+  $(eval $(call BuildDescription))
 
-  $(foreach FIELD, TITLE CATEGORY PRIORITY VERSION,
+  $(foreach FIELD, TITLE CATEGORY PRIORITY SECTION VERSION,
     ifeq ($($(FIELD)),)
       $$(error Package/$(1) is missing the $(FIELD) field)
     endif
   )
 
-  ifeq ($(PKGARCH),)
-    PKGARCH:=$(ARCH)
-  endif
-
-  ifeq ($(DESCRIPTION),)
-    $(eval DESCRIPTION:=$(TITLE))
-  endif
-
   IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
   IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
   INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
@@ -124,6 +125,10 @@ define BuildPackage
 
     ifneq ($(CONFIG_PACKAGE_$(1)),)
       compile-targets: $$(IPKG_$(1))
+    else
+      compile-targets: $(1)-disabled
+      $(1)-disabled:
+       @echo "WARNING: skipping $(1) -- package not selected"
     endif
   endif
 
@@ -157,13 +162,14 @@ define BuildPackage
     endif
 
     DUMPINFO += \
+       if [ "$$$$PREREQ_CHECK" = 1 ]; then echo "Prereq-Check: 1"; fi; \
        echo "Version: $(VERSION)"; \
        echo "Depends: $$(IDEPEND_$(1))"; \
        echo "Build-Depends: $(PKG_BUILDDEP)"; \
        echo "Category: $(CATEGORY)"; \
        echo "Title: $(TITLE)"; \
        echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g';
-
+       
     ifneq ($(URL),)
       DUMPINFO += \
        echo; \
@@ -201,7 +207,7 @@ define BuildPackage
        echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
        echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
        echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
-       echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
+       echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g' | sed -e 's,^[[:space:]]*$$$$, .,g' >> $$(IDIR_$(1))/CONTROL/control
        chmod 644 $$(IDIR_$(1))/CONTROL/control
        (cd $$(IDIR_$(1))/CONTROL; \
                $($(1)_COMMANDS) \
@@ -226,10 +232,25 @@ define BuildPackage
   clean: $(1)-clean
 
   $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH): $(PKG_BUILD_DIR)/.prepared
-       -rm $(PKG_BUILD_DIR)/.version-$(1)_*
+       -@rm $(PKG_BUILD_DIR)/.version-$(1)_* 2>/dev/null
        @touch $$@
 
   $$(eval $$(call Build/DefaultTargets,$(1)))
+
+  ifneq ($$(CONFIG_PACKAGE_$(1)),)
+    ifneq ($(MAKECMDGOALS),prereq)
+      ifneq ($(DUMP),1)
+        ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install '$$(IPKG_$(1))' '$(PKG_BUILD_DIR)'),$$(IPKG_$(1)))
+          _INFO+=$(subst $(TOPDIR)/,,$$(IPKG_$(1)))
+          $(PKG_BUILD_DIR)/.built: package-rebuild
+        endif
+
+        ifneq ($$(_INFO),)
+          $$(info Rebuilding $$(_INFO))
+        endif
+      endif
+    endif
+  endif
 endef
 
 ifneq ($(strip $(PKG_CAT)),)
@@ -247,16 +268,18 @@ ifneq ($(strip $(PKG_CAT)),)
 endif
 
 define Build/Prepare
-  $(call Build/Prepare/Default)
+  $(call Build/Prepare/Default,)
 endef
 
 define Build/Configure/Default
-       @(cd $(PKG_BUILD_DIR)/$(3); \
-       [ -x configure ] && \
+       (cd $(PKG_BUILD_DIR)/$(3); \
+       if [ -x configure ]; then \
                $(TARGET_CONFIGURE_OPTS) \
                CFLAGS="$(TARGET_CFLAGS)" \
+               CXXFLAGS="$(TARGET_CFLAGS)" \
                CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
                LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
+               PKG_CONFIG_PATH="$(STAGING_DIR)/usr/lib/pkgconfig" \
                $(2) \
                ./configure \
                --target=$(GNU_TARGET_NAME) \
@@ -276,7 +299,7 @@ define Build/Configure/Default
                --infodir=/usr/info \
                $(DISABLE_NLS) \
                $(1); \
-               true; \
+       fi; \
        )
 endef
 
@@ -288,7 +311,8 @@ define Build/Compile/Default
        $(MAKE) -C $(PKG_BUILD_DIR) \
                $(TARGET_CONFIGURE_OPTS) \
                CROSS="$(TARGET_CROSS)" \
-               EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/include -I$(STAGING_DIR)/usr/include" \
+               EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include " \
+               EXTRA_LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib " \
                ARCH="$(ARCH)" \
                $(1);
 endef