profile.mk 3.51 KB
Newer Older
1 2 3
ifndef MKIMAGE_PROFILES
$(error this makefile is designed to be included in toplevel one)
endif
4

5 6
# this could have come from env; or could be symlinked; or is made anew
# (the reuse rationale is avoiding extra tmpdir lookups)
7
# NB: immediate assignment matters
8
ifndef BUILDDIR
9 10 11 12 13 14 15
BUILDLINK := $(realpath $(SYMLINK))
BUILDDIR  := $(shell \
if [ -s "$(SYMLINK)" -a "$(NUM_TARGETS)" = 1 ] && \
   [ -n "$(findstring $(BUILDDIR_PREFIX).,$(BUILDLINK))" ]; \
then \
	echo "$(BUILDLINK)"; \
else \
16
	mktmpdir $(BUILDDIR_PREFIX) || exit 200; \
17
fi; )
18 19
endif

20 21 22 23
ifeq (,$(BUILDDIR))
$(error suitable BUILDDIR unavailable)
endif

24 25 26
# even smart caching only hurts when every build goes from scratch
NO_CACHE ?= 1

27
export BUILDDIR NO_CACHE
28

29
CONFIG := $(BUILDDIR)/distcfg.mk
30
RC = $(HOME)/.mkimage/profiles.mk
31

32
# step 1: initialize the off-tree mkimage profile (BUILDDIR)
33
# NB: our output MUST go into stderr to escape POSTPROC
34
profile/init: distclean
35 36
	@{ \
	if [ "`realpath "$(BUILDDIR)/"`" = / ]; then \
37 38
		echo "$(TIME) ERROR: invalid BUILDDIR: \`$(BUILDDIR)'"; \
		exit 128; \
39
	fi; \
40 41 42
	if [ -z $(QUIET) ]; then \
		echo -n "$(TIME) initializing BUILDDIR: "; \
	fi; \
43 44 45
	rsync -qaxH --delete-after image.in/ "$(BUILDDIR)"/; \
	mkdir "$(BUILDDIR)"/.mki; \
	} >&2
46 47
	@$(call put,ifndef DISTCFG_MK)
	@$(call put,DISTCFG_MK = 1)
48
	@{ \
Michael Shigorin's avatar
Michael Shigorin committed
49
	mp-showref $(LOG); \
50
	{ \
51 52 53
		APTCONF="$(wildcard $(APTCONF))"; \
		echo "** using $${APTCONF:-system apt configuration}:"; \
		eval `apt-config shell $${APTCONF:+-c=$$APTCONF} \
54 55 56
			SOURCELIST Dir::Etc::sourcelist/f \
			SOURCEPARTS Dir::Etc::sourceparts/d`; \
		find "$$SOURCEPARTS" -name '*.list' \
57 58
		| xargs egrep -Rhv '^#|^[[:blank:]]*$$' "$$SOURCELIST" \
		| tee $(BUILDDIR)/sources.list; \
59
		echo; \
60
	} $(LOG); \
61
	if ! grep -q "\<$(ARCH)\>" $(BUILDDIR)/sources.list; then \
62 63 64 65 66 67 68 69 70
		if grep -q " noarch " $(BUILDDIR)/sources.list; then \
			echo -n "requested arch '$$ARCH' unavailable" >&2; \
			if [ -z "$(APTCONF)" ]; then \
				echo " (no APTCONF)"; \
			else \
				echo; \
			fi >&2; \
			exit 1; \
		fi; \
71
	fi; \
72
	mp-commit -i "$(BUILDDIR)" "derivative profile initialized"; \
73
	if [ -w . ]; then \
74
		rm -f "$(SYMLINK)" && \
75
		ln -s "$(BUILDDIR)" "$(SYMLINK)" && \
76 77 78
		if [ -z $(QUIET) ]; then \
			echo "$(SYMLINK)/"; \
		fi; \
79
	else \
80 81 82
		if [ -z $(QUIET) ]; then \
			echo "$(BUILDDIR)/"; \
		fi; \
83 84
	fi $(SHORTEN); \
	} >&2
Michael Shigorin's avatar
Michael Shigorin committed
85

86
profile/bare: profile/init
87 88
	@{ \
	NOTE="$${GLOBAL_VERBOSE:+: $(CONFIG)}"; \
89 90 91
	if [ -z "$(QUIET)" ]; then \
		echo "$(TIME) preparing distro config$$NOTE" $(SHORTEN); \
	fi; \
92
	} >&2
93 94
	@$(call try,MKIMAGE_PREFIX,/usr/share/mkimage)
	@$(call try,GLOBAL_VERBOSE,)
95 96
	@$(call try,IMAGEDIR,$(wildcard $(IMAGEDIR)))
	@$(call try,LOGDIR,$(wildcard $(LOGDIR)))
97
	@$(call try,BRANDING,altlinux-sisyphus)
98
ifeq (,$(REPO:altlinux%=))
99
	@$(call set,IMAGE_INIT_LIST,+branding-$$(BRANDING)-release)
100
endif
101
	@$(call xport,ARCH)
Michael Shigorin's avatar
Michael Shigorin committed
102
	@mp-commit "$(BUILDDIR)" "image configuration defaults set"
103

104
# put the derived SUBPROFILE_DIRS here to get it logged in clear text by the way
105
profile/finalize:
106
	@$(call put,SUBPROFILE_DIRS = $$(notdir $$(subst @,/,$$(SUBPROFILES))))
107
	@if [ -s $(RC) ]; then $(call put,-include $(value RC)); fi
108
	@$(call put,endif)
Michael Shigorin's avatar
Michael Shigorin committed
109
	@mp-commit "$(BUILDDIR)" "image configuration finalized"
110

111 112 113 114 115 116 117
# requires already formed distcfg.mk for useful output
profile/dump-vars:
	@if [ -s "$(SYMLINK)" ]; then \
		$(MAKE) --no-print-directory -C "$(SYMLINK)/" -f vars.mk; \
		echo; \
	fi $(LOG)

118
# step 3 entry point: copy the needed parts into BUILDDIR
119
profile/populate: profile/finalize profile/dump-vars
Michael Shigorin's avatar
Michael Shigorin committed
120
	@for dir in sub.in features.in pkg.in; do \
121
		$(MAKE) -C $$dir $(LOG); \
Michael Shigorin's avatar
Michael Shigorin committed
122
	done