blob: 009a7762514dd2ae97cec622910d0de83d2b7583 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#
2# Copyright (C) 2006-2011 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 host tools
8#
9curdir:=tools
10
11# subdirectories to descend into
12tools-y :=
13
14ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
15 BUILD_TOOLCHAIN := y
16 ifdef CONFIG_GCC_USE_GRAPHITE
17 BUILD_ISL = y
18 endif
19endif
20ifneq ($(CONFIG_SDK)$(CONFIG_PACKAGE_kmod-b43)$(CONFIG_BRCMSMAC_USE_FW_FROM_WL),)
21 BUILD_B43_TOOLS = y
22endif
23ifneq ($(CONFIG_SDK)$(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2),)
24 BUILD_BZIP2_TOOLS = y
25endif
26ifneq ($(CONFIG_SDK)$(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4),)
27 BUILD_LZ4_TOOLS = y
28endif
29ifneq ($(CONFIG_SDK)$(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO),)
30 BUILD_LZO_TOOLS = y
31endif
32
33tools-y += autoconf
34tools-y += autoconf-archive
35tools-y += automake
36tools-y += bc
37tools-y += bison
38tools-y += cmake
39tools-y += cpio
40tools-y += dosfstools
41tools-y += e2fsprogs
42tools-y += elfutils
43tools-y += expat
44tools-y += fakeroot
45tools-y += findutils
46tools-y += firmware-utils
47tools-y += flex
48tools-y += gengetopt
49tools-y += gnulib
50tools-y += libressl
51tools-y += libtool
52tools-y += lzma
53tools-y += m4
54tools-y += make-ext4fs
55tools-y += meson
56tools-y += missing-macros
57tools-y += mkimage
58tools-y += mklibs
59tools-y += mtd-utils
60tools-y += mtools
61tools-y += ninja
62tools-y += padjffs2
63tools-y += patch-image
64tools-y += patchelf
65tools-y += pkgconf
66tools-y += quilt
67tools-y += squashfs4
68tools-y += sstrip
69tools-y += util-linux
70tools-y += xz
71tools-y += zip
72tools-y += zlib
73tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS),y) += liblzo
74tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(BUILD_B43_TOOLS),y) += b43-tools
75tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(BUILD_BZIP2_TOOLS),y) += bzip2
76tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(BUILD_ISL),y) += isl
77tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(BUILD_LZ4_TOOLS),y) += lz4
78tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(BUILD_LZO_TOOLS),y) += lzop
79tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(BUILD_TOOLCHAIN),y) += gmp mpc mpfr
80tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_TARGET_apm821xx)$(CONFIG_TARGET_gemini),y) += genext2fs
81tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_TARGET_ath79),y) += lzma-old squashfs3-lzma
82tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_TARGET_mxs),y) += elftosb sdimage
83tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_TARGET_realtek),y) += 7z
84tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_TARGET_tegra),y) += cbootimage cbootimage-configs
85tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_USES_MINOR),y) += yafut
86tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_USE_SPARSE),y) += sparse
87tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_USE_LLVM_BUILD),y) += llvm-bpf
88tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_USE_MOLD),y) += mold
89
90# builddir dependencies
91$(curdir)/autoconf/compile := $(curdir)/m4/compile
92$(curdir)/automake/compile := $(curdir)/autoconf/compile $(curdir)/pkgconf/compile $(curdir)/xz/compile
93$(curdir)/b43-tools/compile := $(curdir)/bison/compile
94$(curdir)/bc/compile := $(curdir)/bison/compile $(curdir)/libtool/compile
95$(curdir)/bison/compile := $(curdir)/flex/compile
96$(curdir)/cbootimage/compile += $(curdir)/automake/compile
97$(curdir)/cmake/compile += $(curdir)/libressl/compile $(curdir)/ninja/compile $(curdir)/expat/compile $(curdir)/xz/compile $(curdir)/zlib/compile $(curdir)/zstd/compile
98$(curdir)/dosfstools/compile := $(curdir)/automake/compile
99$(curdir)/e2fsprogs/compile := $(curdir)/libtool/compile $(curdir)/util-linux/compile
100$(curdir)/elfutils/compile := $(curdir)/m4/compile $(curdir)/zlib/compile $(curdir)/gnulib/compile $(curdir)/libtool/compile
101$(curdir)/fakeroot/compile := $(curdir)/libtool/compile
102$(curdir)/findutils/compile := $(curdir)/bison/compile
103$(curdir)/firmware-utils/compile += $(curdir)/cmake/compile
104$(curdir)/flex/compile := $(curdir)/libtool/compile
105$(curdir)/genext2fs/compile := $(curdir)/libtool/compile
106$(curdir)/gengetopt/compile := $(curdir)/libtool/compile
107$(curdir)/gmp/compile := $(curdir)/libtool/compile
108$(curdir)/isl/compile := $(curdir)/gmp/compile
109$(curdir)/liblzo/compile := $(curdir)/cmake/compile
110$(curdir)/libressl/compile := $(curdir)/pkgconf/compile
111$(curdir)/libtool/compile := $(curdir)/automake/compile $(curdir)/gnulib/compile $(curdir)/missing-macros/compile
112$(curdir)/lz4/compile := $(curdir)/meson/compile
113$(curdir)/lzma-old/compile := $(curdir)/zlib/compile
114$(curdir)/lzop/compile := $(curdir)/cmake/compile $(curdir)/liblzo/compile
115$(curdir)/llvm-bpf/compile := $(curdir)/cmake/compile
116$(curdir)/make-ext4fs/compile := $(curdir)/zlib/compile
117$(curdir)/meson/compile := $(curdir)/ninja/compile
118$(curdir)/missing-macros/compile := $(curdir)/autoconf/compile
119$(curdir)/mkimage/compile += $(curdir)/bison/compile $(curdir)/libressl/compile
120$(curdir)/mklibs/compile := $(curdir)/libtool/compile
121$(curdir)/mold/compile := $(curdir)/cmake/compile $(curdir)/zlib/compile $(curdir)/zstd/compile
122$(curdir)/mpc/compile := $(curdir)/mpfr/compile $(curdir)/gmp/compile
123$(curdir)/mpfr/compile := $(curdir)/gmp/compile
124$(curdir)/mtd-utils/compile := $(curdir)/libtool/compile $(curdir)/zlib/compile $(curdir)/util-linux/compile
125$(curdir)/padjffs2/compile := $(curdir)/findutils/compile
126$(curdir)/patchelf/compile := $(curdir)/libtool/compile
127$(curdir)/pkgconf/compile := $(curdir)/meson/compile
128$(curdir)/quilt/compile := $(curdir)/autoconf/compile $(curdir)/findutils/compile
129$(curdir)/sdcc/compile := $(curdir)/bison/compile
130$(curdir)/squashfs3-lzma/compile := $(curdir)/lzma-old/compile
131$(curdir)/squashfs4/compile := $(curdir)/xz/compile $(curdir)/zlib/compile
132$(curdir)/util-linux/compile := $(curdir)/bison/compile $(curdir)/automake/compile
133$(curdir)/yafut/compile := $(curdir)/cmake/compile
134
135ifneq ($(HOST_OS),Linux)
136 $(curdir)/coreutils/compile += $(curdir)/automake/compile $(curdir)/bison/compile $(curdir)/gnulib/compile
137 $(curdir)/squashfs4/compile += $(curdir)/coreutils/compile
138 tools-y += coreutils
139endif
140ifeq ($(HOST_OS),Darwin)
141 tools-y += bash
142else
143 $(curdir)/dwarves/compile += $(curdir)/elfutils/compile
144 tools-$(if $(CONFIG_BUILD_ALL_HOST_TOOLS)$(CONFIG_DWARVES),y) += dwarves
145endif
146
147ifneq ($(CONFIG_CCACHE)$(CONFIG_SDK),)
148$(foreach tool, $(filter-out zstd zlib xz pkgconf patch ninja meson libressl expat cmake,$(tools-y)), $(eval $(curdir)/$(tool)/compile += $(curdir)/ccache/compile))
149tools-y += ccache
150$(curdir)/ccache/compile := $(curdir)/cmake/compile
151endif
152
153# in case there is no patch tool on the host we need to make patch tool a
154# dependency for tools which have patches directory
155$(foreach tool, $(tools-y), $(if $(wildcard $(curdir)/$(tool)/patches),$(eval $(curdir)/$(tool)/compile += $(curdir)/patch/compile)))
156
157$(foreach tool, $(filter-out zstd,$(tools-y)), $(eval $(curdir)/$(tool)/compile += $(curdir)/zstd/compile))
158
159# make any tool depend on the following to ensure that archives can be unpacked and patched properly
160tools-core += libdeflate
161tools-core += patch
162tools-core += tar
163tools-core += zstd
164
165$(foreach tool, $(tools-y), $(eval $(curdir)/$(tool)/compile += $(patsubst %,$(curdir)/%/compile,$(tools-core))))
166tools-y += $(tools-core)
167
168# make some core tools depend on sed and flock
169$(curdir)/patch/compile += $(curdir)/sed/compile
170$(curdir)/tar/compile += $(curdir)/sed/compile
171$(curdir)/zstd/compile += $(curdir)/libdeflate/compile
172
173$(curdir)/sed/compile := $(curdir)/flock/compile $(curdir)/zstd/compile
174tools-y += flock sed
175
176$(curdir)/autoremove := 1
177$(curdir)/builddirs := $(tools-y) $(tools-dep) $(tools-)
178$(curdir)/builddirs-default := $(tools-y)
179
180ifdef CHECK_ALL
181$(curdir)/builddirs-check:=$($(curdir)/builddirs)
182$(curdir)/builddirs-download:=$($(curdir)/builddirs)
183endif
184
185ifndef DUMP_TARGET_DB
186define PrepareStaging
187 @for dir in $(1); do ( \
188 $(if $(QUIET),,set -x;) \
189 mkdir -p "$$dir"; \
190 cd "$$dir"; \
191 mkdir -p bin lib stamp usr/include usr/lib; \
192 ); done
193endef
194
195$(BIN_DIR):
196 mkdir -p $@
197
198# preparatory work
199$(STAGING_DIR)/.prepared: $(TMP_DIR)/.build
200 $(call PrepareStaging,$(STAGING_DIR))
201 mkdir -p $(BUILD_DIR)/stamp
202 touch $@
203
204$(STAGING_DIR_HOST)/.prepared: $(TMP_DIR)/.build
205 $(call PrepareStaging,$(STAGING_DIR_HOST))
206 mkdir -p $(BUILD_DIR_HOST)/stamp $(STAGING_DIR_HOST)/include/sys
207 $(INSTALL_DATA) $(TOPDIR)/tools/include/*.h $(STAGING_DIR_HOST)/include/
208 $(INSTALL_DATA) $(TOPDIR)/tools/include/sys/*.h $(STAGING_DIR_HOST)/include/sys/
209ifneq ($(HOST_OS),Linux)
210 mkdir -p $(STAGING_DIR_HOST)/include/asm
211 $(INSTALL_DATA) $(TOPDIR)/tools/include/asm/*.h $(STAGING_DIR_HOST)/include/asm/
212endif
213 ln -snf lib $(STAGING_DIR_HOST)/lib64
214 touch $@
215
216endif
217
218$(curdir)//prepare = $(STAGING_DIR)/.prepared $(STAGING_DIR_HOST)/.prepared $(BIN_DIR)
219$(curdir)//compile = $(STAGING_DIR)/.prepared $(STAGING_DIR_HOST)/.prepared $(BIN_DIR)
220
221# prerequisites for the individual targets
222$(curdir)/ := .config prereq
223
224$(curdir)/install: $(curdir)/compile
225
226ifeq ($(TOOLS_REFRESH),1)
227tools_enabled = $(foreach tool,$(sort $(tools-y) $(tools-)),$(if $(filter $(tool),$(tools-y)),y,n))
228$(eval $(call stampfile,$(curdir),tools,compile,,_$(subst $(space),,$(tools_enabled)),$(STAGING_DIR_HOST)))
229$(eval $(call stampfile,$(curdir),tools,check,$(TMP_DIR)/.build,,$(STAGING_DIR_HOST)))
230$(eval $(call subdir,$(curdir)))
231endif