next round of build system cleanup - convert package/ to new structure
[openwrt/staging/chunkeey.git] / include / subdir.mk
1 #
2 # Copyright (C) 2007 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 SUBTARGETS:=clean download prepare compile install update refresh prereq
9
10 define subtarget
11 $(call warn_eval,$(1),t,T,$(1)/$(2): $($(1)/) $(foreach bd,$(if $($(1)/builddirs-$(2)),$(filter-out .,$($(1)/builddirs-$(2))),$($(1)/builddirs)),$(1)/$(bd)/$(2)))
12
13 endef
14
15 # Parameters: <subdir>
16 define subdir
17 $(call warn,$(1),d,D $(1))
18 $(foreach bd,$($(1)/builddirs),
19 $(call warn,$(1),d,BD $(1)/$(bd))
20 $(foreach target,$(SUBTARGETS),
21 $(call warn_eval,$(1)/$(bd),t,T,$(1)/$(bd)/$(target): $($(1)/$(bd)/$(target)) $(call $(1)//$(target),$(1)/$(bd)))
22 @+$$(MAKE) -j1 -C $(1)/$(bd) $(target)
23
24 # legacy targets
25 $(call warn_eval,$(1)/$(bd),l,T,$(1)/$(bd)-$(target): $(1)/$(bd)/$(target))
26 )
27 )
28 $(foreach target,$(SUBTARGETS),$(call subtarget,$(1),$(target)))
29 endef
30
31 # Parameters: <subdir> <name> <target>
32 define stampfile
33 $(1)/stamp-$(3):=$(STAGING_DIR)/stampfiles/.$(2)_$(3)
34 $(call rdep,$(1),$$($(1)/stamp-$(3)),)
35
36 $$($(1)/stamp-$(3)):
37 @+$(MAKE) $(1)/$(3)
38 @mkdir -p $$$$(dirname $$($(1)/stamp-$(3)))
39 @touch $$($(1)/stamp-$(3))
40 .PRECIOUS: $$($(1)/stamp-$(3)) # work around a make bug
41
42 $(1)//clean:=$(1)/stamp-$(3)/clean
43 $(1)/stamp-$(3)/clean: FORCE
44 @rm -f $$($(1)/stamp-$(3))
45
46 endef