forked from xdave/xbps-bulk
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·308 lines (282 loc) · 8.2 KB
/
configure
File metadata and controls
executable file
·308 lines (282 loc) · 8.2 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/usr/bin/env bash
VERSION=0.0.0
CFG_CMDLINE=
CFG_CROSS=
CFG_REPO=
CROSS_ARCH=
PKG_ARCH=
DISTDIR=
MASTERDIR=
HOSTDIR=
SRCPKGS=
XSC=
_append=""
RCV=`command -v xbps-checkvers 2>/dev/null`
RCV_F="repo-checkvers.txt"
RCV_FR="repo-checkvers-remove.txt"
TOBUILD=
_TOBUILD=
USAGE="Usage: $0 [-a cross-arch] [-CN] [-R repo] [-d|-m|-h dir]"
declare -A PKGVER_ASSOC
[ -f $RCV ] || {
printf "ERROR: The 'xbps-checkvers' was not found in the PATH.\n"
exit 1
}
while getopts a:Cc:d:Nm:th:vR: OPT; do
case "$OPT" in
a)
CFG_CROSS="-a $OPTARG"
case "$OPTARG" in
native-*-musl|native-*)
unset CFG_CROSS CROSS_ARCH
export XBPS_ARCH=${OPTARG#native-}
;;
native) unset CFG_CROSS CROSS_ARCH;;
armv6hf) CROSS_ARCH="armv6l";;
armv6hf-musl) CROSS_ARCH="armv6l-musl";;
armv7|armv7hf) CROSS_ARCH="armv7l";;
armv7-musl|armv7hf-musl) CROSS_ARCH="armv7l-musl";;
*) CROSS_ARCH="$OPTARG";;
esac
;;
v)
printf "xbps-bulk version $VERSION\n"
exit 0
;;
C)
rm -rf tobuild built
rm -f *.txt Makefile
exit 0
;;
d)
[ -d $OPTARG ] || {
printf "ERROR: Cannot find DISTDIR "
printf "'%s': No such file or directory.\n" "$OPTARG"
exit 1
}
DISTDIR="$OPTARG"
;;
N) CFG_LOCAL="-N";;
t) CFG_OVERLAYFS="-t";;
m)
[ -d $OPTARG ] || {
printf "ERROR: Cannot find MASTERDIR "
printf "'%s': No such file or directory.\n" "$OPTARG"
exit 1
}
MASTERDIR="$OPTARG"
;;
h)
[ -d $OPTARG ] || {
printf "ERROR: Cannot find HOSTDIR "
printf "'%s': No such file or directory.\n" "$OPTARG"
exit 1
}
HOSTDIR="$OPTARG"
;;
R)
CFG_REPO+="-R $OPTARG "
;;
\?)
printf "%s\n" "$USAGE"
exit 1
;;
esac
done
shift $(($OPTIND - 1))
# Assign defaults
: ${DISTDIR:=$HOME/void-packages}
: ${MASTERDIR:=$DISTDIR/masterdir}
: ${HOSTDIR:=$DISTDIR/hostdir}
PKG_ARCH=${CROSS_ARCH:-$(xbps-uhelper -r "$MASTERDIR" arch)}
SRCPKGS=$DISTDIR/srcpkgs
XBPS_SRCPKGDIR=$SRCPKGS
XSC="$DISTDIR/xbps-src $CFG_CROSS $CFG_LOCAL $CFG_OVERLAYFS -L $CFG_CMDLINE -m $MASTERDIR -H $HOSTDIR"
if [ -n "$CFG_CROSS" ]; then
export XBPS_TARGET_ARCH=$CROSS_ARCH
fi
run_rcv() {
local file=$1 flags=$2
shift 2
RCV_CMD_LINE="$RCV $flags $CFG_REPO --distdir=${DISTDIR} ${*}"
printf "INFO: Getting list of updates, please wait...\n"
printf "INFO: Running '$RCV_CMD_LINE' (${CROSS_ARCH:-native}) ...\n"
_append=""
[ -f $file ] && _append="-a"
$RCV_CMD_LINE | tee ${_append} $file
rval=${PIPESTATUS[0]}
if [ $rval -ne 0 ]; then
echo "ERROR: xbps-checkvers exited with an error: $rval"
exit 1
fi
}
run_rcv $RCV_F "" "$@"
xbps-uhelper pkgmatch "xbps-$($RCV -V | cut -d' ' -f2)_1" 'xbps>=0.54_1'
case "$?" in
0) # version < 0.54
grep pkgname "$RCV_F" | awk '{ print $2 }' >pkgs.txt ;;
1) # version >= 0.54
cut -d' ' -f1 "$RCV_F" >pkgs.txt
while read -r pkgname version remainder; do
PKGVER_ASSOC[$pkgname]=$version
done < "$RCV_F"
;;
*)
echo "ERROR: couldn't determine xbps-checkvers version"
exit 1
;;
esac
RCV_REMOVED=--removed
if $RCV -h 2>&1 | grep -q -e $RCV_REMOVED; then
run_rcv $RCV_FR $RCV_REMOVED "$@"
cut -d' ' -f1-2 "$RCV_FR" >pkgs-removed.txt
fi
printf "INFO: Creating source targets...\n"
TOREMOVE=
TOREMOVE32BIT=
rm -rf tobuild built
mkdir -p tobuild built
for p in `cat pkgs.txt`; do
if [ -f "$SRCPKGS/$p/template" ]; then
$XSC show-avail $p 2>/dev/null
case $? in
0)
touch tobuild/$p
;;
2)
version=${PKGVER_ASSOC[$p]}
TOREMOVE+="$p-$version "
TOREMOVE+="$p-dbg-$version "
[ "$XBPS_ARCH" = i686 ] && TOREMOVE32BIT+="$p-32bit-$version "
while read -r sub; do
TOREMOVE+="$sub-$version "
TOREMOVE+="$sub-dbg-$version "
[ "$XBPS_ARCH" = i686 ] && TOREMOVE32BIT+="$sub-32bit-$version "
done < <($XSC show $p 2>/dev/null | grep '^subpackages:' | cut -d: -f2-)
;;
esac
fi
done
if [ -f pkgs-removed.txt ] ; then
while read p old; do
if ! [ -f "$SRCPKGS/$p/template" ]; then
TOREMOVE+="$p-$old "
fi
done < pkgs-removed.txt
fi
_TOBUILD="`find tobuild -type f`"
concat() {
local found=0
for tb in $TOBUILD; do
if [ "$1" = "$tb" ]; then
found=1
break
fi
done
if [ $found -eq 0 ]; then
TOBUILD="$TOBUILD $1"
fi
}
getlink() {
local p="`basename $1`"
local target="`readlink $SRCPKGS/$p`"
if [ $? -eq 0 -a -n "$target" ]; then
p=$target
fi
echo $p
}
printf "INFO: Generating a proper list (without subpkgs)...\n"
for tb in $_TOBUILD; do
concat "`getlink $tb`"
done
if [ "$(command -v xbps-src-make 2>/dev/null)" ]; then
masterdirarch=$(unset XBPS_ARCH; unset XBPS_TARGET_ARCH; xbps-uhelper -r "$MASTERDIR" arch)
xbps-src-make \
-distdir "$DISTDIR" \
-hostdir "$HOSTDIR" \
-masterdir "$MASTERDIR" \
${masterdirarch:+-arch $masterdirarch} \
${CROSS_ARCH:+-cross ${CROSS_ARCH}} \
-flags "$CFG_LOCAL $CFG_OVERLAYFS -L $CFG_CMDLINE" \
$TOBUILD \
>Makefile
if [ $? -eq 0 ]; then
printf "INFO: 'Makefile' generated.\n"
printf "INFO: Type 'make'\n"
exit 0
fi
fi
printf "INFO: Removing old Makefile (if any)...\n"
[ -f Makefile ] && rm -f Makefile
touch Makefile
printf "INFO: Generating standard targets...\n"
printf "# Generated by configure, do not modify.\n\n" >> Makefile
printf "PKGS = $TOBUILD\n" >> Makefile
printf "TOBUILD = \$(patsubst %%,tobuild/%%,\$(PKGS))\n" >> Makefile
printf "BUILT = \$(patsubst tobuild/%%,built/%%,\$(TOBUILD))\n\n" >> Makefile
printf "PKGS_REMOVED = $TOREMOVE\n" >> Makefile
printf "PKGS_REMOVED_32BIT = $TOREMOVE32BIT\n" >> Makefile
printf "all: allbuilt allremoved\n" >> Makefile
printf "\t@echo \"[Done]\"\n\n" >> Makefile
printf "allbuilt: \$(BUILT)\n\n" >> Makefile
printf "allremoved:\n" >> Makefile
printf "\t@echo \"[xbps-rindex --remove --stage]\t\"\n" >> Makefile
# TODO: xbps-query --stage -s
for subrepo in "" /debug /nonfree; do
printf "\t@( in_repo=\$\$(env XBPS_TARGET_ARCH=$PKG_ARCH xbps-query -i -R --repository=\"$HOSTDIR/binpkgs$subrepo\" -s '' | cut -d' ' -f2 | while read -r indexed; do for removed in \$(PKGS_REMOVED); do [ \"\$\$indexed\" = \"\$\$removed\" ] && echo \"$HOSTDIR/binpkgs$subrepo\"/\$\$removed.$PKG_ARCH.xbps; done; done ); [ \"\$\$in_repo\" ] && env XBPS_TARGET_ARCH=$PKG_ARCH xbps-rindex --remove --stage \$\$in_repo )\n" >> Makefile
done
if [ "$XBPS_ARCH" = i686 ]; then
printf "\t@echo \"[xbps-rindex --remove --stage # multilib]\t\"\n" >> Makefile
for subrepo in /multilib /multilib/nonfree; do
printf "\t@( in_repo=\$\$(env XBPS_TARGET_ARCH=x86_64 xbps-query -i -R --repository=\"$HOSTDIR/binpkgs$subrepo\" -s '' | cut -d' ' -f2 | while read -r indexed; do for removed in \$(PKGS_REMOVED_32BIT); do [ \"\$\$indexed\" = \"\$\$removed\" ] && echo \"$HOSTDIR/binpkgs$subrepo\"/\$\$removed.x86_64.xbps; done; done ); [ \"\$\$in_repo\" ] && env XBPS_TARGET_ARCH=x86_64 xbps-rindex --remove --stage \$\$in_repo )\n" >> Makefile
done
fi
printf "\n" >> Makefile
printf "print_pkgs:\n" >> Makefile
printf "\t@echo \$(PKGS)\n\n" >> Makefile
printf "print_pkgs_removed:\n" >> Makefile
printf "\t@echo \$(PKGS_REMOVED)\n\n" >> Makefile
printf "built/%%: tobuild/%%\n" >> Makefile
printf "\t@echo \"[xbps-src]\t\${@F}\"\n" >> Makefile
printf "\t@( $XSC pkg \${@F}; rval=\$\$?; [ \$\$rval -eq 2 ] && exit 0 || exit \$\$rval )\n" >> Makefile
printf "\t@touch \$@\n" >> Makefile
printf "\t@rm tobuild/\${@F}\n\n" >> Makefile
printf "INFO: Finding and adding dependencies...\n"
printf "# Dependencies\n" >> Makefile
for p in $TOBUILD; do
deps=
sedcmd="s|[<>].*\$||g"
_deps="`$XSC show-build-deps $p 2>/dev/null| sed -e \"$sedcmd\"`"
if [ -z "${_deps}" ]; then
continue
fi
for d in $_deps; do
found=0
realdep=`getlink $d`
for _p in $TOBUILD; do
if [ "$_p" = "$realdep" ]; then
found=1
break;
fi
done
if [ $found -gt 0 ]; then
deps="$deps built/$realdep"
fi
done
printf "built/$p: $deps\n" >> Makefile
done
printf "\n" >> Makefile
printf "# Remove targets\n" >> Makefile
printf "removed/$p:\n" >> Makefile
for p in $TOREMOVE; do
printf "removed/$p:\n" >> Makefile
done
printf "\n" >> Makefile
printf "clean:\n" >> Makefile
printf "\t@rm -f built/*\n" >> Makefile
printf "\t@rm -f removed/*\n" >> Makefile
printf "\t@echo \"[Clean]\"\n\n" >> Makefile
printf ".PHONY: all print_pkgs clean allbuilt allremoved\n" >> Makefile
printf "INFO: 'Makefile' generated.\n"
printf "INFO: Type 'make'\n"
exit 0