summary refs log tree commit diff
path: root/pkgs/build-support/cc-wrapper/ld-solaris-wrapper.sh
blob: 263ea5408e9a316c43c5287ea229c58d130f9b27 (plain) (blame)
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
#!@shell@

set -e
set -u

# I've also tried adding -z direct and -z lazyload, but it gave too many problems with C++ exceptions :'(
# Also made sure libgcc would not be lazy-loaded, as suggested here: https://www.illumos.org/issues/2534#note-3
#   but still no success.
cmd="@ld@ -z ignore"

args=("$@");

# This loop makes sure all -L arguments are before -l arguments, or ld may complain it cannot find a library.
# GNU binutils does not have this problem:
#   http://stackoverflow.com/questions/5817269/does-the-order-of-l-and-l-options-in-the-gnu-linker-matter
i=0;
while [[ $i -lt $# ]]; do
    case "${args[$i]}" in
        -L)  cmd="$cmd ${args[$i]} ${args[($i+1)]}"; i=($i+1); ;;
        -L*) cmd="$cmd ${args[$i]}" ;;
        *)   ;;
    esac
    i=($i+1);
done

i=0;
while [[ $i -lt $# ]]; do
    case "${args[$i]}" in
        -L)  i=($i+1); ;;
        -L*) ;;
        *)   cmd="$cmd ${args[$i]}" ;;
    esac
    i=($i+1);
done

# Trace:
set -x
exec $cmd

exit 0