Makefile 3.52 KB
Newer Older
Michael Shigorin's avatar
Michael Shigorin committed
1 2
# step 3: copy the needed features to $(BUILDDIR)
#         (only regarding the needed subprofiles)
3
ifeq (,$(BUILDDIR))
4 5 6 7 8 9 10 11

help/plus all: banner
	@$(call grepper,'^+')

help/features: banner
	@$(call grepper,'^use/')

banner:
Michael Shigorin's avatar
Michael Shigorin committed
12
	@echo "** BUILDDIR not defined; available features:"
13 14 15

grepper = $(and $(1),$(grepper_body))
define grepper_body
Michael Shigorin's avatar
Michael Shigorin committed
16
	@for dir in */; do \
17
		out="`grep -h $(1) $$dir/config.mk \
Michael Shigorin's avatar
Michael Shigorin committed
18
		| cut -f1 -d: \
19 20
		| tr ' 	' '\n\n' \
		| grep $(1) \
Michael Shigorin's avatar
Michael Shigorin committed
21
		| tr '\n' ' ' \
22 23
		| sort -u`"; \
		[ -z "$$out" ] || echo "$$dir: $$out"; \
Michael Shigorin's avatar
Michael Shigorin committed
24
	done
25 26
endef

27 28 29
check:
	@../bin/check-recipe */config.mk

30 31 32
%:
	$(error BUILDDIR not defined)

Michael Shigorin's avatar
Michael Shigorin committed
33
else
34

35 36
export BUILDDIR

37
include $(BUILDDIR)/distcfg.mk
Michael Shigorin's avatar
Michael Shigorin committed
38

39
# first rsync what's static, and make backups (*~) --
Michael Shigorin's avatar
Michael Shigorin committed
40
# these might signal of file clashes (or plain dirt);
41 42
# second, care for toplevel dirs;
# then handle feature generator scripts
43
#
44
# NB: some subprofiles will be specified as "src/dst"
45 46 47
#     -- then both src/ and dst/ can hold the addons;
#     still both pieces go into a single destination

48
### sorry for somewhat complicated and overly long lines
49 50 51 52 53 54 55

TARGETS := prep $(FEATURES) finalize

.PHONY: $(TARGETS)
all:  | $(TARGETS)

prep:
Michael Shigorin's avatar
Michael Shigorin committed
56
	@echo "** starting feature configuration"
57 58
	@if [ -n "$(GLOBAL_DEBUG)" ]; then \
		echo "** target subprofiles: $(SUBPROFILES)"; \
59 60
		echo "** requested features: $(FEATURES)"; \
	fi
61 62

# feat
63 64 65 66 67
# NB: this is somewhat complicated since it has to handle "$sub" like:
#     - "/": copy feature's toplevel parts to the BUILDDIR toplevel
#     - "stage1": copy feature's stage1 parts into stage1 subprofile
#     - "stage2@live": copy feature's stage2 parts into live subprofile
#     - "rootfs@/": copy feature's rootfs parts into BUILDDIR toplevel
68 69
$(FEATURES):
	@feat=$@; \
70
	args="-qab --exclude README --exclude config.mk"; \
71
	args="$$args --exclude generate.mk --exclude generate.sh"; \
72 73 74 75 76 77 78 79 80
	if [ -n "$(GLOBAL_DEBUG)" ]; then \
		echo "** adding $$feat feature"; \
	fi; \
	pushd "$$feat" >/dev/null && \
	for sub in / $(SUBPROFILES); do \
		if [ "$$sub" = / ]; then \
			srcdirs="."; \
			dst="."; \
		else \
81 82
			src="$${sub%@*}"; \
			dst="$${sub#*@}"; \
83 84 85 86 87 88 89
			if [ "$$src" = / ]; then \
				echo "** src=/: you don't want this" >&2; \
				exit 1; \
			fi; \
			if [ "$$dst" = / -o "$$dst" = "" ]; then \
				dst="."; \
			fi; \
90 91 92
			srcdirs=; \
			if [ -d "$$src" ]; then \
				srcdirs="$$src"; \
93
			fi; \
94
			if [ -d "$$dst" -a "$$dst" != "$$src" ]; then \
95
				srcdirs="$${srcdirs:+$$srcdirs }$$dst"; \
96
			fi; \
97
			: "why this overduplication was done? (still needed)"; \
98
			for srcdir in $$srcdirs; do \
99
				rsync $$args "$$srcdir/" "$(BUILDDIR)/$$dst/"; \
100
			done; \
101 102 103 104 105 106 107
		fi; \
		if [ -n "$(GLOBAL_DEBUG)" ]; then \
			echo "** src=[$$src] dst=[$$dst] srcdirs=[$$srcdirs]"; \
		fi; \
		for srcdir in $$srcdirs; do \
			[ -d "$$srcdir" ] || continue; \
			pushd "$$srcdir" >&/dev/null; \
108
			for part in lib {image-,}scripts.d; do \
109 110 111
				destdir="$(BUILDDIR)/$$dst/$$part"; \
				[ -d "$$destdir" ] || continue; \
				if [ "$$sub" = / -a -d "$$part" ]; then \
112
					rsync $$args "$$part/" "$$destdir/"; \
113 114 115
				fi; \
			done; \
			popd >&/dev/null; \
116
		done; \
117
		if [ -n "$$dst" -a "$$dst" != "." ]; then \
Michael Shigorin's avatar
Michael Shigorin committed
118 119 120
			the="$$sub subprofile"; \
		else \
			the="toplevel"; \
121
		fi; \
Michael Shigorin's avatar
Michael Shigorin committed
122
		mp-commit "$(BUILDDIR)/$$dst/" "$$feat feature: $$the part added"; \
123 124 125
	done; \
	if [ -x "generate.sh" ]; then sh generate.sh; fi; \
	if [ -s "generate.mk" ]; then $(MAKE) -f generate.mk; fi; \
Michael Shigorin's avatar
Michael Shigorin committed
126
	mp-commit "$(BUILDDIR)" "$$feat feature generation complete"; \
127 128 129
	popd >/dev/null

finalize:
130 131
	@find "$(BUILDDIR)/" -name '*~' \
	| sed "s,$(BUILDDIR)/,** warning: file clash: ," >&2
132

Michael Shigorin's avatar
Michael Shigorin committed
133
endif