blob: 2bf6246214683ce235e6fff4f67ef257259bb195 (
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
|
export NIX_DEBUG=1
source $stdenv/setup
mkdir $out
mkdir $out/bin
# 1: link statically against glibc.
res=$out/bin/hello1
gcc -static $src/hello1.c -o $res
case $(ldd $res) in
*"not a dynamic executable"*)
;;
*)
echo "$res not statically linked!"
exit 1
esac
# 2: link dynamically against glibc.
res=$out/bin/hello2
gcc $src/hello1.c -o $res
case $(ldd $res) in
*/store/*glibc*/lib/libc.so*/store/*glibc*/lib/ld-linux.so*)
;;
*)
echo "$res not dynamically linked / bad rpath!"
exit 1
;;
esac
# 3: link C++ dynamically against glibc / libstdc++.
res=$out/bin/hello3
g++ $src/hello2.cc -o $res
case $(ldd $res) in
*/store/*gcc*/lib/*libstdc++*/store/*glibc*/lib/libm*/store/*gcc*/lib/libgcc_s*/store/*glibc*/lib/libc.so*/store/*glibc*/lib/ld-linux.so*)
;;
*)
echo "$res not dynamically linked / bad rpath!"
exit 1
;;
esac
# 4: build dynamic library locally, link against it, copy it.
res=$out/bin/hello4
mkdir bla
gcc -shared $src/text.c -o bla/libtext.so
gcc $src/hello3.c -o $res -L$(pwd)/bla -ltext
mkdir $out/lib
case $(ldd $res) in
*/tmp*)
echo "$res depends on file in /tmp!"
exit 1
;;
esac
cp bla/libtext.so $out/lib
case $(ldd $res) in
*/store/*glibc*/lib/libc.so*/store/*glibc*/lib/ld-linux.so*)
;;
*)
echo "$res not dynamically linked / bad rpath!"
exit 1
;;
esac
# Run the programs we just made.
for i in $out/bin/*; do
$i
done
|