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