bootstrap.mk (4660B)
1 # mk/bootstrap.mk 2 # =========================================================================== 3 # Three-stage self-build verification. Included after mk/rt.mk because it 4 # references RT_BUILD_DIR / RT_DEFAULT_VARIANTS. 5 # 6 # Build kit with the host compiler as stage 1, then rebuild it twice through 7 # the normal Makefile using kit's busybox-style cc/ar/ld symlinks. Stages 2 8 # and 3 must be bitwise identical. 9 10 .PHONY: bootstrap bootstrap-debug bootstrap-release _do-bootstrap \ 11 bootstrap-linux bootstrap-linux-musl bootstrap-linux-glibc \ 12 bootstrap-freebsd 13 14 BOOTSTRAP_DIR = $(BUILD_DIR)/bootstrap 15 BOOTSTRAP_STAGE1_DIR = $(BOOTSTRAP_DIR)/stage1 16 BOOTSTRAP_STAGE2_DIR = $(BOOTSTRAP_DIR)/stage2 17 BOOTSTRAP_STAGE3_DIR = $(BOOTSTRAP_DIR)/stage3 18 BOOTSTRAP_STAGE1_BIN = $(BOOTSTRAP_STAGE1_DIR)/kit 19 BOOTSTRAP_STAGE2_BIN = $(BOOTSTRAP_STAGE2_DIR)/kit 20 BOOTSTRAP_STAGE3_BIN = $(BOOTSTRAP_STAGE3_DIR)/kit 21 BOOTSTRAP_TOOLS = cc ld ar ranlib as 22 BOOTSTRAP_HOST_MODE_CFLAGS = 23 BOOTSTRAP_HOST_MODE_LDFLAGS = 24 25 # When kit itself is the compiler (stages 2/3), drive its hosted profile with a 26 # plain -lc on both the compile and link steps, on every host. -lc makes kit 27 # resolve the hosted libc and add its include + library dirs (the system 28 # headers + libc search path), which is exactly what stages 2/3 need. This 29 # replaces the host CC's HOST_SYSROOT_{C,LD}FLAGS (e.g. Darwin's -isysroot): kit 30 # discovers the SDK / sysroot via its own hosted profile + host probe rather 31 # than an -isysroot it doesn't interpret the same way. Stage1 is built by the 32 # host CC (the outer make) and keeps env.mk's HOST_SYSROOT_* untouched. 33 BOOTSTRAP_KIT_TOOLCHAIN_FLAGS = HOST_SYSROOT_CFLAGS=-lc HOST_SYSROOT_LDFLAGS=-lc 34 35 # Portable SHA-256 display: macOS uses shasum, FreeBSD/Linux have sha256sum. 36 BOOTSTRAP_SHASUM = shasum -a 256 37 ifeq ($(HOST_OS),freebsd) 38 BOOTSTRAP_SHASUM = sha256sum 39 endif 40 ifeq ($(HOST_OS),linux) 41 BOOTSTRAP_SHASUM = sha256sum 42 endif 43 BOOTSTRAP_STAMP = $(BOOTSTRAP_DIR)/.stamp 44 BOOTSTRAP_RT_LIBS = $(addprefix $(RT_BUILD_DIR)/,$(addsuffix /libkit_rt.a,$(RT_DEFAULT_VARIANTS))) 45 BOOTSTRAP_MAKEFILES = Makefile mk/env.mk mk/config.mk mk/flags.mk \ 46 mk/lib_srcs.mk mk/driver_srcs.mk mk/rt.mk 47 48 ifeq ($(RELEASE),1) 49 $(BOOTSTRAP_STAMP): HOST_OPTFLAGS = -O1 50 $(BOOTSTRAP_STAMP): BOOTSTRAP_HOST_MODE_CFLAGS = $(HOST_MODE_CFLAGS) 51 $(BOOTSTRAP_STAMP): BOOTSTRAP_HOST_MODE_LDFLAGS = -Wl,--gc-sections -Wl,-S 52 endif 53 54 bootstrap: bootstrap-debug bootstrap-release 55 56 bootstrap-debug: 57 $(MAKE) RELEASE=0 BUILD_DIR='$(BUILD_DIR)/debug' _do-bootstrap 58 59 bootstrap-release: 60 $(MAKE) RELEASE=1 BUILD_DIR='$(BUILD_DIR)/release' _do-bootstrap 61 62 _do-bootstrap: $(BOOTSTRAP_STAMP) 63 64 # Drive the aarch64-linux self-build from a non-Linux dev host: `make bootstrap` 65 # run natively inside a Linux container (scripts/linux_bootstrap.sh). On a 66 # native Linux host, just run `make bootstrap` directly -- it already selects 67 # the aarch64-linux toolchain off the host uname. 68 bootstrap-linux: bootstrap-linux-musl 69 70 bootstrap-linux-musl: 71 scripts/linux_bootstrap.sh musl both 72 73 bootstrap-linux-glibc: 74 scripts/linux_bootstrap.sh glibc both 75 76 # Drive the aarch64-freebsd self-build via the running FreeBSD aarch64 VM 77 # (scripts/freebsd_vm.sh must be able to SSH to port 2223). The VM must be 78 # running; scripts/freebsd_bootstrap.sh starts it if needed via KIT_TOY_VM_KEEP_UP. 79 bootstrap-freebsd: 80 scripts/freebsd_bootstrap.sh aarch64 81 82 $(BOOTSTRAP_STAMP): $(BIN) $(BOOTSTRAP_RT_LIBS) $(BOOTSTRAP_MAKEFILES) 83 rm -rf $(BOOTSTRAP_DIR) 84 @mkdir -p $(BOOTSTRAP_STAGE1_DIR) 85 cp $(BIN) $(BOOTSTRAP_STAGE1_BIN) 86 @for tool in $(BOOTSTRAP_TOOLS); do ln -sf kit "$(BOOTSTRAP_STAGE1_DIR)/$$tool"; done 87 $(MAKE) lib bin \ 88 BUILD_DIR='$(abspath $(BOOTSTRAP_STAGE2_DIR))' \ 89 RELEASE='$(RELEASE)' \ 90 HOST_OPTFLAGS='$(HOST_OPTFLAGS)' \ 91 HOST_MODE_CFLAGS='$(BOOTSTRAP_HOST_MODE_CFLAGS)' \ 92 HOST_MODE_LDFLAGS='$(BOOTSTRAP_HOST_MODE_LDFLAGS)' \ 93 CC='$(abspath $(BOOTSTRAP_STAGE1_DIR))/cc' \ 94 AR='$(abspath $(BOOTSTRAP_STAGE1_DIR))/ar' \ 95 $(BOOTSTRAP_KIT_TOOLCHAIN_FLAGS) 96 @for tool in $(BOOTSTRAP_TOOLS); do ln -sf kit "$(BOOTSTRAP_STAGE2_DIR)/$$tool"; done 97 $(MAKE) lib bin \ 98 BUILD_DIR='$(abspath $(BOOTSTRAP_STAGE3_DIR))' \ 99 RELEASE='$(RELEASE)' \ 100 HOST_OPTFLAGS='$(HOST_OPTFLAGS)' \ 101 HOST_MODE_CFLAGS='$(BOOTSTRAP_HOST_MODE_CFLAGS)' \ 102 HOST_MODE_LDFLAGS='$(BOOTSTRAP_HOST_MODE_LDFLAGS)' \ 103 CC='$(abspath $(BOOTSTRAP_STAGE2_DIR))/cc' \ 104 AR='$(abspath $(BOOTSTRAP_STAGE2_DIR))/ar' \ 105 $(BOOTSTRAP_KIT_TOOLCHAIN_FLAGS) 106 cmp $(BOOTSTRAP_STAGE2_BIN) $(BOOTSTRAP_STAGE3_BIN) 107 $(BOOTSTRAP_SHASUM) $(BOOTSTRAP_STAGE2_BIN) $(BOOTSTRAP_STAGE3_BIN) 108 @touch $@