暫無描述
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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. cp "$(SRC_DIR)/arch/x86_64/boot/bzImage" "$@";
  45. ln -vfs "$@" bzImage.latest
  46. ls -lah "$@"
  47. upgrade_src:
  48. sh $(UPGRADE_SCRIPT)
  49. can_upgrade:
  50. @sh $(UPGRADE_SCRIPT) check || echo "$(CRED)Kernel sources can be ugraded$(CRAZ)";
  51. kernel: can_upgrade $(BZIMAGE)
  52. commit-config: tested $(KERNEL.CONFIG) can_upgrade
  53. cp -v "$(SRC_DIR)/.config" "$(KERNEL.CONFIG)";
  54. git -C $(CONFIG_REPO) add "$(KERNEL.CONFIG)";
  55. git -C $(CONFIG_REPO) commit -m "Update config for kernel $(VERSION)";
  56. git -C $(CONFIG_REPO) tag -fa "$(VERSION)" -m "$(shell date -Is) Config for kernel $(VERSION)";
  57. archives/:
  58. mkdir -p archives;
  59. archive:
  60. mkdir -p $(ARCHIVE);
  61. cp -v $(BZIMAGE) $(ARCHIVE)/bzImage.new;
  62. cp -v $(BZIMAGE_INSTALL) $(ARCHIVE)/bzImage.old;
  63. clean:
  64. -rm -v $(BZIMAGE) bzImage.latest "$(DEBVM_SWAPFILE)" "$(DEBVM_DISK)" "$(TESTED_HASH)";
  65. $(MAKE) -C $(SRC_DIR) clean;
  66. distclean:
  67. -rm -R "$(shell realpath $(SRC_DIR))" "$(SRC_DIR)"
  68. .PHONY: can_upgrade distclean clean $(BZIMAGE_TEST) $(BZIMAGE_INSTALL) _test tested install
  69. tested:
  70. @$(HASH) -c "$(TESTED_HASH)" 2>/dev/null || {\
  71. echo "$(CRED)$(BZIMAGE) is not tested.";\
  72. echo "run make test as root.$(CRAZ)";\
  73. false;\
  74. };
  75. _test:
  76. if $(MAKE) is_root >/dev/null 2>/dev/null; then \
  77. $(MAKE) _virsh_test;\
  78. else\
  79. $(MAKE) _debvm_test;\
  80. fi
  81. test: _test
  82. $(HASH) "$(BZIMAGE)" > "$(TESTED_HASH)";
  83. # non-privileged user tests
  84. $(DEBVM_DISK): $(BZIMAGE)
  85. @debvm-create -r stable -o "$@" -h "$(TEST_VM_HOSTNAME)" \
  86. --skip autologin --skip kernel --skip systemdnetwork -- \
  87. --customize-hook="echo \"LABEL=$(DEBVM_SWAPLABEL) none swap sw 0 0\" >> \$$1/etc/fstab"\
  88. --customize-hook="mkdir -p \$$1/etc/network; echo \"auto enp0s2\niface enp0s2 inet dhcp\" > \$$1/etc/network/interfaces" \
  89. --include="udev" \
  90. --include="iputils-ping iproute2 ifupdown isc-dhcp-client" \
  91. --include="ssh qemu-guest-agent tzdata initscripts ntpdate ca-certificates console-setup console-common console-data locales acpid vim screen bash-completion rsyslog" \
  92. || { rm "$@"; false;}
  93. $(DEBVM_SWAPFILE):
  94. dd if=/dev/zero "of=$@" bs=4096 count=32768 status=progress &&\
  95. chmod 0600 "$@" &&\
  96. mkswap -L "$(DEBVM_SWAPLABEL)" "$@"
  97. _debvm_test: $(DEBVM_DISK) $(DEBVM_SWAPFILE)
  98. @$(DEBVM_TEST_SCRIPT) "$(TEST_VM_HOSTNAME)" "$(VERSION)" "$(DEBVM_DISK)" "$(BZIMAGE)" "$(DEBVM_SWAPFILE)" "$(DEBVM_SWAPLABEL)" \
  99. || echo "$(CRED)Kernel $(VERSION) [Error]$(CRAZ): Check /tmp/test_vz5_debvm_expect.log" >&2 \
  100. && echo "$(CGRN)Kernel $(VERSION) [OK]$(CRAZ): console logs in /tmp/test_debvm_expect.log" >&2;
  101. # superuser designed targets
  102. is_root:
  103. @[ "$(shell whoami)" = "root" ] || {\
  104. echo "$(CRED)ERROR :$(CRAZ) You need to be root to run this target" >&2;\
  105. false;\
  106. };
  107. $(BZIMAGE_TEST): can_upgrade is_root
  108. cp "$(BZIMAGE)" "$@"
  109. _virsh_test: $(BZIMAGE_TEST) can_upgrade is_root
  110. @$(VIRSH_TEST_SCRIPT) "$(TEST_VM_HOSTNAME)" "$(VERSION)" "$(TEST_VM_NAME)" || {\
  111. echo "$(CRED)Kernel $(VERSION) [Error]$(CRAZ): Check /tmp/test_vz5_expect.log" >&2;\
  112. false;\
  113. } && echo "$(CGRN)Kernel $(VERSION) [OK]$(CRAZ): console logs in /tmp/test_vz5_expect.log" >&2;
  114. $(BZIMAGE_INSTALL): tested can_upgrade is_root
  115. -cp -v $(BZIMAGE_INSTALL) $(BZIMAGE_INSTALL).old;
  116. cp -v $(BZIMAGE) $(BZIMAGE_INSTALL);
  117. install: $(BZIMAGE_INSTALL) archive is_root