summaryrefslogtreecommitdiffstats
path: root/main/abuild/abuild-git-20120908.patch
blob: 847f767495ddf8c50b144e592e1a6c43fec98cf1 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
diff --git a/abuild.in b/abuild.in
index 2780d2e..60cb91c 100755
--- a/abuild.in
+++ b/abuild.in
@@ -404,6 +404,9 @@ default_unpack() {
 	for u in $source; do
 		local s="$SRCDEST/${u##*/}"	# $(basename $s)
 		case "$s" in
+			*.tar)
+				msg "Unpacking $s..."
+				tar -C "$srcdir" -xf "$s" || return 1;;
 			*.tar.gz|*.tgz)
 				msg "Unpacking $s..."
 				tar -C "$srcdir" -zxf "$s" || return 1;;
@@ -772,23 +775,20 @@ EOF
 
 prepare_tracedeps() {
 	local dir=${subpkgdir:-$pkgdir}
+	local etype= soname= file= sover=
 	[ "$arch" = "noarch" ] && return 0
 	options_has "!tracedeps" && return 0
-	# lets tell all the .so files this package provides in .provides-so
-	find -name '*.so' -o -name '*.so.[0-9]*' | sed 's:.*/::' \
-		>"$controldir"/.provides-so
 	# lets tell all the places we should look for .so files - all rpaths
-	scanelf -q -Rr "$dir" | sed -e 's/[[:space:]].*//' -e 's/:/\n/' \
-		| sort | uniq \
+	scanelf --quiet --recursive --rpath "$dir" \
+		| sed -e 's/[[:space:]].*//' -e 's/:/\n/' | sort -u \
 		>"$controldir"/.rpaths
-	# now find the so dependencies
-	scanelf -Rn "$dir" | tr ' ' ':' | awk -F ":" '$1 == "ET_DYN" || $1 == "ET_EXEC" {print $2}'  \
-		| sed 's:,:\n:g' | sort | uniq \
-	| while read i; do
-		# only add files that are not self provided
-		grep "^$i$" "$controldir"/.provides-so >/dev/null \
-			|| echo $i >> "$controldir"/.needs-so
-	done
+	if grep -q -x '/usr/lib' "$controldir"/.rpaths; then
+		warning "Redundat /usr/lib in rpath found"
+	fi
+	if grep '^/home/' "$controldir"/.rpaths; then
+		error "Has /home/... in rpath"
+		return 1
+	fi
 }
 
 # check if dir has arch specific binaries
