blob: 821f418c655b13bbd980e08222a486e77bdfd7ff [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#
2# Copyright (C) 2007-2009 OpenWrt.org
3#
4# This is free software, licensed under the GNU General Public License v2.
5# See /LICENSE for more information.
6#
7# Main makefile for the toolchain
8#
9# Steps:
10# 1) toolchain/binutils/compile
11# build & install binutils
12# 2) toolchain/gcc/minimal/compile
13# build & install a minimal gcc, needed for steps 3 & 4
14# 3) toolchain/kernel-headers/compile
15# install kernel headers, needed for step 4
16# 4) toolchain/libc/headers/compile
17# build & install libc headers & support files, needed for step 5
18# 5) toolchain/gcc/initial/compile
19# build & install an initial gcc, needed for step 6
20# 6) toolchain/libc/compile
21# build & install the final libc
22# 7) toolchain/gcc/final/compile
23# build & install the final gcc
24#
25# For musl, steps 2 and 4 are skipped, and step 3 is done after 5
26
27curdir:=toolchain
28
29# subdirectories to descend into
30$(curdir)/builddirs := $(if $(CONFIG_GDB),gdb) $(if $(CONFIG_EXTERNAL_TOOLCHAIN),wrapper,kernel-headers binutils gcc/initial gcc/final $(LIBC) fortify-headers) $(if $(CONFIG_NASM),nasm) $(if $(CONFIG_USE_MOLD),mold)
31
32# builddir dependencies
33ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
34 ifdef CONFIG_USE_MUSL
35 $(curdir)/gcc/initial/compile:=$(curdir)/binutils/compile
36 $(curdir)/kernel-headers/compile:=$(curdir)/gcc/initial/compile
37 else
38 $(curdir)/builddirs += $(LIBC)/headers gcc/minimal
39 $(curdir)/gcc/minimal/compile:=$(curdir)/binutils/compile
40 $(curdir)/kernel-headers/compile:=$(curdir)/gcc/minimal/compile
41 $(curdir)/$(LIBC)/headers/compile:=$(curdir)/kernel-headers/compile
42 $(curdir)/gcc/initial/compile:=$(curdir)/$(LIBC)/headers/compile
43 endif
44
45 $(curdir)/$(LIBC)/compile:=$(curdir)/gcc/initial/compile $(curdir)/kernel-headers/compile
46 $(curdir)/gcc/final/compile:=$(curdir)/$(LIBC)/compile
47endif
48
49ifndef DUMP_TARGET_DB
50ifneq ($(ARCH),)
51 $(TOOLCHAIN_DIR)/info.mk: .config
52 @for dir in $(TOOLCHAIN_DIR); do ( \
53 $(if $(QUIET),,set -x;) \
54 mkdir -p "$$dir"; \
55 cd "$$dir"; \
56 ln -nsf lib lib64; \
57 ln -nsf lib lib32; \
58 mkdir -p stamp lib usr/include usr/lib ; \
59 ); done
60 @grep GCC_VERSION $@ >/dev/null 2>&1 || $(INSTALL_DATA) $(TOPDIR)/toolchain/info.mk $@
61 @touch $@
62endif
63endif
64
65ifdef CONFIG_BUILDBOT
66ifneq ($(wildcard $(TOPDIR)/.git),)
67 $(TOOLCHAIN_DIR)/stamp/.ver_check: $(TMP_DIR)/.build
68 cd "$(TOPDIR)"; git log --format=%h -1 toolchain > $(TMP_DIR)/.ver_check
69 cmp -s $(TMP_DIR)/.ver_check $@ || { \
70 rm -rf $(BUILD_DIR) $(STAGING_DIR) $(TOOLCHAIN_DIR) $(BUILD_DIR_TOOLCHAIN); \
71 mkdir -p $(TOOLCHAIN_DIR)/stamp; \
72 mv $(TMP_DIR)/.ver_check $@; \
73 }
74
75$(TOOLCHAIN_DIR)/info.mk $(STAGING_DIR)/.prepared: $(TOOLCHAIN_DIR)/stamp/.ver_check
76endif
77endif
78
79# prerequisites for the individual targets
80$(curdir)/ := .config prereq
81$(curdir)//compile = $(STAGING_DIR)/.prepared $(TOOLCHAIN_DIR)/info.mk $(tools/stamp-compile)
82
83ifndef DUMP_TARGET_DB
84$(TOOLCHAIN_DIR)/stamp/.gcc_final_installed:
85endif
86
87$(curdir)/install: $(curdir)/compile
88
89ifeq ($(TOOLS_REFRESH),1)
90$(eval $(call stampfile,$(curdir),toolchain,compile,$(TOOLCHAIN_DIR)/stamp/.gcc_final_installed,,$(TOOLCHAIN_DIR)))
91$(eval $(call stampfile,$(curdir),toolchain,check,$(TMP_DIR)/.build))
92$(eval $(call subdir,$(curdir)))
93else
94$(curdir)/builddirs=
95$(eval $(foreach target,$(SUBTARGETS),$(call subtarget,$(curdir),$(target))))
96endif