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