@@ -862,7 +862,7 @@ trace_apk_deps() {
 	local name="$1"
 	local dir="$2"
 	local i= j= found= autodeps= deppkgs= missing= so_paths= self_provided=
-	msg "Tracing dependencies for $name..."
+	msg "Tracing dependencies..."
 	# add pkgconfig if usr/lib/pkgconfig is found
 	if [ -d "$pkgbasedir"/$name/usr/lib/pkgconfig ] \
 			&& ! grep -q '^depend = pkgconfig' "$dir"/.PKGINFO; then
@@ -880,7 +880,7 @@ trace_apk_deps() {
 		found=
 		# first check if its provide by same apkbuild
 		for j in "$dir"/../.control.*/.provides-so; do
-			grep -w "$i" "$j" >/dev/null || continue
+			grep -q -w "^$i" "$j" || continue
 			found=${j%/.provides-so}
 			found=${found##*/.control.}
 			break
@@ -911,26 +911,106 @@ trace_apk_deps() {
 		fi
 	done
 
-	[ -z "$autodeps" ] && return 0
 	echo "# automatically detected:" >> "$dir"/.PKGINFO
+	if [ -f "$dir"/.provides-so ]; then
+		sed 's/^\(.*\) \([0-9].*\)/provides = so:\1=\2/' "$dir"/.provides-so \
+			>> "$dir"/.PKGINFO
+	fi
+	[ -z "$autodeps" ] && return 0
 	for i in $autodeps; do
 		echo "depend = $i" >> "$dir"/.PKGINFO
 	done
 }
 
+find_scanelf_paths() {
+	local controldir="$1" datadir="$2"
+	local paths="$datadir/lib:$datadir/usr/lib" i= rpath=
+	if [ -n "$ldpath" ]; then
+		paths="$paths:$(echo "$ldpath" | sed "s|\(^\|:\)|\1$datadir|g")"
+	fi
+	# search in all rpaths
+	for rpath in "$pkgbasedir"/.control.*/.rpath; do
+		[ -f "$rpath" ] || continue
+		while read i; do
+			if [ -d "$datadir/$i" ]; then
+				paths="$paths:$datadir/$i"
+			fi
+		done < "$rpath"
+	done
+	echo "$paths"
+}
+
+scan_shared_objects() {
+	local name="$1" controldir="$2" datadir="$3"
+
+	# allow spaces in paths
+	IFS=:
+	set -- $(find_scanelf_paths "$controldir" "$datadir")
+	unset IFS
+
+	msg "Scanning shared objects"
+	# lets tell all the .so files this package provides in .provides-so
+	scanelf --nobanner --soname "$@" | while read etype soname file; do
+		# if soname field is missing, soname will be the filepath
+		sover=0
+		if [ -z "$file" ]; then
+			file="$soname"
+			soname=${soname##*/}
+		fi
+
+		# we only want shared libs
+		case $soname in
+		*.so|*.so.[0-9]*);;
+		*) continue;;
+		esac
+
+		case "$file" in
+		*.so.[0-9]*) sover=${file##*.so.};;
+		*.so)
+			# filter out sonames with version when file does not
+			# have version
+			case "$soname" in
+			*.so.[0-9]*) continue;;
+			esac
+			;;
+		esac
+		echo "$soname $sover"
+	done > "$controldir"/.provides-so
+
+	# now find the so dependencies
+	scanelf --nobanner --recursive --needed "$datadir"  | tr ' ' ':' \
+		| awk -F ":" '$1 == "ET_DYN" || $1 == "ET_EXEC" {print $2}'  \
+		| sed 's:,:\n:g' | sort -u \
+	| while read i; do
+		# only add files that are not self provided
+		grep -q -w "^$i" "$controldir"/.provides-so \
+			|| echo $i
+	done > "$controldir"/.needs-so
+}
+
 create_apks() {
-	local file
+	local file= dir= name= ver= apk= datadir=
 	getpkgver || return 1
 	mkdir -p "$PKGDEST"
+	if [ "$arch" != "noarch" ] && ! options_has "!tracedeps"; then
+		for file in "$pkgbasedir"/.control.*/.PKGINFO; do
+			dir="${file%/.PKGINFO}"
+			name="$(pkginfo_val pkgname $file)"
+			datadir="$pkgbasedir"/$name
+			subpkgname=$name
+			scan_shared_objects "$name" "$dir" "$datadir"
+		done
+	fi
 	for file in "$pkgbasedir"/.control.*/.PKGINFO; do
-		local dir="${file%/.PKGINFO}"
-		local name=$(pkginfo_val pkgname $file)
-		local ver=$(pkginfo_val pkgver $file)
-		local apk=$name-$ver.apk
-		local datadir="$pkgbasedir"/$name
+		dir="${file%/.PKGINFO}"
+		name=$(pkginfo_val pkgname $file)
+		ver=$(pkginfo_val pkgver $file)
+		apk=$name-$ver.apk
+		datadir="$pkgbasedir"/$name
+		subpkgname=$name
 
 		trace_apk_deps "$name" "$dir" || return 1
-		msg "Creating $apk..."
+		msg "Compressing data..."
 		(
 		cd "$datadir"
 		# data.tar.gz
@@ -941,6 +1021,7 @@ create_apks() {
 		fi
 		tar -c "$@" | abuild-tar --hash | gzip -9 >"$dir"/data.tar.gz
 
+		msg "Create checksum..."
 		# append the hash for data.tar.gz
 		local sha256=$(sha256sum "$dir"/data.tar.gz | cut -f1 -d' ')
 		echo "datahash = $sha256" >> "$dir"/.PKGINFO
@@ -951,10 +1032,12 @@ create_apks() {
 			| gzip -9 > control.tar.gz
 		abuild-sign -q control.tar.gz || exit 1
 
+		msg "Create $apk"
 		# create the final apk
 		cat control.tar.gz data.tar.gz > "$PKGDEST"/$apk
-	)
+		)
 	done
+	subpkgname=
 }
 
 clean_abuildrepo() {