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