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