Makefile 3.51 KB
Newer Older
Michael Shigorin's avatar
Michael Shigorin committed
1 2 3
# step 3: copy the needed features to $(BUILDDIR)
#         (only regarding the needed subprofiles)

4
ifndef BUILDDIR
5 6 7 8 9 10 11 12

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

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

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

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

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

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

Michael Shigorin's avatar
Michael Shigorin committed
34
else
35

36 37
export BUILDDIR

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

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

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

TARGETS := prep $(FEATURES) finalize

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

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

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

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

Michael Shigorin's avatar
Michael Shigorin committed
134
endif