remove some more stuff, change package makefile format in rules.mk, port busybox...
[10.03/openwrt.git] / package / rules.mk
1 # invoke ipkg with configuration in $(STAGING_DIR)/etc/ipkg.conf 
2
3 define BuildPackage
4 CONFIGFILE:=
5 NAME:=$(PKG_NAME)
6 SECTION:=opt
7 CATEGORY:=Extra packages
8 DEPENDS:=
9 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
10 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
11 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
12 PKGARCH:=$(ARCH)
13 PRIORITY:=optional
14 TITLE:=
15 DESCRIPTION:=
16
17 $$(eval $$(call Package/$(2)))
18
19 ifeq ($$(NAME),)
20 $$(error Package $(2) has no NAME)
21 endif
22 ifeq ($$(TITLE),)
23 $$(error Package $(2) has no TITLE)
24 endif
25 ifeq ($$(CATEGORY),)
26 $$(error Package $(2) has no CATEGORY)
27 endif
28 ifeq ($$(PRIORITY),)
29 $$(error Package $(2) has no PRIORITY)
30 endif
31 ifeq ($$(VERSION),)
32 $$(error Package $(2) has no VERSION)
33 endif
34 ifeq ($$(PKGARCH),)
35 PKGARCH:=$(ARCH)
36 endif
37
38 IPKG_$(1):=$(PACKAGE_DIR)/$(2)_$(VERSION)_$(PKGARCH).ipk
39 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(2)
40 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(2).list
41
42 ifneq ($(BR2_PACKAGE_$(1)),)
43 compile-targets: $$(IPKG_$(1))
44 endif
45 ifneq ($(DEVELOPER),)
46 compile-targets: $$(IPKG_$(1))
47 endif
48 ifeq ($(BR2_PACKAGE_$(1)),y)
49 install-targets: $$(INFO_$(1))
50 endif
51
52 IDEPEND_$(1):=$$(strip $$(DEPENDS))
53
54 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.prepared
55         mkdir -p $$(IDIR_$(1))/CONTROL
56         echo "Package: $(2)" > $$(IDIR_$(1))/CONTROL/control
57         echo "Version: $$(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
58         echo "Depends: $$(IDEPEND_$(1))" >> $$(IDIR_$(1))/CONTROL/control
59         echo "Source: $$(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
60         echo "Section: $$(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
61         echo "Priority: $$(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
62         echo "Maintainer: $$(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
63         echo "Architecture: $$(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
64         echo "Description: $$(DESCRIPTION)" >> $$(IDIR_$(1))/CONTROL/control
65         chmod 644 $$(IDIR_$(1))/CONTROL/control
66         for file in conffiles preinst postinst prerm postrm; do \
67                 [ -f ./ipkg/$(2).$$$$file ] && cp ./ipkg/$(2).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file || true; \
68         done
69
70 $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $(PKG_BUILD_DIR)/.built $(PACKAGE_DIR)
71
72 $$(INFO_$(1)): $$(IPKG_$(1))
73         $(IPKG) install $$(IPKG_$(1))
74
75 $(2)-clean:
76         rm -f $$(IPKG_$(1))
77 clean: $(2)-clean
78 endef
79
80
81 ifneq ($(strip $(PKG_SOURCE)),)
82 $(DL_DIR)/$(PKG_SOURCE):
83         @$(CMD_TRACE) "downloading... "
84         $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL) $(MAKE_TRACE) 
85 endif
86
87 ifneq ($(strip $(PKG_CAT)),)
88 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
89         rm -rf $(PKG_BUILD_DIR)
90         mkdir -p $(PKG_BUILD_DIR)
91         if [ "$(PKG_CAT)" = "unzip" ]; then \
92                 unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE) ; \
93         else \
94                 $(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) - ; \
95         fi                                                
96         if [ -d ./patches ]; then \
97                 $(PATCH) $(PKG_BUILD_DIR) ./patches ; \
98         fi
99         touch $(PKG_BUILD_DIR)/.prepared
100 endif
101
102 all: compile
103
104 source: $(DL_DIR)/$(PKG_SOURCE)
105 prepare: source
106         @[ -f $(PKG_BUILD_DIR)/.prepared ] || { \
107                 $(CMD_TRACE) "preparing... "; \
108                 $(MAKE) $(PKG_BUILD_DIR)/.prepared $(MAKE_TRACE); \
109         }
110
111 configure: prepare
112         @[ -f $(PKG_BUILD_DIR)/.configured ] || { \
113                 $(CMD_TRACE) "configuring... "; \
114                 $(MAKE) $(PKG_BUILD_DIR)/.configured $(MAKE_TRACE); \
115         }
116
117 compile-targets:
118 compile: configure
119         @$(CMD_TRACE) "compiling... " 
120         @$(MAKE) compile-targets $(MAKE_TRACE)
121
122 install-targets:
123 install:
124         @$(CMD_TRACE) "installing... "
125         @$(MAKE) install-targets $(MAKE_TRACE)
126
127 mostlyclean:
128 rebuild:
129         $(CMD_TRACE) "rebuilding... "
130         @-$(MAKE) mostlyclean 2>&1 >/dev/null
131         if [ -f $(PKG_BUILD_DIR)/.built ]; then \
132                 $(MAKE) clean $(MAKE_TRACE); \
133         fi
134         $(MAKE) compile $(MAKE_TRACE)
135
136 $(PKG_BUILD_DIR)/.configured:
137 $(PKG_BUILD_DIR)/.built:
138
139 $(PACKAGE_DIR):
140         mkdir -p $@
141
142 clean-targets:
143 clean: 
144         @$(CMD_TRACE) "cleaning... " 
145         @$(MAKE) clean-targets $(MAKE_TRACE)
146         rm -rf $(PKG_BUILD_DIR)
147
148 .PHONY: all source prepare compile install clean