1#
2# Copyright (c) 2013 The Linux Foundation. All rights reserved.
3# Copyright (C) 2006-2011 OpenWrt.org
4#
5# This is free software, licensed under the GNU General Public License v2.
6# See /LICENSE for more information.
7#
8# Main makefile for the host tools
9#
10curdir:=tools
11
12# subdirectories to descend into
13tools-y :=
14ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN)$(CONFIG_GCC_LLVM),)
15tools-y += gmp mpfr mpc libelf
16endif
17tools-y += m4 libtool autoconf automake flex bison pkg-config sed mklibs gperf
18tools-y += sstrip ipkg-utils genext2fs e2fsprogs mtd-utils mkimage
19tools-y += firmware-utils patch-cmdline quilt yaffs2 flock padjffs2
20tools-y += mm-macros xorg-macros xfce-macros missing-macros xz cmake scons
21tools-$(CONFIG_TARGET_orion_generic) += wrt350nv2-builder upslug2
22tools-$(CONFIG_powerpc) += upx
23tools-$(CONFIG_TARGET_x86) += qemu
24tools-$(CONFIG_TARGET_brcm2708) += mtools dosfstools
25ifneq ($(CONFIG_TARGET_ar71xx),)
26tools-y += lzma-old squashfs
27endif
28tools-y += lzma squashfs4
29tools-y += makefun
30tools-$(CONFIG_KERNEL_SPARSE) += sparse
31
32ifneq ($(CONFIG_PACKAGE_firmwarehotplug),)
33tools-y += sdcc
34endif
35
36ifdef CONFIG_GCC_USE_GRAPHITE
37  ifeq ($(CONFIG_GCC_USE_SYSTEM_PPL_CLOOG),)
38	tools-y += ppl cloog
39	$(curdir)/cloog/compile := $(curdir)/ppl/install
40  endif
41endif
42
43# builddir dependencies
44$(curdir)/bison/compile := $(curdir)/flex/install
45$(curdir)/flex/compile := $(curdir)/m4/install
46$(curdir)/pkg-config/compile := $(curdir)/sed/install
47$(curdir)/libtool/compile := $(curdir)/sed/install
48$(curdir)/squashfs/compile := $(curdir)/lzma-old/install
49$(curdir)/squashfs4/compile := $(curdir)/xz/install
50$(curdir)/quilt/compile := $(curdir)/sed/install $(curdir)/autoconf/install
51$(curdir)/dtc/compile := $(curdir)/bison/install
52$(curdir)/autoconf/compile := $(curdir)/m4/install $(curdir)/libtool/install
53$(curdir)/automake/compile := $(curdir)/m4/install $(curdir)/autoconf/install $(curdir)/pkg-config/install $(curdir)/xz/install
54$(curdir)/gmp/compile := $(curdir)/automake/install
55$(curdir)/mpc/compile := $(curdir)/mpfr/install $(curdir)/gmp/install
56$(curdir)/mpfr/compile := $(curdir)/gmp/install
57$(curdir)/ppl/compile := $(curdir)/gmp/install
58$(curdir)/cloog/compile := $(curdir)/ppl/install
59$(curdir)/mtd-utils/compile := $(curdir)/e2fsprogs/install $(curdir)/xz/install
60$(curdir)/mkimage/compile := $(curdir)/sed/install
61$(curdir)/qemu/compile := $(curdir)/e2fsprogs/install
62$(curdir)/upslug2/compile := $(curdir)/automake/install
63$(curdir)/mm-macros/compile := $(curdir)/automake/install
64$(curdir)/xorg-macros/compile := $(curdir)/automake/install
65$(curdir)/xfce-macros/compile := $(curdir)/automake/install
66$(curdir)/missing-macros/compile := $(curdir)/automake/install
67$(curdir)/e2fsprogs/compile := $(curdir)/automake/install
68$(curdir)/libelf/compile := $(curdir)/automake/install
69$(curdir)/sdcc/compile := $(curdir)/bison/install
70
71ifneq ($(CONFIG_CCACHE),)
72$(foreach tool, $(tools-y), $(eval $(curdir)/$(tool)/compile += $(curdir)/ccache/install))
73tools-y += ccache
74endif
75
76$(curdir)/builddirs := $(tools-y) $(tools-dep) $(tools-)
77$(curdir)/builddirs-default := $(tools-y)
78
79ifndef DUMP_TARGET_DB
80define PrepareStaging
81	@for dir in $(1); do ( \
82		$(if $(QUIET),,set -x;) \
83		mkdir -p "$$dir"; \
84		cd "$$dir"; \
85		mkdir -p bin lib include stamp; \
86	); done
87endef
88
89# preparatory work
90$(STAGING_DIR)/.prepared: $(TMP_DIR)/.build
91	$(call PrepareStaging,$(STAGING_DIR))
92	mkdir -p $(BUILD_DIR)/stamp
93	touch $@
94
95$(STAGING_DIR_HOST)/.prepared: $(TMP_DIR)/.build
96	$(call PrepareStaging,$(STAGING_DIR_HOST))
97	mkdir -p $(BUILD_DIR_HOST)/stamp $(STAGING_DIR_HOST)/include/sys
98	$(INSTALL_DATA) $(TOPDIR)/tools/include/*.h $(STAGING_DIR_HOST)/include/
99	$(INSTALL_DATA) $(TOPDIR)/tools/include/sys/*.h $(STAGING_DIR_HOST)/include/sys/
100	ln -sf lib $(STAGING_DIR_HOST)/lib64
101	touch $@
102
103
104define PrepareCommand
105$(STAGING_DIR_HOST)/bin/$(1): $(STAGING_DIR)/.prepared
106	@mkdir -p "$$(dir $$@)"; rm -f "$$@"
107	@export FILE="$$$$(which $(2) 2>/dev/null | grep -v 'not found' | head -n1)"; [ -n "$$$$FILE" ] || { \
108		echo "Command $(1) not found."; false; \
109	}; ln -s "$$$$FILE" "$$@"
110
111endef
112endif
113
114$(STAGING_DIR_HOST)/bin/stat: $(STAGING_DIR)/.prepared
115	@rm -f $@
116	@if stat --version > /dev/null 2>&1; then \
117		ln -s `which stat` $@; \
118	elif gstat --version > /dev/null 2>&1; then \
119		ln -s `which gstat` $@; \
120	else \
121		echo "GNU stat not found"; \
122		false; \
123	fi
124
125$(eval $(call PrepareCommand,find,gfind find))
126$(eval $(call PrepareCommand,md5sum,gmd5sum md5sum $(SCRIPT_DIR)/md5sum))
127$(eval $(call PrepareCommand,cp,gcp cp))
128$(eval $(call PrepareCommand,seq,gseq seq))
129$(eval $(call PrepareCommand,python,python2 python))
130
131$(curdir)/cmddeps = $(patsubst %,$(STAGING_DIR_HOST)/bin/%,find md5sum cp stat seq python)
132$(curdir)//prepare = $(STAGING_DIR)/.prepared $(STAGING_DIR_HOST)/.prepared $($(curdir)/cmddeps)
133$(curdir)//compile = $(STAGING_DIR)/.prepared $(STAGING_DIR_HOST)/.prepared $($(curdir)/cmddeps)
134
135# prerequisites for the individual targets
136$(curdir)/ := .config prereq
137$(curdir)//install = $(1)/compile
138
139$(eval $(call stampfile,$(curdir),tools,install,,CONFIG_CCACHE CONFIG_powerpc CONFIG_GCC_VERSION_4_5 CONFIG_GCC_USE_GRAPHITE CONFIG_TARGET_orion_generic))
140$(eval $(call subdir,$(curdir)))
141