Relax tmpfs ram limits while building stuff
[dpa-image-builder.git] / kernel / makefile
1 include ../src/make-helper-functions.mk
2 ifdef KERNEL_CONFIG_TARGET
3
4 .SECONDEXPANSION:
5
6 all: bin/$(KERNEL_CONFIG_TARGET)/.done
7         @true
8
9 menuconfig: $$(call repodir,linux) | configs/.dir
10         with-repo.sh linux bash -ex -c '\
11           if [ -f "configs/$$KERNEL_CONFIG_TARGET" ]; \
12             then cp "configs/$$KERNEL_CONFIG_TARGET" "$$repodir/linux/arch/arm64/configs/$${KERNEL_CONFIG_TARGET}_defconfig"; \
13           fi; \
14           $(MAKE) -C "$$repodir/linux" ARCH=arm64 CROSS_COMPILE="$$CROSS_COMPILER" "$$KERNEL_CONFIG_TARGET"_defconfig; \
15           $(MAKE) -C "$$repodir/linux" ARCH=arm64 CROSS_COMPILE="$$CROSS_COMPILER" menuconfig; \
16           $(MAKE) -C "$$repodir/linux" ARCH=arm64 CROSS_COMPILE="$$CROSS_COMPILER" savedefconfig; \
17           cp "$$repodir/linux/defconfig" "configs/$$KERNEL_CONFIG_TARGET"; \
18         '
19
20 repo: $$(call repodir,linux)
21         @true
22
23 bin/$(KERNEL_CONFIG_TARGET)/.done: $$(call repodir,linux) | bin/$(KERNEL_CONFIG_TARGET)/.dir
24         set -e; \
25         exec 8>bin/$(KERNEL_CONFIG_TARGET)/.lock; \
26         flock 8; \
27         if [ -f "$@" ]; then exit 0; fi; \
28         with-repo.sh linux bash -ex -c '\
29           if [ -f "configs/$$KERNEL_CONFIG_TARGET" ]; \
30             then cp "configs/$$KERNEL_CONFIG_TARGET" "$$repodir/linux/arch/arm64/configs/$${KERNEL_CONFIG_TARGET}_defconfig"; \
31           fi; \
32           patchdir="$$(realpath "patch/$$KERNEL_CONFIG_TARGET/$$KERNEL_PATCHES" || true)"; \
33           if [ -n "$$KERNEL_PATCHES" ] && [ -d "$$patchdir" ]; \
34             then ( cd "$$repodir/linux"; for patch in "$$patchdir"/*.patch; do git apply "$$patch"; done ); \
35           fi; \
36           $(MAKE) --debug=n -C "$$repodir/linux" ARCH=arm64 CROSS_COMPILE="$$CROSS_COMPILER" "$$KERNEL_CONFIG_TARGET"_defconfig; \
37           if [ "$$USE_EFI" = y ]; then ( cd "$$repodir/linux"; ./scripts/config --set-val CONFIG_EFI y; make --debug=n ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- olddefconfig; ); fi; \
38           $(MAKE) --debug=n -C "$$repodir/linux" ARCH=arm64 CROSS_COMPILE="$$CROSS_COMPILER" KBUILD_IMAGE=arch/arm64/boot/Image bindeb-pkg \
39            || $(MAKE) --debug=n -C "$$repodir/linux" ARCH=arm64 CROSS_COMPILE="$$CROSS_COMPILER" bindeb-pkg; \
40           cp "$$repodir"/linux-*.deb "bin/$$KERNEL_CONFIG_TARGET/"; \
41         '; \
42         touch "$@";
43         # Note: Trying to make bindeb-pkg again without KBUILD_IMAGE=arch/arm64/boot/Image if it failed, because some downstream kernels do some funny stuff (https://source.puri.sm/Librem5/linux/-/commit/038b6b85e8b7738e7081780e79bab8410ab07101#b48fea44aa4aea680003375368b4d138ebd75204)
44
45 clean-repo: clean-repo//linux
46         @true
47
48 update-repo: update-repo//linux
49         @true
50
51 clean-build-all:
52         rm -rf "bin/"
53
54 clean-build:
55         rm -rf "bin/$$KERNEL_CONFIG_TARGET/"
56 else
57 all:
58         @true
59 %:
60         @true
61 endif