remove extra targets
[openwrt.git] / package / rules.mk
1 ifneq ($(DUMP),)
2 all: dumpinfo
3 else
4 all: compile
5 endif
6
7 define Build/DefaultTargets
8 $(PKG_BUILD_DIR)/.prepared: FORCE $(DL_DIR)/$(PKG_SOURCE)
9 ifeq ($(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),.)
10         @-rm -rf $(PKG_BUILD_DIR)
11         @mkdir -p $(PKG_BUILD_DIR)
12         $(call Build/Prepare)
13         @touch $$@
14 endif
15
16 $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
17         $(call Build/Configure)
18         touch $$@
19
20 $(PKG_BUILD_DIR)/.built: FORCE $(PKG_BUILD_DIR)/.configured
21 ifeq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg $$(IPKG_$(1)) $(PKG_BUILD_DIR)),$(PKG_BUILD_DIR))
22         $(call Build/Compile)
23         touch $$@
24 endif
25
26 package-clean: FORCE
27         $(call Build/Clean)
28         rm -f $(PKG_BUILD_DIR)/.built
29
30 define Build/DefaultTargets
31 endef
32 endef
33
34 define Package/Default
35 CONFIGFILE:=
36 SECTION:=opt
37 CATEGORY:=Extra packages
38 DEPENDS:=
39 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
40 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
41 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
42 PKGARCH:=$(ARCH)
43 PRIORITY:=optional
44 DEFAULT:=
45 MENU:=
46 TITLE:=
47 DESCRIPTION:=
48 endef
49
50 define RequiredField
51 ifeq ($$($(1)),)
52 $$(error Package/$$(1) is missing the $(1) field)
53 endif
54 endef
55
56 define BuildPackage
57 $(eval $(call Package/Default))
58 $(eval $(call Package/$(1)))
59
60 $(foreach FIELD, TITLE CATEGORY PRIORITY VERSION, $(eval $(call RequiredField,$(FIELD))))
61
62 ifeq ($(PKGARCH),)
63 PKGARCH:=$(ARCH)
64 endif
65 $(eval 
66 ifeq ($(DESCRIPTION),)
67 DESCRIPTION:=$(TITLE)
68 endif
69 )
70
71 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
72 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
73 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
74
75 ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
76 COMPILE_$(1):=1
77 endif
78
79 ifeq ($(CONFIG_PACKAGE_$(1)),y)
80 install-targets: $$(INFO_$(1))
81 endif
82
83 compile-targets: $$(IPKG_$(1))
84 endif
85
86 IDEPEND_$(1):=$$(strip $$(DEPENDS))
87
88 DUMPINFO += \
89         echo "Package: $(1)"; 
90 ifneq ($(MENU),)
91 DUMPINFO += \
92         echo "Menu: $(MENU)";
93 endif
94 ifneq ($(DEFAULT),)
95 DUMPINFO += \
96         echo "Default: $(DEFAULT)";
97 endif
98 DUMPINFO += \
99         echo "Version: $(VERSION)"; \
100         echo "Depends: $$(IDEPEND_$(1))"; \
101         echo "Category: $(CATEGORY)"; \
102         echo "Title: $(TITLE)"; \
103         echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g';
104 ifneq ($(URL),)
105 DUMPINFO += \
106         echo; \
107         echo "$(URL)";
108 endif
109 DUMPINFO += \
110         echo "@@";
111
112
113 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.prepared
114         mkdir -p $$(IDIR_$(1))/CONTROL
115         echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
116         echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
117         echo "Depends: $$(IDEPEND_$(1))" >> $$(IDIR_$(1))/CONTROL/control
118         echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
119         echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
120         echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
121         echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
122         echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
123         echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
124         chmod 644 $$(IDIR_$(1))/CONTROL/control
125         for file in conffiles preinst postinst prerm postrm; do \
126                 [ -f ./ipkg/$(1).$$$$file ] && cp ./ipkg/$(1).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file || true; \
127         done
128
129 $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $(PKG_BUILD_DIR)/.built
130         $(call Package/$(1)/install,$$(IDIR_$(1)))
131         mkdir -p $(PACKAGE_DIR)
132         $(RSTRIP) $$(IDIR_$(1))
133         $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
134
135 $$(INFO_$(1)): $$(IPKG_$(1))
136         $(IPKG) install $$(IPKG_$(1))
137
138 $(1)-clean:
139         rm -f $(PACKAGE_DIR)/$(1)_*
140 clean: $(1)-clean
141
142 ifneq ($(__DEFAULT_TARGETS),1)
143 $(eval $(call Build/DefaultTargets))
144 endif
145
146 endef
147
148 ifneq ($(strip $(PKG_SOURCE)),)
149 $(DL_DIR)/$(PKG_SOURCE):
150         $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
151 endif
152
153 ifneq ($(strip $(PKG_CAT)),)
154 define Build/Prepare/Default
155         @if [ "$(PKG_CAT)" = "unzip" ]; then \
156                 unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE) ; \
157         else \
158                 $(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) - ; \
159         fi                                                
160         @if [ -d ./patches ]; then \
161                 $(PATCH) $(PKG_BUILD_DIR) ./patches ; \
162         fi
163 endef
164 endif
165
166 define Build/Prepare
167 $(call Build/Prepare/Default)
168 endef
169
170 define Build/Configure/Default
171         @(cd $(PKG_BUILD_DIR); \
172         [ -x configure ] && \
173                 $(TARGET_CONFIGURE_OPTS) \
174                 CFLAGS="$(TARGET_CFLAGS)" \
175                 ./configure \
176                 --target=$(GNU_TARGET_NAME) \
177                 --host=$(GNU_TARGET_NAME) \
178                 --build=$(GNU_HOST_NAME) \
179                 --prefix=/usr \
180                 --exec-prefix=/usr \
181                 --bindir=/usr/bin \
182                 --sbindir=/usr/sbin \
183                 --libexecdir=/usr/lib \
184                 --sysconfdir=/etc \
185                 --datadir=/usr/share \
186                 --localstatedir=/var \
187                 --mandir=/usr/man \
188                 --infodir=/usr/info \
189                 $(DISABLE_NLS) \
190                 $(1); \
191         )
192 endef
193
194 define Build/Configure
195 $(call Build/Configure/Default,)
196 endef
197
198 define Build/Compile/Default
199         $(MAKE) -C $(PKG_BUILD_DIR) \
200                 CC=$(TARGET_CC) \
201                 CROSS="$(TARGET_CROSS)" \
202                 PREFIX="$$(IDIR_$(1))" \
203                 EXTRA_CFLAGS="$(TARGET_CFLAGS)" \
204                 ARCH="$(ARCH)" \
205                 DESTDIR="$$(IDIR_$(1))"
206 endef
207
208 define Build/Compile
209 $(call Build/Compile/Default)
210 endef
211
212 define Build/Clean
213         $(MAKE) clean
214 endef
215
216 ifneq ($(DUMP),)
217 dumpinfo:
218         $(DUMPINFO)
219 else
220                 
221 $(PACKAGE_DIR):
222         mkdir -p $@
223
224 source: FORCE $(DL_DIR)/$(PKG_SOURCE)
225 prepare: FORCE $(PKG_BUILD_DIR)/.prepared
226 configure: FORCE $(PKG_BUILD_DIR)/.configured
227
228 compile-targets: FORCE
229 compile: FORCE compile-targets
230
231 install-targets: FORCE
232 install: FORCE install-targets
233
234 clean-targets: FORCE
235 clean: FORCE
236         @$(MAKE) clean-targets
237         rm -rf $(PKG_BUILD_DIR)
238 endif
239
240 .PHONY: FORCE
241 FORCE: