summaryrefslogtreecommitdiff
blob: 00b3a36cade3247b1d6314c708b06f689ae06908 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!@GENTOO_PORTAGE_BPREFIX@/bin/bash

if [ -r /cygdrive/. ]; then
	winpath2unix() { cygpath -u "$1"; }
	unixpath2win() { cygpath -w "$1"; }
fi

myself=${0##*/} # basename $0
link_dirs=()
linkopts=()
opts=()
chost="@GENTOO_PORTAGE_CHOST@"
prefix="@GENTOO_PORTAGE_EPREFIX@"
absprefix=${prefix}
if [[ ${chost} == *"-winnt"* ]]; then
	# we may get called from windows binary, like pkgdata in dev-libs/icu
	# in this case, PATH elements get the "/dev/fs/C/WINDOWS/SUA" prefix
	absprefix=$(winpath2unix "$(unixpath2win "${absprefix}")")
fi
[[ ${myself} == *windres* ]] && mode=compile || mode=link
orig_args=("$@")

for opt in "$@"
do
	if [[ ${chost} == *"-winnt"* ]]; then
		# We depend on dev-libs/pthreads4w, no?
		case ${opt} in
		-pthread | -lpthread)
			case " ${linkopts[*]} " in
			*" -lpthread "*) ;;
			*) linkopts=( "${linkopts[@]}" "-lpthread" ) ;;
			esac
			continue
			;;
		esac
	fi
	case "$opt" in
	-L)
		link_dirs=("${link_dirs[@]}" "-L$1")
		shift
		;;
	-L*)
		link_dirs=("${link_dirs[@]}" "${opt}")
		;;
	*)
		case "${opt}" in
		-v)
			# -v done right: only use mode version if -v is the _only_
			# argument on the command line.
			[[ ${#orig_args[@]} -gt 1 ]] || mode=version
			;;
		--version)	mode=version ;;
		-c|-E|-S)	mode=compile ;;
		-print-search-dirs) mode=dirs ;;
		esac
		opts=("${opts[@]}" "${opt}")
		;;
	esac
done

# remove any path to current prefix, need base prefix only
new_path=
save_ifs=$IFS
IFS=':'
for p in $PATH
do
	IFS=$save_ifs
	[[ ${p#${absprefix}} != "${p}" ]] && continue
	if [[ -z "${new_path}" ]]; then
		new_path="${p}"
	else
		new_path="${new_path}:${p}"
	fi
done
IFS=$save_ifs

PATH=${new_path}

pfx_comp=("-I${prefix}/include" "-I${prefix}/usr/include")
pfx_link=("-L${prefix}/usr/lib" "-L${prefix}/lib")
# binutils-config's ldwrapper understands '-R' for aix and hpux too.
pfx_link_r=("-Wl,-R,${prefix}/lib" "-Wl,-R,${prefix}/usr/lib")
case "${chost}" in
*-winnt*)
	# parity (winnt) understands -rpath only ...
	pfx_link_r=("-Wl,-rpath,${prefix}/lib" "-Wl,-rpath,${prefix}/usr/lib")
	;;
*-linux*)
	# With gcc, -isystem would avoid warning messages in installed headers,
	# but that breaks with AIX host headers.
	pfx_comp=("-isystem" "${prefix}/include" "-isystem" "${prefix}/usr/include")
	;;
esac

# ensure we run the right chost program in base prefix
[[ ${myself} == *-*-*-* ]] || myself=${chost}-${myself#${chost}-}

case "$mode" in
link)    exec "${myself}" "${link_dirs[@]}" "${pfx_link[@]}" "${opts[@]}" "${pfx_comp[@]}" "${pfx_link_r[@]}" "${linkopts[@]}" ;;
compile) exec "${myself}" "${link_dirs[@]}" "${opts[@]}" "${pfx_comp[@]}" ;;
version) exec "${myself}" "${orig_args[@]}" ;;
dirs)
	"${myself}" "${orig_args[@]}" | while read line; do
		if [[ "${line}" == "libraries: ="* ]]; then
			echo "libraries: =${prefix}/usr/lib:${prefix}/lib:${line#"libraries: ="}"
		else
			echo "${line}"
		fi
	done
	;;
*)			echo "cannot infer ${myself}'s mode from comamnd line arguments"; exit 1 ;;
esac