Bez popisu
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.2KB

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