Rebased from upstream / out of band repository.
[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_x86) += qemu
28 tools-$(CONFIG_TARGET_mxs) += elftosb sdimage
29 tools-$(CONFIG_TARGET_ar71xx) += lzma-old
30 tools-$(CONFIG_TARGET_ar71xx)$(CONFIG_TARGET_ath79) += squashfs
31 tools-$(CONFIG_USES_MINOR) += kernel2minor
32 tools-y += lzma squashfs4 zip
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)/mm-macros/compile := $(curdir)/libtool/compile
53 $(curdir)/missing-macros/compile := $(curdir)/autoconf/compile
54 $(curdir)/e2fsprogs/compile := $(curdir)/libtool/compile
55 $(curdir)/libelf/compile := $(curdir)/libtool/compile
56 $(curdir)/sdcc/compile := $(curdir)/bison/compile
57 $(curdir)/padjffs2/compile := $(curdir)/findutils/compile
58 $(curdir)/isl/compile := $(curdir)/gmp/compile
59 $(curdir)/bc/compile := $(curdir)/bison/compile
60 $(curdir)/findutils/compile := $(curdir)/bison/compile
61 $(curdir)/gengetopt/compile := $(curdir)/libtool/compile
62 $(curdir)/patchelf/compile := $(curdir)/libtool/compile
63 $(curdir)/dosfstools/compile := $(curdir)/autoconf/compile $(curdir)/automake/compile
64 $(curdir)/libressl/compile := $(curdir)/pkg-config/compile
65 $(curdir)/mkimage/compile += $(curdir)/libressl/compile
66 $(curdir)/firmware-utils/compile += $(curdir)/libressl/compile $(curdir)/zlib/compile
67 $(curdir)/cmake/compile += $(curdir)/libressl/compile
68 $(curdir)/zlib/compile := $(curdir)/cmake/compile
69 $(curdir)/lzma-old/compile := $(curdir)/zlib/compile
70 $(curdir)/make-ext4fs/compile := $(curdir)/zlib/compile
71
72 ifneq ($(HOST_OS),Linux)
73   tools-y += coreutils
74 endif
75
76 ifneq ($(CONFIG_CCACHE)$(CONFIG_SDK),)
77 $(foreach tool, $(filter-out xz patch,$(tools-y)), $(eval $(curdir)/$(tool)/compile += $(curdir)/ccache/compile))
78 tools-y += ccache
79 endif
80
81 # in case there is no patch tool on the host we need to make patch tool a
82 # dependency for tools which have patches directory
83 $(foreach tool, $(tools-y), $(if $(wildcard $(curdir)/$(tool)/patches),$(eval $(curdir)/$(tool)/compile += $(curdir)/patch/compile)))
84
85 $(foreach tool, $(filter-out xz,$(tools-y)), $(eval $(curdir)/$(tool)/compile += $(curdir)/xz/compile))
86
87 # make any tool depend on tar, xz and patch to ensure that archives can be unpacked and patched properly
88 tools-core := tar xz patch
89
90 $(foreach tool, $(tools-y), $(eval $(curdir)/$(tool)/compile += $(patsubst %,$(curdir)/%/compile,$(tools-core))))
91 tools-y += $(tools-core)
92
93 # make core tools depend on sed and flock
94 $(foreach tool, $(tools-core), $(eval $(curdir)/$(tool)/compile += $(curdir)/sed/compile))
95
96 $(curdir)/sed/compile := $(curdir)/flock/compile
97 tools-y += flock sed
98
99 $(curdir)/autoremove := 1
100 $(curdir)/builddirs := $(tools-y) $(tools-dep) $(tools-)
101 $(curdir)/builddirs-default := $(tools-y)
102
103 ifdef CHECK_ALL
104 $(curdir)/builddirs-check:=$($(curdir)/builddirs)
105 $(curdir)/builddirs-download:=$($(curdir)/builddirs)
106 endif
107
108 ifndef DUMP_TARGET_DB
109 define PrepareStaging
110         @for dir in $(1); do ( \
111                 $(if $(QUIET),,set -x;) \
112                 mkdir -p "$$dir"; \
113                 cd "$$dir"; \
114                 mkdir -p bin lib include stamp; \
115         ); done
116 endef
117
118 # preparatory work
119 $(STAGING_DIR)/.prepared: $(TMP_DIR)/.build
120         $(call PrepareStaging,$(STAGING_DIR))
121         mkdir -p $(BUILD_DIR)/stamp
122         touch $@
123
124 $(STAGING_DIR_HOST)/.prepared: $(TMP_DIR)/.build
125         $(call PrepareStaging,$(STAGING_DIR_HOST))
126         mkdir -p $(BUILD_DIR_HOST)/stamp $(STAGING_DIR_HOST)/include/sys
127         $(INSTALL_DATA) $(TOPDIR)/tools/include/*.h $(STAGING_DIR_HOST)/include/
128         $(INSTALL_DATA) $(TOPDIR)/tools/include/sys/*.h $(STAGING_DIR_HOST)/include/sys/
129         ln -sf lib $(STAGING_DIR_HOST)/lib64
130         touch $@
131
132 endif
133
134 $(curdir)//prepare = $(STAGING_DIR)/.prepared $(STAGING_DIR_HOST)/.prepared
135 $(curdir)//compile = $(STAGING_DIR)/.prepared $(STAGING_DIR_HOST)/.prepared
136
137 # prerequisites for the individual targets
138 $(curdir)/ := .config prereq
139
140 $(curdir)/install: $(curdir)/compile
141
142 tools_enabled = $(foreach tool,$(sort $(tools-y) $(tools-)),$(if $(filter $(tool),$(tools-y)),y,n))
143 $(eval $(call stampfile,$(curdir),tools,compile,,_$(subst $(space),,$(tools_enabled))))
144 $(eval $(call stampfile,$(curdir),tools,check,$(TMP_DIR)/.build))
145 $(eval $(call subdir,$(curdir)))