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