main.mk 3.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
# steps to build an image:
# --- here
# 1. initialize new profile (BUILDDIR) as a copy of image.in/
# 2. configure distro
# 3. copy the needed bits from metaprofile to a new profile
# --- in BUILDDIR
# 4. build subprofiles and subsequently an image

# deal with one target at a time
IMAGE_TARGET := $(firstword $(MAKECMDGOALS))#	ve/generic.tar.gz
ifeq (./,$(dir $(IMAGE_TARGET)))#		convenience fallback
IMAGE_TARGET := distro/$(IMAGE_TARGET)#		for omitted "distro/"
13 14 15
IMAGE_GUESS  := 1
else
IMAGE_GUESS  :=
16 17 18 19
endif
IMAGE_CONF    := $(firstword $(subst ., ,$(IMAGE_TARGET)))# ve/generic
IMAGE_CLASS   := $(firstword $(subst /, ,$(IMAGE_TARGET)))# ve
IMAGE_FILE    := $(lastword  $(subst /, ,$(IMAGE_TARGET)))# generic.tar.gz
20
ifneq (sisyphus,$(BRANCH))
21 22
IMAGE_FILE    := $(subst regular,alt-$(BRANCH),$(IMAGE_FILE))
endif
23 24
IMAGE_NAME    := $(firstword $(subst ., ,$(IMAGE_FILE)))#   generic
IMAGE_TYPE    := $(subst $(IMAGE_NAME).,,$(IMAGE_FILE))#    tar.gz
25
ifeq ($(IMAGE_NAME),$(IMAGE_TYPE)$(IMAGE_GUESS))
26
ifneq (help,$(IMAGE_CLASS))
27 28
$(warning no image type/extension specified, run make help?)
endif
29
endif
30 31 32 33 34 35 36 37

# readjustable
ifeq (1,$(NUM_TARGETS))
BUILDDIR_PREFIX ?= mkimage-profiles.build
else
BUILDDIR_PREFIX ?= mkimage-profiles.build/$(IMAGE_CONF).$(ARCH)
endif

38 39
export MKIMAGE_PROFILES := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))

40 41 42 43
# preferences
-include $(HOME)/.mkimage/profiles.mk

# most of the actual work done elsewhere
Michael Shigorin's avatar
Michael Shigorin committed
44
include $(sort $(wildcard lib/*.mk))
45 46 47
include conf.d/*.mk
include features.in/*/config.mk

48
# ensure the outdir is created and globbable
49
ifneq (,$(IMAGEDIR))
50 51 52 53
$(shell mkdir -p $(IMAGEDIR))
IMAGEDIR := $(wildcard $(IMAGEDIR))
endif

54 55 56 57 58 59 60 61 62 63 64
# conf.d/*.mk can expose parts conditionally (e.g. DEBUG-only bits)
targets = $(shell \
	  for i in conf.d/*.mk; do \
		make IMAGE_CLASS=$(1) -s -r -p -f $$i 2>/dev/null; \
	  done \
	  | sed -rn 's,^($(1)/[^.:]+):.*,\1,p' \
	  | sort -u)

DISTRO_TARGETS := $(call targets,distro)
VE_TARGETS := $(call targets,ve)
VM_TARGETS := $(call targets,vm)
65 66
DISTROS := $(call addsuffices,$(DISTRO_EXTS),$(DISTRO_TARGETS))
VES     := $(call addsuffices,$(VE_EXTS),$(VE_TARGETS))
67
VES_TAR := $(call addsuffices,.tar,$(VE_TARGETS))
68
VMS     := $(call addsuffices,$(VM_EXTS),$(VM_TARGETS)) \
69
 $(call addsuffices,$(VM_TAVOLGA_EXTS), $(filter vm/%-tavolga, $(VM_TARGETS)))
70
VMS_IMG := $(call addsuffices,.img,$(VM_TARGETS))
71
IMAGES  := $(DISTROS) $(VES) $(VMS)
72

73
.PHONY: $(IMAGES) $(DISTRO_TARGETS) $(VE_TARGETS) $(VM_TARGETS)
74 75
.PHONY: debug everything help space

76 77 78
# grepping for localized error messages is not trivial
export LC_MESSAGES=C

79 80
### duplicate but still needed
everything:
81 82
	@n=1; sum=$(words $(DISTROS) $(VES_TAR) $(VMS_IMG)); \
	for distro in $(DISTROS) $(VES_TAR) $(VMS_IMG); do \
83
		echo "** building $$distro [$$n/$$sum]:"; \
84 85
		$(MAKE) -f main.mk --no-print-directory $$distro; \
		[ "$$n" -lt "$$sum" ] && echo; \
86 87 88 89 90 91 92 93 94 95 96 97
		n=$$(($$n+1)); \
	done

# config/with/ve/generic config/like/ve config/name/generic config/pack/tar.gz
$(IMAGES): debug \
	config/with/$(IMAGE_CONF) \
	config/like/$(IMAGE_CLASS) \
	config/name/$(IMAGE_NAME) \
	config/pack/$(IMAGE_TYPE) \
	build; @:

# convenience shortcut
98
$(DISTROS:distro/%=%): %: distro/%; @:
99

100
debug::
101 102 103 104 105
ifeq (2,$(DEBUG))
	@$(foreach v,\
		$(filter IMAGE_%,$(sort $(.VARIABLES))),\
		$(warning $v = $($v)))
endif