main.mk 2.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# 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/"
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
IMAGE_NAME    := $(firstword $(subst ., ,$(IMAGE_FILE)))#   generic
IMAGE_TYPE    := $(subst $(IMAGE_NAME).,,$(IMAGE_FILE))#    tar.gz

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

27 28
export MKIMAGE_PROFILES := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))

29 30 31 32
# preferences
-include $(HOME)/.mkimage/profiles.mk

# most of the actual work done elsewhere
Michael Shigorin's avatar
Michael Shigorin committed
33
include $(sort $(wildcard lib/*.mk))
34 35 36
include conf.d/*.mk
include features.in/*/config.mk

37 38
# FIXME: this is buggy since *.mk can expose parts conditionally
#        (e.g. test.mk does DEBUG-only bits) and these will fail
39 40 41 42
DISTRO_TARGETS := $(shell sed -n 's,^\(distro/[^:.]\+\):.*$$,\1,p' \
		lib/distro.mk $(wildcard conf.d/*.mk) | sort -u)
VE_TARGETS := $(shell sed -n 's,^\(ve/[^:.]\+\):.*$$,\1,p' \
		lib/ve.mk $(wildcard conf.d/*.mk) | sort -u)
43 44
VM_TARGETS := $(shell sed -n 's,^\(vm/[^:.]\+\):.*$$,\1,p' \
		lib/vm.mk $(wildcard conf.d/*.mk) | sort -u)
45 46
DISTROS := $(call addsuffices,$(DISTRO_EXTS),$(DISTRO_TARGETS))
VES     := $(call addsuffices,$(VE_EXTS),$(VE_TARGETS))
47 48
VMS     := $(call addsuffices,$(VM_EXTS),$(VM_TARGETS))
IMAGES  := $(DISTROS) $(VES) $(VMS)
49

50
.PHONY: $(IMAGES) $(DISTRO_TARGETS) $(VE_TARGETS) $(VM_TARGETS)
51 52 53 54 55 56 57
.PHONY: debug everything help space

### duplicate but still needed
everything:
	@n=1; sum=$(words $(DISTROS)); \
	for distro in $(DISTROS); do \
		echo "** building $$distro [$$n/$$sum]:"; \
58 59
		$(MAKE) -f main.mk --no-print-directory $$distro; \
		[ "$$n" -lt "$$sum" ] && echo; \
60 61 62 63 64 65 66 67 68 69 70 71
		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
72
$(DISTROS:distro/%=%): %: distro/%; @:
73 74 75 76 77 78 79

debug:
ifeq (2,$(DEBUG))
	@$(foreach v,\
		$(filter IMAGE_%,$(sort $(.VARIABLES))),\
		$(warning $v = $($v)))
endif