]>
Commit | Line | Data |
---|---|---|
dca10b06 | 1 | #!/bin/bash |
7dacc70b | 2 | # |
1e51b81c | 3 | # makepkg - make packages compatible for use with pacman |
b6387b95 | 4 | # @configure_input@ |
7dacc70b | 5 | # |
1dd34058 | 6 | # Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org> |
c72b4543 | 7 | # Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> |
4470e5ce | 8 | # Copyright (c) 2005 by Aurelien Foret <orelien@chez.com> |
51b8f9ac | 9 | # Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org> |
4470e5ce AG |
10 | # Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu> |
11 | # Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk> | |
12 | # Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org> | |
7dacc70b | 13 | # |
d04baaba JV |
14 | # This program is free software; you can redistribute it and/or modify |
15 | # it under the terms of the GNU General Public License as published by | |
16 | # the Free Software Foundation; either version 2 of the License, or | |
17 | # (at your option) any later version. | |
7dacc70b | 18 | # |
d04baaba JV |
19 | # This program is distributed in the hope that it will be useful, |
20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | # GNU General Public License for more details. | |
7dacc70b | 23 | # |
d04baaba | 24 | # You should have received a copy of the GNU General Public License |
9781d0d6 | 25 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
d04baaba JV |
26 | # |
27 | ||
1d97da94 DM |
28 | # makepkg uses quite a few external programs during its execution. You |
29 | # need to have at least the following installed for makepkg to function: | |
ef977865 | 30 | # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils), |
e8069cfc | 31 | # gettext, gpg, grep, gzip, openssl, sed, tput (ncurses), xz |
1d97da94 | 32 | |
f044e23a | 33 | # gettext initialization |
a4a7006a | 34 | export TEXTDOMAIN='pacman-scripts' |
7f153b72 | 35 | export TEXTDOMAINDIR='@localedir@' |
f044e23a | 36 | |
20ae8719 SN |
37 | # file -i does not work on Mac OSX unless legacy mode is set |
38 | export COMMAND_MODE='legacy' | |
13a1d588 DM |
39 | # Ensure CDPATH doesn't screw with our cd calls |
40 | unset CDPATH | |
950443a4 AG |
41 | # Ensure GREP_OPTIONS doesn't screw with our grep calls |
42 | unset GREP_OPTIONS | |
20ae8719 | 43 | |
b3e82ec5 | 44 | declare -r makepkg_version='@PACKAGE_VERSION@' |
0e4946d5 LF |
45 | declare -r confdir='@sysconfdir@' |
46 | declare -r BUILDSCRIPT='@BUILDSCRIPT@' | |
47 | declare -r startdir="$PWD" | |
9804911c | 48 | |
a03f5f55 SL |
49 | packaging_options=('strip' 'docs' 'libtool' 'staticlibs' 'emptydirs' 'zipman' \ |
50 | 'purge' 'upx' 'debug') | |
2052f29c | 51 | other_options=('ccache' 'distcc' 'buildflags' 'makeflags') |
3a24e442 | 52 | splitpkg_overrides=('pkgver' 'pkgrel' 'epoch' 'pkgdesc' 'arch' 'url' 'license' \ |
03447ce3 AM |
53 | 'groups' 'depends' 'optdepends' 'provides' 'conflicts' \ |
54 | 'replaces' 'backup' 'options' 'install' 'changelog') | |
9804911c | 55 | readonly -a packaging_options other_options splitpkg_overrides |
d04baaba | 56 | |
d0fb27ce | 57 | # Options |
52550a2a | 58 | ASDEPS=0 |
42b492b2 | 59 | NEEDED=0 |
9ff52db3 | 60 | ASROOT=0 |
d0fb27ce | 61 | CLEANUP=0 |
d0fb27ce | 62 | DEP_BIN=0 |
d0fb27ce | 63 | FORCE=0 |
9ff52db3 | 64 | INFAKEROOT=0 |
4470e5ce | 65 | GENINTEG=0 |
6c8def6a | 66 | HOLDVER=0 |
2b3405e0 | 67 | SKIPCHECKSUMS=0 |
94f61c5b | 68 | SKIPPGPCHECK=0 |
d0fb27ce | 69 | INSTALL=0 |
d0fb27ce | 70 | NOBUILD=0 |
d0fb27ce JV |
71 | NODEPS=0 |
72 | NOEXTRACT=0 | |
2259dff7 | 73 | VERIFYSOURCE=0 |
d0fb27ce | 74 | RMDEPS=0 |
42a6acf7 | 75 | REPKG=0 |
4470e5ce | 76 | LOGGING=0 |
f4d6efee | 77 | SOURCEONLY=0 |
c1b6a6d6 | 78 | IGNOREARCH=0 |
065b7f86 | 79 | PREPAREFUNC=0 |
4d2ec375 | 80 | BUILDFUNC=0 |
0c29eb43 | 81 | CHECKFUNC=0 |
fba5771f | 82 | PKGFUNC=0 |
a818766c | 83 | PKGVERFUNC=0 |
e946ee77 | 84 | SPLITPKG=0 |
7f5c4866 | 85 | PKGLIST=() |
e8069cfc | 86 | SIGNPKG='' |
d0fb27ce | 87 | |
8a9c83dd SH |
88 | # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call |
89 | # when dealing with svn/cvs/etc PKGBUILDs. | |
90 | FORCE_VER="" | |
91 | ||
041e51f6 AF |
92 | PACMAN_OPTS= |
93 | ||
0e79802c DR |
94 | shopt -s extglob |
95 | ||
d04baaba JV |
96 | ### SUBROUTINES ### |
97 | ||
98 | plain() { | |
124693af | 99 | local mesg=$1; shift |
013fc9a7 | 100 | printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 |
d04baaba | 101 | } |
42a6acf7 | 102 | |
d04baaba | 103 | msg() { |
124693af | 104 | local mesg=$1; shift |
013fc9a7 | 105 | printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 |
d04baaba | 106 | } |
4470e5ce AG |
107 | |
108 | msg2() { | |
124693af | 109 | local mesg=$1; shift |
013fc9a7 | 110 | printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 |
4470e5ce AG |
111 | } |
112 | ||
d04baaba | 113 | warning() { |
124693af | 114 | local mesg=$1; shift |
013fc9a7 | 115 | printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 |
d04baaba | 116 | } |
42a6acf7 | 117 | |
d04baaba | 118 | error() { |
124693af | 119 | local mesg=$1; shift |
013fc9a7 | 120 | printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 |
d04baaba JV |
121 | } |
122 | ||
b69edc1c AF |
123 | |
124 | ## | |
125 | # Special exit call for traps, Don't print any error messages when inside, | |
126 | # the fakeroot call, the error message will be printed by the main call. | |
127 | ## | |
128 | trap_exit() { | |
1a8c3e52 DR |
129 | local signal=$1; shift |
130 | ||
966c8158 | 131 | if (( ! INFAKEROOT )); then |
b69edc1c AF |
132 | echo |
133 | error "$@" | |
134 | fi | |
a6cca6e4 | 135 | [[ -n $srclinks ]] && rm -rf "$srclinks" |
1a8c3e52 DR |
136 | |
137 | # unset the trap for this signal, and then call the default handler | |
138 | trap -- "$signal" | |
139 | kill "-$signal" "$$" | |
b69edc1c AF |
140 | } |
141 | ||
142 | ||
143 | ## | |
144 | # Clean up function. Called automatically when the script exits. | |
145 | ## | |
146 | clean_up() { | |
147 | local EXIT_CODE=$? | |
148 | ||
966c8158 | 149 | if (( INFAKEROOT )); then |
b69edc1c AF |
150 | # Don't clean up when leaving fakeroot, we're not done yet. |
151 | return | |
152 | fi | |
153 | ||
966c8158 | 154 | if (( ! EXIT_CODE && CLEANUP )); then |
1a9db4ca A |
155 | local pkg file |
156 | ||
b69edc1c AF |
157 | # If it's a clean exit and -c/--clean has been passed... |
158 | msg "$(gettext "Cleaning up...")" | |
f170a94c | 159 | rm -rf "$pkgdirbase" "$srcdir" |
966c8158 | 160 | if [[ -n $pkgbase ]]; then |
ccdb2fa8 | 161 | local fullver=$(get_full_version) |
b69edc1c | 162 | # Can't do this unless the BUILDSCRIPT has been sourced. |
4d2ec375 | 163 | if (( BUILDFUNC )); then |
b8ab96a2 | 164 | rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"* |
4d2ec375 | 165 | fi |
0c29eb43 | 166 | if (( CHECKFUNC )); then |
b8ab96a2 | 167 | rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"* |
0c29eb43 | 168 | fi |
966c8158 | 169 | if (( PKGFUNC )); then |
b8ab96a2 | 170 | rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"* |
966c8158 | 171 | elif (( SPLITPKG )); then |
7370fd59 | 172 | for pkg in ${pkgname[@]}; do |
b8ab96a2 | 173 | rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"* |
7370fd59 AM |
174 | done |
175 | fi | |
93862bd7 EB |
176 | |
177 | # clean up dangling symlinks to packages | |
178 | for pkg in ${pkgname[@]}; do | |
d38a1c02 | 179 | for file in ${pkg}-*-*-*{${PKGEXT},${SRCEXT}}; do |
93862bd7 | 180 | if [[ -h $file && ! -e $file ]]; then |
f988aa6b | 181 | rm -f "$file" |
93862bd7 EB |
182 | fi |
183 | done | |
184 | done | |
b69edc1c AF |
185 | fi |
186 | fi | |
187 | ||
188 | remove_deps | |
189 | } | |
190 | ||
191 | ||
d21f6ca4 | 192 | enter_fakeroot() { |
4bdb868a | 193 | msg "$(gettext "Entering %s environment...")" "fakeroot" |
d338b398 | 194 | fakeroot -- $0 -F "${ARGLIST[@]}" || exit $? |
d21f6ca4 AM |
195 | } |
196 | ||
41f9fa9b AM |
197 | |
198 | # a source entry can have two forms : | |
199 | # 1) "filename::http://path/to/file" | |
200 | # 2) "http://path/to/file" | |
201 | ||
5cddcc90 | 202 | # Return the absolute filename of a source entry |
5cddcc90 CS |
203 | get_filepath() { |
204 | local file="$(get_filename "$1")" | |
cca9849f | 205 | local proto="$(get_protocol "$1")" |
5cddcc90 | 206 | |
cca9849f | 207 | case $proto in |
3b02f80d | 208 | bzr*|git*|hg*|svn*) |
cca9849f AM |
209 | if [[ -d "$startdir/$file" ]]; then |
210 | file="$startdir/$file" | |
211 | elif [[ -d "$SRCDEST/$file" ]]; then | |
212 | file="$SRCDEST/$file" | |
213 | else | |
214 | return 1 | |
215 | fi | |
216 | ;; | |
217 | *) | |
218 | if [[ -f "$startdir/$file" ]]; then | |
219 | file="$startdir/$file" | |
220 | elif [[ -f "$SRCDEST/$file" ]]; then | |
221 | file="$SRCDEST/$file" | |
222 | else | |
223 | return 1 | |
224 | fi | |
225 | ;; | |
226 | esac | |
5cddcc90 | 227 | |
1917c845 | 228 | printf "%s\n" "$file" |
5cddcc90 CS |
229 | } |
230 | ||
d6f62ba2 XC |
231 | # extract the filename from a source entry |
232 | get_filename() { | |
aa6fe116 AM |
233 | local netfile=$1 |
234 | ||
d6f62ba2 | 235 | # if a filename is specified, use it |
aa6fe116 AM |
236 | if [[ $netfile = *::* ]]; then |
237 | printf "%s\n" ${netfile%%::*} | |
238 | return | |
239 | fi | |
240 | ||
241 | local proto=$(get_protocol "$netfile") | |
242 | ||
243 | case $proto in | |
3b02f80d | 244 | bzr*|git*|hg*|svn*) |
03ea8ca6 GM |
245 | filename=${netfile%%#*} |
246 | filename=${filename%/} | |
247 | filename=${filename##*/} | |
2bf2700b MG |
248 | if [[ $proto = bzr* ]]; then |
249 | filename=${filename#*lp:} | |
250 | fi | |
03ea8ca6 GM |
251 | if [[ $proto = git* ]]; then |
252 | filename=${filename%%.git*} | |
253 | fi | |
aa6fe116 AM |
254 | ;; |
255 | *) | |
256 | # if it is just an URL, we only keep the last component | |
257 | filename="${netfile##*/}" | |
258 | ;; | |
259 | esac | |
260 | printf "%s\n" "${filename}" | |
d04baaba JV |
261 | } |
262 | ||
1e51b81c | 263 | # extract the URL from a source entry |
d6f62ba2 XC |
264 | get_url() { |
265 | # strip an eventual filename | |
1917c845 | 266 | printf "%s\n" "${1#*::}" |
d6f62ba2 | 267 | } |
2fb2613e | 268 | |
a922d180 AM |
269 | # extract the protocol from a source entry - return "local" for local sources |
270 | get_protocol() { | |
271 | if [[ $1 = *://* ]]; then | |
272 | # strip leading filename | |
273 | local proto="${1##*::}" | |
274 | printf "%s\n" "${proto%%://*}" | |
2bf2700b MG |
275 | elif [[ $1 = *lp:* ]]; then |
276 | local proto="${1##*::}" | |
277 | printf "%s\n" "${proto%%lp:*}" | |
a922d180 AM |
278 | else |
279 | printf "%s\n" local | |
280 | fi | |
281 | } | |
282 | ||
e8064144 | 283 | get_downloadclient() { |
1a04e2e1 | 284 | local proto=$1 |
e8064144 AM |
285 | |
286 | # loop through DOWNLOAD_AGENTS variable looking for protocol | |
287 | local i | |
288 | for i in "${DLAGENTS[@]}"; do | |
289 | local handler="${i%%::*}" | |
290 | if [[ $proto = "$handler" ]]; then | |
291 | local agent="${i##*::}" | |
292 | break | |
293 | fi | |
294 | done | |
295 | ||
296 | # if we didn't find an agent, return an error | |
297 | if [[ -z $agent ]]; then | |
306c2742 | 298 | error "$(gettext "Unknown download protocol: %s")" "$proto" |
e8064144 AM |
299 | plain "$(gettext "Aborting...")" |
300 | exit 1 # $E_CONFIG_ERROR | |
301 | fi | |
302 | ||
303 | # ensure specified program is installed | |
304 | local program="${agent%% *}" | |
305 | if [[ ! -x $program ]]; then | |
306 | local baseprog="${program##*/}" | |
307 | error "$(gettext "The download program %s is not installed.")" "$baseprog" | |
308 | plain "$(gettext "Aborting...")" | |
309 | exit 1 # $E_MISSING_PROGRAM | |
310 | fi | |
311 | ||
312 | printf "%s\n" "$agent" | |
313 | } | |
314 | ||
1a04e2e1 AM |
315 | download_local() { |
316 | local netfile=$1 | |
317 | local filepath=$(get_filepath "$netfile") | |
318 | ||
319 | if [[ -n "$filepath" ]]; then | |
320 | msg2 "$(gettext "Found %s")" "${filepath##*/}" | |
321 | rm -f "$srcdir/${filepath##*/}" | |
322 | ln -s "$filepath" "$srcdir/" | |
1a04e2e1 AM |
323 | else |
324 | local filename=$(get_filename "$netfile") | |
325 | error "$(gettext "%s was not found in the build directory and is not a URL.")" "$filename" | |
326 | exit 1 # $E_MISSING_FILE | |
327 | fi | |
328 | } | |
329 | ||
e8064144 | 330 | download_file() { |
1a04e2e1 AM |
331 | local netfile=$1 |
332 | ||
333 | local filepath=$(get_filepath "$netfile") | |
334 | if [[ -n "$filepath" ]]; then | |
335 | msg2 "$(gettext "Found %s")" "${filepath##*/}" | |
336 | rm -f "$srcdir/${filepath##*/}" | |
337 | ln -s "$filepath" "$srcdir/" | |
338 | return | |
339 | fi | |
340 | ||
341 | local proto=$(get_protocol "$netfile") | |
342 | ||
343 | # find the client we should use for this URL | |
344 | local dlcmd | |
345 | dlcmd=$(get_downloadclient "$proto") || exit $? | |
346 | ||
347 | local filename=$(get_filename "$netfile") | |
348 | local url=$(get_url "$netfile") | |
349 | ||
350 | if [[ $proto = "scp" ]]; then | |
351 | # scp downloads should not pass the protocol in the url | |
352 | url="${url##*://}" | |
353 | fi | |
354 | ||
355 | msg2 "$(gettext "Downloading %s...")" "$filename" | |
356 | ||
e8064144 AM |
357 | # temporary download file, default to last component of the URL |
358 | local dlfile="${url##*/}" | |
359 | ||
360 | # replace %o by the temporary dlfile if it exists | |
361 | if [[ $dlcmd = *%o* ]]; then | |
1a04e2e1 AM |
362 | dlcmd=${dlcmd//\%o/\"$filename.part\"} |
363 | dlfile="$filename.part" | |
e8064144 AM |
364 | fi |
365 | # add the URL, either in place of %u or at the end | |
366 | if [[ $dlcmd = *%u* ]]; then | |
367 | dlcmd=${dlcmd//\%u/\"$url\"} | |
368 | else | |
369 | dlcmd="$dlcmd \"$url\"" | |
370 | fi | |
371 | ||
372 | local ret=0 | |
373 | eval "$dlcmd || ret=\$?" | |
374 | if (( ret )); then | |
375 | [[ ! -s $dlfile ]] && rm -f -- "$dlfile" | |
1a04e2e1 AM |
376 | error "$(gettext "Failure while downloading %s")" "$filename" |
377 | plain "$(gettext "Aborting...")" | |
378 | exit 1 | |
e8064144 AM |
379 | fi |
380 | ||
381 | # rename the temporary download file to the final destination | |
1a04e2e1 AM |
382 | if [[ $dlfile != "$filename" ]]; then |
383 | mv -f "$SRCDEST/$dlfile" "$SRCDEST/$filename" | |
e8064144 | 384 | fi |
1a04e2e1 AM |
385 | |
386 | rm -f "$srcdir/$filename" | |
387 | ln -s "$SRCDEST/$filename" "$srcdir/" | |
e8064144 AM |
388 | } |
389 | ||
fcdaa46b WG |
390 | extract_file() { |
391 | local file=$1 | |
247b9af0 | 392 | # do not rely on extension for file type |
fcdaa46b WG |
393 | local file_type=$(file -bizL "$file") |
394 | local ext=${file##*.} | |
395 | local cmd='' | |
396 | case "$file_type" in | |
397 | *application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*) | |
398 | cmd="bsdtar" ;; | |
399 | *application/x-gzip*) | |
400 | case "$ext" in | |
401 | gz|z|Z) cmd="gzip" ;; | |
402 | *) continue;; | |
403 | esac ;; | |
404 | *application/x-bzip*) | |
405 | case "$ext" in | |
406 | bz2|bz) cmd="bzip2" ;; | |
407 | *) continue;; | |
408 | esac ;; | |
409 | *application/x-xz*) | |
410 | case "$ext" in | |
411 | xz) cmd="xz" ;; | |
412 | *) continue;; | |
413 | esac ;; | |
414 | *) | |
415 | # See if bsdtar can recognize the file | |
416 | if bsdtar -tf "$file" -q '*' &>/dev/null; then | |
417 | cmd="bsdtar" | |
418 | else | |
419 | continue | |
420 | fi ;; | |
421 | esac | |
422 | ||
423 | local ret=0 | |
424 | msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd" | |
425 | if [[ $cmd = "bsdtar" ]]; then | |
426 | $cmd -xf "$file" || ret=$? | |
427 | else | |
428 | rm -f -- "${file%.*}" | |
429 | $cmd -dcf "$file" > "${file%.*}" || ret=$? | |
430 | fi | |
431 | if (( ret )); then | |
432 | error "$(gettext "Failed to extract %s")" "$file" | |
433 | plain "$(gettext "Aborting...")" | |
434 | exit 1 | |
435 | fi | |
436 | ||
437 | if (( EUID == 0 )); then | |
438 | # change perms of all source files to root user & root group | |
439 | chown -R 0:0 "$srcdir" | |
440 | fi | |
441 | } | |
442 | ||
3b02f80d GM |
443 | download_bzr() { |
444 | local netfile=$1 | |
445 | ||
446 | local url=$(get_url "$netfile") | |
447 | url=${url##*bzr+} | |
448 | url=${url%%#*} | |
449 | ||
93fa63ee | 450 | local repo=$(get_filename "$netfile") |
3b02f80d | 451 | local displaylocation="$url" |
3b02f80d GM |
452 | |
453 | local dir=$(get_filepath "$netfile") | |
454 | [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" | |
455 | ||
456 | if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then | |
457 | msg2 "$(gettext "Branching %s ...")" "${displaylocation}" | |
72c6d19d | 458 | if ! bzr branch "$url" "$dir" --no-tree --use-existing-dir; then |
3b02f80d GM |
459 | error "$(gettext "Failure while branching %s")" "${displaylocation}" |
460 | plain "$(gettext "Aborting...")" | |
461 | exit 1 | |
462 | fi | |
463 | elif (( ! HOLDVER )); then | |
464 | # Make sure we are fetching the right repo | |
2bf2700b MG |
465 | local distant_url="$(bzr info $url 2> /dev/null | sed -n '/branch root/{s/ branch root: //p;q;}')" |
466 | local local_url="$(bzr config parent_location -d $dir)" | |
467 | if [[ -n $distant_url ]]; then | |
468 | if [[ $distant_url != "$local_url" ]]; then | |
469 | error "$(gettext "%s is not a branch of %s")" "$dir" "$url" | |
470 | plain "$(gettext "Aborting...")" | |
471 | exit 1 | |
472 | fi | |
473 | else | |
474 | if [[ $url != "$local_url" ]] ; then | |
475 | error "$(gettext "%s is not a branch of %s")" "$dir" "$url" | |
476 | error "$(gettext "The local URL is %s")" "$local_url" | |
477 | plain "$(gettext "Aborting...")" | |
478 | exit 1 | |
479 | fi | |
3b02f80d GM |
480 | fi |
481 | msg2 "$(gettext "Pulling %s ...")" "${displaylocation}" | |
482 | cd_safe "$dir" | |
72c6d19d | 483 | if ! bzr pull "$url" --overwrite; then |
3b02f80d GM |
484 | # only warn on failure to allow offline builds |
485 | warning "$(gettext "Failure while pulling %s")" "${displaylocation}" | |
486 | fi | |
487 | fi | |
fcdaa46b WG |
488 | } |
489 | ||
490 | extract_bzr() { | |
491 | local netfile=$1 | |
492 | ||
72c6d19d | 493 | local repo=$(get_filename "$netfile") |
fcdaa46b WG |
494 | local fragment=${netfile#*#} |
495 | if [[ $fragment = "$netfile" ]]; then | |
496 | unset fragment | |
497 | fi | |
498 | ||
72c6d19d DR |
499 | if [[ -n $fragment ]]; then |
500 | case ${fragment%%=*} in | |
501 | revision) | |
502 | revision=("-r" "${fragment#*=}") | |
503 | displaylocation="$url -r ${fragment#*=}" | |
504 | ;; | |
505 | *) | |
506 | error "$(gettext "Unrecognized reference: %s")" "${fragment}" | |
507 | plain "$(gettext "Aborting...")" | |
508 | exit 1 | |
509 | esac | |
510 | fi | |
511 | ||
fcdaa46b WG |
512 | local dir=$(get_filepath "$netfile") |
513 | [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" | |
3b02f80d | 514 | |
93fa63ee | 515 | msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "bzr" |
3b02f80d GM |
516 | pushd "$srcdir" &>/dev/null |
517 | rm -rf "${dir##*/}" | |
518 | ||
72c6d19d DR |
519 | if ! { bzr checkout "$dir" "${revision[@]}" --lightweight && |
520 | ( cd "$repo" && bzr pull "$dir" -q --overwrite "${revision[@]}" ); }; then | |
93fa63ee | 521 | error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "bzr" |
3b02f80d GM |
522 | plain "$(gettext "Aborting...")" |
523 | exit 1 | |
524 | fi | |
525 | ||
526 | popd &>/dev/null | |
527 | } | |
528 | ||
91d119af AM |
529 | download_git() { |
530 | local netfile=$1 | |
531 | ||
cca9849f AM |
532 | local dir=$(get_filepath "$netfile") |
533 | [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" | |
aa6fe116 | 534 | |
93fa63ee | 535 | local repo=$(get_filename "$netfile") |
91d119af | 536 | |
91d119af AM |
537 | local url=$(get_url "$netfile") |
538 | url=${url##*git+} | |
539 | url=${url%%#*} | |
540 | ||
34b52c9a | 541 | if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then |
91d119af AM |
542 | msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git" |
543 | if ! git clone --mirror "$url" "$dir"; then | |
544 | error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "git" | |
545 | plain "$(gettext "Aborting...")" | |
546 | exit 1 | |
547 | fi | |
6c8def6a | 548 | elif (( ! HOLDVER )); then |
91d119af | 549 | cd_safe "$dir" |
c926c39b | 550 | # Make sure we are fetching the right repo |
8e533b03 | 551 | if [[ "$url" != "$(git config --get remote.origin.url)" ]] ; then |
c926c39b MA |
552 | error "$(gettext "%s is not a clone of %s")" "$dir" "$url" |
553 | plain "$(gettext "Aborting...")" | |
554 | exit 1 | |
555 | fi | |
556 | msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "git" | |
91d119af AM |
557 | if ! git fetch --all -p; then |
558 | # only warn on failure to allow offline builds | |
559 | warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "git" | |
560 | fi | |
561 | fi | |
fcdaa46b WG |
562 | } |
563 | ||
564 | extract_git() { | |
565 | local netfile=$1 | |
566 | ||
567 | local fragment=${netfile#*#} | |
568 | if [[ $fragment = "$netfile" ]]; then | |
569 | unset fragment | |
570 | fi | |
571 | ||
572 | local repo=${netfile##*/} | |
573 | repo=${repo%%#*} | |
574 | repo=${repo%%.git*} | |
575 | ||
576 | local dir=$(get_filepath "$netfile") | |
577 | [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" | |
91d119af AM |
578 | |
579 | msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "git" | |
580 | pushd "$srcdir" &>/dev/null | |
581 | rm -rf "${dir##*/}" | |
582 | ||
0ba9b262 | 583 | if ! git clone "$dir"; then |
91d119af AM |
584 | error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "git" |
585 | plain "$(gettext "Aborting...")" | |
586 | exit 1 | |
587 | fi | |
588 | ||
589 | cd_safe "${dir##*/}" | |
590 | ||
591 | local ref | |
592 | if [[ -n $fragment ]]; then | |
593 | case ${fragment%%=*} in | |
594 | commit|tag) | |
595 | ref=${fragment##*=} | |
596 | ;; | |
597 | branch) | |
598 | ref=origin/${fragment##*=} | |
599 | ;; | |
600 | *) | |
601 | error "$(gettext "Unrecognized reference: %s")" "${fragment}" | |
602 | plain "$(gettext "Aborting...")" | |
603 | exit 1 | |
604 | esac | |
605 | fi | |
606 | ||
607 | if [[ -n $ref ]]; then | |
608 | if ! git checkout -b makepkg $ref; then | |
609 | error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "git" | |
610 | plain "$(gettext "Aborting...")" | |
611 | exit 1 | |
612 | fi | |
613 | fi | |
614 | ||
615 | popd &>/dev/null | |
616 | } | |
617 | ||
7e4aa9e5 AM |
618 | download_hg() { |
619 | local netfile=$1 | |
620 | ||
7e4aa9e5 AM |
621 | local dir=$(get_filepath "$netfile") |
622 | [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" | |
623 | ||
93fa63ee | 624 | local repo=$(get_filename "$netfile") |
7e4aa9e5 AM |
625 | |
626 | local url=$(get_url "$netfile") | |
627 | url=${url##*hg+} | |
628 | url=${url%%#*} | |
629 | ||
2d347132 | 630 | if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then |
7e4aa9e5 | 631 | msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "hg" |
800799ea | 632 | if ! hg clone -U "$url" "$dir"; then |
7e4aa9e5 AM |
633 | error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "hg" |
634 | plain "$(gettext "Aborting...")" | |
635 | exit 1 | |
636 | fi | |
637 | elif (( ! HOLDVER )); then | |
638 | msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "hg" | |
639 | cd_safe "$dir" | |
800799ea | 640 | if ! hg pull; then |
7e4aa9e5 AM |
641 | # only warn on failure to allow offline builds |
642 | warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "hg" | |
643 | fi | |
644 | fi | |
fcdaa46b WG |
645 | } |
646 | ||
647 | extract_hg() { | |
648 | local netfile=$1 | |
649 | ||
650 | local fragment=${netfile#*#} | |
651 | if [[ $fragment = "$netfile" ]]; then | |
652 | unset fragment | |
653 | fi | |
654 | ||
655 | local dir=$(get_filepath "$netfile") | |
656 | [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" | |
657 | ||
658 | local repo=${netfile##*/} | |
659 | repo=${repo%%#*} | |
7e4aa9e5 AM |
660 | |
661 | msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "hg" | |
662 | pushd "$srcdir" &>/dev/null | |
663 | rm -rf "${dir##*/}" | |
664 | ||
665 | local ref | |
666 | if [[ -n $fragment ]]; then | |
667 | case ${fragment%%=*} in | |
668 | branch|revision|tag) | |
669 | ref=('-u' "${fragment##*=}") | |
670 | ;; | |
671 | *) | |
672 | error "$(gettext "Unrecognized reference: %s")" "${fragment}" | |
673 | plain "$(gettext "Aborting...")" | |
674 | exit 1 | |
675 | esac | |
676 | fi | |
677 | ||
678 | if ! hg clone "${ref[@]}" "$dir" "${dir##*/}"; then | |
679 | error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "hg" | |
680 | plain "$(gettext "Aborting...")" | |
681 | exit 1 | |
682 | fi | |
683 | ||
684 | popd &>/dev/null | |
685 | } | |
686 | ||
2042b79b AM |
687 | download_svn() { |
688 | local netfile=$1 | |
689 | ||
8b9cb8e0 | 690 | local fragment=${netfile#*#} |
2042b79b AM |
691 | if [[ $fragment = "$netfile" ]]; then |
692 | unset fragment | |
693 | fi | |
694 | ||
695 | local dir=$(get_filepath "$netfile") | |
696 | [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" | |
697 | ||
93fa63ee | 698 | local repo=$(get_filename "$netfile") |
2042b79b AM |
699 | |
700 | local url=$(get_url "$netfile") | |
701 | if [[ $url != svn+ssh* ]]; then | |
702 | url=${url##*svn+} | |
703 | fi | |
704 | url=${url%%#*} | |
705 | ||
2d347132 | 706 | if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then |
2042b79b | 707 | msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "svn" |
7e0f5282 AM |
708 | mkdir -p "$dir/.makepkg" |
709 | if ! svn checkout --config-dir "$dir/.makepkg" "$url" "$dir"; then | |
2042b79b AM |
710 | error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "svn" |
711 | plain "$(gettext "Aborting...")" | |
712 | exit 1 | |
713 | fi | |
6c8def6a | 714 | elif (( ! HOLDVER )); then |
2042b79b AM |
715 | msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "svn" |
716 | cd_safe "$dir" | |
717 | if ! svn update; then | |
718 | # only warn on failure to allow offline builds | |
719 | warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "svn" | |
720 | fi | |
721 | fi | |
fcdaa46b WG |
722 | } |
723 | ||
724 | extract_svn() { | |
725 | local netfile=$1 | |
726 | ||
727 | local fragment=${netfile#*#} | |
728 | if [[ $fragment = "$netfile" ]]; then | |
729 | unset fragment | |
730 | fi | |
731 | ||
732 | local dir=$(get_filepath "$netfile") | |
733 | [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" | |
734 | ||
735 | local repo=${netfile##*/} | |
736 | repo=${repo%%#*} | |
2042b79b AM |
737 | |
738 | msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "svn" | |
739 | pushd "$srcdir" &>/dev/null | |
740 | rm -rf "${dir##*/}" | |
741 | ||
742 | local ref | |
743 | if [[ -n $fragment ]]; then | |
744 | case ${fragment%%=*} in | |
745 | revision) | |
695f0e44 | 746 | ref="${fragment##*=}" |
2042b79b AM |
747 | ;; |
748 | *) | |
749 | error "$(gettext "Unrecognized reference: %s")" "${fragment}" | |
750 | plain "$(gettext "Aborting...")" | |
751 | exit 1 | |
752 | esac | |
753 | fi | |
754 | ||
695f0e44 AM |
755 | cp -a "$dir" . |
756 | ||
757 | if [[ -n ${ref} ]]; then | |
758 | cd_safe "$(get_filename "$netfile")" | |
759 | if ! svn update -r ${ref}; then | |
760 | error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "svn" | |
761 | plain "$(gettext "Aborting...")" | |
762 | fi | |
2042b79b AM |
763 | fi |
764 | ||
765 | popd &>/dev/null | |
766 | } | |
767 | ||
e8064144 | 768 | download_sources() { |
3536975b | 769 | msg "$(gettext "Retrieving sources...")" |
e8064144 | 770 | |
7fd56118 AM |
771 | local GET_VCS=1 |
772 | if [[ $1 == "fast" ]]; then | |
773 | GET_VCS=0 | |
774 | fi | |
775 | ||
e8064144 AM |
776 | local netfile |
777 | for netfile in "${source[@]}"; do | |
a6291858 | 778 | pushd "$SRCDEST" &>/dev/null |
1a04e2e1 | 779 | |
a6291858 | 780 | local proto=$(get_protocol "$netfile") |
1a04e2e1 AM |
781 | case "$proto" in |
782 | local) | |
783 | download_local "$netfile" | |
784 | ;; | |
3b02f80d GM |
785 | bzr*) |
786 | (( GET_VCS )) && download_bzr "$netfile" | |
787 | ;; | |
91d119af | 788 | git*) |
7fd56118 | 789 | (( GET_VCS )) && download_git "$netfile" |
91d119af | 790 | ;; |
7e4aa9e5 AM |
791 | hg*) |
792 | (( GET_VCS )) && download_hg "$netfile" | |
793 | ;; | |
2042b79b | 794 | svn*) |
7fd56118 | 795 | (( GET_VCS )) && download_svn "$netfile" |
2042b79b | 796 | ;; |
1a04e2e1 | 797 | *) |
306c2742 | 798 | download_file "$netfile" |
1a04e2e1 AM |
799 | ;; |
800 | esac | |
e8064144 | 801 | |
a6291858 AM |
802 | popd &>/dev/null |
803 | done | |
e8064144 AM |
804 | } |
805 | ||
888020de AM |
806 | # Automatically update pkgver variable if a pkgver() function is provided |
807 | # Re-sources the PKGBUILD afterwards to allow for other variables that use $pkgver | |
808 | update_pkgver() { | |
809 | newpkgver=$(run_function_safe pkgver) | |
810 | ||
811 | if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then | |
812 | if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then | |
813 | @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE" | |
814 | @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE" | |
815 | source "$BUILDFILE" | |
fe0586e2 WG |
816 | local fullver=$(get_full_version) |
817 | msg "$(gettext "Updated version: %s")" "$pkgbase $fullver" | |
888020de AM |
818 | else |
819 | warning "$(gettext "%s is not writeable -- pkgver will not be updated")" \ | |
820 | "$BUILDFILE" | |
821 | fi | |
822 | fi | |
823 | } | |
824 | ||
e8064144 AM |
825 | # Print 'source not found' error message and exit makepkg |
826 | missing_source_file() { | |
827 | error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")" | |
828 | plain "$(gettext "Aborting...")" | |
829 | exit 1 # $E_MISSING_FILE | |
830 | } | |
831 | ||
b8ab96a2 | 832 | ## |
ccdb2fa8 | 833 | # usage : get_full_version( [$pkgname] ) |
b8ab96a2 DM |
834 | # return : full version spec, including epoch (if necessary), pkgver, pkgrel |
835 | ## | |
836 | get_full_version() { | |
ccdb2fa8 | 837 | if [[ -z $1 ]]; then |
1a919a11 | 838 | if [[ $epoch ]] && (( ! $epoch )); then |
1917c845 | 839 | printf "%s\n" "$pkgver-$pkgrel" |
ccdb2fa8 | 840 | else |
1917c845 | 841 | printf "%s\n" "$epoch:$pkgver-$pkgrel" |
ccdb2fa8 | 842 | fi |
b8ab96a2 | 843 | else |
ccdb2fa8 AM |
844 | for i in pkgver pkgrel epoch; do |
845 | local indirect="${i}_override" | |
846 | eval $(declare -f package_$1 | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p") | |
2ca27ab3 | 847 | [[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\" |
ccdb2fa8 AM |
848 | done |
849 | if (( ! $epoch_override )); then | |
1917c845 | 850 | printf "%s\n" "$pkgver_override-$pkgrel_override" |
ccdb2fa8 | 851 | else |
1917c845 | 852 | printf "%s\n" "$epoch_override:$pkgver_override-$pkgrel_override" |
ccdb2fa8 | 853 | fi |
b8ab96a2 DM |
854 | fi |
855 | } | |
856 | ||
d38a1c02 AM |
857 | ## |
858 | # usage : get_pkg_arch( [$pkgname] ) | |
859 | # return : architecture of the package | |
860 | ## | |
861 | get_pkg_arch() { | |
862 | if [[ -z $1 ]]; then | |
863 | if [[ $arch = "any" ]]; then | |
864 | printf "%s\n" "any" | |
865 | else | |
866 | printf "%s\n" "$CARCH" | |
867 | fi | |
868 | else | |
869 | local arch_override | |
870 | eval $(declare -f package_$1 | sed -n 's/\(^[[:space:]]*arch=\)/arch_override=/p') | |
9d9c12e4 | 871 | (( ${#arch_override[@]} == 0 )) && arch_override=("${arch[@]}") |
d38a1c02 AM |
872 | if [[ $arch_override = "any" ]]; then |
873 | printf "%s\n" "any" | |
874 | else | |
875 | printf "%s\n" "$CARCH" | |
876 | fi | |
877 | fi | |
878 | } | |
879 | ||
2fb2613e AF |
880 | ## |
881 | # Checks to see if options are present in makepkg.conf or PKGBUILD; | |
882 | # PKGBUILD options always take precedence. | |
883 | # | |
9dd42dc0 DR |
884 | # usage : check_option( $option, $expected_val ) |
885 | # return : 0 - matches expected | |
886 | # 1 - does not match expected | |
887 | # 127 - not found | |
2fb2613e | 888 | ## |
d0fb27ce | 889 | check_option() { |
9dd42dc0 DR |
890 | in_opt_array "$1" ${options[@]} |
891 | case $? in | |
892 | 0) # assert enabled | |
893 | [[ $2 = y ]] | |
894 | return ;; | |
895 | 1) # assert disabled | |
896 | [[ $2 = n ]] | |
897 | return | |
898 | esac | |
2fb2613e | 899 | |
2fb2613e | 900 | # fall back to makepkg.conf options |
9dd42dc0 DR |
901 | in_opt_array "$1" ${OPTIONS[@]} |
902 | case $? in | |
903 | 0) # assert enabled | |
904 | [[ $2 = y ]] | |
905 | return ;; | |
906 | 1) # assert disabled | |
907 | [[ $2 = n ]] | |
908 | return | |
909 | esac | |
2fb2613e | 910 | |
9dd42dc0 DR |
911 | # not found |
912 | return 127 | |
b1cc72eb DM |
913 | } |
914 | ||
2fb2613e AF |
915 | |
916 | ## | |
917 | # Check if option is present in BUILDENV | |
918 | # | |
9dd42dc0 DR |
919 | # usage : check_buildenv( $option, $expected_val ) |
920 | # return : 0 - matches expected | |
921 | # 1 - does not match expected | |
922 | # 127 - not found | |
2fb2613e | 923 | ## |
b1cc72eb | 924 | check_buildenv() { |
452bf71c | 925 | in_opt_array "$1" ${BUILDENV[@]} |
9dd42dc0 DR |
926 | case $? in |
927 | 0) # assert enabled | |
928 | [[ $2 = "y" ]] | |
929 | return ;; | |
930 | 1) # assert disabled | |
931 | [[ $2 = "n" ]] | |
932 | return ;; | |
933 | esac | |
934 | ||
935 | # not found | |
936 | return 127 | |
2fb2613e AF |
937 | } |
938 | ||
939 | ||
940 | ## | |
941 | # usage : in_opt_array( $needle, $haystack ) | |
9dd42dc0 DR |
942 | # return : 0 - enabled |
943 | # 1 - disabled | |
944 | # 127 - not found | |
2fb2613e AF |
945 | ## |
946 | in_opt_array() { | |
a164c840 | 947 | local needle=$1; shift |
2fb2613e | 948 | |
fbf96203 AM |
949 | local i opt |
950 | for (( i = $#; i > 0; i-- )); do | |
951 | opt=${!i} | |
d11192c7 | 952 | if [[ $opt = "$needle" ]]; then |
9dd42dc0 DR |
953 | # enabled |
954 | return 0 | |
966c8158 | 955 | elif [[ $opt = "!$needle" ]]; then |
9dd42dc0 DR |
956 | # disabled |
957 | return 1 | |
d0fb27ce JV |
958 | fi |
959 | done | |
2fb2613e | 960 | |
9dd42dc0 DR |
961 | # not found |
962 | return 127 | |
d0fb27ce JV |
963 | } |
964 | ||
2fb2613e AF |
965 | |
966 | ## | |
967 | # usage : in_array( $needle, $haystack ) | |
968 | # return : 0 - found | |
969 | # 1 - not found | |
970 | ## | |
4470e5ce | 971 | in_array() { |
2fb2613e | 972 | local needle=$1; shift |
2fb2613e AF |
973 | local item |
974 | for item in "$@"; do | |
d11192c7 | 975 | [[ $item = "$needle" ]] && return 0 # Found |
74e347f0 | 976 | done |
2fb2613e | 977 | return 1 # Not Found |
4470e5ce AG |
978 | } |
979 | ||
5f0df423 | 980 | source_has_signatures() { |
94f61c5b WH |
981 | local file |
982 | for file in "${source[@]}"; do | |
5f0df423 | 983 | if [[ ${file%%::*} = *.@(sig?(n)|asc) ]]; then |
94f61c5b WH |
984 | return 0 |
985 | fi | |
986 | done | |
987 | return 1 | |
988 | } | |
989 | ||
82443e00 | 990 | run_pacman() { |
622326bb | 991 | local cmd |
edd4276b | 992 | if [[ ! $1 = -@(T|Qq) ]]; then |
3531533c | 993 | cmd=("$PACMAN_PATH" $PACMAN_OPTS "$@") |
edd4276b | 994 | else |
3531533c | 995 | cmd=("$PACMAN_PATH" "$@") |
edd4276b | 996 | fi |
0e79802c | 997 | if (( ! ASROOT )) && [[ ! $1 = -@(T|Qq) ]]; then |
c02556e2 | 998 | if type -p sudo >/dev/null; then |
8d26df5e | 999 | cmd=(sudo "${cmd[@]}") |
590606a5 | 1000 | else |
8d26df5e | 1001 | cmd=(su root -c "$(printf '%q ' "${cmd[@]}")") |
590606a5 | 1002 | fi |
82443e00 | 1003 | fi |
8d26df5e | 1004 | "${cmd[@]}" |
82443e00 CS |
1005 | } |
1006 | ||
214f264b | 1007 | check_deps() { |
07a9effd | 1008 | (( $# > 0 )) || return 0 |
fe25662d | 1009 | |
82443e00 | 1010 | local ret=0 |
1a9db4ca | 1011 | local pmout |
dca10b06 DR |
1012 | pmout=$(run_pacman -T "$@") |
1013 | ret=$? | |
3ceef977 | 1014 | |
966c8158 | 1015 | if (( ret == 127 )); then #unresolved deps |
1917c845 | 1016 | printf "%s\n" "$pmout" |
966c8158 | 1017 | elif (( ret )); then |
66c6d288 | 1018 | error "$(gettext "'%s' returned a fatal error (%i): %s")" "$PACMAN" "$ret" "$pmout" |
579533d1 | 1019 | return "$ret" |
d04baaba | 1020 | fi |
d04baaba JV |
1021 | } |
1022 | ||
68200676 | 1023 | handle_deps() { |
85fbf528 AF |
1024 | local R_DEPS_SATISFIED=0 |
1025 | local R_DEPS_MISSING=1 | |
1026 | ||
966c8158 | 1027 | (( $# == 0 )) && return $R_DEPS_SATISFIED |
d04baaba | 1028 | |
85fbf528 | 1029 | local deplist="$*" |
62d0a005 | 1030 | |
966c8158 | 1031 | if (( ! DEP_BIN )); then |
85fbf528 | 1032 | return $R_DEPS_MISSING |
85fbf528 AF |
1033 | fi |
1034 | ||
966c8158 | 1035 | if (( DEP_BIN )); then |
85fbf528 AF |
1036 | # install missing deps from binary packages (using pacman -S) |
1037 | msg "$(gettext "Installing missing dependencies...")" | |
85fbf528 | 1038 | |
82443e00 | 1039 | if ! run_pacman -S --asdeps $deplist; then |
66c6d288 | 1040 | error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN" |
85fbf528 AF |
1041 | exit 1 # TODO: error code |
1042 | fi | |
d04baaba | 1043 | fi |
42a6acf7 | 1044 | |
0e0a8461 | 1045 | # we might need the new system environment |
31091963 AM |
1046 | # save our shell options and turn off extglob |
1047 | local shellopts=$(shopt -p) | |
1048 | shopt -u extglob | |
0e0a8461 | 1049 | source /etc/profile &>/dev/null |
31091963 | 1050 | eval "$shellopts" |
4470e5ce | 1051 | |
85fbf528 | 1052 | return $R_DEPS_SATISFIED |
d04baaba JV |
1053 | } |
1054 | ||
214f264b | 1055 | resolve_deps() { |
85fbf528 | 1056 | local R_DEPS_SATISFIED=0 |
3b1e6762 | 1057 | local R_DEPS_MISSING=1 |
85fbf528 | 1058 | |
579533d1 A |
1059 | # deplist cannot be declared like this: local deplist=$(foo) |
1060 | # Otherwise, the return value will depend on the assignment. | |
1061 | local deplist | |
1062 | deplist="$(set +E; check_deps $*)" || exit 1 | |
1063 | [[ -z $deplist ]] && return $R_DEPS_SATISFIED | |
85fbf528 | 1064 | |
68200676 | 1065 | if handle_deps $deplist; then |
85fbf528 | 1066 | # check deps again to make sure they were resolved |
579533d1 | 1067 | deplist="$(set +E; check_deps $*)" || exit 1 |
966c8158 | 1068 | [[ -z $deplist ]] && return $R_DEPS_SATISFIED |
7e9fdfd4 AG |
1069 | fi |
1070 | ||
3536975b | 1071 | msg "$(gettext "Missing dependencies:")" |
85fbf528 AF |
1072 | local dep |
1073 | for dep in $deplist; do | |
1074 | msg2 "$dep" | |
1075 | done | |
1076 | ||
1077 | return $R_DEPS_MISSING | |
7e9fdfd4 AG |
1078 | } |
1079 | ||
214f264b | 1080 | remove_deps() { |
966c8158 | 1081 | (( ! RMDEPS )) && return |
85fbf528 | 1082 | |
ccbef232 AM |
1083 | # check for packages removed during dependency install (e.g. due to conflicts) |
1084 | # removing all installed packages is risky in this case | |
a521cea9 | 1085 | if [[ -n $(grep -xvFf <(printf '%s\n' "${current_packagelist[@]}") \ |
df47136b | 1086 | <(printf '%s\n' "${original_packagelist[@]}") || true) ]]; then |
a521cea9 DR |
1087 | warning "$(gettext "Failed to remove installed dependencies.")" |
1088 | return 0 | |
ccbef232 | 1089 | fi |
b882f463 | 1090 | |
a521cea9 | 1091 | local deplist |
df47136b AM |
1092 | deplist=($(grep -xvFf <(printf "%s\n" "${original_pkglist[@]}") \ |
1093 | <(printf "%s\n" "${current_pkglist[@]}") || true)) | |
edd81f3e | 1094 | if [[ -z $deplist ]]; then |
a521cea9 DR |
1095 | return |
1096 | fi | |
9577c07d | 1097 | |
ccbef232 | 1098 | msg "Removing installed dependencies..." |
82443e00 | 1099 | # exit cleanly on failure to remove deps as package has been built successfully |
ccbef232 | 1100 | if ! run_pacman -Rn ${deplist[@]}; then |
9577c07d AM |
1101 | warning "$(gettext "Failed to remove installed dependencies.")" |
1102 | return 0 | |
31e05618 AG |
1103 | fi |
1104 | } | |
1105 | ||
79987c92 XC |
1106 | get_integlist() { |
1107 | local integ | |
1108 | local integlist=() | |
1109 | ||
1110 | for integ in md5 sha1 sha256 sha384 sha512; do | |
1111 | local integrity_sums=($(eval echo "\${${integ}sums[@]}")) | |
1112 | if [[ -n "$integrity_sums" ]]; then | |
1113 | integlist=(${integlist[@]} $integ) | |
1114 | fi | |
1115 | done | |
1116 | ||
1117 | if (( ${#integlist[@]} > 0 )); then | |
1917c845 | 1118 | printf "%s\n" "${integlist[@]}" |
79987c92 | 1119 | else |
1917c845 | 1120 | printf "%s\n" "${INTEGRITY_CHECK[@]}" |
79987c92 XC |
1121 | fi |
1122 | } | |
1123 | ||
e19d7da4 AF |
1124 | generate_checksums() { |
1125 | msg "$(gettext "Generating checksums for source files...")" | |
e19d7da4 | 1126 | |
95145d4c | 1127 | if ! type -p openssl >/dev/null; then |
4bdb868a | 1128 | error "$(gettext "Cannot find the %s binary required for generating sourcefile checksums.")" "openssl" |
496b687c DM |
1129 | exit 1 # $E_MISSING_PROGRAM |
1130 | fi | |
1131 | ||
79987c92 XC |
1132 | local integlist |
1133 | if (( $# == 0 )); then | |
1134 | integlist=$(get_integlist) | |
1135 | else | |
1136 | integlist=$@ | |
1137 | fi | |
1138 | ||
e19d7da4 | 1139 | local integ |
79987c92 | 1140 | for integ in ${integlist[@]}; do |
e19d7da4 AF |
1141 | case "$integ" in |
1142 | md5|sha1|sha256|sha384|sha512) : ;; | |
1143 | *) | |
1144 | error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ" | |
1145 | exit 1;; # $E_CONFIG_ERROR | |
1146 | esac | |
1147 | ||
e19d7da4 AF |
1148 | local ct=0 |
1149 | local numsrc=${#source[@]} | |
1917c845 | 1150 | printf "%s" "${integ}sums=(" |
e19d7da4 | 1151 | |
6c8f8170 | 1152 | local i |
e19d7da4 | 1153 | local indent='' |
6c8f8170 | 1154 | for (( i = 0; i < ${#integ} + 6; i++ )); do |
e19d7da4 | 1155 | indent="$indent " |
e19d7da4 AF |
1156 | done |
1157 | ||
1158 | local netfile | |
b9445c12 | 1159 | for netfile in "${source[@]}"; do |
682c9af8 AM |
1160 | local proto sum |
1161 | proto="$(get_protocol "$netfile")" | |
1162 | ||
1163 | case $proto in | |
3b02f80d | 1164 | bzr*|git*|hg*|svn*) |
682c9af8 AM |
1165 | sum="SKIP" |
1166 | ;; | |
1167 | *) | |
93148d08 AM |
1168 | if [[ ! $netfile = *.@(sig?(n)|asc) ]]; then |
1169 | local file | |
1170 | file="$(get_filepath "$netfile")" || missing_source_file "$netfile" | |
1171 | sum="$(openssl dgst -${integ} "$file")" | |
1172 | sum=${sum##* } | |
1173 | else | |
1174 | sum="SKIP" | |
1175 | fi | |
682c9af8 AM |
1176 | ;; |
1177 | esac | |
1178 | ||
1917c845 AM |
1179 | (( ct )) && printf "%s" "$indent" |
1180 | printf "%s" "'$sum'" | |
e19d7da4 | 1181 | ct=$(($ct+1)) |
966c8158 | 1182 | (( $ct < $numsrc )) && echo |
e19d7da4 AF |
1183 | done |
1184 | ||
1185 | echo ")" | |
1186 | done | |
e19d7da4 AF |
1187 | } |
1188 | ||
1189 | check_checksums() { | |
2b3405e0 | 1190 | (( SKIPCHECKSUMS )) && return 0 |
966c8158 | 1191 | (( ! ${#source[@]} )) && return 0 |
687f04ab | 1192 | |
e3a06961 | 1193 | local correlation=0 |
496b687c DM |
1194 | local integ required |
1195 | for integ in md5 sha1 sha256 sha384 sha512; do | |
7ff5a917 | 1196 | local integrity_sums=($(eval echo "\${${integ}sums[@]}")) |
966c8158 | 1197 | if (( ${#integrity_sums[@]} == ${#source[@]} )); then |
76fd8545 | 1198 | msg "$(gettext "Validating source files with %s...")" "${integ}sums" |
e3a06961 | 1199 | correlation=1 |
e19d7da4 AF |
1200 | local errors=0 |
1201 | local idx=0 | |
1202 | local file | |
1203 | for file in "${source[@]}"; do | |
52d184da | 1204 | local found=1 |
d6f62ba2 | 1205 | file="$(get_filename "$file")" |
1917c845 | 1206 | printf "%s" " $file ... " >&2 |
e19d7da4 | 1207 | |
57e06394 AM |
1208 | if [[ ${integrity_sums[$idx]} = 'SKIP' ]]; then |
1209 | echo "$(gettext "Skipped")" >&2 | |
1210 | idx=$((idx + 1)) | |
1211 | continue | |
1212 | fi | |
1213 | ||
5cddcc90 | 1214 | if ! file="$(get_filepath "$file")"; then |
9e9835f4 | 1215 | printf -- "$(gettext "NOT FOUND")\n" >&2 |
5cddcc90 CS |
1216 | errors=1 |
1217 | found=0 | |
142225fd AF |
1218 | fi |
1219 | ||
966c8158 | 1220 | if (( $found )) ; then |
57e06394 AM |
1221 | local expectedsum="${integrity_sums[idx],,}" |
1222 | local realsum="$(openssl dgst -${integ} "$file")" | |
1223 | realsum="${realsum##* }" | |
1224 | if [[ $expectedsum = "$realsum" ]]; then | |
1225 | printf -- "$(gettext "Passed")\n" >&2 | |
52d184da | 1226 | else |
57e06394 AM |
1227 | printf -- "$(gettext "FAILED")\n" >&2 |
1228 | errors=1 | |
52d184da | 1229 | fi |
e19d7da4 | 1230 | fi |
47ee89ad AF |
1231 | |
1232 | idx=$((idx + 1)) | |
e19d7da4 AF |
1233 | done |
1234 | ||
966c8158 | 1235 | if (( errors )); then |
e19d7da4 AF |
1236 | error "$(gettext "One or more files did not pass the validity check!")" |
1237 | exit 1 # TODO: error code | |
1238 | fi | |
966c8158 | 1239 | elif (( ${#integrity_sums[@]} )); then |
e3a06961 AS |
1240 | error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ" |
1241 | exit 1 # TODO: error code | |
e19d7da4 AF |
1242 | fi |
1243 | done | |
e3a06961 | 1244 | |
966c8158 | 1245 | if (( ! correlation )); then |
2ce444ee AM |
1246 | error "$(gettext "Integrity checks are missing.")" |
1247 | exit 1 # TODO: error code | |
e3a06961 | 1248 | fi |
e19d7da4 AF |
1249 | } |
1250 | ||
94f61c5b WH |
1251 | check_pgpsigs() { |
1252 | (( SKIPPGPCHECK )) && return 0 | |
1253 | ! source_has_signatures && return 0 | |
1254 | ||
1255 | msg "$(gettext "Verifying source file signatures with %s...")" "gpg" | |
1256 | ||
3d9f961d | 1257 | local file pubkey |
94f61c5b WH |
1258 | local warning=0 |
1259 | local errors=0 | |
1260 | local statusfile=$(mktemp) | |
1261 | ||
1262 | for file in "${source[@]}"; do | |
1263 | file="$(get_filename "$file")" | |
e7b56f48 | 1264 | if [[ ! $file = *.@(sig?(n)|asc) ]]; then |
94f61c5b WH |
1265 | continue |
1266 | fi | |
1267 | ||
3d9f961d | 1268 | printf " %s ... " "${file%.*}" >&2 |
94f61c5b WH |
1269 | |
1270 | if ! file="$(get_filepath "$file")"; then | |
3d9f961d | 1271 | printf '%s\n' "$(gettext "SIGNATURE NOT FOUND")" >&2 |
94f61c5b WH |
1272 | errors=1 |
1273 | continue | |
1274 | fi | |
1275 | ||
1276 | if ! sourcefile="$(get_filepath "${file%.*}")"; then | |
3d9f961d | 1277 | printf '%s\n' "$(gettext "SOURCE FILE NOT FOUND")" >&2 |
94f61c5b WH |
1278 | errors=1 |
1279 | continue | |
1280 | fi | |
1281 | ||
1282 | if ! gpg --quiet --batch --status-file "$statusfile" --verify "$file" "$sourcefile" 2> /dev/null; then | |
3d9f961d DR |
1283 | printf '%s' "$(gettext "FAILED")" >&2 |
1284 | if ! pubkey=$(awk '/NO_PUBKEY/ { print $3; exit 1; }' "$statusfile"); then | |
1285 | printf ' (%s)' "$(gettext "unknown public key") $pubkey" >&2 | |
94f61c5b WH |
1286 | warnings=1 |
1287 | else | |
94f61c5b WH |
1288 | errors=1 |
1289 | fi | |
3d9f961d | 1290 | printf '\n' >&2 |
94f61c5b | 1291 | else |
3d9f961d | 1292 | if grep -q "REVKEYSIG" "$statusfile"; then |
d1e04c1b | 1293 | printf '%s (%s)' "$(gettext "FAILED")" "$(gettext "the key has been revoked.")" >&2 |
94f61c5b | 1294 | errors=1 |
94f61c5b | 1295 | else |
3d9f961d DR |
1296 | printf '%s' "$(gettext "Passed")" >&2 |
1297 | if grep -q "EXPSIG" "$statusfile"; then | |
d1e04c1b | 1298 | printf ' (%s)' "$(gettext "WARNING:") $(gettext "the signature has expired.")" >&2 |
3d9f961d DR |
1299 | warnings=1 |
1300 | elif grep -q "EXPKEYSIG" "$statusfile"; then | |
d1e04c1b | 1301 | printf ' (%s)' "$(gettext "WARNING:") $(gettext "the key has expired.")" >&2 |
3d9f961d DR |
1302 | warnings=1 |
1303 | fi | |
94f61c5b | 1304 | fi |
d1e04c1b | 1305 | printf '\n' >&2 |
94f61c5b WH |
1306 | fi |
1307 | done | |
1308 | ||
1309 | rm -f "$statusfile" | |
1310 | ||
1311 | if (( errors )); then | |
1312 | error "$(gettext "One or more PGP signatures could not be verified!")" | |
1313 | exit 1 | |
1314 | fi | |
1315 | ||
1316 | if (( warnings )); then | |
1317 | warning "$(gettext "Warnings have occurred while verifying the signatures.")" | |
1318 | plain "$(gettext "Please make sure you really trust them.")" | |
1319 | fi | |
1320 | } | |
1321 | ||
49d9426b AM |
1322 | check_source_integrity() { |
1323 | if (( SKIPCHECKSUMS && SKIPPGPCHECK )); then | |
1324 | warning "$(gettext "Skipping all source file integrity checks.")" | |
1325 | elif (( SKIPCHECKSUMS )); then | |
1326 | warning "$(gettext "Skipping verification of source file checksums.")" | |
1327 | check_pgpsigs | |
1328 | elif (( SKIPPGPCHECK )); then | |
1329 | warning "$(gettext "Skipping verification of source file PGP signatures.")" | |
1330 | check_checksums | |
1331 | else | |
1332 | check_checksums | |
1333 | check_pgpsigs | |
1334 | fi | |
1335 | } | |
1336 | ||
e19d7da4 | 1337 | extract_sources() { |
3536975b | 1338 | msg "$(gettext "Extracting sources...")" |
e19d7da4 AF |
1339 | local netfile |
1340 | for netfile in "${source[@]}"; do | |
1a9db4ca | 1341 | local file=$(get_filename "$netfile") |
297cd789 | 1342 | if in_array "$file" "${noextract[@]}"; then |
e19d7da4 AF |
1343 | #skip source files in the noextract=() array |
1344 | # these are marked explicitly to NOT be extracted | |
1345 | continue | |
1346 | fi | |
fcdaa46b WG |
1347 | local proto=$(get_protocol "$netfile") |
1348 | case "$proto" in | |
1349 | bzr*) | |
1350 | extract_bzr "$netfile" | |
1351 | ;; | |
1352 | git*) | |
1353 | extract_git "$netfile" | |
1354 | ;; | |
1355 | hg*) | |
1356 | extract_hg "$netfile" | |
1357 | ;; | |
1358 | svn*) | |
1359 | extract_svn "$netfile" | |
1360 | ;; | |
3b1e6762 | 1361 | *) |
fcdaa46b WG |
1362 | extract_file "$file" |
1363 | ;; | |
e19d7da4 | 1364 | esac |
e19d7da4 AF |
1365 | done |
1366 | ||
fcdaa46b WG |
1367 | if (( PKGVERFUNC )); then |
1368 | update_pkgver | |
1369 | check_pkgver || exit 1 | |
1370 | check_build_status | |
e19d7da4 AF |
1371 | fi |
1372 | } | |
1373 | ||
cb072658 | 1374 | error_function() { |
966c8158 | 1375 | if [[ -p $logpipe ]]; then |
545eac14 HG |
1376 | rm "$logpipe" |
1377 | fi | |
1378 | # first exit all subshells, then print the error | |
966c8158 | 1379 | if (( ! BASH_SUBSHELL )); then |
c11bf581 | 1380 | error "$(gettext "A failure occurred in %s().")" "$1" |
76fd8545 | 1381 | plain "$(gettext "Aborting...")" |
eda7e5fc | 1382 | fi |
545eac14 | 1383 | exit 2 # $E_BUILD_FAILED |
eda7e5fc AF |
1384 | } |
1385 | ||
92321449 AM |
1386 | cd_safe() { |
1387 | if ! cd "$1"; then | |
1388 | error "$(gettext "Failed to change to directory %s")" "$1" | |
1389 | plain "$(gettext "Aborting...")" | |
1390 | exit 1 | |
1391 | fi | |
1392 | } | |
1393 | ||
8fe67919 DR |
1394 | source_safe() { |
1395 | shopt -u extglob | |
1396 | if ! source "$@"; then | |
1397 | error "$(gettext "Failed to source %s")" "$1" | |
1398 | exit 1 | |
1399 | fi | |
1400 | shopt -s extglob | |
1401 | } | |
1402 | ||
dca10b06 DR |
1403 | run_function_safe() { |
1404 | local restoretrap | |
1405 | ||
1406 | set -e | |
1407 | set -E | |
1408 | ||
1409 | restoretrap=$(trap -p ERR) | |
1410 | trap 'error_function $pkgfunc' ERR | |
1411 | ||
1412 | run_function "$1" | |
1413 | ||
1414 | eval $restoretrap | |
1415 | ||
1416 | set +E | |
1417 | set +e | |
1418 | } | |
1419 | ||
cb072658 | 1420 | run_function() { |
966c8158 | 1421 | if [[ -z $1 ]]; then |
cb072658 | 1422 | return 1 |
21b8a541 | 1423 | fi |
1a9db4ca | 1424 | local pkgfunc="$1" |
21b8a541 | 1425 | |
2052f29c | 1426 | # clear user-specified buildflags if requested |
9dd42dc0 | 1427 | if check_option "buildflags" "n"; then |
8abef73b | 1428 | unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS |
2052f29c AM |
1429 | fi |
1430 | ||
6c22ef2c AM |
1431 | if check_option "debug" "y"; then |
1432 | CFLAGS+=" $DEBUG_CFLAGS" | |
1433 | CXXFLAGS+=" $DEBUG_CXXFLAGS" | |
1434 | fi | |
1435 | ||
08034ceb | 1436 | # clear user-specified makeflags if requested |
9dd42dc0 | 1437 | if check_option "makeflags" "n"; then |
29ad9e0a | 1438 | unset MAKEFLAGS |
08034ceb AM |
1439 | fi |
1440 | ||
21b8a541 | 1441 | msg "$(gettext "Starting %s()...")" "$pkgfunc" |
92321449 | 1442 | cd_safe "$srcdir" |
08034ceb AM |
1443 | |
1444 | # ensure all necessary build variables are exported | |
8abef73b | 1445 | export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST |
cb072658 XC |
1446 | # save our shell options so pkgfunc() can't override what we need |
1447 | local shellopts=$(shopt -p) | |
08034ceb AM |
1448 | |
1449 | local ret=0 | |
966c8158 | 1450 | if (( LOGGING )); then |
ccdb2fa8 | 1451 | local fullver=$(get_full_version) |
0c74ffd6 | 1452 | local BUILDLOG="$LOGDEST/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log" |
966c8158 | 1453 | if [[ -f $BUILDLOG ]]; then |
08034ceb AM |
1454 | local i=1 |
1455 | while true; do | |
966c8158 | 1456 | if [[ -f $BUILDLOG.$i ]]; then |
08034ceb AM |
1457 | i=$(($i +1)) |
1458 | else | |
1459 | break | |
1460 | fi | |
1461 | done | |
1462 | mv "$BUILDLOG" "$BUILDLOG.$i" | |
1463 | fi | |
1464 | ||
1e51b81c | 1465 | # ensure overridden package variables survive tee with split packages |
8335e169 | 1466 | logpipe=$(mktemp -u "$LOGDEST/logpipe.XXXXXXXX") |
fb79d581 | 1467 | mkfifo "$logpipe" |
708ce148 | 1468 | tee "$BUILDLOG" < "$logpipe" & |
14474a32 JS |
1469 | local teepid=$! |
1470 | ||
14474a32 | 1471 | $pkgfunc &>"$logpipe" |
14474a32 JS |
1472 | |
1473 | wait $teepid | |
708ce148 | 1474 | rm "$logpipe" |
08034ceb | 1475 | else |
c5a4b355 | 1476 | "$pkgfunc" |
08034ceb | 1477 | fi |
cb072658 XC |
1478 | # reset our shell options |
1479 | eval "$shellopts" | |
1480 | } | |
1481 | ||
065b7f86 E |
1482 | run_prepare() { |
1483 | run_function_safe "prepare" | |
1484 | } | |
1485 | ||
cb072658 XC |
1486 | run_build() { |
1487 | # use distcc if it is requested (check buildenv and PKGBUILD opts) | |
1b08e268 | 1488 | if check_buildenv "distcc" "y" && ! check_option "distcc" "n"; then |
966c8158 | 1489 | [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH" |
cb072658 | 1490 | export DISTCC_HOSTS |
cb072658 XC |
1491 | fi |
1492 | ||
1493 | # use ccache if it is requested (check buildenv and PKGBUILD opts) | |
9dd42dc0 | 1494 | if check_buildenv "ccache" "y" && ! check_option "ccache" "n"; then |
966c8158 | 1495 | [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH" |
cb072658 XC |
1496 | fi |
1497 | ||
dca10b06 | 1498 | run_function_safe "build" |
cb072658 XC |
1499 | } |
1500 | ||
0c29eb43 | 1501 | run_check() { |
dca10b06 | 1502 | run_function_safe "check" |
0c29eb43 AM |
1503 | } |
1504 | ||
cb072658 | 1505 | run_package() { |
1a9db4ca | 1506 | local pkgfunc |
966c8158 | 1507 | if [[ -z $1 ]]; then |
cb072658 XC |
1508 | pkgfunc="package" |
1509 | else | |
1510 | pkgfunc="package_$1" | |
1511 | fi | |
1512 | ||
dca10b06 | 1513 | run_function_safe "$pkgfunc" |
08034ceb AM |
1514 | } |
1515 | ||
bd4ff4a3 AM |
1516 | build_id() { |
1517 | LANG=C readelf -n $1 | sed -n '/Build ID/ { s/.*: //p; q; }' | |
1518 | } | |
1519 | ||
6be96e76 AM |
1520 | strip_file() { |
1521 | local binary=$1; shift | |
bd4ff4a3 AM |
1522 | |
1523 | if check_option "debug" "y"; then | |
1524 | local bid=$(build_id "$binary") | |
1525 | ||
1526 | # has this file already been stripped | |
1527 | if [[ -n "$bid" ]]; then | |
dbbe3e7c | 1528 | if [[ -f "$dbgdir/.build_id/${bid:0:2}/${bid:2}.debug" ]]; then |
bd4ff4a3 AM |
1529 | return |
1530 | fi | |
dbbe3e7c | 1531 | elif [[ -f "$dbgdir/$binary.debug" ]]; then |
bd4ff4a3 AM |
1532 | return |
1533 | fi | |
1534 | ||
dbbe3e7c AM |
1535 | mkdir -p "$dbgdir/${binary%/*}" |
1536 | objcopy --only-keep-debug "$binary" "$dbgdir/$binary.debug" | |
1537 | objcopy --add-gnu-debuglink="$dbgdir/${binary#/}.debug" "$binary" | |
bd4ff4a3 AM |
1538 | |
1539 | # create any needed hardlinks | |
1540 | while read -d '' file ; do | |
dbbe3e7c AM |
1541 | if [[ "${binary}" -ef "${file}" && ! -f "$dbgdir/${file}.debug" ]]; then |
1542 | mkdir -p "$dbgdir/${file%/*}" | |
1543 | ln "$dbgdir/${binary}.debug" "$dbgdir/${file}.debug" | |
bd4ff4a3 AM |
1544 | fi |
1545 | done < <(find . -type f -perm -u+w -print0 2>/dev/null) | |
1546 | ||
1547 | if [[ -n "$bid" ]]; then | |
1548 | local target | |
dbbe3e7c | 1549 | mkdir -p "$dbgdir/.build_id/${bid:0:2}" |
bd4ff4a3 AM |
1550 | |
1551 | target="../../../../../${binary#./}" | |
1552 | target="${target/..\/..\/usr\/lib\/}" | |
1553 | target="${target/..\/usr\/}" | |
dbbe3e7c | 1554 | ln -s "$target" "$dbgdir/.build_id/${bid:0:2}/${bid:2}" |
bd4ff4a3 AM |
1555 | |
1556 | target="../../${binary#./}.debug" | |
dbbe3e7c | 1557 | ln -s "$target" "$dbgdir/.build_id/${bid:0:2}/${bid:2}.debug" |
bd4ff4a3 AM |
1558 | fi |
1559 | fi | |
1560 | ||
6be96e76 AM |
1561 | strip $@ "$binary" |
1562 | } | |
1563 | ||
e2f42947 | 1564 | tidy_install() { |
92321449 | 1565 | cd_safe "$pkgdir" |
53f2dcaa | 1566 | msg "$(gettext "Tidying install...")" |
9b85864e | 1567 | |
9dd42dc0 | 1568 | if check_option "docs" "n" && [[ -n ${DOC_DIRS[*]} ]]; then |
7865fb9a | 1569 | msg2 "$(gettext "Removing doc files...")" |
44de3183 | 1570 | rm -rf -- ${DOC_DIRS[@]} |
e2f42947 AF |
1571 | fi |
1572 | ||
9dd42dc0 | 1573 | if check_option "purge" "y" && [[ -n ${PURGE_TARGETS[*]} ]]; then |
700a5374 | 1574 | msg2 "$(gettext "Purging unwanted files...")" |
9a7f6831 AM |
1575 | local pt |
1576 | for pt in "${PURGE_TARGETS[@]}"; do | |
d11192c7 | 1577 | if [[ ${pt} = "${pt//\/}" ]]; then |
6831a5f4 | 1578 | find . ! -type d -name "${pt}" -exec rm -f -- '{}' + |
9a7f6831 AM |
1579 | else |
1580 | rm -f ${pt} | |
1581 | fi | |
1582 | done | |
1583 | fi | |
1584 | ||
266b3dd7 CE |
1585 | if check_option "libtool" "n"; then |
1586 | msg2 "$(gettext "Removing "%s" files...")" "libtool" | |
6831a5f4 | 1587 | find . ! -type d -name "*.la" -exec rm -f -- '{}' + |
266b3dd7 CE |
1588 | fi |
1589 | ||
a03f5f55 SL |
1590 | if check_option "staticlibs" "n"; then |
1591 | msg2 "$(gettext "Removing "%s" files...")" "static library" | |
1592 | find . ! -type d -name "*.a" -exec rm -f -- '{}' + | |
1593 | fi | |
1594 | ||
266b3dd7 CE |
1595 | if check_option "emptydirs" "n"; then |
1596 | msg2 "$(gettext "Removing empty directories...")" | |
1597 | find . -depth -type d -exec rmdir '{}' + 2>/dev/null | |
1598 | fi | |
1599 | ||
1600 | # check existence of backup files | |
1601 | local file | |
1602 | for file in "${backup[@]}"; do | |
1603 | if [[ ! -f $file ]]; then | |
1604 | warning "$(gettext "%s entry file not in package : %s")" "backup" "$file" | |
1605 | fi | |
1606 | done | |
1607 | ||
1608 | # check for references to the build and package directory | |
8e533b03 | 1609 | if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${srcdir}" ; then |
266b3dd7 CE |
1610 | warning "$(gettext "Package contains reference to %s")" "\$srcdir" |
1611 | fi | |
8e533b03 | 1612 | if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${pkgdirbase}" ; then |
266b3dd7 CE |
1613 | warning "$(gettext "Package contains reference to %s")" "\$pkgdir" |
1614 | fi | |
1615 | ||
9dd42dc0 | 1616 | if check_option "zipman" "y" && [[ -n ${MAN_DIRS[*]} ]]; then |
7865fb9a | 1617 | msg2 "$(gettext "Compressing man and info pages...")" |
19c23475 JH |
1618 | local file files inode link |
1619 | while read -rd ' ' inode; do | |
1620 | read file | |
1621 | find ${MAN_DIRS[@]} -type l 2>/dev/null | | |
1622 | while read link ; do | |
1623 | if [[ "${file}" -ef "${link}" ]] ; then | |
51ed7dff | 1624 | rm -f "$link" "${link}.gz" |
19c23475 JH |
1625 | if [[ ${file%/*} = ${link%/*} ]]; then |
1626 | ln -s -- "${file##*/}.gz" "${link}.gz" | |
1627 | else | |
1628 | ln -s -- "/${file}.gz" "${link}.gz" | |
1629 | fi | |
dae3f9de | 1630 | fi |
19c23475 JH |
1631 | done |
1632 | if [[ -z ${files[$inode]} ]]; then | |
1633 | files[$inode]=$file | |
7a4f76c2 | 1634 | gzip -9 -n -f "$file" |
19c23475 JH |
1635 | else |
1636 | rm -f "$file" | |
1637 | ln "${files[$inode]}.gz" "${file}.gz" | |
1638 | chmod 644 "${file}.gz" | |
9615d823 | 1639 | fi |
19c23475 JH |
1640 | done < <(find ${MAN_DIRS[@]} -type f \! -name "*.gz" \! -name "*.bz2" \ |
1641 | -exec @INODECMD@ '{}' + 2>/dev/null) | |
dae3f9de | 1642 | fi |
e2f42947 | 1643 | |
9dd42dc0 | 1644 | if check_option "strip" "y"; then |
5fe41df8 | 1645 | msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")" |
3c8816f7 AM |
1646 | # make sure library stripping variables are defined to prevent excess stripping |
1647 | [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S" | |
1648 | [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S" | |
bd4ff4a3 AM |
1649 | |
1650 | if check_option "debug" "y"; then | |
dbbe3e7c AM |
1651 | dbgdir="$pkgdir-@DEBUGSUFFIX@/usr/lib/debug" |
1652 | mkdir -p "$dbgdir" | |
bd4ff4a3 AM |
1653 | fi |
1654 | ||
6be96e76 | 1655 | local binary strip_flags |
8a9c666a | 1656 | find . -type f -perm -u+w -print0 2>/dev/null | while read -d '' binary ; do |
52c3f871 | 1657 | case "$(file -bi "$binary")" in |
a8405847 | 1658 | *application/x-sharedlib*) # Libraries (.so) |
6be96e76 | 1659 | strip_flags="$STRIP_SHARED";; |
a8405847 | 1660 | *application/x-archive*) # Libraries (.a) |
6be96e76 | 1661 | strip_flags="$STRIP_STATIC";; |
e2f42947 | 1662 | *application/x-executable*) # Binaries |
6be96e76 AM |
1663 | strip_flags="$STRIP_BINARIES";; |
1664 | *) | |
1665 | continue ;; | |
e2f42947 | 1666 | esac |
6be96e76 | 1667 | strip_file "$binary" ${strip_flags} |
e2f42947 AF |
1668 | done |
1669 | fi | |
1670 | ||
9dd42dc0 | 1671 | if check_option "upx" "y"; then |
b803a33a AM |
1672 | msg2 "$(gettext "Compressing binaries with %s...")" "UPX" |
1673 | local binary | |
1674 | find . -type f -perm -u+w 2>/dev/null | while read binary ; do | |
1675 | if [[ $(file -bi "$binary") = *'application/x-executable'* ]]; then | |
1676 | upx $UPXFLAGS "$binary" &>/dev/null || | |
1677 | warning "$(gettext "Could not compress binary : %s")" "${binary/$pkgdir\//}" | |
1678 | fi | |
1679 | done | |
1680 | fi | |
e2f42947 AF |
1681 | } |
1682 | ||
73d5eb1e | 1683 | find_libdepends() { |
9a76a458 AM |
1684 | local d sodepends; |
1685 | ||
1686 | sodepends=0; | |
1687 | for d in "${depends[@]}"; do | |
1688 | if [[ $d = *.so ]]; then | |
1689 | sodepends=1; | |
1690 | break; | |
1691 | fi | |
1692 | done | |
1693 | ||
1694 | if (( sodepends == 0 )); then | |
1695 | printf '%s\n' "${depends[@]}" | |
1696 | return; | |
1697 | fi | |
1698 | ||
1699 | local libdeps filename soarch sofile soname soversion; | |
1700 | declare -A libdeps; | |
1701 | ||
1702 | while read filename; do | |
73d5eb1e FP |
1703 | # get architecture of the file; if soarch is empty it's not an ELF binary |
1704 | soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p') | |
9a76a458 AM |
1705 | [[ -n "$soarch" ]] || continue |
1706 | ||
73d5eb1e FP |
1707 | # process all libraries needed by the binary |
1708 | for sofile in $(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p') | |
1709 | do | |
1710 | # extract the library name: libfoo.so | |
fbfcd866 | 1711 | soname="${sofile%.so?(+(.+([0-9])))}".so |
73d5eb1e FP |
1712 | # extract the major version: 1 |
1713 | soversion="${sofile##*\.so\.}" | |
9a76a458 AM |
1714 | |
1715 | if [[ ${libdeps[$soname]} ]]; then | |
1716 | if [[ ${libdeps[$soname]} != *${soversion}-${soarch}* ]]; then | |
1717 | libdeps[$soname]+=" ${soversion}-${soarch}" | |
73d5eb1e | 1718 | fi |
9a76a458 AM |
1719 | else |
1720 | libdeps[$soname]="${soversion}-${soarch}" | |
73d5eb1e FP |
1721 | fi |
1722 | done | |
9a76a458 AM |
1723 | done < <(find "$pkgdir" -type f -perm -u+x) |
1724 | ||
1725 | local libdepends v | |
1726 | for d in "${depends[@]}"; do | |
1727 | case "$d" in | |
1728 | *.so) | |
1729 | if [[ ${libdeps[$d]} ]]; then | |
1730 | for v in ${libdeps[$d]}; do | |
1731 | libdepends+=("$d=$v") | |
1732 | done | |
1733 | else | |
1734 | warning "$(gettext "Library listed in %s is not required by any files: %s")" "'depends'" "$d" | |
1735 | libdepends+=("$d") | |
1736 | fi | |
1737 | ;; | |
1738 | *) | |
1739 | libdepends+=("$d") | |
1740 | ;; | |
1741 | esac | |
73d5eb1e | 1742 | done |
9a76a458 AM |
1743 | |
1744 | printf '%s\n' "${libdepends[@]}" | |
73d5eb1e FP |
1745 | } |
1746 | ||
9a76a458 | 1747 | |
79f1a3c4 | 1748 | find_libprovides() { |
9a76a458 | 1749 | local p libprovides missing |
569876f9 | 1750 | for p in "${provides[@]}"; do |
5bbe3429 AM |
1751 | missing=0 |
1752 | case "$p" in | |
1753 | *.so) | |
9d3e59e3 | 1754 | mapfile -t filename < <(find "$pkgdir" -type f -name $p\*) |
5bbe3429 AM |
1755 | if [[ $filename ]]; then |
1756 | # packages may provide multiple versions of the same library | |
569876f9 | 1757 | for fn in "${filename[@]}"; do |
5bbe3429 AM |
1758 | # check if we really have a shared object |
1759 | if LC_ALL=C readelf -h "$fn" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then | |
1760 | # get the string binaries link to (e.g. libfoo.so.1.2 -> libfoo.so.1) | |
1761 | local sofile=$(LC_ALL=C readelf -d "$fn" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p') | |
1762 | if [[ -z "$sofile" ]]; then | |
1763 | warning "$(gettext "Library listed in %s is not versioned: %s")" "'provides'" "$p" | |
ecd6eddf | 1764 | libprovides+=("$p") |
5bbe3429 AM |
1765 | continue |
1766 | fi | |
1767 | ||
1768 | # get the library architecture (32 or 64 bit) | |
1769 | local soarch=$(LC_ALL=C readelf -h "$fn" | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p') | |
1770 | ||
1771 | # extract the library major version | |
1772 | local soversion="${sofile##*\.so\.}" | |
1773 | ||
ecd6eddf | 1774 | libprovides+=("${p}=${soversion}-${soarch}") |
5bbe3429 AM |
1775 | else |
1776 | warning "$(gettext "Library listed in %s is not a shared object: %s")" "'provides'" "$p" | |
ecd6eddf | 1777 | libprovides+=("$p") |
5bbe3429 AM |
1778 | fi |
1779 | done | |
1780 | else | |
ecd6eddf | 1781 | libprovides+=("$p") |
5bbe3429 | 1782 | missing=1 |
79f1a3c4 | 1783 | fi |
5bbe3429 AM |
1784 | ;; |
1785 | *) | |
ecd6eddf | 1786 | libprovides+=("$p") |
5bbe3429 AM |
1787 | ;; |
1788 | esac | |
1789 | ||
1790 | if (( missing )); then | |
3536975b | 1791 | warning "$(gettext "Cannot find library listed in %s: %s")" "'provides'" "$p" |
5bbe3429 | 1792 | fi |
79f1a3c4 | 1793 | done |
5bbe3429 | 1794 | |
87c4fb51 | 1795 | printf '%s\n' "${libprovides[@]}" |
79f1a3c4 FP |
1796 | } |
1797 | ||
225ee71c DR |
1798 | check_license() { |
1799 | # TODO maybe remove this at some point | |
1800 | # warn if license array is not present or empty | |
1801 | if [[ -z $license ]]; then | |
1802 | warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT" | |
1803 | plain "$(gettext "Example for GPL\'ed software: %s.")" "license=('GPL')" | |
1804 | fi | |
1805 | } | |
1806 | ||
01f9ae63 | 1807 | write_pkginfo() { |
47622eef | 1808 | local builddate=$(date -u "+%s") |
966c8158 | 1809 | if [[ -n $PACKAGER ]]; then |
7fb1dc3f | 1810 | local packager="$PACKAGER" |
5b4a4af9 | 1811 | else |
20bad3b8 | 1812 | local packager="Unknown Packager" |
5b4a4af9 | 1813 | fi |
7f258619 | 1814 | |
241d6b88 | 1815 | local size="$(@DUPATH@ @DUFLAGS@)" |
3f1ea8b6 | 1816 | size="$(( ${size%%[^0-9]*} * 1024 ))" |
5b4a4af9 | 1817 | |
4bdb868a | 1818 | msg2 "$(gettext "Generating %s file...")" ".PKGINFO" |
b27886ab WG |
1819 | printf "# Generated by makepkg %s\n" "$makepkg_version" |
1820 | (( INFAKEROOT )) && printf "# using %s\n" "$(fakeroot -v)" | |
1821 | printf "# %s\n" "$(LC_ALL=C date -u)" | |
a5e81f55 | 1822 | printf "pkgname = %s\n" "$pkgname" |
b27886ab WG |
1823 | (( SPLITPKG )) && printf "pkgbase = %s\n" "$pkgbase" |
1824 | printf "pkgver = %s\n" "$(get_full_version)" | |
c8417f33 | 1825 | printf "pkgdesc = %s\n" "${pkgdesc//+([[:space:]])/ }" |
1917c845 AM |
1826 | printf "url = %s\n" "$url" |
1827 | printf "builddate = %s\n" "$builddate" | |
1828 | printf "packager = %s\n" "$packager" | |
1829 | printf "size = %s\n" "$size" | |
d38a1c02 | 1830 | printf "arch = %s\n" "$pkgarch" |
5b4a4af9 | 1831 | |
9d3e59e3 | 1832 | mapfile -t provides < <(find_libprovides) |
9a76a458 AM |
1833 | mapfile -t depends < <(find_libdepends) |
1834 | ||
e253968b AM |
1835 | [[ $license ]] && printf "license = %s\n" "${license[@]}" |
1836 | [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}" | |
1837 | [[ $groups ]] && printf "group = %s\n" "${groups[@]}" | |
1838 | [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}" | |
1839 | [[ $provides ]] && printf "provides = %s\n" "${provides[@]}" | |
1840 | [[ $backup ]] && printf "backup = %s\n" "${backup[@]}" | |
1841 | [[ $depends ]] && printf "depend = %s\n" "${depends[@]}" | |
1842 | [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]//+([[:space:]])/ }" | |
1843 | [[ $makedepends ]] && printf "makedepend = %s\n" "${makedepends[@]}" | |
1844 | [[ $checkdepends ]] && printf "checkdepend = %s\n" "${checkdepends[@]}" | |
79f1a3c4 | 1845 | |
5bbe3429 | 1846 | local it |
774c2527 | 1847 | for it in "${packaging_options[@]}"; do |
9dd42dc0 DR |
1848 | check_option "$it" "y" |
1849 | case $? in | |
1850 | 0) | |
1917c845 | 1851 | printf "makepkgopt = %s\n" "$it" |
9dd42dc0 DR |
1852 | ;; |
1853 | 1) | |
1917c845 | 1854 | printf "makepkgopt = %s\n" "!$it" |
9dd42dc0 DR |
1855 | ;; |
1856 | esac | |
774c2527 | 1857 | done |
5b4a4af9 | 1858 | |
225ee71c | 1859 | check_license |
01f9ae63 LC |
1860 | } |
1861 | ||
1862 | create_package() { | |
966c8158 | 1863 | if [[ ! -d $pkgdir ]]; then |
4bdb868a | 1864 | error "$(gettext "Missing %s directory.")" "pkg/" |
01f9ae63 LC |
1865 | plain "$(gettext "Aborting...")" |
1866 | exit 1 # $E_MISSING_PKGDIR | |
1867 | fi | |
1868 | ||
92321449 | 1869 | cd_safe "$pkgdir" |
a5e81f55 | 1870 | msg "$(gettext "Creating package \"%s\"...")" "$pkgname" |
01f9ae63 | 1871 | |
d38a1c02 | 1872 | pkgarch=$(get_pkg_arch) |
c7e4d10d | 1873 | |
a5e81f55 | 1874 | write_pkginfo > .PKGINFO |
01f9ae63 | 1875 | |
bc311a24 | 1876 | local comp_files=('.PKGINFO') |
7fb1dc3f | 1877 | |
f27fed14 | 1878 | # check for changelog/install files |
541c2470 | 1879 | for i in 'changelog/.CHANGELOG' 'install/.INSTALL'; do |
5f6e8c92 | 1880 | IFS='/' read -r orig dest < <(printf '%s\n' "$i") |
f27fed14 | 1881 | |
541c2470 DR |
1882 | if [[ -n ${!orig} ]]; then |
1883 | msg2 "$(gettext "Adding %s file...")" "$orig" | |
1884 | cp "$startdir/${!orig}" "$dest" | |
f27fed14 | 1885 | chmod 644 "$dest" |
bc311a24 | 1886 | comp_files+=("$dest") |
f27fed14 A |
1887 | fi |
1888 | done | |
5b4a4af9 AF |
1889 | |
1890 | # tar it up | |
ccdb2fa8 | 1891 | local fullver=$(get_full_version) |
a5e81f55 | 1892 | local pkg_file="$PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT}" |
c8beffa7 | 1893 | local ret=0 |
5b4a4af9 | 1894 | |
82e22596 DM |
1895 | [[ -f $pkg_file ]] && rm -f "$pkg_file" |
1896 | [[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig" | |
1897 | ||
9bc799ec XC |
1898 | # when fileglobbing, we want * in an empty directory to expand to |
1899 | # the null string rather than itself | |
1900 | shopt -s nullglob | |
ad3a26c6 AM |
1901 | |
1902 | msg2 "$(gettext "Generating .MTREE file...")" | |
1903 | bsdtar -czf .MTREE --format=mtree \ | |
1904 | --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' \ | |
1905 | "${comp_files[@]}" * | |
1906 | comp_files+=(".MTREE") | |
1907 | ||
1908 | msg2 "$(gettext "Compressing package...")" | |
38a60f49 JH |
1909 | # TODO: Maybe this can be set globally for robustness |
1910 | shopt -s -o pipefail | |
94bc64ae | 1911 | # bsdtar's gzip compression always saves the time stamp, making one |
1912 | # archive created using the same command line distinct from another. | |
1913 | # Disable bsdtar compression and use gzip -n for now. | |
bc311a24 | 1914 | bsdtar -cf - "${comp_files[@]}" * | |
38a60f49 | 1915 | case "$PKGEXT" in |
09a93b2e CH |
1916 | *tar.gz) ${COMPRESSGZ[@]:-gzip -c -f -n} ;; |
1917 | *tar.bz2) ${COMPRESSBZ2[@]:-bzip2 -c -f} ;; | |
1918 | *tar.xz) ${COMPRESSXZ[@]:-xz -c -z -} ;; | |
572b1a5d | 1919 | *tar.lrz) ${COMPRESSLRZ[@]:-lrzip -q} ;; |
0a5b79e1 | 1920 | *tar.lzo) ${COMPRESSLZO[@]:-lzop -q} ;; |
09a93b2e | 1921 | *tar.Z) ${COMPRESSZ[@]:-compress -c -f} ;; |
94bc64ae | 1922 | *tar) cat ;; |
1923 | *) warning "$(gettext "'%s' is not a valid archive extension.")" \ | |
1924 | "$PKGEXT"; cat ;; | |
8fd9037c | 1925 | esac > "${pkg_file}" || ret=$? |
9bc799ec | 1926 | |
38a60f49 JH |
1927 | shopt -u nullglob |
1928 | shopt -u -o pipefail | |
c8beffa7 | 1929 | |
966c8158 | 1930 | if (( ret )); then |
5b4a4af9 | 1931 | error "$(gettext "Failed to create package file.")" |
7fb1dc3f | 1932 | exit 1 # TODO: error code |
5b4a4af9 | 1933 | fi |
93862bd7 | 1934 | |
2f2f53dd AM |
1935 | create_signature "$pkg_file" |
1936 | ||
960c2cdc | 1937 | if (( ! ret )) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then |
51ed7dff EB |
1938 | rm -f "${pkg_file/$PKGDEST/$startdir}" |
1939 | ln -s "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}" | |
93862bd7 | 1940 | ret=$? |
51ed7dff EB |
1941 | if [[ -f $pkg_file.sig ]]; then |
1942 | rm -f "${pkg_file/$PKGDEST/$startdir}.sig" | |
1943 | ln -s "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig" | |
1944 | fi | |
93862bd7 EB |
1945 | fi |
1946 | ||
1947 | if (( ret )); then | |
1948 | warning "$(gettext "Failed to create symlink to package file.")" | |
1949 | fi | |
a8c552d4 DO |
1950 | } |
1951 | ||
7e8d9dfd AM |
1952 | create_debug_package() { |
1953 | # check if a debug package was requested | |
1954 | if ! check_option "debug" "y" || ! check_option "strip" "y"; then | |
1955 | return | |
1956 | fi | |
1957 | ||
13667fd4 | 1958 | pkgdir="${pkgdir}-@DEBUGSUFFIX@" |
7e8d9dfd AM |
1959 | |
1960 | # check if we have any debug symbols to package | |
1961 | if dir_is_empty "$pkgdir/usr/lib/debug"; then | |
1962 | return | |
1963 | fi | |
1964 | ||
1965 | depends=("$pkgname=$(get_full_version)") | |
1966 | pkgdesc="Detached debugging symbols for $pkgname" | |
13667fd4 | 1967 | pkgname=$pkgname-@DEBUGSUFFIX@ |
7e8d9dfd AM |
1968 | |
1969 | unset groups optdepends provides conflicts replaces backup install changelog | |
1970 | ||
1971 | create_package | |
1972 | } | |
1973 | ||
ee34869e | 1974 | create_signature() { |
e8069cfc | 1975 | if [[ $SIGNPKG != 'y' ]]; then |
ee34869e GC |
1976 | return |
1977 | fi | |
1978 | local ret=0 | |
82e22596 | 1979 | local filename="$1" |
ee34869e | 1980 | msg "$(gettext "Signing package...")" |
e8069cfc DAF |
1981 | |
1982 | local SIGNWITHKEY="" | |
4c31bc6e AM |
1983 | if [[ -n $GPGKEY ]]; then |
1984 | SIGNWITHKEY="-u ${GPGKEY}" | |
e8069cfc DAF |
1985 | fi |
1986 | # The signature will be generated directly in ascii-friendly format | |
1987 | gpg --detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev/null || ret=$? | |
1988 | ||
1989 | ||
ee34869e | 1990 | if (( ! ret )); then |
82e22596 | 1991 | msg2 "$(gettext "Created signature file %s.")" "$filename.sig" |
ee34869e GC |
1992 | else |
1993 | warning "$(gettext "Failed to sign package file.")" | |
1994 | fi | |
1995 | } | |
1996 | ||
f4d6efee | 1997 | create_srcpackage() { |
b0543440 | 1998 | local ret=0 |
f4d6efee | 1999 | msg "$(gettext "Creating source package...")" |
4979157c | 2000 | local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)" |
7df0d048 | 2001 | mkdir "${srclinks}"/${pkgbase} |
4979157c | 2002 | |
41db62b7 DR |
2003 | check_license |
2004 | ||
420c8846 | 2005 | msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT" |
5dc0b80c | 2006 | ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}" |
f4d6efee | 2007 | |
5cddcc90 CS |
2008 | local file |
2009 | for file in "${source[@]}"; do | |
d11192c7 | 2010 | if [[ "$file" = "$(get_filename "$file")" ]] || (( SOURCEONLY == 2 )); then |
36413aa8 AM |
2011 | local absfile |
2012 | absfile=$(get_filepath "$file") || missing_source_file "$file" | |
5cddcc90 CS |
2013 | msg2 "$(gettext "Adding %s...")" "${absfile##*/}" |
2014 | ln -s "$absfile" "$srclinks/$pkgbase" | |
f4d6efee DM |
2015 | fi |
2016 | done | |
2017 | ||
fe1e3471 A |
2018 | local i |
2019 | for i in 'changelog' 'install'; do | |
64c3255b | 2020 | local file |
5bb2d2e0 | 2021 | while read -r file; do |
64c3255b | 2022 | # evaluate any bash variables used |
35d8cc8b | 2023 | eval file=\"$(sed 's/^\(['\''"]\)\(.*\)\1$/\2/' <<< "$file")\" |
42e2f8bf | 2024 | if [[ $file && ! -f "${srclinks}/${pkgbase}/$file" ]]; then |
ac5c2fd0 | 2025 | msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}" |
64c3255b AM |
2026 | ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/" |
2027 | fi | |
5bb2d2e0 | 2028 | done < <(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE") |
fe1e3471 | 2029 | done |
64c3255b | 2030 | |
91a013a8 DM |
2031 | local TAR_OPT |
2032 | case "$SRCEXT" in | |
572b1a5d AM |
2033 | *tar.gz) TAR_OPT="-z" ;; |
2034 | *tar.bz2) TAR_OPT="-j" ;; | |
2035 | *tar.xz) TAR_OPT="-J" ;; | |
2036 | *tar.lrz) TAR_OPT="--lrzip" ;; | |
0a5b79e1 | 2037 | *tar.lzo) TAR_OPT="--lzop" ;; |
572b1a5d | 2038 | *tar.Z) TAR_OPT="-Z" ;; |
81555711 | 2039 | *tar) TAR_OPT="" ;; |
91a013a8 DM |
2040 | *) warning "$(gettext "'%s' is not a valid archive extension.")" \ |
2041 | "$SRCEXT" ;; | |
2042 | esac | |
2043 | ||
ccdb2fa8 | 2044 | local fullver=$(get_full_version) |
b8ab96a2 | 2045 | local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}" |
f4d6efee DM |
2046 | |
2047 | # tar it up | |
2048 | msg2 "$(gettext "Compressing source package...")" | |
92321449 | 2049 | cd_safe "${srclinks}" |
572b1a5d | 2050 | if ! bsdtar -cL ${TAR_OPT} -f "$pkg_file" ${pkgbase}; then |
f4d6efee DM |
2051 | error "$(gettext "Failed to create source package file.")" |
2052 | exit 1 # TODO: error code | |
2053 | fi | |
71330a43 | 2054 | |
b0543440 | 2055 | if [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then |
51ed7dff EB |
2056 | rm -f "${pkg_file/$SRCPKGDEST/$startdir}" |
2057 | ln -s "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}" | |
3444146b CS |
2058 | ret=$? |
2059 | fi | |
2060 | ||
2061 | if (( ret )); then | |
2062 | warning "$(gettext "Failed to create symlink to source package file.")" | |
2063 | fi | |
71330a43 | 2064 | |
92321449 | 2065 | cd_safe "${startdir}" |
74eb2f5c | 2066 | rm -rf "${srclinks}" |
f4d6efee DM |
2067 | } |
2068 | ||
214f264b | 2069 | install_package() { |
c2999619 | 2070 | (( ! INSTALL )) && return |
4c27a776 | 2071 | |
c2999619 | 2072 | if (( ! SPLITPKG )); then |
4bdb868a | 2073 | msg "$(gettext "Installing package %s with %s...")" "$pkgname" "$PACMAN -U" |
4c27a776 | 2074 | else |
4bdb868a | 2075 | msg "$(gettext "Installing %s package group with %s...")" "$pkgbase" "$PACMAN -U" |
4c27a776 AM |
2076 | fi |
2077 | ||
d38a1c02 | 2078 | local fullver pkgarch pkg pkglist |
52550a2a | 2079 | (( ASDEPS )) && pkglist+=('--asdeps') |
42b492b2 | 2080 | (( NEEDED )) && pkglist+=('--needed') |
52550a2a | 2081 | |
4c27a776 | 2082 | for pkg in ${pkgname[@]}; do |
ccdb2fa8 | 2083 | fullver=$(get_full_version $pkg) |
d38a1c02 | 2084 | pkgarch=$(get_pkg_arch $pkg) |
22050f18 | 2085 | pkglist+=("$PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT}") |
254329f6 AM |
2086 | |
2087 | if [[ -f "$PKGDEST/${pkg}-debug-${fullver}-${pkgarch}${PKGEXT}" ]]; then | |
2088 | pkglist+=("$PKGDEST/${pkg}-debug-${fullver}-${pkgarch}${PKGEXT}") | |
2089 | fi | |
4c27a776 AM |
2090 | done |
2091 | ||
af1c9863 | 2092 | if ! run_pacman -U "${pkglist[@]}"; then |
deff57ce AM |
2093 | warning "$(gettext "Failed to install built package(s).")" |
2094 | return 0 | |
b6d991cf DM |
2095 | fi |
2096 | } | |
31e05618 | 2097 | |
3b4e74cb AM |
2098 | have_function() { |
2099 | declare -f "$1" >/dev/null | |
2100 | } | |
2101 | ||
e61ab153 DM |
2102 | check_sanity() { |
2103 | # check for no-no's in the build script | |
cd042640 | 2104 | local i |
a88cb03a | 2105 | local ret=0 |
4b129d48 | 2106 | for i in 'pkgname' 'pkgrel'; do |
cd042640 A |
2107 | if [[ -z ${!i} ]]; then |
2108 | error "$(gettext "%s is not allowed to be empty.")" "$i" | |
a88cb03a | 2109 | ret=1 |
cd042640 A |
2110 | fi |
2111 | done | |
564352c4 | 2112 | |
08e1d476 AM |
2113 | for i in "${pkgname[@]}"; do |
2114 | if [[ ${i:0:1} = "-" ]]; then | |
564352c4 | 2115 | error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname" |
a88cb03a | 2116 | ret=1 |
564352c4 | 2117 | fi |
fe794ccb AM |
2118 | if [[ ${i:0:1} = "." ]]; then |
2119 | error "$(gettext "%s is not allowed to start with a dot.")" "pkgname" | |
2120 | ret=1 | |
2121 | fi | |
5f71570e DR |
2122 | if [[ $i = *[^[:alnum:]+_.@-]* ]]; then |
2123 | error "$(gettext "%s contains invalid characters: '%s'")" \ | |
2124 | 'pkgname' "${pkgname//[[:alnum:]+_.@-]}" | |
2125 | ret=1 | |
2126 | fi | |
564352c4 CS |
2127 | done |
2128 | ||
2129 | if [[ ${pkgbase:0:1} = "-" ]]; then | |
2130 | error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgbase" | |
a88cb03a | 2131 | ret=1 |
fb97d325 | 2132 | fi |
00949db1 | 2133 | |
a818766c | 2134 | if (( ! PKGVERFUNC )) ; then |
4b129d48 AM |
2135 | check_pkgver || ret=1 |
2136 | fi | |
00949db1 | 2137 | |
36f31dd1 | 2138 | awk -F'=' '$1 ~ /^[[:space:]]*pkgrel$/' "$BUILDFILE" | sed "s/[[:space:]]*#.*//" | |
905ae640 | 2139 | while IFS='=' read -r _ i; do |
b8ef2231 | 2140 | eval i=\"$(sed 's/^\(['\''"]\)\(.*\)\1$/\2/' <<< "${i%%+([[:space:]])}")\" |
708a2275 DR |
2141 | if [[ $i != +([0-9])?(.+([0-9])) ]]; then |
2142 | error "$(gettext "%s must be a decimal.")" "pkgrel" | |
819f6750 AM |
2143 | return 1 |
2144 | fi | |
2145 | done || ret=1 | |
e61ab153 | 2146 | |
905ae640 DR |
2147 | awk -F'=' '$1 ~ /^[[:space:]]*epoch$/' "$BUILDFILE" | |
2148 | while IFS='=' read -r _ i; do | |
b8ef2231 | 2149 | eval i=\"$(sed 's/^\(['\''"]\)\(.*\)\1$/\2/' <<< "${i%%+([[:space:]])}")\" |
0e79802c | 2150 | if [[ $i != *([[:digit:]]) ]]; then |
03447ce3 AM |
2151 | error "$(gettext "%s must be an integer.")" "epoch" |
2152 | return 1 | |
2153 | fi | |
2154 | done || ret=1 | |
93718046 | 2155 | |
c2999619 | 2156 | if [[ $arch != 'any' ]]; then |
c7e4d10d | 2157 | if ! in_array $CARCH ${arch[@]}; then |
c2999619 | 2158 | if (( ! IGNOREARCH )); then |
c7e4d10d AM |
2159 | error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH" |
2160 | plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT" | |
4bdb868a | 2161 | plain "$(gettext "such as %s.")" "arch=('$CARCH')" |
a88cb03a | 2162 | ret=1 |
c7e4d10d | 2163 | fi |
e61ab153 DM |
2164 | fi |
2165 | fi | |
2166 | ||
a7940e74 AM |
2167 | if (( ${#pkgname[@]} > 1 )); then |
2168 | for i in ${pkgname[@]}; do | |
2169 | local arch_list="" | |
2170 | eval $(declare -f package_${i} | sed -n 's/\(^[[:space:]]*arch=\)/arch_list=/p') | |
2171 | if [[ ${arch_list[@]} && ${arch_list} != 'any' ]]; then | |
2172 | if ! in_array $CARCH ${arch_list[@]}; then | |
2173 | if (( ! IGNOREARCH )); then | |
2174 | error "$(gettext "%s is not available for the '%s' architecture.")" "$i" "$CARCH" | |
2175 | ret=1 | |
2176 | fi | |
2177 | fi | |
2178 | fi | |
2179 | done | |
2180 | fi | |
2181 | ||
f8927753 | 2182 | local provides_list=() |
b6cada3e | 2183 | eval $(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \ |
37df0d4f | 2184 | sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//') |
ef977865 | 2185 | for i in ${provides_list[@]}; do |
497501d1 | 2186 | if [[ $i == *['<>']* ]]; then |
4bdb868a | 2187 | error "$(gettext "%s array cannot contain comparison (< or >) operators.")" "provides" |
a88cb03a | 2188 | ret=1 |
e61ab153 DM |
2189 | fi |
2190 | done | |
2191 | ||
f8927753 | 2192 | local backup_list=() |
b6cada3e | 2193 | eval $(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \ |
37df0d4f | 2194 | sed -e "s/backup=/backup_list+=/" -e "s/#.*//" -e 's/\\$//') |
ef977865 | 2195 | for i in "${backup_list[@]}"; do |
08e1d476 | 2196 | if [[ ${i:0:1} = "/" ]]; then |
4bdb868a | 2197 | error "$(gettext "%s entry should not contain leading slash : %s")" "backup" "$i" |
a88cb03a | 2198 | ret=1 |
b53aa87e XC |
2199 | fi |
2200 | done | |
2201 | ||
f8927753 | 2202 | local optdepends_list=() |
40fd8123 | 2203 | eval $(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(#.*)?$/' "$BUILDFILE" | \ |
37df0d4f | 2204 | sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//') |
ef977865 | 2205 | for i in "${optdepends_list[@]}"; do |
6adf502f | 2206 | local pkg=${i%%:[[:space:]]*} |
619c3629 DR |
2207 | # the '-' character _must_ be first or last in the character range |
2208 | if [[ $pkg != +([-[:alnum:]><=.+_:]) ]]; then | |
4bdb868a | 2209 | error "$(gettext "Invalid syntax for %s : '%s'")" "optdepend" "$i" |
35a8cf13 | 2210 | ret=1 |
0845b2f1 XC |
2211 | fi |
2212 | done | |
2213 | ||
fe1e3471 | 2214 | for i in 'changelog' 'install'; do |
64c3255b | 2215 | local file |
5bb2d2e0 | 2216 | while read -r file; do |
64c3255b | 2217 | # evaluate any bash variables used |
35d8cc8b | 2218 | eval file=\"$(sed 's/^\(['\''"]\)\(.*\)\1$/\2/' <<< "$file")\" |
0f69e2ec | 2219 | if [[ $file && ! -f $file ]]; then |
8b23aa17 | 2220 | error "$(gettext "%s file (%s) does not exist.")" "$i" "$file" |
a88cb03a | 2221 | ret=1 |
64c3255b | 2222 | fi |
5bb2d2e0 | 2223 | done < <(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE") |
fe1e3471 | 2224 | done |
2cabe336 | 2225 | |
e61ab153 | 2226 | local valid_options=1 |
ef977865 | 2227 | local known kopt options_list |
b6cada3e | 2228 | eval $(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \ |
37df0d4f | 2229 | sed -e "s/options=/options_list+=/" -e "s/#.*//" -e 's/\\$//') |
ef977865 | 2230 | for i in ${options_list[@]}; do |
e61ab153 DM |
2231 | known=0 |
2232 | # check if option matches a known option or its inverse | |
2233 | for kopt in ${packaging_options[@]} ${other_options[@]}; do | |
d11192c7 | 2234 | if [[ ${i} = "${kopt}" || ${i} = "!${kopt}" ]]; then |
e61ab153 DM |
2235 | known=1 |
2236 | fi | |
2237 | done | |
c2999619 | 2238 | if (( ! known )); then |
4bdb868a | 2239 | error "$(gettext "%s array contains unknown option '%s'")" "options" "$i" |
e61ab153 DM |
2240 | valid_options=0 |
2241 | fi | |
2242 | done | |
c2999619 | 2243 | if (( ! valid_options )); then |
a88cb03a | 2244 | ret=1 |
e61ab153 DM |
2245 | fi |
2246 | ||
dece66ac AM |
2247 | if (( ${#pkgname[@]} == 1 )); then |
2248 | if have_function build && ! ( have_function package || have_function package_${pkgname}); then | |
2249 | error "$(gettext "Missing %s function in %s")" "package()" "$BUILDFILE" | |
2250 | ret=1 | |
2251 | fi | |
2252 | else | |
08e1d476 | 2253 | for i in ${pkgname[@]}; do |
3b4e74cb | 2254 | if ! have_function package_${i}; then |
4bdb868a | 2255 | error "$(gettext "Missing %s function for split package '%s'")" "package_$i()" "$i" |
a88cb03a | 2256 | ret=1 |
6092dda1 AM |
2257 | fi |
2258 | done | |
2259 | fi | |
2260 | ||
08e1d476 AM |
2261 | for i in ${PKGLIST[@]}; do |
2262 | if ! in_array $i ${pkgname[@]}; then | |
4bdb868a | 2263 | error "$(gettext "Requested package %s is not provided in %s")" "$i" "$BUILDFILE" |
a88cb03a | 2264 | ret=1 |
f04530eb AM |
2265 | fi |
2266 | done | |
f2c9e51e | 2267 | |
a88cb03a | 2268 | return $ret |
e61ab153 DM |
2269 | } |
2270 | ||
4b129d48 AM |
2271 | check_pkgver() { |
2272 | local ret=0 | |
2273 | ||
2274 | if [[ -z ${pkgver} ]]; then | |
2275 | error "$(gettext "%s is not allowed to be empty.")" "pkgver" | |
2276 | ret=1 | |
2277 | fi | |
2278 | ||
2279 | awk -F'=' '$1 ~ /^[[:space:]]*pkgver$/' "$BUILDFILE" | sed "s/[[:space:]]*#.*//" | | |
2280 | while IFS='=' read -r _ i; do | |
2281 | eval i=\"$(sed 's/^\(['\''"]\)\(.*\)\1$/\2/' <<< "${i%%+([[:space:]])}")\" | |
2282 | if [[ $i = *[[:space:]:-]* ]]; then | |
2283 | error "$(gettext "%s is not allowed to contain colons, hyphens or whitespace.")" "pkgver" | |
2284 | return 1 | |
2285 | fi | |
2286 | done || ret=1 | |
2287 | ||
2288 | return $ret | |
2289 | } | |
2290 | ||
74689562 AM |
2291 | check_software() { |
2292 | # check for needed software | |
2293 | local ret=0 | |
2294 | ||
3531533c AM |
2295 | # check for PACMAN if we need it |
2296 | if (( ! INFAKEROOT && ( ! NODEPS || DEP_BIN || RMDEPS || INSTALL ) )); then | |
2297 | if [[ -z $PACMAN_PATH ]]; then | |
2298 | error "$(gettext "Cannot find the %s binary required for dependency operations.")" "$PACMAN" | |
2299 | ret=1 | |
2300 | fi | |
2301 | fi | |
2302 | ||
bdd8ebd6 EB |
2303 | # check for sudo if we will need it during makepkg execution |
2304 | if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then | |
2305 | if ! type -p sudo >/dev/null; then | |
242411a1 | 2306 | warning "$(gettext "Cannot find the %s binary. Will use %s to acquire root privileges.")" "sudo" "su" |
bdd8ebd6 EB |
2307 | fi |
2308 | fi | |
2309 | ||
74689562 | 2310 | # fakeroot - building as non-root user |
9dd42dc0 | 2311 | if check_buildenv "fakeroot" "y" && (( EUID > 0 )); then |
74689562 AM |
2312 | if ! type -p fakeroot >/dev/null; then |
2313 | error "$(gettext "Cannot find the %s binary required for building as non-root user.")" "fakeroot" | |
2314 | ret=1 | |
2315 | fi | |
2316 | fi | |
2317 | ||
2318 | # gpg - package signing | |
9dd42dc0 | 2319 | if [[ $SIGNPKG == 'y' ]] || { [[ -z $SIGNPKG ]] && check_buildenv "sign" "y"; }; then |
74689562 AM |
2320 | if ! type -p gpg >/dev/null; then |
2321 | error "$(gettext "Cannot find the %s binary required for signing packages.")" "gpg" | |
2322 | ret=1 | |
2323 | fi | |
2324 | fi | |
2325 | ||
94f61c5b | 2326 | # gpg - source verification |
17c3de3e | 2327 | if (( ! SKIPPGPCHECK )) && source_has_signatures; then |
94f61c5b WH |
2328 | if ! type -p gpg >/dev/null; then |
2329 | error "$(gettext "Cannot find the %s binary required for verifying source files.")" "gpg" | |
2330 | ret=1 | |
2331 | fi | |
2332 | fi | |
2333 | ||
74689562 | 2334 | # openssl - checksum operations |
2b3405e0 | 2335 | if (( ! SKIPCHECKSUMS )); then |
74689562 AM |
2336 | if ! type -p openssl >/dev/null; then |
2337 | error "$(gettext "Cannot find the %s binary required for validating sourcefile checksums.")" "openssl" | |
2338 | ret=1 | |
2339 | fi | |
2340 | fi | |
2341 | ||
2342 | # upx - binary compression | |
9dd42dc0 | 2343 | if check_option "upx" "y"; then |
74689562 AM |
2344 | if ! type -p upx >/dev/null; then |
2345 | error "$(gettext "Cannot find the %s binary required for compressing binaries.")" "upx" | |
2346 | ret=1 | |
2347 | fi | |
2348 | fi | |
2349 | ||
eedd56f3 | 2350 | # distcc - compilation with distcc |
9dd42dc0 | 2351 | if check_buildenv "distcc" "y" && ! check_option "distcc" "n" ]]; then |
eedd56f3 EB |
2352 | if ! type -p distcc >/dev/null; then |
2353 | error "$(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc" | |
2354 | ret=1 | |
2355 | fi | |
2356 | fi | |
2357 | ||
2358 | # ccache - compilation with ccache | |
9dd42dc0 | 2359 | if check_buildenv "ccache" "y" && ! check_option "ccache" "n"; then |
eedd56f3 EB |
2360 | if ! type -p ccache >/dev/null; then |
2361 | error "$(gettext "Cannot find the %s binary required for compiler cache usage.")" "ccache" | |
2362 | ret=1 | |
2363 | fi | |
2364 | fi | |
2365 | ||
2366 | # strip - strip symbols from binaries/libraries | |
9dd42dc0 | 2367 | if check_option "strip" "y"; then |
eedd56f3 EB |
2368 | if ! type -p strip >/dev/null; then |
2369 | error "$(gettext "Cannot find the %s binary required for object file stripping.")" "strip" | |
2370 | ret=1 | |
2371 | fi | |
2372 | fi | |
2373 | ||
2374 | # gzip - compressig man and info pages | |
9dd42dc0 | 2375 | if check_option "zipman" "y"; then |
eedd56f3 EB |
2376 | if ! type -p gzip >/dev/null; then |
2377 | error "$(gettext "Cannot find the %s binary required for compressing man and info pages.")" "gzip" | |
2378 | ret=1 | |
2379 | fi | |
2380 | fi | |
2381 | ||
74689562 AM |
2382 | return $ret |
2383 | } | |
2384 | ||
a818766c AM |
2385 | check_build_status() { |
2386 | if (( ! SPLITPKG )); then | |
2387 | fullver=$(get_full_version) | |
2388 | pkgarch=$(get_pkg_arch) | |
2389 | if [[ -f $PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT} ]] \ | |
2390 | && ! (( FORCE || SOURCEONLY || NOBUILD )); then | |
2391 | if (( INSTALL )); then | |
2392 | warning "$(gettext "A package has already been built, installing existing package...")" | |
2393 | install_package | |
2394 | exit $? | |
2395 | else | |
2396 | error "$(gettext "A package has already been built. (use %s to overwrite)")" "-f" | |
2397 | exit 1 | |
2398 | fi | |
2399 | fi | |
2400 | else | |
2401 | allpkgbuilt=1 | |
2402 | somepkgbuilt=0 | |
2403 | for pkg in ${pkgname[@]}; do | |
2404 | fullver=$(get_full_version $pkg) | |
2405 | pkgarch=$(get_pkg_arch $pkg) | |
2406 | if [[ -f $PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT} ]]; then | |
2407 | somepkgbuilt=1 | |
2408 | else | |
2409 | allpkgbuilt=0 | |
2410 | fi | |
2411 | done | |
2412 | if ! (( FORCE || SOURCEONLY || NOBUILD )); then | |
2413 | if (( allpkgbuilt )); then | |
2414 | if (( INSTALL )); then | |
2415 | warning "$(gettext "The package group has already been built, installing existing packages...")" | |
2416 | install_package | |
2417 | exit $? | |
2418 | else | |
2419 | error "$(gettext "The package group has already been built. (use %s to overwrite)")" "-f" | |
2420 | exit 1 | |
2421 | fi | |
2422 | fi | |
2423 | if (( somepkgbuilt && ! PKGVERFUNC )); then | |
2424 | error "$(gettext "Part of the package group has already been built. (use %s to overwrite)")" "-f" | |
2425 | exit 1 | |
2426 | fi | |
2427 | fi | |
2428 | unset allpkgbuilt somepkgbuilt | |
2429 | fi | |
2430 | } | |
2431 | ||
9804911c | 2432 | backup_package_variables() { |
1a9db4ca | 2433 | local var |
9804911c | 2434 | for var in ${splitpkg_overrides[@]}; do |
1a9db4ca | 2435 | local indirect="${var}_backup" |
db756ed9 | 2436 | eval "${indirect}=(\"\${$var[@]}\")" |
9804911c AM |
2437 | done |
2438 | } | |
2439 | ||
2440 | restore_package_variables() { | |
1a9db4ca | 2441 | local var |
9804911c | 2442 | for var in ${splitpkg_overrides[@]}; do |
1a9db4ca | 2443 | local indirect="${var}_backup" |
c2999619 | 2444 | if [[ -n ${!indirect} ]]; then |
db756ed9 | 2445 | eval "${var}=(\"\${$indirect[@]}\")" |
9804911c AM |
2446 | else |
2447 | unset ${var} | |
2448 | fi | |
2449 | done | |
2450 | } | |
2451 | ||
70418e48 | 2452 | run_split_packaging() { |
eb939554 AM |
2453 | local pkgname_backup=${pkgname[@]} |
2454 | for pkgname in ${pkgname_backup[@]}; do | |
f170a94c AM |
2455 | pkgdir="$pkgdirbase/$pkgname" |
2456 | mkdir "$pkgdir" | |
70418e48 | 2457 | backup_package_variables |
eb939554 | 2458 | run_package $pkgname |
70418e48 | 2459 | tidy_install |
a5e81f55 | 2460 | create_package |
7e8d9dfd | 2461 | create_debug_package |
70418e48 | 2462 | restore_package_variables |
70418e48 | 2463 | done |
eb939554 | 2464 | pkgname=${pkgname_backup[@]} |
70418e48 A |
2465 | } |
2466 | ||
c0f58ea9 AM |
2467 | # Canonicalize a directory path if it exists |
2468 | canonicalize_path() { | |
2469 | local path="$1"; | |
2470 | ||
2471 | if [[ -d $path ]]; then | |
2472 | ( | |
92321449 | 2473 | cd_safe "$path" |
c0f58ea9 AM |
2474 | pwd -P |
2475 | ) | |
2476 | else | |
1917c845 | 2477 | printf "%s\n" "$path" |
c0f58ea9 AM |
2478 | fi |
2479 | } | |
2480 | ||
aa50df63 DR |
2481 | dir_is_empty() { |
2482 | ( | |
2483 | shopt -s dotglob nullglob | |
2484 | files=("$1"/*) | |
2485 | (( ${#files} == 0 )) | |
2486 | ) | |
2487 | } | |
2488 | ||
d85c7186 | 2489 | m4_include(library/parseopts.sh) |
08980fb4 | 2490 | |
d04baaba | 2491 | usage() { |
b3e82ec5 | 2492 | printf "makepkg (pacman) %s\n" "$makepkg_version" |
041e51f6 | 2493 | echo |
9e9835f4 | 2494 | printf -- "$(gettext "Usage: %s [options]")\n" "$0" |
041e51f6 | 2495 | echo |
17e71fc9 | 2496 | printf -- "$(gettext "Options:")\n" |
9e9835f4 DR |
2497 | printf -- "$(gettext " -A, --ignorearch Ignore incomplete %s field in %s")\n" "arch" "$BUILDSCRIPT" |
2498 | printf -- "$(gettext " -c, --clean Clean up work files after build")\n" | |
2499 | printf -- "$(gettext " -d, --nodeps Skip all dependency checks")\n" | |
2500 | printf -- "$(gettext " -e, --noextract Do not extract source files (use existing %s dir)")\n" "src/" | |
2501 | printf -- "$(gettext " -f, --force Overwrite existing package")\n" | |
2502 | printf -- "$(gettext " -g, --geninteg Generate integrity checks for source files")\n" | |
2503 | printf -- "$(gettext " -h, --help Show this help message and exit")\n" | |
2504 | printf -- "$(gettext " -i, --install Install package after successful build")\n" | |
2505 | printf -- "$(gettext " -L, --log Log package build process")\n" | |
2506 | printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n" | |
2507 | printf -- "$(gettext " -o, --nobuild Download and extract files only")\n" | |
2508 | printf -- "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT" | |
2509 | printf -- "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")\n" | |
2510 | printf -- "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")\n" | |
2511 | printf -- "$(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "pacman" | |
2512 | printf -- "$(gettext " -S, --source Generate a source-only tarball without downloaded sources")\n" | |
91b9ea92 | 2513 | printf -- "$(gettext " -V, --version Show version information and exit")\n" |
9e9835f4 | 2514 | printf -- "$(gettext " --allsource Generate a source-only tarball including downloaded sources")\n" |
2259dff7 | 2515 | printf -- "$(gettext " --verifysource Download source files (if needed) and perform integrity checks")\n" |
9e9835f4 DR |
2516 | printf -- "$(gettext " --asroot Allow %s to run as root user")\n" "makepkg" |
2517 | printf -- "$(gettext " --check Run the %s function in the %s")\n" "check()" "$BUILDSCRIPT" | |
2518 | printf -- "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf" | |
6c8def6a | 2519 | printf -- "$(gettext " --holdver Do not update VCS sources")\n" |
9e9835f4 DR |
2520 | printf -- "$(gettext " --key <key> Specify a key to use for %s signing instead of the default")\n" "gpg" |
2521 | printf -- "$(gettext " --nocheck Do not run the %s function in the %s")\n" "check()" "$BUILDSCRIPT" | |
9de33488 | 2522 | printf -- "$(gettext " --noprepare Do not run the %s function in the %s")\n" "prepare()" "$BUILDSCRIPT" |
9e9835f4 DR |
2523 | printf -- "$(gettext " --nosign Do not create a signature for the package")\n" |
2524 | printf -- "$(gettext " --pkg <list> Only build listed packages from a split package")\n" | |
2525 | printf -- "$(gettext " --sign Sign the resulting package with %s")\n" "gpg" | |
2526 | printf -- "$(gettext " --skipchecksums Do not verify checksums of the source files")\n" | |
2527 | printf -- "$(gettext " --skipinteg Do not perform any verification checks on source files")\n" | |
2528 | printf -- "$(gettext " --skippgpcheck Do not verify source files with PGP signatures")\n" | |
d04baaba | 2529 | echo |
9e9835f4 | 2530 | printf -- "$(gettext "These options can be passed to %s:")\n" "pacman" |
041e51f6 | 2531 | echo |
52550a2a | 2532 | printf -- "$(gettext " --asdeps Install packages as non-explicitly installed")\n" |
ea452d02 | 2533 | printf -- "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")\n" |
6b1deedf | 2534 | printf -- "$(gettext " --needed Do not reinstall the targets that are already up to date")\n" |
9e9835f4 | 2535 | printf -- "$(gettext " --noprogressbar Do not show a progress bar when downloading files")\n" |
041e51f6 | 2536 | echo |
9e9835f4 | 2537 | printf -- "$(gettext "If %s is not specified, %s will look for '%s'")\n" "-p" "makepkg" "$BUILDSCRIPT" |
d04baaba JV |
2538 | echo |
2539 | } | |
2540 | ||
103c7243 | 2541 | version() { |
b3e82ec5 | 2542 | printf "makepkg (pacman) %s\n" "$makepkg_version" |
9e9835f4 | 2543 | printf -- "$(gettext "\ |
1dd34058 | 2544 | Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org>.\n\ |
c72b4543 | 2545 | Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\ |
a501b72e DM |
2546 | This is free software; see the source for copying conditions.\n\ |
2547 | There is NO WARRANTY, to the extent permitted by law.\n")" | |
103c7243 DM |
2548 | } |
2549 | ||
35593065 DM |
2550 | # PROGRAM START |
2551 | ||
2552 | # determine whether we have gettext; make it a no-op if we do not | |
95145d4c | 2553 | if ! type -p gettext >/dev/null; then |
35593065 | 2554 | gettext() { |
1917c845 | 2555 | printf "%s\n" "$@" |
35593065 DM |
2556 | } |
2557 | fi | |
2558 | ||
fff6d9dc | 2559 | ARGLIST=("$@") |
d04baaba | 2560 | |
54b71f04 | 2561 | # Parse Command Line Options. |
4a7f3bbc | 2562 | OPT_SHORT="AcdefFghiLmop:rRsSV" |
d338b398 | 2563 | OPT_LONG=('allsource' 'asroot' 'check' 'clean' 'config:' 'force' 'geninteg' |
6c8def6a | 2564 | 'help' 'holdver' 'ignorearch' 'install' 'key:' 'log' 'nobuild' 'nocolor' |
9de33488 | 2565 | 'nocheck' 'nodeps' 'noextract' 'noprepare' 'nosign' 'pkg:' 'repackage' 'rmdeps' |
6e2c1509 AM |
2566 | 'sign' 'skipchecksums' 'skipinteg' 'skippgpcheck' 'source' 'syncdeps' |
2567 | 'verifysource' 'version') | |
2b3405e0 | 2568 | |
54b71f04 | 2569 | # Pacman Options |
6b1deedf | 2570 | OPT_LONG+=('asdeps' 'noconfirm' 'needed' 'noprogressbar') |
d85c7186 DR |
2571 | |
2572 | if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then | |
62dbf7ec | 2573 | exit 1 # E_INVALID_OPTION; |
54b71f04 | 2574 | fi |
d85c7186 DR |
2575 | set -- "${OPTRET[@]}" |
2576 | unset OPT_SHORT OPT_LONG OPTRET | |
54b71f04 AF |
2577 | |
2578 | while true; do | |
2579 | case "$1" in | |
2580 | # Pacman Options | |
52550a2a | 2581 | --asdeps) ASDEPS=1;; |
c7a37d03 | 2582 | --noconfirm) PACMAN_OPTS+=" --noconfirm" ;; |
42b492b2 | 2583 | --needed) NEEDED=1;; |
c7a37d03 | 2584 | --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;; |
54b71f04 AF |
2585 | |
2586 | # Makepkg Options | |
4979157c | 2587 | --allsource) SOURCEONLY=2 ;; |
54b71f04 AF |
2588 | --asroot) ASROOT=1 ;; |
2589 | -A|--ignorearch) IGNOREARCH=1 ;; | |
54b71f04 | 2590 | -c|--clean) CLEANUP=1 ;; |
0c29eb43 | 2591 | --check) RUN_CHECK='y' ;; |
4b183bf9 | 2592 | --config) shift; MAKEPKG_CONF=$1 ;; |
54b71f04 AF |
2593 | -d|--nodeps) NODEPS=1 ;; |
2594 | -e|--noextract) NOEXTRACT=1 ;; | |
2595 | -f|--force) FORCE=1 ;; | |
7bd4486e | 2596 | -F) INFAKEROOT=1 ;; |
54b71f04 | 2597 | -g|--geninteg) GENINTEG=1 ;; |
6c8def6a | 2598 | --holdver) HOLDVER=1 ;; |
54b71f04 | 2599 | -i|--install) INSTALL=1 ;; |
4c31bc6e | 2600 | --key) shift; GPGKEY=$1 ;; |
54b71f04 AF |
2601 | -L|--log) LOGGING=1 ;; |
2602 | -m|--nocolor) USE_COLOR='n' ;; | |
0c29eb43 | 2603 | --nocheck) RUN_CHECK='n' ;; |
9de33488 | 2604 | --noprepare) RUN_PREPARE='n' ;; |
e8069cfc | 2605 | --nosign) SIGNPKG='n' ;; |
54b71f04 | 2606 | -o|--nobuild) NOBUILD=1 ;; |
5dc0b80c | 2607 | -p) shift; BUILDFILE=$1 ;; |
3f9cf847 | 2608 | --pkg) shift; IFS=, read -ra p <<<"$1"; PKGLIST+=("${p[@]}"); unset p ;; |
54b71f04 AF |
2609 | -r|--rmdeps) RMDEPS=1 ;; |
2610 | -R|--repackage) REPKG=1 ;; | |
2b3405e0 AM |
2611 | --skipchecksums) SKIPCHECKSUMS=1 ;; |
2612 | --skipinteg) SKIPCHECKSUMS=1; SKIPPGPCHECK=1 ;; | |
94f61c5b | 2613 | --skippgpcheck) SKIPPGPCHECK=1;; |
e8069cfc | 2614 | --sign) SIGNPKG='y' ;; |
54b71f04 | 2615 | -s|--syncdeps) DEP_BIN=1 ;; |
4a7f3bbc | 2616 | -S|--source) SOURCEONLY=1 ;; |
2259dff7 | 2617 | --verifysource) VERIFYSOURCE=1 ;; |
76fd8545 | 2618 | |
54b71f04 AF |
2619 | -h|--help) usage; exit 0 ;; # E_OK |
2620 | -V|--version) version; exit 0 ;; # E_OK | |
2621 | ||
d85c7186 | 2622 | --) OPT_IND=0; shift; break 2;; |
d04baaba JV |
2623 | esac |
2624 | shift | |
2625 | done | |
2626 | ||
3d3c7ebb DR |
2627 | # attempt to consume any extra argv as environment variables. this supports |
2628 | # overriding (e.g. CC=clang) as well as overriding (e.g. CFLAGS+=' -g'). | |
2629 | extra_environment=() | |
2630 | while [[ $1 ]]; do | |
2631 | if [[ $1 = [_[:alpha:]]*([[:alnum:]_])?(+)=* ]]; then | |
2632 | extra_environment+=("$1") | |
2633 | fi | |
2634 | shift | |
2635 | done | |
2636 | ||
020bdb42 DM |
2637 | # setup signal traps |
2638 | trap 'clean_up' 0 | |
2639 | for signal in TERM HUP QUIT; do | |
1a8c3e52 | 2640 | trap "trap_exit $signal \"$(gettext "%s signal caught. Exiting...")\" \"$signal\"" "$signal" |
020bdb42 | 2641 | done |
1a8c3e52 DR |
2642 | trap 'trap_exit INT "$(gettext "Aborted by user! Exiting...")"' INT |
2643 | trap 'trap_exit USR1 "$(gettext "An unknown error has occurred. Exiting...")"' ERR | |
020bdb42 | 2644 | |
c0f58ea9 AM |
2645 | # preserve environment variables and canonicalize path |
2646 | [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST}) | |
2647 | [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST}) | |
2648 | [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST}) | |
0c74ffd6 | 2649 | [[ -n ${LOGDEST} ]] && _LOGDEST=$(canonicalize_path ${LOGDEST}) |
508b360c | 2650 | [[ -n ${BUILDDIR} ]] && _BUILDDIR=$(canonicalize_path ${BUILDDIR}) |
43dacceb RK |
2651 | [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT} |
2652 | [[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT} | |
4c31bc6e | 2653 | [[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY} |
5ba8b83b | 2654 | [[ -n ${PACKAGER} ]] && _PACKAGER=${PACKAGER} |
5bcc058d | 2655 | [[ -n ${CARCH} ]] && _CARCH=${CARCH} |
4b183bf9 XC |
2656 | |
2657 | # default config is makepkg.conf | |
2658 | MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf} | |
2659 | ||
2660 | # Source the config file; fail if it is not found | |
c2999619 | 2661 | if [[ -r $MAKEPKG_CONF ]]; then |
8fe67919 | 2662 | source_safe "$MAKEPKG_CONF" |
4b183bf9 XC |
2663 | else |
2664 | error "$(gettext "%s not found.")" "$MAKEPKG_CONF" | |
2665 | plain "$(gettext "Aborting...")" | |
2666 | exit 1 # $E_CONFIG_ERROR | |
2667 | fi | |
2668 | ||
c2e6a01a DM |
2669 | # Source user-specific makepkg.conf overrides, but only if no override config |
2670 | # file was specified | |
2671 | if [[ $MAKEPKG_CONF = "$confdir/makepkg.conf" && -r ~/.makepkg.conf ]]; then | |
8fe67919 | 2672 | source_safe ~/.makepkg.conf |
4b183bf9 XC |
2673 | fi |
2674 | ||
66c6d288 CS |
2675 | # set pacman command if not already defined |
2676 | PACMAN=${PACMAN:-pacman} | |
3531533c AM |
2677 | # save full path to command as PATH may change when sourcing /etc/profile |
2678 | PACMAN_PATH=$(type -P $PACMAN) || true | |
66c6d288 | 2679 | |
7a8ba5a9 | 2680 | # check if messages are to be printed using color |
013fc9a7 | 2681 | unset ALL_OFF BOLD BLUE GREEN RED YELLOW |
9dd42dc0 | 2682 | if [[ -t 2 && ! $USE_COLOR = "n" ]] && check_buildenv "color" "y"; then |
b02bda75 AM |
2683 | # prefer terminal safe colored and bold text when tput is supported |
2684 | if tput setaf 0 &>/dev/null; then | |
2685 | ALL_OFF="$(tput sgr0)" | |
2686 | BOLD="$(tput bold)" | |
2687 | BLUE="${BOLD}$(tput setaf 4)" | |
2688 | GREEN="${BOLD}$(tput setaf 2)" | |
2689 | RED="${BOLD}$(tput setaf 1)" | |
2690 | YELLOW="${BOLD}$(tput setaf 3)" | |
2691 | else | |
fa601c41 AG |
2692 | ALL_OFF="\e[0m" |
2693 | BOLD="\e[1m" | |
2694 | BLUE="${BOLD}\e[34m" | |
2695 | GREEN="${BOLD}\e[32m" | |
2696 | RED="${BOLD}\e[31m" | |
2697 | YELLOW="${BOLD}\e[33m" | |
b02bda75 | 2698 | fi |
7a8ba5a9 | 2699 | fi |
013fc9a7 | 2700 | readonly ALL_OFF BOLD BLUE GREEN RED YELLOW |
7a8ba5a9 | 2701 | |
4b183bf9 | 2702 | # override settings with an environment variable for batch processing |
508b360c AM |
2703 | BUILDDIR=${_BUILDDIR:-$BUILDDIR} |
2704 | BUILDDIR=${BUILDDIR:-$startdir} #default to $startdir if undefined | |
2705 | if [[ ! -d $BUILDDIR ]]; then | |
573bd80f AM |
2706 | if ! mkdir -p "$BUILDDIR"; then |
2707 | error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR" | |
2708 | plain "$(gettext "Aborting...")" | |
2709 | exit 1 | |
2710 | fi | |
508b360c AM |
2711 | chmod a-s "$BUILDDIR" |
2712 | fi | |
2713 | if [[ ! -w $BUILDDIR ]]; then | |
2714 | error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR" | |
2715 | plain "$(gettext "Aborting...")" | |
2716 | exit 1 | |
2717 | fi | |
508b360c | 2718 | |
3d3c7ebb DR |
2719 | # override settings from extra variables on commandline, if any |
2720 | if (( ${#extra_environment[*]} )); then | |
2721 | export "${extra_environment[@]}" | |
2722 | fi | |
2723 | ||
4b183bf9 XC |
2724 | PKGDEST=${_PKGDEST:-$PKGDEST} |
2725 | PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined | |
3a04267c | 2726 | if (( ! (NOBUILD || GENINTEG) )) && [[ ! -w $PKGDEST ]]; then |
65d43fbb AM |
2727 | error "$(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST" |
2728 | plain "$(gettext "Aborting...")" | |
2729 | exit 1 | |
2730 | fi | |
2731 | ||
4b183bf9 XC |
2732 | SRCDEST=${_SRCDEST:-$SRCDEST} |
2733 | SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined | |
65d43fbb AM |
2734 | if [[ ! -w $SRCDEST ]] ; then |
2735 | error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST" | |
2736 | plain "$(gettext "Aborting...")" | |
2737 | exit 1 | |
2738 | fi | |
2739 | ||
afc37c58 | 2740 | SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST} |
d8c4b12c | 2741 | SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined |
47313ace AM |
2742 | if (( SOURCEONLY )) && [[ ! -w $SRCPKGDEST ]]; then |
2743 | error "$(gettext "You do not have write permission to store source tarballs in %s.")" "$SRCPKGDEST" | |
2744 | plain "$(gettext "Aborting...")" | |
2745 | exit 1 | |
2746 | fi | |
4b183bf9 | 2747 | |
0c74ffd6 WG |
2748 | LOGDEST=${_LOGDEST:-$LOGDEST} |
2749 | LOGDEST=${LOGDEST:-$startdir} #default to $startdir if undefined | |
2750 | if (( LOGGING )) && [[ ! -w $LOGDEST ]]; then | |
2751 | error "$(gettext "You do not have write permission to store logs in %s.")" "$LOGDEST" | |
2752 | plain "$(gettext "Aborting...")" | |
2753 | exit 1 | |
2754 | fi | |
2755 | ||
43dacceb RK |
2756 | PKGEXT=${_PKGEXT:-$PKGEXT} |
2757 | SRCEXT=${_SRCEXT:-$SRCEXT} | |
4c31bc6e | 2758 | GPGKEY=${_GPGKEY:-$GPGKEY} |
5ba8b83b | 2759 | PACKAGER=${_PACKAGER:-$PACKAGER} |
5bcc058d | 2760 | CARCH=${_CARCH:-$CARCH} |
4b183bf9 | 2761 | |
c2999619 IG |
2762 | if (( ! INFAKEROOT )); then |
2763 | if (( EUID == 0 && ! ASROOT )); then | |
9ff52db3 | 2764 | # Warn those who like to live dangerously. |
1d16875d DM |
2765 | error "$(gettext "Running %s as root is a BAD idea and can cause permanent,\n\ |
2766 | catastrophic damage to your system. If you wish to run as root, please\n\ | |
2767 | use the %s option.")" "makepkg" "--asroot" | |
fb10e0c7 | 2768 | exit 1 # $E_USER_ABORT |
c2999619 | 2769 | elif (( EUID > 0 && ASROOT )); then |
fb10e0c7 | 2770 | # Warn those who try to use the --asroot option when they are not root |
1d16875d DM |
2771 | error "$(gettext "The %s option is meant for the root user only. Please\n\ |
2772 | rerun %s without the %s flag.")" "--asroot" "makepkg" "--asroot" | |
9ff52db3 | 2773 | exit 1 # $E_USER_ABORT |
9dd42dc0 | 2774 | elif (( EUID > 0 )) && ! check_buildenv "fakeroot" "y"; then |
1d16875d DM |
2775 | warning "$(gettext "Running %s as an unprivileged user will result in non-root\n\ |
2776 | ownership of the packaged files. Try using the %s environment by\n\ | |
2777 | placing %s in the %s array in %s.")" "makepkg" "fakeroot" "'fakeroot'" "BUILDENV" "$MAKEPKG_CONF" | |
9ff52db3 AF |
2778 | sleep 1 |
2779 | fi | |
2780 | else | |
c2999619 | 2781 | if [[ -z $FAKEROOTKEY ]]; then |
4bdb868a | 2782 | error "$(gettext "Do not use the %s option. This option is only for use by %s.")" "'-F'" "makepkg" |
9ff52db3 AF |
2783 | exit 1 # TODO: error code |
2784 | fi | |
2785 | fi | |
2786 | ||
b8ab96a2 | 2787 | unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides |
2cabe336 | 2788 | unset md5sums replaces depends conflicts backup source install changelog build |
7df0d048 | 2789 | unset makedepends optdepends options noextract |
4470e5ce | 2790 | |
5dc0b80c | 2791 | BUILDFILE=${BUILDFILE:-$BUILDSCRIPT} |
c2999619 | 2792 | if [[ ! -f $BUILDFILE ]]; then |
28dd29de AM |
2793 | error "$(gettext "%s does not exist.")" "$BUILDFILE" |
2794 | exit 1 | |
818fae32 | 2795 | else |
87acfef1 | 2796 | if [[ $(<"$BUILDFILE") = *$'\r'* ]]; then |
4bdb868a | 2797 | error "$(gettext "%s contains %s characters and cannot be sourced.")" "$BUILDFILE" "CRLF" |
818fae32 DM |
2798 | exit 1 |
2799 | fi | |
d04baaba | 2800 | |
c2999619 | 2801 | if [[ ${BUILDFILE:0:1} != "/" ]]; then |
5dc0b80c AM |
2802 | BUILDFILE="$startdir/$BUILDFILE" |
2803 | fi | |
8fe67919 | 2804 | source_safe "$BUILDFILE" |
250e66e5 | 2805 | fi |
d04baaba | 2806 | |
62fc9668 DM |
2807 | # set defaults if they weren't specified in buildfile |
2808 | pkgbase=${pkgbase:-${pkgname[0]}} | |
2809 | epoch=${epoch:-0} | |
2810 | ||
03465ad6 AM |
2811 | if [[ $BUILDDIR = "$startdir" ]]; then |
2812 | srcdir="$BUILDDIR/src" | |
f170a94c | 2813 | pkgdirbase="$BUILDDIR/pkg" |
03465ad6 AM |
2814 | else |
2815 | srcdir="$BUILDDIR/$pkgbase/src" | |
f170a94c AM |
2816 | pkgdirbase="$BUILDDIR/$pkgbase/pkg" |
2817 | ||
03465ad6 AM |
2818 | fi |
2819 | ||
f170a94c AM |
2820 | # set pkgdir to something "sensible" for (not recommended) use during build() |
2821 | pkgdir="$pkgdirbase/$pkgbase" | |
2822 | ||
c2999619 | 2823 | if (( GENINTEG )); then |
c11bdf19 | 2824 | mkdir -p "$srcdir" |
22331fda | 2825 | chmod a-s "$srcdir" |
92321449 | 2826 | cd_safe "$srcdir" |
7fd56118 | 2827 | download_sources fast |
c11bdf19 AM |
2828 | generate_checksums |
2829 | exit 0 # $E_OK | |
2830 | fi | |
2831 | ||
3b4e74cb | 2832 | if have_function pkgver; then |
a818766c AM |
2833 | PKGVERFUNC=1 |
2834 | fi | |
2835 | ||
e61ab153 | 2836 | # check the PKGBUILD for some basic requirements |
04d5c429 | 2837 | check_sanity || exit 1 |
c1a5616c | 2838 | |
74689562 | 2839 | # check we have the software required to process the PKGBUILD |
886a31ef | 2840 | check_software || exit 1 |
74689562 | 2841 | |
c2999619 | 2842 | if (( ${#pkgname[@]} > 1 )); then |
7df0d048 AM |
2843 | SPLITPKG=1 |
2844 | fi | |
2845 | ||
4d2ec375 | 2846 | # test for available PKGBUILD functions |
3b4e74cb | 2847 | if have_function prepare; then |
9de33488 EB |
2848 | # "Hide" prepare() function if not going to be run |
2849 | if [[ $RUN_PREPARE != "n" ]]; then | |
2850 | PREPAREFUNC=1 | |
2851 | fi | |
065b7f86 | 2852 | fi |
3b4e74cb | 2853 | if have_function build; then |
4d2ec375 CS |
2854 | BUILDFUNC=1 |
2855 | fi | |
3b4e74cb | 2856 | if have_function check; then |
0c29eb43 | 2857 | # "Hide" check() function if not going to be run |
9dd42dc0 | 2858 | if [[ $RUN_CHECK = 'y' ]] || { ! check_buildenv "check" "n" && [[ $RUN_CHECK != "n" ]]; }; then |
0c29eb43 AM |
2859 | CHECKFUNC=1 |
2860 | fi | |
2861 | fi | |
3b4e74cb | 2862 | if have_function package; then |
9c34dfd9 | 2863 | PKGFUNC=1 |
3b4e74cb | 2864 | elif [[ $SPLITPKG -eq 0 ]] && have_function package_${pkgname}; then |
9c34dfd9 AM |
2865 | SPLITPKG=1 |
2866 | fi | |
2867 | ||
f2c9e51e AM |
2868 | if [[ -n "${PKGLIST[@]}" ]]; then |
2869 | unset pkgname | |
7f5c4866 | 2870 | pkgname=("${PKGLIST[@]}") |
f2c9e51e AM |
2871 | fi |
2872 | ||
e8069cfc | 2873 | # check if gpg signature is to be created and if signing key is valid |
9dd42dc0 | 2874 | if { [[ -z $SIGNPKG ]] && check_buildenv "sign" "y"; } || [[ $SIGNPKG == 'y' ]]; then |
0285c678 | 2875 | SIGNPKG='y' |
4c31bc6e AM |
2876 | if ! gpg --list-key ${GPGKEY} &>/dev/null; then |
2877 | if [[ ! -z $GPGKEY ]]; then | |
4bdb868a | 2878 | error "$(gettext "The key %s does not exist in your keyring.")" "${GPGKEY}" |
e8069cfc DAF |
2879 | else |
2880 | error "$(gettext "There is no key in your keyring.")" | |
2881 | fi | |
2882 | exit 1 | |
2883 | fi | |
2884 | fi | |
2885 | ||
a818766c AM |
2886 | if (( ! PKGVERFUNC )); then |
2887 | check_build_status | |
d04baaba JV |
2888 | fi |
2889 | ||
8a9c83dd | 2890 | # Run the bare minimum in fakeroot |
c2999619 | 2891 | if (( INFAKEROOT )); then |
d21f6ca4 AM |
2892 | if (( SOURCEONLY )); then |
2893 | create_srcpackage | |
4bdb868a | 2894 | msg "$(gettext "Leaving %s environment.")" "fakeroot" |
d21f6ca4 AM |
2895 | exit 0 # $E_OK |
2896 | fi | |
2897 | ||
f170a94c | 2898 | chmod 755 "$pkgdirbase" |
c2999619 | 2899 | if (( ! SPLITPKG )); then |
f170a94c AM |
2900 | pkgdir="$pkgdirbase/$pkgname" |
2901 | mkdir "$pkgdir" | |
dece66ac | 2902 | if (( PKGFUNC )); then |
fba5771f | 2903 | run_package |
08034ceb | 2904 | fi |
7199fb3b | 2905 | tidy_install |
e946ee77 | 2906 | create_package |
7e8d9dfd | 2907 | create_debug_package |
e946ee77 | 2908 | else |
70418e48 | 2909 | run_split_packaging |
d04baaba | 2910 | fi |
9ff52db3 | 2911 | |
4bdb868a | 2912 | msg "$(gettext "Leaving %s environment.")" "fakeroot" |
9ff52db3 | 2913 | exit 0 # $E_OK |
d04baaba JV |
2914 | fi |
2915 | ||
ccdb2fa8 | 2916 | fullver=$(get_full_version) |
b8ab96a2 | 2917 | msg "$(gettext "Making package: %s")" "$pkgbase $fullver ($(date))" |
d04baaba | 2918 | |
f4d6efee | 2919 | # if we are creating a source-only package, go no further |
c2999619 | 2920 | if (( SOURCEONLY )); then |
b8ab96a2 | 2921 | if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \ |
8e533b03 | 2922 | && (( ! FORCE )); then |
4bdb868a | 2923 | error "$(gettext "A source package has already been built. (use %s to overwrite)")" "-f" |
f4d6efee DM |
2924 | exit 1 |
2925 | fi | |
d21f6ca4 AM |
2926 | |
2927 | # Get back to our src directory so we can begin with sources. | |
2928 | mkdir -p "$srcdir" | |
2929 | chmod a-s "$srcdir" | |
92321449 | 2930 | cd_safe "$srcdir" |
7fd56118 | 2931 | if (( SOURCEONLY == 2 )); then |
d21f6ca4 | 2932 | download_sources |
7fd56118 AM |
2933 | elif ( (( ! SKIPCHECKSUMS )) || \ |
2934 | ( (( ! SKIPPGPCHECK )) && source_has_signatures ) ); then | |
2935 | download_sources fast | |
d21f6ca4 | 2936 | fi |
49d9426b | 2937 | check_source_integrity |
92321449 | 2938 | cd_safe "$startdir" |
d21f6ca4 AM |
2939 | |
2940 | # if we are root or if fakeroot is not enabled, then we don't use it | |
9dd42dc0 | 2941 | if ! check_buildenv "fakeroot" "y" || (( EUID == 0 )); then |
d21f6ca4 AM |
2942 | create_srcpackage |
2943 | else | |
2944 | enter_fakeroot | |
2945 | fi | |
2946 | ||
7df0d048 | 2947 | msg "$(gettext "Source package created: %s")" "$pkgbase ($(date))" |
f4d6efee DM |
2948 | exit 0 |
2949 | fi | |
2950 | ||
81dd6ddf AM |
2951 | if (( NODEPS || (NOBUILD && !DEP_BIN ) )); then |
2952 | # no warning message needed for nobuild | |
2953 | if (( NODEPS )); then | |
76fd8545 | 2954 | warning "$(gettext "Skipping dependency checks.")" |
fafeb32c | 2955 | fi |
3531533c | 2956 | else |
b7c06d6d | 2957 | if (( RMDEPS && ! INSTALL )); then |
d7dccd54 | 2958 | original_pkglist=($(run_pacman -Qq)) # required by remove_dep |
ccbef232 | 2959 | fi |
7e9fdfd4 AG |
2960 | deperr=0 |
2961 | ||
1b93a116 | 2962 | msg "$(gettext "Checking runtime dependencies...")" |
3b1e6762 | 2963 | resolve_deps ${depends[@]} || deperr=1 |
7e9fdfd4 | 2964 | |
b7c06d6d AG |
2965 | if (( RMDEPS && INSTALL )); then |
2966 | original_pkglist=($(run_pacman -Qq)) # required by remove_dep | |
2967 | fi | |
2968 | ||
1b93a116 | 2969 | msg "$(gettext "Checking buildtime dependencies...")" |
0c29eb43 | 2970 | if (( CHECKFUNC )); then |
a774e4d5 AW |
2971 | resolve_deps "${makedepends[@]}" "${checkdepends[@]}" || deperr=1 |
2972 | else | |
2973 | resolve_deps "${makedepends[@]}" || deperr=1 | |
0c29eb43 AM |
2974 | fi |
2975 | ||
ccbef232 | 2976 | if (( RMDEPS )); then |
d7dccd54 | 2977 | current_pkglist=($(run_pacman -Qq)) # required by remove_deps |
ccbef232 AM |
2978 | fi |
2979 | ||
c2999619 | 2980 | if (( deperr )); then |
76fd8545 | 2981 | error "$(gettext "Could not resolve all dependencies.")" |
d04baaba JV |
2982 | exit 1 |
2983 | fi | |
d04baaba JV |
2984 | fi |
2985 | ||
17180890 CX |
2986 | # ensure we have a sane umask set |
2987 | umask 0022 | |
2988 | ||
9883c157 | 2989 | # get back to our src directory so we can begin with sources |
c6c60bcc | 2990 | mkdir -p "$srcdir" |
22331fda | 2991 | chmod a-s "$srcdir" |
92321449 | 2992 | cd_safe "$srcdir" |
df290b49 | 2993 | |
2259dff7 | 2994 | if (( NOEXTRACT && ! VERIFYSOURCE )); then |
85506809 | 2995 | warning "$(gettext "Using existing %s tree")" "src/" |
dece66ac | 2996 | elif (( !REPKG )); then |
9883c157 | 2997 | download_sources |
49d9426b | 2998 | check_source_integrity |
2259dff7 | 2999 | (( VERIFYSOURCE )) && exit 0 # $E_OK |
e19d7da4 | 3000 | extract_sources |
065b7f86 E |
3001 | if (( PREPAREFUNC )); then |
3002 | run_prepare | |
3003 | fi | |
7dacc70b | 3004 | fi |
d04baaba | 3005 | |
c2999619 | 3006 | if (( NOBUILD )); then |
f044e23a | 3007 | msg "$(gettext "Sources are ready.")" |
9883c157 | 3008 | exit 0 #E_OK |
7dacc70b | 3009 | else |
dece66ac AM |
3010 | # clean existing pkg directory |
3011 | if [[ -d $pkgdirbase ]]; then | |
4bdb868a | 3012 | msg "$(gettext "Removing existing %s directory...")" "pkg/" |
f170a94c | 3013 | rm -rf "$pkgdirbase" |
42a6acf7 | 3014 | fi |
f170a94c AM |
3015 | mkdir -p "$pkgdirbase" |
3016 | chmod a-srwx "$pkgdirbase" | |
92321449 | 3017 | cd_safe "$startdir" |
d04baaba | 3018 | |
69be73f6 | 3019 | # if we are root or if fakeroot is not enabled, then we don't use it |
9dd42dc0 | 3020 | if ! check_buildenv "fakeroot" "y" || (( EUID == 0 )); then |
c2999619 | 3021 | if (( ! REPKG )); then |
f170a94c AM |
3022 | if (( ! ( SPLITPKG || PKGFUNC ) )); then |
3023 | chmod 755 "$pkgdirbase" | |
3024 | mkdir -p "$pkgdir" | |
3025 | fi | |
4d2ec375 | 3026 | (( BUILDFUNC )) && run_build |
0c29eb43 | 3027 | (( CHECKFUNC )) && run_check |
fba5771f | 3028 | fi |
f170a94c | 3029 | chmod 755 "$pkgdirbase" |
c2999619 | 3030 | if (( ! SPLITPKG )); then |
f170a94c | 3031 | pkgdir="$pkgdirbase/$pkgname" |
a53fd796 | 3032 | mkdir -p "$pkgdir" |
c2999619 | 3033 | if (( PKGFUNC )); then |
fba5771f | 3034 | run_package |
e946ee77 | 3035 | fi |
7199fb3b | 3036 | tidy_install |
e946ee77 | 3037 | create_package |
7e8d9dfd | 3038 | create_debug_package |
e946ee77 | 3039 | else |
70418e48 | 3040 | run_split_packaging |
9ff52db3 | 3041 | fi |
9ff52db3 | 3042 | else |
dece66ac | 3043 | if (( ! REPKG )); then |
4d2ec375 | 3044 | (( BUILDFUNC )) && run_build |
0c29eb43 | 3045 | (( CHECKFUNC )) && run_check |
92321449 | 3046 | cd_safe "$startdir" |
08034ceb AM |
3047 | fi |
3048 | ||
d21f6ca4 | 3049 | enter_fakeroot |
9ff52db3 AF |
3050 | fi |
3051 | fi | |
5a48e4f1 | 3052 | |
ccdb2fa8 | 3053 | fullver=$(get_full_version) |
b8ab96a2 | 3054 | msg "$(gettext "Finished making: %s")" "$pkgbase $fullver ($(date))" |
d04baaba | 3055 | |
214f264b | 3056 | install_package |
d04baaba | 3057 | |
9883c157 | 3058 | exit 0 #E_OK |
f044e23a | 3059 | |
e2f42947 | 3060 | # vim: set ts=2 sw=2 noet: |