No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. include config.mk
  2. SRC_DIR=linux-source
  3. VERSION=$(shell $(MAKE) -s -C $(SRC_DIR) kernelversion)
  4. BZIMAGE=archives/bzImage.$(VERSION)
  5. CONFIG_REPO=kernel-config
  6. KERNEL.CONFIG=$(shell realpath "$(CONFIG_REPO)/kernel.config")
  7. TESTED_HASH=.bzImage_tested.sha512
  8. CHECKCONFIG_SCRIPT=./scripts/checkconfig.sh
  9. VIRSH_TEST_SCRIPT=./scripts/test_libvirt.expect
  10. DEBVM_TEST_SCRIPT=./scripts/test_debvm.expect
  11. DEBVM_IMG_DIR=/tmp
  12. DEBVM_DISK=$(DEBVM_IMG_DIR)/vz5_kernel_test.ext4
  13. DEBVM_SWAPFILE=$(DEBVM_IMG_DIR)/vz5_kernel_test.swapfile
  14. DEBVM_SWAPLABEL=testswap
  15. UPGRADE_SCRIPT=./scripts/upgrade.sh
  16. HASH=sha512sum
  17. CRED=$(shell tput setaf 1)
  18. CGRN=$(shell tput setaf 2)
  19. CRAZ=$(shell tput sgr0)
  20. ARCHIVE=archives/install_$(shell date "+%Y_%m_%dT%H_%M_%S")_$(VERSION)
  21. all: status
  22. status:
  23. @echo "Images :\n========\n";
  24. @[ -f "bzImage.latest" ] && echo 'Latest : $(shell [ -f "bzImage.latest" ] && file -L bzImage.latest | cut -d ',' -f2)' || echo "Latest : $(CRED)None built$(CRAZ)";
  25. @[ -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)";
  26. @[ -f "$(BZIMAGE_INSTALL)" ] && echo 'Installed : $(shell [ -f "$(BZIMAGE_INSTALL)" ] && file -L $(BZIMAGE_INSTALL) | cut -d ',' -f2)' || echo "Installed : $(CRED)None installed$(CRAZ)";
  27. @echo "\nLatest tested :\n----------";
  28. @[ -f "bzImage.latest" ] && $(MAKE) -s tested || true;
  29. @echo "\nSources :\n=========";
  30. @sh $(UPGRADE_SCRIPT) check >/dev/null \
  31. && echo "$(CGRN)Kernel sources are up to date$(CRAZ)" \
  32. || echo "$(CRED)Kernel sources can be upgraded$(CRAZ)";
  33. @echo "\nKernel config git repo :\n========================"
  34. @git -C $(CONFIG_REPO) status
  35. $(SRC_DIR)/.config: $(KERNEL.CONFIG)
  36. cp -v "$<" "$@"
  37. $(KERNEL.CONFIG): $(SRC_DIR)/.config
  38. cp -v "$<" "$@"
  39. $(CONFIG_REPO):
  40. mkdir $(CONFIG_REPO) && git -C $(CONFIG_REPO) init;
  41. menuconfig: $(SRC_DIR)/.config
  42. $(MAKE) -C $(SRC_DIR) menuconfig
  43. sh "$(CHECKCONFIG_SCRIPT)" -v "$(SRC_DIR)/.config"
  44. $(BZIMAGE): $(SRC_DIR)/.config
  45. $(MAKE) -C $(SRC_DIR);
  46. mkdir -p archives/;
  47. cp "$(SRC_DIR)/arch/x86_64/boot/bzImage" "$@";
  48. ln -vfs "$@" bzImage.latest
  49. ls -lah "$@"
  50. upgrade_src:
  51. sh $(UPGRADE_SCRIPT)
  52. can_upgrade:
  53. @sh $(UPGRADE_SCRIPT) check || echo "$(CRED)Kernel sources can be ugraded$(CRAZ)";
  54. kernel: can_upgrade $(BZIMAGE)
  55. commit-config: tested $(KERNEL.CONFIG) can_upgrade checkconfig
  56. cp -v "$(SRC_DIR)/.config" "$(KERNEL.CONFIG)";
  57. git -C $(CONFIG_REPO) add "$(KERNEL.CONFIG)";
  58. git -C $(CONFIG_REPO) commit -m "Update config for kernel $(VERSION)";
  59. git -C $(CONFIG_REPO) tag -fa "$(VERSION)" -m "$(shell date -Is) Config for kernel $(VERSION)";
  60. archives/:
  61. mkdir -p archives;
  62. archive:
  63. mkdir -p $(ARCHIVE);
  64. cp -v $(BZIMAGE) $(ARCHIVE)/bzImage.new;
  65. cp -v $(BZIMAGE_INSTALL) $(ARCHIVE)/bzImage.old;
  66. clean:
  67. -rm -v $(BZIMAGE) bzImage.latest "$(DEBVM_SWAPFILE)" "$(DEBVM_DISK)" "$(TESTED_HASH)";
  68. $(MAKE) -C $(SRC_DIR) clean;
  69. distclean:
  70. -rm -R "$(shell realpath $(SRC_DIR))" "$(SRC_DIR)"
  71. .PHONY: can_upgrade distclean clean $(BZIMAGE_TEST) $(BZIMAGE_INSTALL) _test tested install checkconfig
  72. checkconfig: $(KERNEL.CONFIG)
  73. -sh $(CHECKCONFIG_SCRIPT) -v $(KERNEL.CONFIG)
  74. tested:
  75. @$(HASH) -c "$(TESTED_HASH)" 2>/dev/null || {\
  76. echo "$(CRED)$(BZIMAGE) is not tested.";\
  77. echo "run make test as root.$(CRAZ)";\
  78. false;\
  79. };
  80. _test:
  81. if $(MAKE) is_root >/dev/null 2>/dev/null; then \
  82. $(MAKE) _virsh_test;\
  83. else\
  84. $(MAKE) _debvm_test;\
  85. fi
  86. test: _test
  87. $(HASH) "$(BZIMAGE)" > "$(TESTED_HASH)";
  88. # non-privileged user tests
  89. $(DEBVM_DISK): $(BZIMAGE)
  90. @debvm-create -r stable -o "$@" -h "$(TEST_VM_HOSTNAME)" \
  91. --skip autologin --skip kernel --skip systemdnetwork -- \
  92. --customize-hook="echo \"LABEL=$(DEBVM_SWAPLABEL) none swap sw 0 0\" >> \$$1/etc/fstab"\
  93. --customize-hook="mkdir -p \$$1/etc/network; echo \"auto enp0s2\niface enp0s2 inet dhcp\" > \$$1/etc/network/interfaces" \
  94. --include="udev" \
  95. --include="iputils-ping iproute2 ifupdown isc-dhcp-client" \
  96. --include="ssh qemu-guest-agent tzdata initscripts ntpdate ca-certificates console-setup console-common console-data locales acpid acpi-support-base vim screen bash-completion rsyslog" \
  97. || { rm "$@"; false;}
  98. $(DEBVM_SWAPFILE):
  99. dd if=/dev/zero "of=$@" bs=4096 count=32768 status=progress &&\
  100. chmod 0600 "$@" &&\
  101. /usr/sbin/mkswap -L "$(DEBVM_SWAPLABEL)" "$@"
  102. _debvm_test: $(DEBVM_DISK) $(DEBVM_SWAPFILE)
  103. @$(DEBVM_TEST_SCRIPT) "$(TEST_VM_HOSTNAME)" "$(VERSION)" "$(DEBVM_DISK)" "$(BZIMAGE)" "$(DEBVM_SWAPFILE)" "$(DEBVM_SWAPLABEL)" \
  104. || { echo "$(CRED)Kernel $(VERSION) [Error]$(CRAZ): Check /tmp/test_vz5_debvm_expect.log" >&2; false; } \
  105. && echo "$(CGRN)Kernel $(VERSION) [OK]$(CRAZ): console logs in /tmp/test_debvm_expect.log" >&2;
  106. # superuser designed targets
  107. is_root:
  108. @[ "$(shell whoami)" = "root" ] || {\
  109. echo "$(CRED)ERROR :$(CRAZ) You need to be root to run this target" >&2;\
  110. false;\
  111. };
  112. $(BZIMAGE_TEST): can_upgrade is_root
  113. cp "$(BZIMAGE)" "$@"
  114. _virsh_test: $(BZIMAGE_TEST) can_upgrade is_root
  115. @$(VIRSH_TEST_SCRIPT) "$(TEST_VM_HOSTNAME)" "$(VERSION)" "$(TEST_VM_NAME)" "$(TEST_VM_IFNAME)" "$(TEST_VM_IPV4)" "$(TEST_VM_IPV6)" || {\
  116. echo "$(CRED)Kernel $(VERSION) [Error]$(CRAZ): Check /tmp/test_vz5_expect.log" >&2;\
  117. false;\
  118. } && echo "$(CGRN)Kernel $(VERSION) [OK]$(CRAZ): console logs in /tmp/test_vz5_expect.log" >&2;
  119. $(BZIMAGE_INSTALL): tested can_upgrade is_root
  120. -cp -v $(BZIMAGE_INSTALL) $(BZIMAGE_INSTALL).old;
  121. cp -v $(BZIMAGE) $(BZIMAGE_INSTALL);
  122. install: $(BZIMAGE_INSTALL) archive is_root