Relax tmpfs ram limits while building stuff
[dpa-image-builder.git] / makefile
1 PLATFORM_AGNOSTIC_TARGETS += clean-fs-all clean-image-all
2
3 include src/make-helper-functions.mk
4
5 all: bin/$(IMAGE_NAME)
6
7 ifdef KERNEL_CONFIG_TARGET
8 KERNEL_TARGET=kernel/bin/$(KERNEL_CONFIG_TARGET)/.done
9 linux: $(KERNEL_TARGET)
10         @true
11 $(KERNEL_TARGET):
12         $(MAKE) -C kernel
13 else
14 linux:
15         @true
16 endif
17
18 extra_packages:
19         if [ "$(BUILD_PACKAGES)" != no ]; \
20           then $(MAKE) -C chroot-build-helper; \
21         fi
22
23 clean-fs-all: build/bin/usernsexec
24         uexec rm -rf "$(project_root)/build/"*.img
25
26 clean-fs: build/bin/usernsexec
27         uexec rm -rf "$(project_root)/build/$(IMAGE_NAME)/"
28
29 clean-image-all:
30         rm -f bin/*.img
31
32 clean-image:
33         rm -f "bin/$(IMAGE_NAME)"
34
35 enter-buildenv:
36         export PROMPT_COMMAND='if [ -z "$$PS_SET" ]; then PS_SET=1; PS1="(buildenv) $$PS1"; fi'; \
37         $(USER_SHELL)
38
39 build/$(DISTRO)-$(RELEASE)/deb/%.deb: | build/$(DISTRO)-$(RELEASE)/deb/.dir
40         getdeb.sh "$@"
41
42 $(DEBOOTSTRAP_SCRIPT): build/$(DISTRO)-$(RELEASE)/deb/debootstrap.deb
43         set -ex; \
44         exec 8>"build/.debootstrap-$(DISTRO)-$(RELEASE).lock"; \
45         flock 8; \
46         if [ -e "$@" ]; then exit 0; fi; \
47         rm -rf "$$X_DEBOOTSTRAP_DIR"; \
48         mkdir -p "$$X_DEBOOTSTRAP_DIR"; \
49         debootstrap_deb="$$(realpath "build/$$DISTRO-$$RELEASE/deb/debootstrap.deb")"; \
50         cd "$$X_DEBOOTSTRAP_DIR"; \
51         ar x "$$debootstrap_deb"; \
52         tar xzf data.tar.*;
53         [ -e "$@" ]
54         touch "$@"
55
56 build/$(IMAGE_NAME)/root.fs/: \
57   $(KERNEL_TARGET) \
58   build/bin/usernsexec \
59   $(DEBOOTSTRAP_SCRIPT) \
60   bin/.dir \
61   build/$(IMAGE_NAME)/.dir
62         $(MAKE) extra_packages
63         ./script/debootstrap.sh
64
65 bin/$(IMAGE_NAME): \
66   $(KERNEL_TARGET) \
67   build/bin/fuseloop \
68   build/bin/tar2ext \
69   build/$(IMAGE_NAME)/root.fs/ \
70   $(PLATFORM_FILES)
71         ./script/assemble_image.sh
72
73 always:
74
75 .PHONY: always
76
77 rebuild: clean-fs clean-image always
78         $(MAKE) all
79
80 clean-repo: clean-repo//fuseloop clean-repo//usernsexec clean-repo//tar2ext
81         $(MAKE) -C platform clean-repo
82         $(MAKE) -C kernel clean-repo
83         $(MAKE) -C chroot-build-helper clean-repo
84
85 update-repo: update-repo//fuseloop update-repo//usernsexec update-repo//tar2ext
86         $(MAKE) -C platform update-repo
87         $(MAKE) -C kernel update-repo
88         if [ "$(BUILD_PACKAGES)" != no ]; \
89           then $(MAKE) -C chroot-build-helper update-repo; \
90         fi
91
92 clean-build: clean-image clean-fs
93         $(MAKE) -C platform clean-build
94         $(MAKE) -C kernel clean-build
95         $(MAKE) -C chroot-build-helper clean-build
96         rm -rf build/bin/
97         rmdir build/ 2>/dev/null || true
98
99 clean-build-all: clean-image-all clean-fs-all
100         $(MAKE) -C platform clean-build-all
101         $(MAKE) -C kernel clean-build-all
102         $(MAKE) -C chroot-build-helper clean-build-all
103         rm -rf build/
104
105 .SECONDEXPANSION:
106 repo: always \
107   $$(call repodir,fuseloop) \
108   $$(call repodir,usernsexec) \
109   $$(call repodir,tar2ext)
110         $(MAKE) -C platform repo
111         $(MAKE) -C kernel repo
112         if [ "$(BUILD_PACKAGES)" != no ]; \
113           then $(MAKE) -C chroot-build-helper repo; \
114         fi
115
116 build/bin/fuseloop: $$(call repodir,fuseloop) | build/bin/.dir
117         with-repo.sh fuseloop bash -ex -c "\
118           $(MAKE) -C \"\$$repodir/fuseloop\"; \
119           cp \"\$$repodir/fuseloop/fuseloop\" build/bin/; \
120         "
121
122 build/bin/usernsexec: $$(call repodir,usernsexec) | build/bin/.dir
123         with-repo.sh usernsexec bash -ex -c "\
124           $(MAKE) -C \"\$$repodir/usernsexec/\"; \
125           cp \"\$$repodir/usernsexec/bin/usernsexec\" build/bin/; \
126           cp \"\$$repodir/usernsexec/script/uexec\" build/bin/; \
127         "
128
129 build/bin/tar2ext: $$(call repodir,tar2ext) | build/bin/.dir
130         with-repo.sh tar2ext bash -ex -c "\
131           $(MAKE) -C \"\$$repodir/tar2ext/\"; \
132           cp \"\$$repodir/tar2ext/scripts/sload.ext4\" build/bin/; \
133           cp \"\$$repodir/tar2ext/bin/tar2ext\" build/bin/; \
134         "
135         ( cd build/bin/; ln -sf sload.ext4 sload.ext3; ln -sf sload.ext4 sload.ext2; )