only run trap error code in the configure template, if the configure script was not...
[openwrt/openwrt.git] / openwrt / include / package.mk
1 #
2 # Copyright (C) 2006 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7 ifneq ($(DUMP),)
8 all: dumpinfo
9 else
10 all: compile
11 endif
12
13 include $(INCLUDE_DIR)/prereq.mk
14
15 define Build/DefaultTargets
16 ifeq ($(DUMP),)
17 ifeq ($(CONFIG_AUTOREBUILD),y)
18 _INFO:=
19 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR))
20 _INFO+=$(subst $(TOPDIR)/,,$(PKG_BUILD_DIR))
21 $(PKG_BUILD_DIR)/.prepared: package-clean
22 endif
23
24 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install $(IPKG_$(1)) $(PKG_BUILD_DIR)),$(IPKG_$(1)))
25 _INFO+=$(subst $(TOPDIR)/,,$(IPKG_$(1)))
26 $(PKG_BUILD_DIR)/.built: package-rebuild
27 endif
28
29 ifneq ($(MAKECMDGOALS),prereq)
30 ifneq ($$(_INFO),)
31 $$(info Rebuilding $$(_INFO))
32 endif
33 endif
34 endif
35 endif
36
37 $(PKG_BUILD_DIR)/.prepared:
38 @-rm -rf $(PKG_BUILD_DIR)
39 @mkdir -p $(PKG_BUILD_DIR)
40 $(call Build/Prepare)
41 touch $$@
42
43 $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
44 $(call Build/Configure)
45 touch $$@
46
47 $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured
48 $(call Build/Compile)
49 touch $$@
50
51 ifdef Build/InstallDev
52 $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
53 mkdir -p $(STAGING_DIR)/stampfiles
54 $(call Build/InstallDev)
55 touch $$@
56
57 compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
58 endif
59
60 package-clean: FORCE
61 $(call Build/Clean)
62 $(call Build/UninstallDev)
63 -rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
64
65 package-rebuild: FORCE
66 @-rm -f $(PKG_BUILD_DIR)/.built
67
68 define Build/DefaultTargets
69 endef
70 endef
71
72 define Package/Default
73 CONFIGFILE:=
74 SECTION:=opt
75 CATEGORY:=Extra packages
76 DEPENDS:=
77 EXTRA_DEPENDS:=
78 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
79 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
80 ifneq ($(PKG_VERSION),)
81 ifneq ($(PKG_RELEASE),)
82 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
83 else
84 VERSION:=$(PKG_VERSION)
85 endif
86 else
87 VERSION:=$(PKG_RELEASE)
88 endif
89 PKGARCH:=$(ARCH)
90 PRIORITY:=optional
91 DEFAULT:=
92 MENU:=
93 SUBMENU:=
94 SUBMENUDEP:=
95 TITLE:=
96 DESCRIPTION:=
97 endef
98
99 define BuildIPKGVariable
100 pkg_$(subst .,_,$(subst -,_,$(1)))_$(2) = $$(Package/$(1)/$(2))
101 export pkg_$(subst .,_,$(subst -,_,$(1))_$(2))
102 $(1)_COMMANDS += if [ -n "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" ]; then echo "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" > $(2); fi;
103 endef
104
105 define BuildPackage
106 $(eval $(call Package/Default))
107 $(eval $(call Package/$(1)))
108
109 $(foreach FIELD, TITLE CATEGORY PRIORITY VERSION,
110 ifeq ($($(FIELD)),)
111 $$(error Package/$(1) is missing the $(FIELD) field)
112 endif
113 )
114
115 ifeq ($(PKGARCH),)
116 PKGARCH:=$(ARCH)
117 endif
118
119 ifeq ($(DESCRIPTION),)
120 $(eval DESCRIPTION:=$(TITLE))
121 endif
122
123 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
124 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
125 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
126
127 ifdef Package/$(1)/install
128 ifeq ($(CONFIG_PACKAGE_$(1)),y)
129 install-targets: $$(INFO_$(1))
130 endif
131
132 ifneq ($(CONFIG_PACKAGE_$(1)),)
133 compile-targets: $$(IPKG_$(1))
134 else
135 compile-targets: $(1)-disabled
136 $(1)-disabled:
137 @echo "WARNING: skipping $(1) -- package not selected"
138 endif
139 endif
140
141 ifeq ($(FORCEREBUILD),y)
142 $$(IPKG_$(1)): FORCE
143 endif
144
145 IDEPEND_$(1):=$$(strip $$(DEPENDS))
146
147 ifneq ($(DUMP),)
148 DUMPINFO += \
149 echo "Package: $(1)";
150
151 ifneq ($(MENU),)
152 DUMPINFO += \
153 echo "Menu: $(MENU)";
154 endif
155
156 ifneq ($(SUBMENU),)
157 DUMPINFO += \
158 echo "Submenu: $(SUBMENU)";
159 ifneq ($(SUBMENUDEP),)
160 DUMPINFO += \
161 echo "Submenu-Depends: $(SUBMENUDEP)";
162 endif
163 endif
164
165 ifneq ($(DEFAULT),)
166 DUMPINFO += \
167 echo "Default: $(DEFAULT)";
168 endif
169
170 DUMPINFO += \
171 echo "Version: $(VERSION)"; \
172 echo "Depends: $$(IDEPEND_$(1))"; \
173 echo "Build-Depends: $(PKG_BUILDDEP)"; \
174 echo "Category: $(CATEGORY)"; \
175 echo "Title: $(TITLE)"; \
176 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g';
177
178 ifneq ($(URL),)
179 DUMPINFO += \
180 echo; \
181 echo "$(URL)";
182 endif
183
184 DUMPINFO += \
185 echo "@@";
186
187 ifneq ($(CONFIG),)
188 DUMPINFO += \
189 echo "Config: $(CONFIG)" | sed -e 's,\\,\n,g'; \
190 echo "@@";
191 endif
192 endif
193
194 $(eval $(call BuildIPKGVariable,$(1),conffiles))
195 $(eval $(call BuildIPKGVariable,$(1),preinst))
196 $(eval $(call BuildIPKGVariable,$(1),postinst))
197 $(eval $(call BuildIPKGVariable,$(1),prerm))
198 $(eval $(call BuildIPKGVariable,$(1),postrm))
199 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH)
200 mkdir -p $$(IDIR_$(1))/CONTROL
201 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
202 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
203 ( \
204 DEPENDS=; \
205 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
206 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
207 done; \
208 echo "Depends: $(EXTRA_DEPENDS) $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
209 )
210 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
211 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
212 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
213 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
214 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
215 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
216 chmod 644 $$(IDIR_$(1))/CONTROL/control
217 (cd $$(IDIR_$(1))/CONTROL; \
218 $($(1)_COMMANDS) \
219 )
220
221 $$(IPKG_$(1)): $(PKG_BUILD_DIR)/.built $$(IDIR_$(1))/CONTROL/control
222 $(call Package/$(1)/install,$$(IDIR_$(1)))
223 mkdir -p $(PACKAGE_DIR)
224 -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
225 -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
226 -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
227 $(RSTRIP) $$(IDIR_$(1))
228 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
229 @[ -f $$(IPKG_$(1)) ] || false
230
231 $$(INFO_$(1)): $$(IPKG_$(1))
232 $(IPKG) install $$(IPKG_$(1))
233
234 $(1)-clean:
235 rm -f $(PACKAGE_DIR)/$(1)_*
236
237 clean: $(1)-clean
238
239 $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH): $(PKG_BUILD_DIR)/.prepared
240 -rm $(PKG_BUILD_DIR)/.version-$(1)_*
241 @touch $$@
242
243 $$(eval $$(call Build/DefaultTargets,$(1)))
244 endef
245
246 ifneq ($(strip $(PKG_CAT)),)
247 ifeq ($(PKG_CAT),unzip)
248 UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
249 else
250 UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
251 endif
252 define Build/Prepare/Default
253 $(UNPACK)
254 @if [ -d ./patches ]; then \
255 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
256 fi
257 endef
258 endif
259
260 define Build/Prepare
261 $(call Build/Prepare/Default)
262 endef
263
264 define Build/Configure/Default
265 @(cd $(PKG_BUILD_DIR)/$(3); \
266 [ -x configure ] && { \
267 $(TARGET_CONFIGURE_OPTS) \
268 CFLAGS="$(TARGET_CFLAGS)" \
269 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
270 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
271 $(2) \
272 ./configure \
273 --target=$(GNU_TARGET_NAME) \
274 --host=$(GNU_TARGET_NAME) \
275 --build=$(GNU_HOST_NAME) \
276 --program-prefix="" \
277 --program-suffix="" \
278 --prefix=/usr \
279 --exec-prefix=/usr \
280 --bindir=/usr/bin \
281 --sbindir=/usr/sbin \
282 --libexecdir=/usr/lib \
283 --sysconfdir=/etc \
284 --datadir=/usr/share \
285 --localstatedir=/var \
286 --mandir=/usr/man \
287 --infodir=/usr/info \
288 $(DISABLE_NLS) \
289 $(1); \
290 } || true; \
291 )
292 endef
293
294 define Build/Configure
295 $(call Build/Configure/Default,)
296 endef
297
298 define Build/Compile/Default
299 $(MAKE) -C $(PKG_BUILD_DIR) \
300 $(TARGET_CONFIGURE_OPTS) \
301 CROSS="$(TARGET_CROSS)" \
302 EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/include -I$(STAGING_DIR)/usr/include" \
303 ARCH="$(ARCH)" \
304 $(1);
305 endef
306
307 define Build/Compile
308 $(call Build/Compile/Default,)
309 endef
310
311 ifneq ($(DUMP),)
312 dumpinfo: FORCE
313 @$(DUMPINFO)
314 else
315 $(PACKAGE_DIR):
316 mkdir -p $@
317
318 ifneq ($(strip $(PKG_SOURCE)),)
319 download: $(DL_DIR)/$(PKG_SOURCE)
320
321 $(DL_DIR)/$(PKG_SOURCE):
322 mkdir -p $(DL_DIR)
323 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
324
325 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
326 endif
327
328 download:
329 prepare: $(PKG_BUILD_DIR)/.prepared
330 configure: $(PKG_BUILD_DIR)/.configured
331
332 compile-targets:
333 compile: compile-targets
334
335 install-targets:
336 install: install-targets
337
338 clean-targets:
339 clean: FORCE
340 @$(MAKE) clean-targets
341 $(call Build/Clean)
342 rm -rf $(PKG_BUILD_DIR)
343 endif