forked from xdave/xbps-bulk
-
Notifications
You must be signed in to change notification settings - Fork 11
/
configure
executable file
·239 lines (216 loc) · 5.41 KB
/
configure
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
#!/bin/bash
VERSION=0.0.0
CFG_CMDLINE=
CFG_CROSS=
CFG_REPO=
CROSS_ARCH=
DISTDIR=
MASTERDIR=
HOSTDIR=
SRCPKGS=
XSC=
_append=""
RCV=`command -v xbps-checkvers 2>/dev/null`
RCV_F="repo-checkvers.txt"
TOBUILD=
_TOBUILD=
USAGE="Usage: $0 [-a cross-arch] [-CN] [-R repo] [-d|-m|-h dir]"
[ -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}
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
RCV_CMD_LINE="$RCV $CFG_REPO --distdir=${DISTDIR} ${*}"
printf "INFO: Getting list of updates, please wait...\n"
printf "INFO: Running '$RCV_CMD_LINE' (${CROSS_ARCH:-native}) ...\n"
[ -f $RCV_F ] && _append="-a"
$RCV_CMD_LINE | tee ${_append} $RCV_F
rval=${PIPESTATUS[0]}
if [ $rval -ne 0 ]; then
echo "ERROR: xbps-checkvers exited with an error: $rval"
exit 1
fi
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 ;;
*)
echo "ERROR: couldn't determine xbps-checkvers version"
exit 1
;;
esac
printf "INFO: Creating source targets...\n"
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
if [ $? -eq 0 ]; then
touch tobuild/$p
fi
fi
done
_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 "all: \$(BUILT)\n" >> Makefile
printf "\t@echo \"[Done]\"\n\n" >> Makefile
printf "print_pkgs:\n" >> Makefile
printf "\t@echo \$(PKGS)\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 "clean:\n" >> Makefile
printf "\t@rm -f built/*\n" >> Makefile
printf "\t@echo \"[Clean]\"\n\n" >> Makefile
printf ".PHONY: all print_pkgs clean\n" >> Makefile
printf "INFO: 'Makefile' generated.\n"
printf "INFO: Type 'make'\n"
exit 0