#
# Copyright (C) 2006-2007 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
ifneq ($(__prereq_inc),1)
__prereq_inc:=1
prereq:
if [ -f $(TMP_DIR)/.prereq-error ]; then \
echo; \
cat $(TMP_DIR)/.prereq-error; \
rm -f $(TMP_DIR)/.prereq-error; \
echo; \
false; \
fi
.SILENT: prereq
endif
define Require
export PREREQ_CHECK=1
ifeq ($$(CHECK_$(1)),)
prereq: prereq-$(1)
prereq-$(1): FORCE
echo -n "Checking '$(1)'... "
if $(NO_TRACE_MAKE) -f $(firstword $(MAKEFILE_LIST)) check-$(1) >/dev/null 2>/dev/null; then \
echo 'ok.'; \
else \
echo 'failed.'; \
echo -e "$(PKG_NAME): $(strip $(2))" | perl -ne 's/\\\s*/\n/g,print' >> $(TMP_DIR)/.prereq-error; \
fi
check-$(1): FORCE
$(call Require/$(1))
CHECK_$(1):=1
.SILENT: prereq-$(1) check-$(1)
.NOTPARALLEL:
endif
endef
define RequireCommand
define Require/$(1)
which $(1)
endef
$$(eval $$(call Require,$(1),$(2)))
endef
define RequireHeader
define Require/$(1)
[ -e "$(1)" ]
endef
$$(eval $$(call Require,$(1),$(2)))
endef
calmer
blob: 3307b6b0904501a83a5f8bc8824d91c9304c6fd1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#!/usr/bin/env bash
DIR="$1"
if [ -d "$DIR" ]; then
DIR="$(cd "$DIR"; pwd)"
else
echo "Usage: $0 toolchain-dir"
exit 1
fi
echo -n "Locating cpp ... "
for bin in bin usr/bin usr/local/bin; do
for cmd in "$DIR/$bin/"*-cpp; do
if [ -x "$cmd" ]; then
echo "$cmd"
CPP="$cmd"
break
fi
done
done
if [ ! -x "$CPP" ]; then
echo "Can't locate a cpp executable in '$DIR' !"
exit 1
fi
patch_specs() {
local found=0
for lib in $(STAGING_DIR="$DIR" "$CPP" -x c -v /dev/null 2>&1 | sed -ne 's#:# #g; s#^LIBRARY_PATH=##p'); do
if [ -d "$lib" ]; then
grep -qs "STAGING_DIR" "$lib/specs" && rm -f "$lib/specs"
if [ $found -lt 1 ]; then
echo -n "Patching specs ... "
STAGING_DIR="$DIR" "$CPP" -dumpspecs | awk '
mode ~ "link" {
sub("%{L.}", "%{L*} -L %:getenv(STAGING_DIR /usr/lib) -rpath-link %:getenv(STAGING_DIR /usr/lib)")
}
mode ~ "cpp" {
$0 = $0 " -idirafter %:getenv(STAGING_DIR /usr/include)"
}
{
print $0
mode = ""
}
/^\*cpp:/ {
mode = "cpp"
}
/^\*link.*:/ {
mode = "link"
}
' > "$lib/specs"
echo "ok"
found=1
fi
fi
done
[ $found -gt 0 ]
return $?
}
VERSION="$(STAGING_DIR="$DIR" "$CPP" --version | sed -ne 's/^.* (.*) //; s/ .*$//; 1p')"
VERSION="${VERSION:-unknown}"
case "${VERSION##* }" in
2.*|3.*|4.0.*|4.1.*|4.2.*)
echo "The compiler version does not support getenv() in spec files."
echo -n "Wrapping binaries instead ... "
if "${0%/*}/ext-toolchain.sh" --toolchain "$DIR" --wrap "${CPP%/*}"; then
echo "ok"
exit 0
else
echo "failed"
exit $?
fi
;;
*)
if patch_specs; then
echo "Toolchain successfully patched."
exit 0
else
echo "Failed to locate library directory!"
exit 1
fi
;;
esac
|