check if the Package/$(NAME) template is defined before packaging or installing ipkg...
[openwrt/openwrt.git] / openwrt / include / package.mk
index 82298b02498677b08c81a001b24f01f414e8d803..2784cc888175d20fc0adb102d1fc1669a775fd46 100644 (file)
@@ -1,3 +1,9 @@
+# 
+# Copyright (C) 2006 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
 ifneq ($(DUMP),)
   all: dumpinfo
 else
@@ -6,7 +12,7 @@ endif
 
 define Build/DefaultTargets
   ifeq ($(DUMP),)
-    ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) . $(TOPDIR)/package/rules.mk),$(PKG_BUILD_DIR))
+    ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR))
       ifeq ($(CONFIG_AUTOREBUILD),y)
         $(PKG_BUILD_DIR)/.prepared: package-clean
       endif
@@ -59,6 +65,7 @@ define Package/Default
   SECTION:=opt
   CATEGORY:=Extra packages
   DEPENDS:=
+  EXTRA_DEPENDS:=
   MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
   SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
   ifneq ($(PKG_VERSION),)
@@ -74,6 +81,7 @@ define Package/Default
   PRIORITY:=optional
   DEFAULT:=
   MENU:=
+  SUBMENU:=
   TITLE:=
   DESCRIPTION:=
 endef
@@ -106,12 +114,18 @@ define BuildPackage
   IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
   INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
 
-  ifeq ($(CONFIG_PACKAGE_$(1)),y)
-    install-targets: $$(INFO_$(1))
+  ifdef Package/$(1)/install
+    ifeq ($(CONFIG_PACKAGE_$(1)),y)
+      install-targets: $$(INFO_$(1))
+    endif
+
+    ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
+      compile-targets: $$(IPKG_$(1))
+    endif
   endif
 
-  ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
-    compile-targets: $$(IPKG_$(1))
+  ifeq ($(FORCEREBUILD),y)
+    $$(IPKG_$(1)): FORCE
   endif
 
   IDEPEND_$(1):=$$(strip $$(DEPENDS))
@@ -124,6 +138,11 @@ define BuildPackage
        echo "Menu: $(MENU)";
   endif
 
+  ifneq ($(SUBMENU),)
+    DUMPINFO += \
+       echo "Submenu: $(SUBMENU)";
+  endif
+
   ifneq ($(DEFAULT),)
     DUMPINFO += \
        echo "Default: $(DEFAULT)";
@@ -157,7 +176,7 @@ define BuildPackage
   $(eval $(call BuildIPKGVariable,$(1),postinst))
   $(eval $(call BuildIPKGVariable,$(1),prerm))
   $(eval $(call BuildIPKGVariable,$(1),postrm))
-  $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.prepared
+  $$(IDIR_$(1))/CONTROL/control: Makefile $(PKG_BUILD_DIR)/.prepared
        mkdir -p $$(IDIR_$(1))/CONTROL
        echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
        echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
@@ -166,7 +185,7 @@ define BuildPackage
                for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
                        DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
                done; \
-               echo "Depends: $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
+               echo "Depends: $(EXTRA_DEPENDS) $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
        )
        echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
        echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
@@ -201,14 +220,15 @@ define BuildPackage
 endef
 
 ifneq ($(strip $(PKG_CAT)),)
+  ifeq ($(PKG_CAT),unzip)
+    UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
+  else
+    UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
+  endif
   define Build/Prepare/Default
-       @if [ "$(PKG_CAT)" = "unzip" ]; then \
-               unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE) ; \
-       else \
-               $(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) - ; \
-       fi                                                
+       $(UNPACK)
        @if [ -d ./patches ]; then \
-               $(PATCH) $(PKG_BUILD_DIR) ./patches ; \
+               $(PATCH) $(PKG_BUILD_DIR) ./patches; \
        fi
   endef
 endif