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