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