1export NIX_DEBUG=1
2
3source $stdenv/setup
4
5mkdir $out
6mkdir $out/bin
7
8
9# 1: link statically against glibc.
10res=$out/bin/hello1
11gcc -static $src/hello1.c -o $res
12
13case $(ldd $res) in
14 *"not a dynamic executable"*)
15 ;;
16 *)
17 echo "$res not statically linked!"
18 exit 1
19esac
20
21
22# 2: link dynamically against glibc.
23res=$out/bin/hello2
24gcc $src/hello1.c -o $res
25
26case $(ldd $res) in
27 */store/*glibc*/lib/libc.so*/store/*glibc*/lib/ld-linux.so*)
28 ;;
29 *)
30 echo "$res not dynamically linked / bad rpath!"
31 exit 1
32 ;;
33esac
34
35
36# 3: link C++ dynamically against glibc / libstdc++.
37res=$out/bin/hello3
38g++ $src/hello2.cc -o $res
39
40case $(ldd $res) in
41 */store/*gcc*/lib/*libstdc++*/store/*glibc*/lib/libm*/store/*gcc*/lib/libgcc_s*/store/*glibc*/lib/libc.so*/store/*glibc*/lib/ld-linux.so*)
42 ;;
43 *)
44 echo "$res not dynamically linked / bad rpath!"
45 exit 1
46 ;;
47esac
48
49
50# 4: build dynamic library locally, link against it, copy it.
51res=$out/bin/hello4
52mkdir bla
53gcc -shared $src/text.c -o bla/libtext.so
54gcc $src/hello3.c -o $res -L$(pwd)/bla -ltext
55mkdir $out/lib
56
57case $(ldd $res) in
58 */tmp*)
59 echo "$res depends on file in /tmp!"
60 exit 1
61 ;;
62esac
63
64cp bla/libtext.so $out/lib
65
66case $(ldd $res) in
67 */store/*glibc*/lib/libc.so*/store/*glibc*/lib/ld-linux.so*)
68 ;;
69 *)
70 echo "$res not dynamically linked / bad rpath!"
71 exit 1
72 ;;
73esac
74
75
76# Run the programs we just made.
77for i in $out/bin/*; do
78 $i
79done