backport r18788 to 8.09
[openwrt/svn-archive/archive.git] / tools / Makefile
1 #
2 # Copyright (C) 2007 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 $(curdir)/builddirs := sed sstrip ipkg-utils genext2fs squashfs mtd-utils lzma mkimage firmware-utils patch-cmdline pkg-config automake $(if $(CONFIG_CCACHE),ccache) bison $(if $(CONFIG_powerpc),dtc) lua quilt autoconf
13
14 # builddir dependencies
15 $(curdir)/automake/compile := $(curdir)/autoconf/install
16 $(curdir)/squashfs/compile := $(curdir)/lzma/install
17 $(curdir)/quilt/compile := $(curdir)/sed/install
18
19 # preparatory work
20 $(STAGING_DIR)/.prepared: $(TMP_DIR)/.build
21 @for dir in $(STAGING_DIR) $(STAGING_DIR_HOST); do ( \
22 set -x; \
23 mkdir -p "$$dir"; \
24 cd "$$dir"; \
25 mkdir -p bin lib include stamp; \
26 ); done
27 mkdir -p $(BUILD_DIR_HOST)/stamp $(BUILD_DIR)/stamp
28 $(INSTALL_DATA) $(TOPDIR)/tools/include/*.h $(STAGING_DIR_HOST)/include/
29 touch $@
30
31 define PrepareCommand
32 $(STAGING_DIR_HOST)/bin/$(1): $(STAGING_DIR)/.prepared
33 @mkdir -p "$$(dir $$@)"; rm -f "$$@"
34 @export FILE="$$$$(which $(2) 2>/dev/null | grep -v 'not found' | head -n1)"; [ -n "$$$$FILE" ] || { \
35 echo "Command $(1) not found."; false; \
36 }; ln -s "$$$$FILE" "$$@"
37
38 endef
39
40 $(eval $(call PrepareCommand,find,gfind find))
41 $(eval $(call PrepareCommand,md5sum,md5sum $(SCRIPT_DIR)/md5sum))
42 $(eval $(call PrepareCommand,cp,gcp cp))
43 $(eval $(call PrepareCommand,stat,gstat stat))
44
45 $(curdir)/cmddeps = $(patsubst %,$(STAGING_DIR_HOST)/bin/%,find md5sum cp stat)
46 $(curdir)//prepare = $(STAGING_DIR)/.prepared $($(curdir)/cmddeps)
47 $(curdir)//compile = $(STAGING_DIR)/.prepared $($(curdir)/cmddeps)
48
49 # prerequisites for the individual targets
50 $(curdir)/ := .config prereq
51 $(curdir)//install = $(1)/compile
52
53 $(eval $(call stampfile,$(curdir),tools,install))
54 $(eval $(call subdir,$(curdir)))