123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- include config.mk
-
- SRC_DIR=linux-source
- VERSION=$(shell $(MAKE) -s -C $(SRC_DIR) kernelversion)
- BZIMAGE=archives/bzImage.$(VERSION)
- CONFIG_REPO=kernel-config
- KERNEL.CONFIG=$(shell realpath "$(CONFIG_REPO)/kernel.config")
- TESTED_HASH=.bzImage_tested.sha512
- VIRSH_TEST_SCRIPT=./scripts/test_libvirt.expect
- DEBVM_TEST_SCRIPT=./scripts/test_debvm.expect
- DEBVM_IMG_DIR=/tmp
- DEBVM_DISK=$(DEBVM_IMG_DIR)/vz5_kernel_test.ext4
- DEBVM_SWAPFILE=$(DEBVM_IMG_DIR)/vz5_kernel_test.swapfile
- DEBVM_SWAPLABEL=testswap
- UPGRADE_SCRIPT=./scripts/upgrade.sh
- HASH=sha512sum
-
- CRED=$(shell tput setaf 1)
- CGRN=$(shell tput setaf 2)
- CRAZ=$(shell tput sgr0)
-
-
- ARCHIVE=archives/install_$(shell date "+%Y_%m_%dT%H_%M_%S")_$(VERSION)
-
- all: status
-
- status:
- @echo "Images :\n========\n";
- @[ -f "bzImage.latest" ] && echo 'Latest : $(shell [ -f "bzImage.latest" ] && file -L bzImage.latest | cut -d ',' -f2)' || echo "Latest : $(CRED)None built$(CRAZ)";
- @[ -f "$(BZIMAGE_INSTALL)" ] && echo 'Installed : $(shell [ -f "$(BZIMAGE_INSTALL)" ] && file -L $(BZIMAGE_INSTALL) | cut -d ',' -f2)' || echo "Installed : $(CRED)None installed$(CRAZ)";
- @[ -f "$(BZIMAGE_TEST)" ] && echo 'In test : $(shell [ -f "$(BZIMAGE_TEST)" ] && file -L $(BZIMAGE_TEST) | cut -d ',' -f2)' || echo "In test : $(CRED)None in test$(CRAZ)";
- @echo "\nLatest tested :\n----------";
- @[ -f "bzImage.latest" ] && $(MAKE) -s tested || true;
- @echo "\nSources :\n=========";
- @sh $(UPGRADE_SCRIPT) check >/dev/null \
- && echo "$(CGRN)Kernel sources are up to date$(CRAZ)" \
- || echo "$(CRED)Kernel sources can be upgraded$(CRAZ)";
- @echo "\nKernel config git repo :\n========================"
- @git -C $(CONFIG_REPO) status
-
-
- $(SRC_DIR)/.config: $(KERNEL.CONFIG)
- cp -v "$<" "$@"
-
- $(KERNEL.CONFIG): $(SRC_DIR)/.config
- cp -v "$<" "$@"
-
- $(CONFIG_REPO):
- mkdir $(CONFIG_REPO) && git -C $(CONFIG_REPO) init;
-
- menuconfig: $(SRC_DIR)/.config
- $(MAKE) -C $(SRC_DIR) menuconfig
-
- $(BZIMAGE): $(SRC_DIR)/.config
- $(MAKE) -C $(SRC_DIR);
- mkdir -p archives/;
- cp "$(SRC_DIR)/arch/x86_64/boot/bzImage" "$@";
- ln -vfs "$@" bzImage.latest
- ls -lah "$@"
-
- upgrade_src:
- sh $(UPGRADE_SCRIPT)
-
- can_upgrade:
- @sh $(UPGRADE_SCRIPT) check || echo "$(CRED)Kernel sources can be ugraded$(CRAZ)";
-
- kernel: can_upgrade $(BZIMAGE)
-
- commit-config: tested $(KERNEL.CONFIG) can_upgrade
- cp -v "$(SRC_DIR)/.config" "$(KERNEL.CONFIG)";
- git -C $(CONFIG_REPO) add "$(KERNEL.CONFIG)";
- git -C $(CONFIG_REPO) commit -m "Update config for kernel $(VERSION)";
- git -C $(CONFIG_REPO) tag -fa "$(VERSION)" -m "$(shell date -Is) Config for kernel $(VERSION)";
-
- archives/:
- mkdir -p archives;
-
- archive:
- mkdir -p $(ARCHIVE);
- cp -v $(BZIMAGE) $(ARCHIVE)/bzImage.new;
- cp -v $(BZIMAGE_INSTALL) $(ARCHIVE)/bzImage.old;
-
-
- clean:
- -rm -v $(BZIMAGE) bzImage.latest "$(DEBVM_SWAPFILE)" "$(DEBVM_DISK)" "$(TESTED_HASH)";
- $(MAKE) -C $(SRC_DIR) clean;
-
- distclean:
- -rm -R "$(shell realpath $(SRC_DIR))" "$(SRC_DIR)"
-
- .PHONY: can_upgrade distclean clean $(BZIMAGE_TEST) $(BZIMAGE_INSTALL) _test tested install
-
- tested:
- @$(HASH) -c "$(TESTED_HASH)" 2>/dev/null || {\
- echo "$(CRED)$(BZIMAGE) is not tested.";\
- echo "run make test as root.$(CRAZ)";\
- false;\
- };
-
- _test:
- if $(MAKE) is_root >/dev/null 2>/dev/null; then \
- $(MAKE) _virsh_test;\
- else\
- $(MAKE) _debvm_test;\
- fi
-
- test: _test
- $(HASH) "$(BZIMAGE)" > "$(TESTED_HASH)";
-
- # non-privileged user tests
-
- $(DEBVM_DISK): $(BZIMAGE)
- @debvm-create -r stable -o "$@" -h "$(TEST_VM_HOSTNAME)" \
- --skip autologin --skip kernel --skip systemdnetwork -- \
- --customize-hook="echo \"LABEL=$(DEBVM_SWAPLABEL) none swap sw 0 0\" >> \$$1/etc/fstab"\
- --customize-hook="mkdir -p \$$1/etc/network; echo \"auto enp0s2\niface enp0s2 inet dhcp\" > \$$1/etc/network/interfaces" \
- --include="udev" \
- --include="iputils-ping iproute2 ifupdown isc-dhcp-client" \
- --include="ssh qemu-guest-agent tzdata initscripts ntpdate ca-certificates console-setup console-common console-data locales acpid vim screen bash-completion rsyslog" \
- || { rm "$@"; false;}
-
- $(DEBVM_SWAPFILE):
- dd if=/dev/zero "of=$@" bs=4096 count=32768 status=progress &&\
- chmod 0600 "$@" &&\
- /usr/sbin/mkswap -L "$(DEBVM_SWAPLABEL)" "$@"
-
- _debvm_test: $(DEBVM_DISK) $(DEBVM_SWAPFILE)
- @$(DEBVM_TEST_SCRIPT) "$(TEST_VM_HOSTNAME)" "$(VERSION)" "$(DEBVM_DISK)" "$(BZIMAGE)" "$(DEBVM_SWAPFILE)" "$(DEBVM_SWAPLABEL)" \
- || echo "$(CRED)Kernel $(VERSION) [Error]$(CRAZ): Check /tmp/test_vz5_debvm_expect.log" >&2 \
- && echo "$(CGRN)Kernel $(VERSION) [OK]$(CRAZ): console logs in /tmp/test_debvm_expect.log" >&2;
-
- # superuser designed targets
-
- is_root:
- @[ "$(shell whoami)" = "root" ] || {\
- echo "$(CRED)ERROR :$(CRAZ) You need to be root to run this target" >&2;\
- false;\
- };
-
- $(BZIMAGE_TEST): can_upgrade is_root
- cp "$(BZIMAGE)" "$@"
-
- _virsh_test: $(BZIMAGE_TEST) can_upgrade is_root
- @$(VIRSH_TEST_SCRIPT) "$(TEST_VM_HOSTNAME)" "$(VERSION)" "$(TEST_VM_NAME)" || {\
- echo "$(CRED)Kernel $(VERSION) [Error]$(CRAZ): Check /tmp/test_vz5_expect.log" >&2;\
- false;\
- } && echo "$(CGRN)Kernel $(VERSION) [OK]$(CRAZ): console logs in /tmp/test_vz5_expect.log" >&2;
-
-
-
- $(BZIMAGE_INSTALL): tested can_upgrade is_root
- -cp -v $(BZIMAGE_INSTALL) $(BZIMAGE_INSTALL).old;
- cp -v $(BZIMAGE) $(BZIMAGE_INSTALL);
-
- install: $(BZIMAGE_INSTALL) archive is_root
|