generate.mk 3.7 KB
Newer Older
1
ifneq (,$(BUILDDIR))
Alexey Shabalin's avatar
Alexey Shabalin committed
2

3 4
# in seconds
DEFAULT_TIMEOUT = 60
Alexey Shabalin's avatar
Alexey Shabalin committed
5 6 7 8 9 10

# prepare data for grub installation;
# see also stage1/scripts.d/01-grub

include $(BUILDDIR)/distcfg.mk

11
ifeq (,$(BOOTLOADER))
Alexey Shabalin's avatar
Alexey Shabalin committed
12 13 14
$(error grub feature enabled but BOOTLOADER undefined)
endif

15 16
STAGE1_INITRD_BOOTARGS := $(STAGE1_INITRD_TYPEARGS)=$(STAGE1_INITRD_BOOTMETHOD)

17
ifeq (,$(GRUB_DIRECT))
Alexey Shabalin's avatar
Alexey Shabalin committed
18 19 20
# SUBPROFILES are considered GRUB_CFG too
# (note these can appear like stage2@live);
# 01defaults.cfg is included indefinitely
21
GRUB_CFG := $(GRUB_CFG) defaults fwsetup_efi
Alexey Shabalin's avatar
Alexey Shabalin committed
22 23
endif

24
ifneq (,$(GRUB_UI))
25 26 27
GRUB_CFG := $(GRUB_CFG) gfxterm
endif

28
ifeq (,$(DISABLE_LANG_MENU))
29
ifneq (,$(LOCALES))
30
ifneq ($(words $(LOCALES)),1)
31 32
GRUB_CFG := $(GRUB_CFG) lang
endif
33
endif
34
endif
35

36
ifneq (,$(KFLAVOURS))
37 38 39
ifneq ($(words $(KFLAVOURS)),1)
GRUB_CFG := $(GRUB_CFG) kernel
endif
40
endif
41

42
DSTDIR  := $(BUILDDIR)/stage1/files/boot/grub/.in
Alexey Shabalin's avatar
Alexey Shabalin committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
DSTCFGS := $(DSTDIR)/*.cfg

# we can do GRUB_{CFG,MODULES,FILES}
# CFG have only cfg snippet
cfg = $(wildcard cfg.in/??$(1).cfg)

# NB: list position determined by file numbering (*.cfg sorting)
#
# config snippets are copied into generated profile where they can
# be also tested against grub modules (some can be unavailable);
# we can't do tests right now since that implies host grub being
# identical to build system one which might be not the case...
#
# have to piggyback parameters as we're running in host system yet,
# and files involved will appear inside instrumental chroot
#
# arguments get evaluated before recipe body execution thus prep

all: debug timeout
	@### proper text branding should be implemented
	@echo $(GRUB_FILES) > $(DSTDIR)/grub.list
	@sed -i \
		-e 's,@mkimage-profiles@,$(IMAGE_NAME),' \
		$(DSTCFGS)

# integerity check
timeout: distro
	@if [ "$(GRUB_TIMEOUT)" -ge 0 ] 2>/dev/null; then \
		TIMEOUT="$(GRUB_TIMEOUT)"; \
	else \
		TIMEOUT="$(DEFAULT_TIMEOUT)"; \
	fi; \
	sed -i "s,@timeout@,$$TIMEOUT," $(DSTCFGS)

distro: bootargs
78 79
	@if [ -n "$(META_VOL_ID)" ]; then \
		DISTRO="$(META_VOL_ID)"; \
Alexey Shabalin's avatar
Alexey Shabalin committed
80
	else \
81
		DISTRO="$(RELNAME)"; \
Alexey Shabalin's avatar
Alexey Shabalin committed
82 83 84 85 86 87
	fi; \
	sed -i "s,@distro@,$$DISTRO," $(DSTCFGS)

# pass over additional parameters, if any
bootargs: clean
	@if [ -n "$(STAGE2_BOOTARGS)" ]; then \
88
		sed -i "s,$(STAGE2_BOOTARGS),," $(DSTCFGS); \
Alexey Shabalin's avatar
Alexey Shabalin committed
89 90 91 92 93 94 95 96 97 98 99
		sed -i "s,@bootargs@,$(STAGE2_BOOTARGS)," $(DSTCFGS); \
	fi; \
	sed -i "s,@bootargs@,," $(DSTCFGS)
	@if [ -n "$(RESCUE_BOOTARGS)" ]; then \
		sed -i "s,@rescue_bootargs@,$(RESCUE_BOOTARGS)," $(DSTCFGS); \
	fi; \
	sed -i "s,@rescue_bootargs@,," $(DSTCFGS)
	@if [ -n "$(BOOTVGA)" ]; then \
		sed -i "s,@bootvga@,$(BOOTVGA)," $(DSTCFGS); \
	fi; \
	sed -i "s,@bootvga@,,;s,vga= ,," $(DSTCFGS)
100 101 102 103 104 105
	@if [ -n "$(LOCALE)" ]; then \
		sed -i "s,@LOCALE@,$(LOCALE),g" $(DSTCFGS); \
	else \
		sed -i "s, lang=.lang,,g" $(DSTCFGS); \
	fi; \
	sed -i "/lang=@LOCALE@/d" $(DSTCFGS)
106 107 108
	@if [ -n "$(LOCALES)" ]; then \
		sed -i "s,@LOCALES@,$(LOCALES),g" $(DSTCFGS); \
	fi
109
	@GRUBTHEME=$(GRUBTHEME); \
110
	[ -n "$$GRUBTHEME" ] || GRUBTHEME=$$(cut -d "-" -f2 <<< $(BRANDING)); \
111
	sed -i "s,@grubtheme@,$$GRUBTHEME,g" $(DSTCFGS)
112 113
	@sed -i "s,@initrd@,initrd," $(DSTCFGS)
	@sed -i "s,@initrd_ext@,img," $(DSTCFGS)
114
	@sed -i "s|@initrd_bootargs@|$(STAGE1_INITRD_BOOTARGS)|g" $(DSTCFGS)
115
	@sed -i "s|@initrd_bootmethod@|$(STAGE1_INITRD_BOOTMETHOD)|g" $(DSTCFGS)
116
	@sed -i "s|@initrd_typeargs@|$(STAGE1_INITRD_TYPEARGS)|g" $(DSTCFGS)
117
	@sed -i "s,@stagename@,$(STAGE1_INITRD_STAGE2_OPTION),g" $(DSTCFGS)
Alexey Shabalin's avatar
Alexey Shabalin committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

clean: copy
	@if [ "$(GRUB_UI)" = gfxboot ]; then \
		sed -i "s/\^//;/menu label /d" $(DSTCFGS); \
	fi

copy: prep
	@cp -pLt $(DSTDIR) -- $(sort \
		$(foreach C,$(GRUB_CFG),$(call cfg,$(C))))

prep:
	@mkdir -p $(DSTDIR)

debug:
	@if [ -n "$(DEBUG)" ]; then \
		echo "** BOOTLOADER: $(BOOTLOADER)"; \
		echo "** GRUB_CFG: $(GRUB_CFG)"; \
		echo "** GRUB_FILES: $(GRUB_FILES)"; \
	fi

endif