v1.5 branch refresh based upon upstream master @ c8677ca89e53e3be7988d54280fce166cc894a7e
[librecmc/librecmc.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
21 tools-$(BUILD_TOOLCHAIN) += gmp mpfr mpc libelf expat
22 tools-y += m4 libtool autoconf automake flex bison pkg-config mklibs zlib
23 tools-y += sstrip make-ext4fs e2fsprogs mtd-utils mkimage
24 tools-y += firmware-utils patch-image quilt padjffs2
25 tools-y += mm-macros missing-macros cmake scons bc findutils gengetopt patchelf
26 tools-y += mtools dosfstools libressl
27 tools-$(CONFIG_TARGET_orion_generic) += wrt350nv2-builder upslug2
28 tools-$(CONFIG_TARGET_x86) += qemu
29 tools-$(CONFIG_TARGET_mxs) += elftosb sdimage
30 tools-$(CONFIG_TARGET_ar71xx) += lzma-old squashfs
31 tools-$(CONFIG_USES_MINOR) += kernel2minor
32 tools-y += lzma squashfs4
33 tools-$(BUILD_ISL) += isl
34 tools-$(CONFIG_USE_SPARSE) += sparse
35 tools-$(CONFIG_TARGET_apm821xx) += genext2fs
36
37 # builddir dependencies
38 $(curdir)/bison/compile := $(curdir)/flex/compile
39 $(curdir)/flex/compile := $(curdir)/libtool/compile
40 $(curdir)/libtool/compile := $(curdir)/m4/compile $(curdir)/autoconf/compile $(curdir)/automake/compile $(curdir)/missing-macros/compile
41 $(curdir)/squashfs/compile := $(curdir)/lzma-old/compile
42 $(curdir)/squashfs4/compile := $(curdir)/xz/compile $(curdir)/zlib/compile
43 $(curdir)/quilt/compile := $(curdir)/autoconf/compile $(curdir)/findutils/compile
44 $(curdir)/autoconf/compile := $(curdir)/m4/compile
45 $(curdir)/automake/compile := $(curdir)/m4/compile $(curdir)/autoconf/compile $(curdir)/pkg-config/compile $(curdir)/xz/compile
46 $(curdir)/gmp/compile := $(curdir)/libtool/compile
47 $(curdir)/mpc/compile := $(curdir)/mpfr/compile $(curdir)/gmp/compile
48 $(curdir)/mpfr/compile := $(curdir)/gmp/compile
49 $(curdir)/mtd-utils/compile := $(curdir)/libtool/compile $(curdir)/e2fsprogs/compile $(curdir)/zlib/compile
50 $(curdir)/mklibs/compile := $(curdir)/libtool/compile
51 $(curdir)/qemu/compile := $(curdir)/e2fsprogs/compile $(curdir)/zlib/compile
52 $(curdir)/upslug2/compile := $(curdir)/libtool/compile
53 $(curdir)/mm-macros/compile := $(curdir)/libtool/compile
54 $(curdir)/missing-macros/compile := $(curdir)/autoconf/compile
55 $(curdir)/e2fsprogs/compile := $(curdir)/libtool/compile
56 $(curdir)/libelf/compile := $(curdir)/libtool/compile
57 $(curdir)/sdcc/compile := $(curdir)/bison/compile
58 $(curdir)/padjffs2/compile := $(curdir)/findutils/compile
59 $(curdir)/isl/compile := $(curdir)/gmp/compile
60 $(curdir)/bc/compile := $(curdir)/bison/compile
61 $(curdir)/findutils/compile := $(curdir)/bison/compile
62 $(curdir)/gengetopt/compile := $(curdir)/libtool/compile
63 $(curdir)/patchelf/compile := $(curdir)/libtool/compile
64 $(curdir)/dosfstools/compile := $(curdir)/autoconf/compile $(curdir)/automake/compile
65 $(curdir)/libressl/compile := $(curdir)/pkg-config/compile
66 $(curdir)/mkimage/compile += $(curdir)/libressl/compile
67 $(curdir)/firmware-utils/compile += $(curdir)/libressl/compile $(curdir)/zlib/compile
68 $(curdir)/cmake/compile += $(curdir)/libressl/compile
69 $(curdir)/zlib/compile := $(curdir)/cmake/compile
70 $(curdir)/wrt350nv2-builder/compile := $(curdir)/zlib/compile
71 $(curdir)/lzma-old/compile := $(curdir)/zlib/compile
72 $(curdir)/make-ext4fs/compile := $(curdir)/zlib/compile
73
74 ifneq ($(HOST_OS),Linux)
75   tools-y += coreutils
76 endif
77
78 ifneq ($(CONFIG_CCACHE)$(CONFIG_SDK),)
79 $(foreach tool, $(filter-out xz patch,$(tools-y)), $(eval $(curdir)/$(tool)/compile += $(curdir)/ccache/compile))
80 tools-y += ccache
81 endif
82
83 # in case there is no patch tool on the host we need to make patch tool a
84 # dependency for tools which have patches directory
85 $(foreach tool, $(tools-y), $(if $(wildcard $(curdir)/$(tool)/patches),$(eval $(curdir)/$(tool)/compile += $(curdir)/patch/compile)))
86
87 $(foreach tool, $(filter-out xz,$(tools-y)), $(eval $(curdir)/$(tool)/compile += $(curdir)/xz/compile))
88
89 # make any tool depend on tar, xz and patch to ensure that archives can be unpacked and patched properly
90 tools-core := tar xz patch
91
92 $(foreach tool, $(tools-y), $(eval $(curdir)/$(tool)/compile += $(patsubst %,$(curdir)/%/compile,$(tools-core))))
93 tools-y += $(tools-core)
94
95 # make core tools depend on sed and flock
96 $(foreach tool, $(tools-core), $(eval $(curdir)/$(tool)/compile += $(curdir)/sed/compile))
97
98 $(curdir)/sed/compile := $(curdir)/flock/compile
99 tools-y += flock sed
100
101 $(curdir)/autoremove := 1
102 $(curdir)/builddirs := $(tools-y) $(tools-dep) $(tools-)
103 $(curdir)/builddirs-default := $(tools-y)
104
105 ifdef CHECK_ALL
106 $(curdir)/builddirs-check:=$($(curdir)/builddirs)
107 $(curdir)/builddirs-download:=$($(curdir)/builddirs)
108 endif
109
110 ifndef DUMP_TARGET_DB
111 define PrepareStaging
112         @for dir in $(1); do ( \
113                 $(if $(QUIET),,set -x;) \
114                 mkdir -p "$$dir"; \
115                 cd "$$dir"; \
116                 mkdir -p bin lib include stamp; \
117         ); done
118 endef
119
120 # preparatory work
121 $(STAGING_DIR)/.prepared: $(TMP_DIR)/.build
122         $(call PrepareStaging,$(STAGING_DIR))
123         mkdir -p $(BUILD_DIR)/stamp
124         touch $@
125
126 $(STAGING_DIR_HOST)/.prepared: $(TMP_DIR)/.build
127         $(call PrepareStaging,$(STAGING_DIR_HOST))
128         mkdir -p $(BUILD_DIR_HOST)/stamp $(STAGING_DIR_HOST)/include/sys
129         $(INSTALL_DATA) $(TOPDIR)/tools/include/*.h $(STAGING_DIR_HOST)/include/
130         $(INSTALL_DATA) $(TOPDIR)/tools/include/sys/*.h $(STAGING_DIR_HOST)/include/sys/
131         ln -sf lib $(STAGING_DIR_HOST)/lib64
132         touch $@
133
134 endif
135
136 $(curdir)//prepare = $(STAGING_DIR)/.prepared $(STAGING_DIR_HOST)/.prepared
137 $(curdir)//compile = $(STAGING_DIR)/.prepared $(STAGING_DIR_HOST)/.prepared
138
139 # prerequisites for the individual targets
140 $(curdir)/ := .config prereq
141
142 $(curdir)/install: $(curdir)/compile
143
144 tools_enabled = $(foreach tool,$(sort $(tools-y) $(tools-)),$(if $(filter $(tool),$(tools-y)),y,n))
145 $(eval $(call stampfile,$(curdir),tools,compile,,_$(subst $(space),,$(tools_enabled))))
146 $(eval $(call stampfile,$(curdir),tools,check,$(TMP_DIR)/.build))
147 $(eval $(call subdir,$(curdir)))