makepkg: allow specifying alternative build directory
[pacman-ng.git] / scripts / makepkg.sh.in
blob09eacbb1ec2fc934e16a3405c532a1b21aee224a
1 #!@BASH_SHELL@ -e
3 # makepkg - make packages compatible for use with pacman
4 # @configure_input@
6 # Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
7 # Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
8 # Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
9 # Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
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>
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.
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.
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
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:
30 # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils),
31 # gettext, gpg, grep, gzip, openssl, sed, tput (ncurses), xz
33 # gettext initialization
34 export TEXTDOMAIN='pacman'
35 export TEXTDOMAINDIR='@localedir@'
37 # file -i does not work on Mac OSX unless legacy mode is set
38 export COMMAND_MODE='legacy'
40 myver='@PACKAGE_VERSION@'
41 confdir='@sysconfdir@'
42 BUILDSCRIPT='@BUILDSCRIPT@'
43 startdir="$PWD"
45 packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge' 'upx')
46 other_options=('ccache' 'distcc' 'buildflags' 'makeflags')
47 splitpkg_overrides=('pkgver' 'pkgrel' 'pkgdesc' 'arch' 'license' 'groups' \
48 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' \
49 'backup' 'options' 'install' 'changelog')
50 readonly -a packaging_options other_options splitpkg_overrides
52 # Options
53 ASROOT=0
54 CLEANUP=0
55 CLEANCACHE=0
56 DEP_BIN=0
57 FORCE=0
58 INFAKEROOT=0
59 GENINTEG=0
60 SKIPINTEG=0
61 INSTALL=0
62 NOBUILD=0
63 NODEPS=0
64 NOEXTRACT=0
65 RMDEPS=0
66 REPKG=0
67 LOGGING=0
68 SOURCEONLY=0
69 IGNOREARCH=0
70 HOLDVER=0
71 BUILDFUNC=0
72 CHECKFUNC=0
73 PKGFUNC=0
74 SPLITPKG=0
75 PKGLIST=()
76 SIGNPKG=''
78 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
79 # when dealing with svn/cvs/etc PKGBUILDs.
80 FORCE_VER=""
82 PACMAN_OPTS=
84 ### SUBROUTINES ###
86 plain() {
87 local mesg=$1; shift
88 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
91 msg() {
92 local mesg=$1; shift
93 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
96 msg2() {
97 local mesg=$1; shift
98 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
101 warning() {
102 local mesg=$1; shift
103 printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
106 error() {
107 local mesg=$1; shift
108 printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
113 # Special exit call for traps, Don't print any error messages when inside,
114 # the fakeroot call, the error message will be printed by the main call.
116 trap_exit() {
117 if (( ! INFAKEROOT )); then
118 echo
119 error "$@"
121 [[ -n $srclinks ]] && rm -rf "$srclinks"
122 exit 1
127 # Clean up function. Called automatically when the script exits.
129 clean_up() {
130 local EXIT_CODE=$?
132 if (( INFAKEROOT )); then
133 # Don't clean up when leaving fakeroot, we're not done yet.
134 return
137 if (( ! EXIT_CODE && CLEANUP )); then
138 local pkg file
140 # If it's a clean exit and -c/--clean has been passed...
141 msg "$(gettext "Cleaning up...")"
142 rm -rf "$pkgdir" "$srcdir"
143 if [[ -n $pkgbase ]]; then
144 # TODO: this wasn't properly fixed in commit 2020e629
145 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
146 # Can't do this unless the BUILDSCRIPT has been sourced.
147 if (( BUILDFUNC )); then
148 rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
150 if (( CHECKFUNC )); then
151 rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"*
153 if (( PKGFUNC )); then
154 rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"*
155 elif (( SPLITPKG )); then
156 for pkg in ${pkgname[@]}; do
157 rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"*
158 done
161 # clean up dangling symlinks to packages
162 for pkg in ${pkgname[@]}; do
163 for file in ${pkg}-*-*-${CARCH}{${PKGEXT},${SRCEXT}}; do
164 if [[ -h $file && ! -e $file ]]; then
165 rm -f $file
167 done
168 done
172 remove_deps
177 # Signal Traps
179 set -E
180 trap 'clean_up' 0
181 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
182 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
183 trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
185 # a source entry can have two forms :
186 # 1) "filename::http://path/to/file"
187 # 2) "http://path/to/file"
189 enter_fakeroot() {
190 msg "$(gettext "Entering fakeroot environment...")"
192 if [[ -n $newpkgver ]]; then
193 fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $?
194 else
195 fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
199 # Return the absolute filename of a source entry
201 # This function accepts a source entry or the already extracted filename of a
202 # source entry as input
203 get_filepath() {
204 local file="$(get_filename "$1")"
206 if [[ -f "$startdir/$file" ]]; then
207 file="$startdir/$file"
208 elif [[ -f "$SRCDEST/$file" ]]; then
209 file="$SRCDEST/$file"
210 else
211 return 1
214 echo "$file"
217 # Print 'source not found' error message and exit makepkg
218 missing_source_file() {
219 error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")"
220 plain "$(gettext "Aborting...")"
221 exit 1 # $E_MISSING_FILE
224 # extract the filename from a source entry
225 get_filename() {
226 # if a filename is specified, use it
227 local filename="${1%%::*}"
228 # if it is just an URL, we only keep the last component
229 echo "${filename##*/}"
232 # extract the URL from a source entry
233 get_url() {
234 # strip an eventual filename
235 echo "${1#*::}"
239 # usage : get_full_version( $epoch, $pkgver, $pkgrel )
240 # return : full version spec, including epoch (if necessary), pkgver, pkgrel
242 get_full_version() {
243 if [[ $1 -eq 0 ]]; then
244 # zero epoch case, don't include it in version
245 echo $2-$3
246 else
247 echo $1:$2-$3
252 # Checks to see if options are present in makepkg.conf or PKGBUILD;
253 # PKGBUILD options always take precedence.
255 # usage : check_option( $option )
256 # return : y - enabled
257 # n - disabled
258 # ? - not found
260 check_option() {
261 local ret=$(in_opt_array "$1" ${options[@]})
262 if [[ $ret != '?' ]]; then
263 echo $ret
264 return
267 # fall back to makepkg.conf options
268 ret=$(in_opt_array "$1" ${OPTIONS[@]})
269 if [[ $ret != '?' ]]; then
270 echo $ret
271 return
274 echo '?' # Not Found
279 # Check if option is present in BUILDENV
281 # usage : check_buildenv( $option )
282 # return : y - enabled
283 # n - disabled
284 # ? - not found
286 check_buildenv() {
287 echo $(in_opt_array "$1" ${BUILDENV[@]})
292 # usage : in_opt_array( $needle, $haystack )
293 # return : y - enabled
294 # n - disabled
295 # ? - not found
297 in_opt_array() {
298 local needle=$1; shift
300 local opt
301 for opt in "$@"; do
302 if [[ $opt = $needle ]]; then
303 echo 'y' # Enabled
304 return
305 elif [[ $opt = "!$needle" ]]; then
306 echo 'n' # Disabled
307 return
309 done
311 echo '?' # Not Found
316 # usage : in_array( $needle, $haystack )
317 # return : 0 - found
318 # 1 - not found
320 in_array() {
321 local needle=$1; shift
322 [[ -z $1 ]] && return 1 # Not Found
323 local item
324 for item in "$@"; do
325 [[ $item = $needle ]] && return 0 # Found
326 done
327 return 1 # Not Found
330 get_downloadclient() {
331 # $1 = URL with valid protocol prefix
332 local url=$1
333 local proto="${url%%://*}"
335 # loop through DOWNLOAD_AGENTS variable looking for protocol
336 local i
337 for i in "${DLAGENTS[@]}"; do
338 local handler="${i%%::*}"
339 if [[ $proto = $handler ]]; then
340 local agent="${i##*::}"
341 break
343 done
345 # if we didn't find an agent, return an error
346 if [[ -z $agent ]]; then
347 error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF"
348 plain "$(gettext "Aborting...")"
349 exit 1 # $E_CONFIG_ERROR
352 # ensure specified program is installed
353 local program="${agent%% *}"
354 if [[ ! -x $program ]]; then
355 local baseprog="${program##*/}"
356 error "$(gettext "The download program %s is not installed.")" "$baseprog"
357 plain "$(gettext "Aborting...")"
358 exit 1 # $E_MISSING_PROGRAM
361 echo "$agent"
364 download_file() {
365 # download command
366 local dlcmd=$1
367 # URL of the file
368 local url=$2
369 # destination file
370 local file=$3
371 # temporary download file, default to last component of the URL
372 local dlfile="${url##*/}"
374 # replace %o by the temporary dlfile if it exists
375 if [[ $dlcmd = *%o* ]]; then
376 dlcmd=${dlcmd//\%o/\"$file.part\"}
377 dlfile="$file.part"
379 # add the URL, either in place of %u or at the end
380 if [[ $dlcmd = *%u* ]]; then
381 dlcmd=${dlcmd//\%u/\"$url\"}
382 else
383 dlcmd="$dlcmd \"$url\""
386 local ret=0
387 eval "$dlcmd || ret=\$?"
388 if (( ret )); then
389 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
390 return $ret
393 # rename the temporary download file to the final destination
394 if [[ $dlfile != $file ]]; then
395 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
399 run_pacman() {
400 local cmd
401 printf -v cmd "%q " "$PACMAN" $PACMAN_OPTS "$@"
402 if (( ! ASROOT )) && [[ ! $1 =~ ^-(T|Qq)$ ]]; then
403 if type -p sudo >/dev/null; then
404 cmd="sudo $cmd"
405 else
406 cmd="su root -c '$cmd'"
409 eval "$cmd"
412 check_deps() {
413 (( $# > 0 )) || return 0
415 # Disable error trap in pacman subshell call as this breaks bash-3.2 compatibility
416 # Also, a non-zero return value is not unexpected and we are manually dealing them
417 set +E
418 local ret=0
419 local pmout
420 pmout=$(run_pacman -T "$@") || ret=$?
421 set -E
423 if (( ret == 127 )); then #unresolved deps
424 echo "$pmout"
425 elif (( ret )); then
426 error "$(gettext "'%s' returned a fatal error (%i): %s")" "$PACMAN" "$ret" "$pmout"
427 return "$ret"
431 handle_deps() {
432 local R_DEPS_SATISFIED=0
433 local R_DEPS_MISSING=1
435 (( $# == 0 )) && return $R_DEPS_SATISFIED
437 local deplist="$*"
439 if (( ! DEP_BIN )); then
440 return $R_DEPS_MISSING
443 if (( DEP_BIN )); then
444 # install missing deps from binary packages (using pacman -S)
445 msg "$(gettext "Installing missing dependencies...")"
447 if ! run_pacman -S --asdeps $deplist; then
448 error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN"
449 exit 1 # TODO: error code
453 # we might need the new system environment
454 # avoid triggering the ERR trap
455 local restoretrap=$(trap -p ERR)
456 trap - ERR
457 source /etc/profile &>/dev/null
458 eval $restoretrap
460 return $R_DEPS_SATISFIED
463 resolve_deps() {
464 local R_DEPS_SATISFIED=0
465 local R_DEPS_MISSING=1
467 # deplist cannot be declared like this: local deplist=$(foo)
468 # Otherwise, the return value will depend on the assignment.
469 local deplist
470 deplist="$(set +E; check_deps $*)" || exit 1
471 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
473 if handle_deps $deplist; then
474 # check deps again to make sure they were resolved
475 deplist="$(set +E; check_deps $*)" || exit 1
476 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
479 msg "$(gettext "Missing Dependencies:")"
480 local dep
481 for dep in $deplist; do
482 msg2 "$dep"
483 done
485 return $R_DEPS_MISSING
488 remove_deps() {
489 (( ! RMDEPS )) && return
491 # check for packages removed during dependency install (e.g. due to conflicts)
492 # removing all installed packages is risky in this case
493 if [[ -n $(comm -23 <(printf "%s\n" "${original_pkglist[@]}") \
494 <(printf "%s\n" "${current_pkglist[@]}")) ]]; then
495 warning "$(gettext "Failed to remove installed dependencies.")"
496 return 0
499 local deplist=($(comm -13 <(printf "%s\n" "${original_pkglist[@]}") \
500 <(printf "%s\n" "${current_pkglist[@]}")))
501 (( ${#deplist[@]} == 0 )) && return
503 msg "Removing installed dependencies..."
504 # exit cleanly on failure to remove deps as package has been built successfully
505 if ! run_pacman -Rn ${deplist[@]}; then
506 warning "$(gettext "Failed to remove installed dependencies.")"
507 return 0
511 download_sources() {
512 msg "$(gettext "Retrieving Sources...")"
514 pushd "$SRCDEST" &>/dev/null
516 local netfile
517 for netfile in "${source[@]}"; do
518 local file=$(get_filepath "$netfile" || true)
519 if [[ -n "$file" ]]; then
520 msg2 "$(gettext "Found %s")" "${file##*/}"
521 ln -sf "$file" "$srcdir/"
522 continue
525 file=$(get_filename "$netfile")
526 local url=$(get_url "$netfile")
528 # if we get here, check to make sure it was a URL, else fail
529 if [[ $file = $url ]]; then
530 error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file"
531 exit 1 # $E_MISSING_FILE
534 # find the client we should use for this URL
535 local dlclient=$(get_downloadclient "$url") || exit $?
537 msg2 "$(gettext "Downloading %s...")" "$file"
538 # fix flyspray bug #3289
539 local ret=0
540 download_file "$dlclient" "$url" "$file" || ret=$?
541 if (( ret )); then
542 error "$(gettext "Failure while downloading %s")" "$file"
543 plain "$(gettext "Aborting...")"
544 exit 1
546 rm -f "$srcdir/$file"
547 ln -s "$SRCDEST/$file" "$srcdir/"
548 done
550 popd &>/dev/null
553 get_integlist() {
554 local integ
555 local integlist=()
557 for integ in md5 sha1 sha256 sha384 sha512; do
558 local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
559 if [[ -n "$integrity_sums" ]]; then
560 integlist=(${integlist[@]} $integ)
562 done
564 if (( ${#integlist[@]} > 0 )); then
565 echo ${integlist[@]}
566 else
567 echo ${INTEGRITY_CHECK[@]}
571 generate_checksums() {
572 msg "$(gettext "Generating checksums for source files...")"
573 plain ""
575 if ! type -p openssl >/dev/null; then
576 error "$(gettext "Cannot find openssl.")"
577 exit 1 # $E_MISSING_PROGRAM
580 local integlist
581 if (( $# == 0 )); then
582 integlist=$(get_integlist)
583 else
584 integlist=$@
587 local integ
588 for integ in ${integlist[@]}; do
589 case "$integ" in
590 md5|sha1|sha256|sha384|sha512) : ;;
592 error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
593 exit 1;; # $E_CONFIG_ERROR
594 esac
596 local ct=0
597 local numsrc=${#source[@]}
598 echo -n "${integ}sums=("
600 local i
601 local indent=''
602 for (( i = 0; i < ${#integ} + 6; i++ )); do
603 indent="$indent "
604 done
606 local netfile
607 for netfile in "${source[@]}"; do
608 local file="$(get_filepath "$netfile")" || missing_source_file "$netfile"
609 local sum="$(openssl dgst -${integ} "$file")"
610 sum=${sum##* }
611 (( ct )) && echo -n "$indent"
612 echo -n "'$sum'"
613 ct=$(($ct+1))
614 (( $ct < $numsrc )) && echo
615 done
617 echo ")"
618 done
621 check_checksums() {
622 (( ! ${#source[@]} )) && return 0
624 if ! type -p openssl >/dev/null; then
625 error "$(gettext "Cannot find openssl.")"
626 exit 1 # $E_MISSING_PROGRAM
629 local correlation=0
630 local integ required
631 for integ in md5 sha1 sha256 sha384 sha512; do
632 local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
633 if (( ${#integrity_sums[@]} == ${#source[@]} )); then
634 msg "$(gettext "Validating source files with %s...")" "${integ}sums"
635 correlation=1
636 local errors=0
637 local idx=0
638 local file
639 for file in "${source[@]}"; do
640 local found=1
641 file="$(get_filename "$file")"
642 echo -n " $file ... " >&2
644 if ! file="$(get_filepath "$file")"; then
645 echo "$(gettext "NOT FOUND")" >&2
646 errors=1
647 found=0
650 if (( $found )) ; then
651 local expectedsum=$(tr '[:upper:]' '[:lower:]' <<< "${integrity_sums[$idx]}")
652 local realsum="$(openssl dgst -${integ} "$file")"
653 realsum="${realsum##* }"
654 if [[ $expectedsum = $realsum ]]; then
655 echo "$(gettext "Passed")" >&2
656 else
657 echo "$(gettext "FAILED")" >&2
658 errors=1
662 idx=$((idx + 1))
663 done
665 if (( errors )); then
666 error "$(gettext "One or more files did not pass the validity check!")"
667 exit 1 # TODO: error code
669 elif (( ${#integrity_sums[@]} )); then
670 error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
671 exit 1 # TODO: error code
673 done
675 if (( ! correlation )); then
676 error "$(gettext "Integrity checks are missing.")"
677 exit 1 # TODO: error code
681 extract_sources() {
682 msg "$(gettext "Extracting Sources...")"
683 local netfile
684 for netfile in "${source[@]}"; do
685 local file=$(get_filename "$netfile")
686 if in_array "$file" ${noextract[@]}; then
687 #skip source files in the noextract=() array
688 # these are marked explicitly to NOT be extracted
689 continue
693 # fix flyspray #6246
694 local file_type=$(file -bizL "$file")
695 local ext=${file##*.}
696 local cmd=''
697 case "$file_type" in
698 *application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*)
699 cmd="bsdtar" ;;
700 *application/x-gzip*)
701 case "$ext" in
702 gz|z|Z) cmd="gzip" ;;
703 *) continue;;
704 esac ;;
705 *application/x-bzip*)
706 case "$ext" in
707 bz2|bz) cmd="bzip2" ;;
708 *) continue;;
709 esac ;;
710 *application/x-xz*)
711 case "$ext" in
712 xz) cmd="xz" ;;
713 *) continue;;
714 esac ;;
716 # See if bsdtar can recognize the file
717 if bsdtar -tf "$file" -q '*' &>/dev/null; then
718 cmd="bsdtar"
719 else
720 continue
721 fi ;;
722 esac
724 local ret=0
725 msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd"
726 if [[ $cmd = bsdtar ]]; then
727 $cmd -xf "$file" || ret=$?
728 else
729 rm -f "${file%.*}"
730 $cmd -dcf "$file" > "${file%.*}" || ret=$?
732 if (( ret )); then
733 error "$(gettext "Failed to extract %s")" "$file"
734 plain "$(gettext "Aborting...")"
735 exit 1
737 done
739 if (( EUID == 0 )); then
740 # change perms of all source files to root user & root group
741 chown -R 0:0 "$srcdir"
745 error_function() {
746 if [[ -p $logpipe ]]; then
747 rm "$logpipe"
749 # first exit all subshells, then print the error
750 if (( ! BASH_SUBSHELL )); then
751 error "$(gettext "A failure occurred in %s().")" "$1"
752 plain "$(gettext "Aborting...")"
753 remove_deps
755 exit 2 # $E_BUILD_FAILED
758 run_function() {
759 if [[ -z $1 ]]; then
760 return 1
762 local pkgfunc="$1"
764 # clear user-specified buildflags if requested
765 if [[ $(check_option buildflags) = "n" ]]; then
766 CFLAGS=""
767 CXXFLAGS=""
768 LDFLAGS=""
771 # clear user-specified makeflags if requested
772 if [[ $(check_option makeflags) = "n" ]]; then
773 MAKEFLAGS=""
776 msg "$(gettext "Starting %s()...")" "$pkgfunc"
777 cd "$srcdir"
779 # ensure all necessary build variables are exported
780 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
781 # save our shell options so pkgfunc() can't override what we need
782 local shellopts=$(shopt -p)
784 local ret=0
785 local restoretrap
786 if (( LOGGING )); then
787 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
788 local BUILDLOG="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
789 if [[ -f $BUILDLOG ]]; then
790 local i=1
791 while true; do
792 if [[ -f $BUILDLOG.$i ]]; then
793 i=$(($i +1))
794 else
795 break
797 done
798 mv "$BUILDLOG" "$BUILDLOG.$i"
801 # ensure overridden package variables survive tee with split packages
802 logpipe=$(mktemp -u "$startdir/logpipe.XXXXXXXX")
803 mkfifo "$logpipe"
804 tee "$BUILDLOG" < "$logpipe" &
805 local teepid=$!
807 restoretrap=$(trap -p ERR)
808 trap 'error_function $pkgfunc' ERR
809 $pkgfunc &>"$logpipe"
810 eval $restoretrap
812 wait $teepid
813 rm "$logpipe"
814 else
815 restoretrap=$(trap -p ERR)
816 trap 'error_function $pkgfunc' ERR
817 $pkgfunc 2>&1
818 eval $restoretrap
820 # reset our shell options
821 eval "$shellopts"
824 run_build() {
825 # use distcc if it is requested (check buildenv and PKGBUILD opts)
826 if [[ $(check_buildenv distcc) = "y" && $(check_option distcc) != "n" ]]; then
827 [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH"
828 export DISTCC_HOSTS
829 elif [[ $(check_option distcc) = "n" ]]; then
830 # if it is not wanted, clear the makeflags too
831 MAKEFLAGS=""
834 # use ccache if it is requested (check buildenv and PKGBUILD opts)
835 if [[ $(check_buildenv ccache) = "y" && $(check_option ccache) != "n" ]]; then
836 [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH"
839 run_function "build"
842 run_check() {
843 run_function "check"
846 run_package() {
847 local pkgfunc
848 if [[ -z $1 ]]; then
849 pkgfunc="package"
850 else
851 pkgfunc="package_$1"
854 run_function "$pkgfunc"
857 tidy_install() {
858 cd "$pkgdir"
859 msg "$(gettext "Tidying install...")"
861 if [[ $(check_option docs) = "n" && -n ${DOC_DIRS[*]} ]]; then
862 msg2 "$(gettext "Removing doc files...")"
863 rm -rf ${DOC_DIRS[@]}
866 if [[ $(check_option purge) = "y" && -n ${PURGE_TARGETS[*]} ]]; then
867 msg2 "$(gettext "Purging unwanted files...")"
868 local pt
869 for pt in "${PURGE_TARGETS[@]}"; do
870 if [[ ${pt} = ${pt//\/} ]]; then
871 find . -type f -name "${pt}" -exec rm -f -- '{}' \;
872 else
873 rm -f ${pt}
875 done
878 if [[ $(check_option zipman) = "y" && -n ${MAN_DIRS[*]} ]]; then
879 msg2 "$(gettext "Compressing man and info pages...")"
880 local manpage ext file link hardlinks hl
881 find ${MAN_DIRS[@]} -type f 2>/dev/null |
882 while read manpage ; do
883 ext="${manpage##*.}"
884 file="${manpage##*/}"
885 if [[ $ext != gz && $ext != bz2 ]]; then
886 # update symlinks to this manpage
887 find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null |
888 while read link ; do
889 rm -f "$link"
890 ln -sf "${file}.gz" "${link}.gz"
891 done
893 # check file still exists (potentially already compressed due to hardlink)
894 if [[ -f ${manpage} ]]; then
895 # find hard links and remove them
896 # the '|| true' part keeps the script from bailing if find returned an
897 # error, such as when one of the man directories doesn't exist
898 hardlinks="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
899 for hl in ${hardlinks}; do
900 rm -f "${hl}";
901 done
902 # compress the original
903 gzip -9 "$manpage"
904 # recreate hard links removed earlier
905 for hl in ${hardlinks}; do
906 ln "${manpage}.gz" "${hl}.gz"
907 chmod 644 ${hl}.gz
908 done
911 done
914 if [[ $(check_option strip) = y ]]; then
915 msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")"
916 # make sure library stripping variables are defined to prevent excess stripping
917 [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S"
918 [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S"
919 local binary
920 find . -type f -perm -u+w 2>/dev/null | while read binary ; do
921 case "$(file -bi "$binary")" in
922 *application/x-sharedlib*) # Libraries (.so)
923 /usr/bin/strip $STRIP_SHARED "$binary";;
924 *application/x-archive*) # Libraries (.a)
925 /usr/bin/strip $STRIP_STATIC "$binary";;
926 *application/x-executable*) # Binaries
927 /usr/bin/strip $STRIP_BINARIES "$binary";;
928 esac
929 done
932 if [[ $(check_option libtool) = "n" ]]; then
933 msg2 "$(gettext "Removing libtool .la files...")"
934 find . ! -type d -name "*.la" -exec rm -f -- '{}' \;
937 if [[ $(check_option emptydirs) = "n" ]]; then
938 msg2 "$(gettext "Removing empty directories...")"
939 find . -depth -type d -empty -delete
942 if [[ $(check_option upx) = "y" ]]; then
943 msg2 "$(gettext "Compressing binaries with %s...")" "UPX"
944 local binary
945 find . -type f -perm -u+w 2>/dev/null | while read binary ; do
946 if [[ $(file -bi "$binary") = *'application/x-executable'* ]]; then
947 upx $UPXFLAGS "$binary" &>/dev/null ||
948 warning "$(gettext "Could not compress binary : %s")" "${binary/$pkgdir\//}"
950 done
954 find_libdepends() {
955 local libdepends
956 find "$pkgdir" -type f -perm -u+x | while read filename
958 # get architecture of the file; if soarch is empty it's not an ELF binary
959 soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
960 [ -n "$soarch" ] || continue
961 # process all libraries needed by the binary
962 for sofile in $(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
964 # extract the library name: libfoo.so
965 soname="${sofile%%\.so\.*}.so"
966 # extract the major version: 1
967 soversion="${sofile##*\.so\.}"
968 if in_array "${soname}" ${depends[@]}; then
969 if ! in_array "${soname}=${soversion}-${soarch}" ${libdepends[@]}; then
970 # libfoo.so=1-64
971 echo "${soname}=${soversion}-${soarch}"
972 libdepends=(${libdepends[@]} "${soname}=${soversion}-${soarch}")
975 done
976 done
979 find_libprovides() {
980 local libprovides
981 find "$pkgdir" -type f -name \*.so\* | while read filename
983 # check if we really have a shared object
984 if LC_ALL=C readelf -h "$filename" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then
985 # 64
986 soarch=$(LC_ALL=C readelf -h "$filename" | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
987 # get the string binaries link to: libfoo.so.1.2 -> libfoo.so.1
988 sofile=$(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
989 [ -z "$sofile" ] && sofile="${filename##*/}"
991 # extract the library name: libfoo.so
992 soname="${sofile%%\.so\.*}.so"
993 # extract the major version: 1
994 soversion="${sofile##*\.so\.}"
995 if in_array "${soname}" ${provides[@]}; then
996 if ! in_array "${soname}=${soversion}-${soarch}" ${libprovides[@]}; then
997 # libfoo.so=1-64
998 echo "${soname}=${soversion}-${soarch}"
999 libprovides=(${libprovides[@]} "${soname}=${soversion}-${soarch}")
1003 done
1006 write_pkginfo() {
1007 local builddate=$(date -u "+%s")
1008 if [[ -n $PACKAGER ]]; then
1009 local packager="$PACKAGER"
1010 else
1011 local packager="Unknown Packager"
1013 local size="$(@DUPATH@ -sk)"
1014 size="$(( ${size%%[^0-9]*} * 1024 ))"
1016 msg2 "$(gettext "Generating .PKGINFO file...")"
1017 echo "# Generated by makepkg $myver"
1018 if (( INFAKEROOT )); then
1019 echo "# using $(fakeroot -v)"
1021 echo "# $(LC_ALL=C date -u)"
1022 echo "pkgname = $1"
1023 (( SPLITPKG )) && echo pkgbase = $pkgbase
1024 echo "pkgver = $(get_full_version $epoch $pkgver $pkgrel)"
1025 echo "pkgdesc = $pkgdesc"
1026 echo "url = $url"
1027 echo "builddate = $builddate"
1028 echo "packager = $packager"
1029 echo "size = $size"
1030 echo "arch = $PKGARCH"
1032 [[ $license ]] && printf "license = %s\n" "${license[@]}"
1033 [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
1034 [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
1035 [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]}"
1036 [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
1037 [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
1039 local it
1041 libprovides=$(find_libprovides)
1042 libdepends=$(find_libdepends)
1043 provides=("${provides[@]}" ${libprovides})
1044 depends=("${depends[@]}" ${libdepends})
1046 for it in "${depends[@]}"; do
1047 if [[ $it = *.so ]]; then
1048 # check if the entry has been found by find_libdepends
1049 # if not, it's unneeded; tell the user so he can remove it
1050 if [[ ! $libdepends =~ (^|\s)${it}=.* ]]; then
1051 error "$(gettext "Can't find library listed in \$depends: %s")" "$it"
1052 return 1
1054 else
1055 echo "depend = $it"
1057 done
1059 for it in "${provides[@]}"; do
1060 # ignore versionless entires (those come from the PKGBUILD)
1061 if [[ $it = *.so ]]; then
1062 # check if the entry has been found by find_libprovides
1063 # if not, it's unneeded; tell the user so he can remove it
1064 if [[ ! $libprovides =~ (^|\s)${it}=.* ]]; then
1065 error "$(gettext "Can't find library listed in \$provides: %s")" "$it"
1066 return 1
1068 else
1069 echo "provides = $it"
1071 done
1073 for it in "${packaging_options[@]}"; do
1074 local ret="$(check_option $it)"
1075 if [[ $ret != "?" ]]; then
1076 if [[ $ret = y ]]; then
1077 echo "makepkgopt = $it"
1078 else
1079 echo "makepkgopt = !$it"
1082 done
1084 # TODO maybe remove this at some point
1085 # warn if license array is not present or empty
1086 if [[ -z $license ]]; then
1087 warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT"
1088 plain "$(gettext "Example for GPL\'ed software: license=('GPL').")"
1092 check_package() {
1093 cd "$pkgdir"
1095 # check existence of backup files
1096 local file
1097 for file in "${backup[@]}"; do
1098 if [[ ! -f $file ]]; then
1099 warning "$(gettext "Backup entry file not in package : %s")" "$file"
1101 done
1103 # check for references to the build and package directory
1104 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${srcdir}" ; then
1105 warning "$(gettext "Package contains reference to %s")" "\$srcdir"
1107 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${pkgdir}" ; then
1108 warning "$(gettext "Package contains reference to %s")" "\$pkgdir"
1113 create_package() {
1114 if [[ ! -d $pkgdir ]]; then
1115 error "$(gettext "Missing pkg/ directory.")"
1116 plain "$(gettext "Aborting...")"
1117 exit 1 # $E_MISSING_PKGDIR
1120 check_package
1122 cd "$pkgdir"
1123 msg "$(gettext "Creating package...")"
1125 local nameofpkg
1126 if [[ -z $1 ]]; then
1127 nameofpkg="$pkgname"
1128 else
1129 nameofpkg="$1"
1132 if [[ $arch = "any" ]]; then
1133 PKGARCH="any"
1134 else
1135 PKGARCH=$CARCH
1138 write_pkginfo $nameofpkg > .PKGINFO
1140 local comp_files=".PKGINFO"
1142 # check for changelog/install files
1143 for i in 'changelog/.CHANGELOG' 'install/.INSTALL'; do
1144 IFS='/' read -r orig dest <<< "$i"
1146 if [[ -n ${!orig} ]]; then
1147 msg2 "$(gettext "Adding %s file...")" "$orig"
1148 cp "$startdir/${!orig}" "$dest"
1149 chmod 644 "$dest"
1150 comp_files+=" $dest"
1152 done
1154 # tar it up
1155 msg2 "$(gettext "Compressing package...")"
1157 local EXT
1158 case "$PKGEXT" in
1159 *tar.gz) EXT=${PKGEXT%.gz} ;;
1160 *tar.bz2) EXT=${PKGEXT%.bz2} ;;
1161 *tar.xz) EXT=${PKGEXT%.xz} ;;
1162 *tar) EXT=${PKGEXT} ;;
1163 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1164 "$PKGEXT" ; EXT=$PKGEXT ;;
1165 esac
1167 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1168 local pkg_file="$PKGDEST/${nameofpkg}-${fullver}-${PKGARCH}${PKGEXT}"
1169 local ret=0
1171 [[ -f $pkg_file ]] && rm -f "$pkg_file"
1172 [[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig"
1174 # when fileglobbing, we want * in an empty directory to expand to
1175 # the null string rather than itself
1176 shopt -s nullglob
1177 # TODO: Maybe this can be set globally for robustness
1178 shopt -s -o pipefail
1179 bsdtar -cf - $comp_files * |
1180 case "$PKGEXT" in
1181 *tar.gz) gzip -c -f -n ;;
1182 *tar.bz2) bzip2 -c -f ;;
1183 *tar.xz) xz -c -z - ;;
1184 *tar) cat ;;
1185 esac > "${pkg_file}" || ret=$?
1187 shopt -u nullglob
1188 shopt -u -o pipefail
1190 if (( ret )); then
1191 error "$(gettext "Failed to create package file.")"
1192 exit 1 # TODO: error code
1195 create_signature "$pkg_file"
1197 if (( ! ret )) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
1198 ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1199 ret=$?
1200 [[ -f $pkg_file.sig ]] && ln -sf "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
1203 if (( ret )); then
1204 warning "$(gettext "Failed to create symlink to package file.")"
1208 create_signature() {
1209 if [[ $SIGNPKG != 'y' ]]; then
1210 return
1212 local ret=0
1213 local filename="$1"
1214 msg "$(gettext "Signing package...")"
1215 if ! type -p gpg >/dev/null; then
1216 error "$(gettext "Cannot find the gpg binary! Is gnupg installed?")"
1217 exit 1 # $E_MISSING_PROGRAM
1220 local SIGNWITHKEY=""
1221 if [[ -n $GPGKEY ]]; then
1222 SIGNWITHKEY="-u ${GPGKEY}"
1224 # The signature will be generated directly in ascii-friendly format
1225 gpg --detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev/null || ret=$?
1228 if (( ! ret )); then
1229 msg2 "$(gettext "Created signature file %s.")" "$filename.sig"
1230 else
1231 warning "$(gettext "Failed to sign package file.")"
1235 create_srcpackage() {
1236 msg "$(gettext "Creating source package...")"
1237 local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1238 mkdir "${srclinks}"/${pkgbase}
1240 msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
1241 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1243 local file
1244 for file in "${source[@]}"; do
1245 if [[ -f $file ]]; then
1246 msg2 "$(gettext "Adding %s...")" "$file"
1247 ln -s "${startdir}/$file" "$srclinks/$pkgbase"
1248 elif (( SOURCEONLY == 2 )); then
1249 local absfile=$(get_filepath "$file") || missing_source_file "$file"
1250 msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
1251 ln -s "$absfile" "$srclinks/$pkgbase"
1253 done
1255 local i
1256 for i in 'changelog' 'install'; do
1257 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1258 local file
1259 for file in $filelist; do
1260 # evaluate any bash variables used
1261 eval file=${file}
1262 if [[ ! -f "${srclinks}/${pkgbase}/$file" ]]; then
1263 msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}"
1264 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
1266 done
1267 done
1269 local TAR_OPT
1270 case "$SRCEXT" in
1271 *tar.gz) TAR_OPT="z" ;;
1272 *tar.bz2) TAR_OPT="j" ;;
1273 *tar.xz) TAR_OPT="J" ;;
1274 *tar) TAR_OPT="" ;;
1275 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1276 "$SRCEXT" ;;
1277 esac
1279 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1280 local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
1282 # tar it up
1283 msg2 "$(gettext "Compressing source package...")"
1284 cd "${srclinks}"
1285 if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgbase}; then
1286 error "$(gettext "Failed to create source package file.")"
1287 exit 1 # TODO: error code
1290 if (( ! ret )) && [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
1291 ln -sf "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
1292 ret=$?
1295 if (( ret )); then
1296 warning "$(gettext "Failed to create symlink to source package file.")"
1299 cd "${startdir}"
1300 rm -rf "${srclinks}"
1303 install_package() {
1304 (( ! INSTALL )) && return
1306 if (( ! SPLITPKG )); then
1307 msg "$(gettext "Installing package %s with %s -U...")" "$pkgname" "$PACMAN"
1308 else
1309 msg "$(gettext "Installing %s package group with %s -U...")" "$pkgbase" "$PACMAN"
1312 local fullver pkg pkglist
1313 for pkg in ${pkgname[@]}; do
1314 # TODO: this wasn't properly fixed in commit 2020e629
1315 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1316 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} ]]; then
1317 pkglist+=" $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT}"
1318 else
1319 pkglist+=" $PKGDEST/${pkg}-${fullver}-any${PKGEXT}"
1321 done
1323 if ! run_pacman -U $pkglist; then
1324 warning "$(gettext "Failed to install built package(s).")"
1325 return 0
1329 check_sanity() {
1330 # check for no-no's in the build script
1331 local i
1332 local ret=0
1333 for i in 'pkgname' 'pkgrel' 'pkgver'; do
1334 if [[ -z ${!i} ]]; then
1335 error "$(gettext "%s is not allowed to be empty.")" "$i"
1336 ret=1
1338 done
1340 for i in "${pkgname[@]}"; do
1341 if [[ ${i:0:1} = "-" ]]; then
1342 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname"
1343 ret=1
1345 done
1347 if [[ ${pkgbase:0:1} = "-" ]]; then
1348 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgbase"
1349 ret=1
1351 if [[ $pkgver =~ [:-] ]]; then
1352 error "$(gettext "%s is not allowed to contain colons or hyphens.")" "pkgver"
1353 ret=1
1355 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1356 error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
1357 ret=1
1360 if [[ ! $epoch =~ ^[0-9]*$ ]]; then
1361 error "$(gettext "%s must be an integer.")" "epoch"
1362 ret=1
1365 if [[ $arch != 'any' ]]; then
1366 if ! in_array $CARCH ${arch[@]}; then
1367 if (( ! IGNOREARCH )); then
1368 error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH"
1369 plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
1370 plain "$(gettext "such as arch=('%s').")" "$CARCH"
1371 ret=1
1376 local provides_list=()
1377 eval $(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \
1378 sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//')
1379 for i in ${provides_list[@]}; do
1380 if [[ $i != ${i//</} || $i != ${i//>/} ]]; then
1381 error "$(gettext "Provides array cannot contain comparison (< or >) operators.")"
1382 ret=1
1384 done
1386 local backup_list=()
1387 eval $(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \
1388 sed -e "s/backup=/backup_list+=/" -e "s/#.*//" -e 's/\\$//')
1389 for i in "${backup_list[@]}"; do
1390 if [[ ${i:0:1} = "/" ]]; then
1391 error "$(gettext "Backup entry should not contain leading slash : %s")" "$i"
1392 ret=1
1394 done
1396 local optdepends_list=()
1397 eval $(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(#.*)?$/' "$BUILDFILE" | \
1398 sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//')
1399 for i in "${optdepends_list[@]}"; do
1400 local pkg=${i%%:*}
1401 if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]+$ ]]; then
1402 error "$(gettext "Invalid syntax for optdepend : '%s'")" "$i"
1403 ret=1
1405 done
1407 for i in 'changelog' 'install'; do
1408 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1409 local file
1410 for file in $filelist; do
1411 # evaluate any bash variables used
1412 eval file=${file}
1413 if [[ ! -f $file ]]; then
1414 error "$(gettext "%s file (%s) does not exist.")" "$i" "$file"
1415 ret=1
1417 done
1418 done
1420 local valid_options=1
1421 local known kopt options_list
1422 eval $(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \
1423 sed -e "s/options=/options_list+=/" -e "s/#.*//" -e 's/\\$//')
1424 for i in ${options_list[@]}; do
1425 known=0
1426 # check if option matches a known option or its inverse
1427 for kopt in ${packaging_options[@]} ${other_options[@]}; do
1428 if [[ ${i} = ${kopt} || ${i} = "!${kopt}" ]]; then
1429 known=1
1431 done
1432 if (( ! known )); then
1433 error "$(gettext "options array contains unknown option '%s'")" "$i"
1434 valid_options=0
1436 done
1437 if (( ! valid_options )); then
1438 ret=1
1441 if (( ${#pkgname[@]} > 1 )); then
1442 for i in ${pkgname[@]}; do
1443 if ! declare -f package_${i} >/dev/null; then
1444 error "$(gettext "missing package function for split package '%s'")" "$i"
1445 ret=1
1447 done
1450 for i in ${PKGLIST[@]}; do
1451 if ! in_array $i ${pkgname[@]}; then
1452 error "$(gettext "requested package %s is not provided in %s")" "$i" "$BUILDFILE"
1453 ret=1
1455 done
1457 return $ret
1460 devel_check() {
1461 newpkgver=""
1463 # Do not update pkgver if --holdver is set, when building a source package, repackaging,
1464 # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1465 if (( HOLDVER || SOURCEONLY || REPKG )) \
1466 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1467 return
1470 if [[ -z $FORCE_VER ]]; then
1471 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1472 # This will only be used on the first call to makepkg; subsequent
1473 # calls to makepkg via fakeroot will explicitly pass the version
1474 # number to avoid having to determine the version number twice.
1475 # Also do a brief check to make sure we have the VCS tool available.
1476 oldpkgver=$pkgver
1477 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1478 type -p darcs >/dev/null || return 0
1479 msg "$(gettext "Determining latest %s revision...")" 'darcs'
1480 newpkgver=$(date +%Y%m%d)
1481 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1482 type -p cvs >/dev/null || return 0
1483 msg "$(gettext "Determining latest %s revision...")" 'cvs'
1484 newpkgver=$(date +%Y%m%d)
1485 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1486 type -p git >/dev/null || return 0
1487 msg "$(gettext "Determining latest %s revision...")" 'git'
1488 newpkgver=$(date +%Y%m%d)
1489 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1490 type -p svn >/dev/null || return 0
1491 msg "$(gettext "Determining latest %s revision...")" 'svn'
1492 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1493 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1494 type -p bzr >/dev/null || return 0
1495 msg "$(gettext "Determining latest %s revision...")" 'bzr'
1496 newpkgver=$(bzr revno ${_bzrtrunk})
1497 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1498 type -p hg >/dev/null || return 0
1499 msg "$(gettext "Determining latest %s revision...")" 'hg'
1500 if [[ -d ./src/$_hgrepo ]] ; then
1501 cd ./src/$_hgrepo
1502 hg pull
1503 hg update
1504 else
1505 [[ ! -d ./src/ ]] && mkdir ./src/
1506 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1507 cd ./src/$_hgrepo
1509 newpkgver=$(hg tip --template "{rev}")
1510 cd ../../
1513 if [[ -n $newpkgver ]]; then
1514 msg2 "$(gettext "Version found: %s")" "$newpkgver"
1517 else
1518 # Version number retrieved from fakeroot->makepkg argument
1519 newpkgver=$FORCE_VER
1523 devel_update() {
1524 # This is lame, but if we're wanting to use an updated pkgver for
1525 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1526 # the new pkgver and then re-source it. This is the most robust
1527 # method for dealing with PKGBUILDs that use, e.g.:
1529 # pkgver=23
1530 # ...
1531 # _foo=pkgver
1533 if [[ -n $newpkgver ]]; then
1534 if [[ $newpkgver != $pkgver ]]; then
1535 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1536 @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE"
1537 @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE"
1538 source "$BUILDFILE"
1544 backup_package_variables() {
1545 local var
1546 for var in ${splitpkg_overrides[@]}; do
1547 local indirect="${var}_backup"
1548 eval "${indirect}=(\"\${$var[@]}\")"
1549 done
1552 restore_package_variables() {
1553 local var
1554 for var in ${splitpkg_overrides[@]}; do
1555 local indirect="${var}_backup"
1556 if [[ -n ${!indirect} ]]; then
1557 eval "${var}=(\"\${$indirect[@]}\")"
1558 else
1559 unset ${var}
1561 done
1564 run_split_packaging() {
1565 local pkgname_backup=${pkgname[@]}
1566 for pkgname in ${pkgname_backup[@]}; do
1567 pkgdir="$pkgdir/$pkgname"
1568 mkdir -p "$pkgdir"
1569 chmod a-s "$pkgdir"
1570 backup_package_variables
1571 run_package $pkgname
1572 tidy_install
1573 create_package $pkgname
1574 restore_package_variables
1575 pkgdir="${pkgdir%/*}"
1576 done
1577 pkgname=${pkgname_backup[@]}
1580 # Canonicalize a directory path if it exists
1581 canonicalize_path() {
1582 local path="$1";
1584 if [[ -d $path ]]; then
1586 cd "$path"
1587 pwd -P
1589 else
1590 echo "$path"
1594 m4_include(library/parse_options.sh)
1596 usage() {
1597 printf "makepkg (pacman) %s\n" "$myver"
1598 echo
1599 printf "$(gettext "Usage: %s [options]")\n" "$0"
1600 echo
1601 echo "$(gettext "Options:")"
1602 printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
1603 echo "$(gettext " -c, --clean Clean up work files after build")"
1604 echo "$(gettext " -C, --cleancache Clean up source files from the cache")"
1605 echo "$(gettext " -d, --nodeps Skip all dependency checks")"
1606 echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
1607 echo "$(gettext " -f, --force Overwrite existing package")"
1608 echo "$(gettext " -g, --geninteg Generate integrity checks for source files")"
1609 echo "$(gettext " -h, --help Show this help message and exit")"
1610 echo "$(gettext " -i, --install Install package after successful build")"
1611 echo "$(gettext " -L, --log Log package build process")"
1612 echo "$(gettext " -m, --nocolor Disable colorized output messages")"
1613 echo "$(gettext " -o, --nobuild Download and extract files only")"
1614 printf "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1615 echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1616 echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1617 echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")"
1618 echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1619 echo "$(gettext " --asroot Allow makepkg to run as root user")"
1620 printf "$(gettext " --check Run the check() function in the %s")\n" "$BUILDSCRIPT"
1621 printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf"
1622 printf "$(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT"
1623 echo "$(gettext " --key <key> Specify a key to use for gpg signing instead of the default")"
1624 printf "$(gettext " --nocheck Do not run the check() function in the %s")\n" "$BUILDSCRIPT"
1625 echo "$(gettext " --nosign Do not create a signature for the package")"
1626 echo "$(gettext " --pkg <list> Only build listed packages from a split package")"
1627 echo "$(gettext " --sign Sign the resulting package with gpg")"
1628 echo "$(gettext " --skipinteg Do not fail when integrity checks are missing")"
1629 echo "$(gettext " --source Generate a source-only tarball without downloaded sources")"
1630 echo
1631 echo "$(gettext "These options can be passed to pacman:")"
1632 echo
1633 echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1634 echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1635 echo
1636 printf "$(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1637 echo
1640 version() {
1641 printf "makepkg (pacman) %s\n" "$myver"
1642 printf "$(gettext "\
1643 Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1644 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1645 This is free software; see the source for copying conditions.\n\
1646 There is NO WARRANTY, to the extent permitted by law.\n")"
1649 # PROGRAM START
1651 # determine whether we have gettext; make it a no-op if we do not
1652 if ! type -p gettext >/dev/null; then
1653 gettext() {
1654 echo "$@"
1658 ARGLIST=("$@")
1660 # Parse Command Line Options.
1661 OPT_SHORT="AcCdefFghiLmop:rRsV"
1662 OPT_LONG="allsource,asroot,ignorearch,check,clean,cleancache,nodeps"
1663 OPT_LONG+=",noextract,force,forcever:,geninteg,help,holdver"
1664 OPT_LONG+=",install,key:,log,nocolor,nobuild,nocheck,nosign,pkg:,rmdeps"
1665 OPT_LONG+=",repackage,skipinteg,sign,source,syncdeps,version,config:"
1666 # Pacman Options
1667 OPT_LONG+=",noconfirm,noprogressbar"
1668 OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')"
1669 if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then
1670 # This is a small hack to stop the script bailing with 'set -e'
1671 echo; usage; exit 1 # E_INVALID_OPTION;
1673 eval set -- "$OPT_TEMP"
1674 unset OPT_SHORT OPT_LONG OPT_TEMP
1676 while true; do
1677 case "$1" in
1678 # Pacman Options
1679 --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
1680 --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
1682 # Makepkg Options
1683 --allsource) SOURCEONLY=2 ;;
1684 --asroot) ASROOT=1 ;;
1685 -A|--ignorearch) IGNOREARCH=1 ;;
1686 -c|--clean) CLEANUP=1 ;;
1687 -C|--cleancache) CLEANCACHE=1 ;;
1688 --check) RUN_CHECK='y' ;;
1689 --config) shift; MAKEPKG_CONF=$1 ;;
1690 -d|--nodeps) NODEPS=1 ;;
1691 -e|--noextract) NOEXTRACT=1 ;;
1692 -f|--force) FORCE=1 ;;
1693 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1694 --forcever) shift; FORCE_VER=$1;;
1695 -F) INFAKEROOT=1 ;;
1696 -g|--geninteg) GENINTEG=1 ;;
1697 --holdver) HOLDVER=1 ;;
1698 -i|--install) INSTALL=1 ;;
1699 --key) shift; GPGKEY=$1 ;;
1700 -L|--log) LOGGING=1 ;;
1701 -m|--nocolor) USE_COLOR='n' ;;
1702 --nocheck) RUN_CHECK='n' ;;
1703 --nosign) SIGNPKG='n' ;;
1704 -o|--nobuild) NOBUILD=1 ;;
1705 -p) shift; BUILDFILE=$1 ;;
1706 --pkg) shift; PKGLIST=($1) ;;
1707 -r|--rmdeps) RMDEPS=1 ;;
1708 -R|--repackage) REPKG=1 ;;
1709 --skipinteg) SKIPINTEG=1 ;;
1710 --sign) SIGNPKG='y' ;;
1711 --source) SOURCEONLY=1 ;;
1712 -s|--syncdeps) DEP_BIN=1 ;;
1714 -h|--help) usage; exit 0 ;; # E_OK
1715 -V|--version) version; exit 0 ;; # E_OK
1717 --) OPT_IND=0; shift; break;;
1718 *) usage; exit 1 ;; # E_INVALID_OPTION
1719 esac
1720 shift
1721 done
1723 # preserve environment variables and canonicalize path
1724 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
1725 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
1726 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
1727 [[ -n ${BUILDDIR} ]] && _BUILDDIR=$(canonicalize_path ${BUILDDIR})
1728 [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
1729 [[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
1730 [[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY}
1732 # default config is makepkg.conf
1733 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1735 # Source the config file; fail if it is not found
1736 if [[ -r $MAKEPKG_CONF ]]; then
1737 source "$MAKEPKG_CONF"
1738 else
1739 error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
1740 plain "$(gettext "Aborting...")"
1741 exit 1 # $E_CONFIG_ERROR
1744 # Source user-specific makepkg.conf overrides
1745 if [[ -r ~/.makepkg.conf ]]; then
1746 source ~/.makepkg.conf
1749 # set pacman command if not already defined
1750 PACMAN=${PACMAN:-pacman}
1752 # check if messages are to be printed using color
1753 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1754 if [[ -t 2 && ! $USE_COLOR = "n" && $(check_buildenv color) = "y" ]]; then
1755 # prefer terminal safe colored and bold text when tput is supported
1756 if tput setaf 0 &>/dev/null; then
1757 ALL_OFF="$(tput sgr0)"
1758 BOLD="$(tput bold)"
1759 BLUE="${BOLD}$(tput setaf 4)"
1760 GREEN="${BOLD}$(tput setaf 2)"
1761 RED="${BOLD}$(tput setaf 1)"
1762 YELLOW="${BOLD}$(tput setaf 3)"
1763 else
1764 ALL_OFF="\e[1;0m"
1765 BOLD="\e[1;1m"
1766 BLUE="${BOLD}\e[1;34m"
1767 GREEN="${BOLD}\e[1;32m"
1768 RED="${BOLD}\e[1;31m"
1769 YELLOW="${BOLD}\e[1;33m"
1772 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1774 # override settings with an environment variable for batch processing
1775 BUILDDIR=${_BUILDDIR:-$BUILDDIR}
1776 BUILDDIR=${BUILDDIR:-$startdir} #default to $startdir if undefined
1777 if [[ ! -d $BUILDDIR ]]; then
1778 mkdir -p "$BUILDDIR" ||
1779 error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
1780 chmod a-s "$BUILDDIR"
1782 if [[ ! -w $BUILDDIR ]]; then
1783 error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
1784 plain "$(gettext "Aborting...")"
1785 exit 1
1787 srcdir="$BUILDDIR/src"
1788 pkgdir="$BUILDDIR/pkg"
1790 PKGDEST=${_PKGDEST:-$PKGDEST}
1791 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1792 if [[ ! -w $PKGDEST ]]; then
1793 error "$(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
1794 plain "$(gettext "Aborting...")"
1795 exit 1
1798 SRCDEST=${_SRCDEST:-$SRCDEST}
1799 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1800 if [[ ! -w $SRCDEST ]] ; then
1801 error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
1802 plain "$(gettext "Aborting...")"
1803 exit 1
1806 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
1807 SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
1809 PKGEXT=${_PKGEXT:-$PKGEXT}
1810 SRCEXT=${_SRCEXT:-$SRCEXT}
1811 GPGKEY=${_GPGKEY:-$GPGKEY}
1813 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1814 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1815 error "$(gettext "\\0--holdver and --forcever cannot both be specified" )"
1816 exit 1
1819 if (( CLEANCACHE )); then
1820 #fix flyspray feature request #5223
1821 if [[ -n $SRCDEST && ! $SRCDEST -ef "${startdir}" ]]; then
1822 msg "$(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1823 echo -n "$(gettext " Are you sure you wish to do this? ")"
1824 echo -n "$(gettext "[y/N]")"
1825 read answer
1826 answer=$(tr '[:lower:]' '[:upper:]' <<< "$answer")
1827 if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then
1828 rm "$SRCDEST"/*
1829 if (( $? )); then
1830 error "$(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1831 exit 1
1832 else
1833 # removal worked
1834 msg "$(gettext "Source cache cleaned.")"
1835 exit 0
1837 else
1838 # answer = no
1839 msg "$(gettext "No files have been removed.")"
1840 exit 0
1842 else
1843 # $SRCDEST is $startdir, two possibilities
1844 error "$(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
1845 plain "$(gettext "In addition, please run makepkg -C outside of your cache directory.")"
1846 exit 1
1850 if (( ! INFAKEROOT )); then
1851 if (( EUID == 0 && ! ASROOT )); then
1852 # Warn those who like to live dangerously.
1853 error "$(gettext "Running makepkg as root is a BAD idea and can cause")"
1854 plain "$(gettext "permanent, catastrophic damage to your system. If you")"
1855 plain "$(gettext "wish to run as root, please use the --asroot option.")"
1856 exit 1 # $E_USER_ABORT
1857 elif (( EUID > 0 && ASROOT )); then
1858 # Warn those who try to use the --asroot option when they are not root
1859 error "$(gettext "The --asroot option is meant for the root user only.")"
1860 plain "$(gettext "Please rerun makepkg without the --asroot flag.")"
1861 exit 1 # $E_USER_ABORT
1862 elif [[ $(check_buildenv fakeroot) = "y" ]] && (( EUID > 0 )); then
1863 if ! type -p fakeroot >/dev/null; then
1864 error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
1865 plain "$(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1866 exit 1
1868 elif (( EUID > 0 )); then
1869 warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")"
1870 plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
1871 plain "$(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1872 sleep 1
1874 else
1875 if [[ -z $FAKEROOTKEY ]]; then
1876 error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
1877 exit 1 # TODO: error code
1881 # check for sudo if we will need it during makepkg execution
1882 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1883 if ! type -p sudo >/dev/null; then
1884 warning "$(gettext "Sudo can not be found. Will use su to acquire root privileges.")"
1888 unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
1889 unset md5sums replaces depends conflicts backup source install changelog build
1890 unset makedepends optdepends options noextract
1892 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1893 if [[ ! -f $BUILDFILE ]]; then
1894 if [[ -t 0 ]]; then
1895 error "$(gettext "%s does not exist.")" "$BUILDFILE"
1896 exit 1
1897 else
1898 # PKGBUILD passed through a pipe
1899 BUILDFILE=/dev/stdin
1900 source "$BUILDFILE"
1902 else
1903 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1904 if [[ -n $crlftest ]]; then
1905 error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE"
1906 exit 1
1909 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1910 BUILDFILE="$startdir/$BUILDFILE"
1912 source "$BUILDFILE"
1915 # set defaults if they weren't specified in buildfile
1916 pkgbase=${pkgbase:-${pkgname[0]}}
1917 epoch=${epoch:-0}
1919 if (( GENINTEG )); then
1920 mkdir -p "$srcdir"
1921 chmod a-s "$srcdir"
1922 cd "$srcdir"
1923 download_sources
1924 generate_checksums
1925 exit 0 # $E_OK
1928 # check the PKGBUILD for some basic requirements
1929 check_sanity || exit 1
1931 # We need to run devel_update regardless of whether we are in the fakeroot
1932 # build process so that if the user runs makepkg --forcever manually, we
1933 # 1) output the correct pkgver, and 2) use the correct filename when
1934 # checking if the package file already exists - fixes FS #9194
1935 devel_check
1936 devel_update
1938 if (( ${#pkgname[@]} > 1 )); then
1939 SPLITPKG=1
1942 # test for available PKGBUILD functions
1943 if declare -f build >/dev/null; then
1944 BUILDFUNC=1
1946 if declare -f check >/dev/null; then
1947 # "Hide" check() function if not going to be run
1948 if [[ $RUN_CHECK = 'y' || (! $(check_buildenv check) = "n" && ! $RUN_CHECK = "n") ]]; then
1949 CHECKFUNC=1
1952 if declare -f package >/dev/null; then
1953 PKGFUNC=1
1954 elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then
1955 SPLITPKG=1
1958 if [[ -n "${PKGLIST[@]}" ]]; then
1959 unset pkgname
1960 pkgname=("${PKGLIST[@]}")
1963 # check if gpg signature is to be created and if signing key is valid
1964 if [[ -z "$SIGNPKG" && $(check_buildenv sign) == 'y' ]]; then
1965 SIGNPKG='y'
1967 if [[ $SIGNPKG == 'y' ]]; then
1968 if ! gpg --list-key ${GPGKEY} &>/dev/null; then
1969 if [[ ! -z $GPGKEY ]]; then
1970 error "$(gettext "The key ${GPGKEY} does not exist in your keyring.")"
1971 else
1972 error "$(gettext "There is no key in your keyring.")"
1974 exit 1
1979 if (( ! SPLITPKG )); then
1980 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1981 if [[ -f $PKGDEST/${pkgname}-${fullver}-${CARCH}${PKGEXT} \
1982 || -f $PKGDEST/${pkgname}-${fullver}-any${PKGEXT} ]] \
1983 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
1984 if (( INSTALL )); then
1985 warning "$(gettext "A package has already been built, installing existing package...")"
1986 install_package
1987 exit $?
1988 else
1989 error "$(gettext "A package has already been built. (use -f to overwrite)")"
1990 exit 1
1993 else
1994 allpkgbuilt=1
1995 somepkgbuilt=0
1996 for pkg in ${pkgname[@]}; do
1997 # TODO: this wasn't properly fixed in commit 2020e629
1998 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1999 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} \
2000 || -f $PKGDEST/${pkg}-${fullver}-any${PKGEXT} ]]; then
2001 somepkgbuilt=1
2002 else
2003 allpkgbuilt=0
2005 done
2006 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
2007 if (( allpkgbuilt )); then
2008 if (( INSTALL )); then
2009 warning "$(gettext "The package group has already been built, installing existing packages...")"
2010 install_package
2011 exit $?
2012 else
2013 error "$(gettext "The package group has already been built. (use -f to overwrite)")"
2014 exit 1
2017 if (( somepkgbuilt )); then
2018 error "$(gettext "Part of the package group has already been built. (use -f to overwrite)")"
2019 exit 1
2022 unset allpkgbuilt somepkgbuilt
2025 # Run the bare minimum in fakeroot
2026 if (( INFAKEROOT )); then
2027 if (( SOURCEONLY )); then
2028 create_srcpackage
2029 msg "$(gettext "Leaving fakeroot environment.")"
2030 exit 0 # $E_OK
2033 if (( ! SPLITPKG )); then
2034 if (( ! PKGFUNC )); then
2035 if (( ! REPKG )); then
2036 if (( BUILDFUNC )); then
2037 run_build
2038 (( CHECKFUNC )) && run_check
2039 tidy_install
2041 else
2042 warning "$(gettext "Repackaging without the use of a package() function is deprecated.")"
2043 plain "$(gettext "File permissions may not be preserved.")"
2045 else
2046 run_package
2047 tidy_install
2049 create_package
2050 else
2051 run_split_packaging
2054 msg "$(gettext "Leaving fakeroot environment.")"
2055 exit 0 # $E_OK
2058 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2059 msg "$(gettext "Making package: %s")" "$pkgbase $fullver ($(date))"
2061 # if we are creating a source-only package, go no further
2062 if (( SOURCEONLY )); then
2063 if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \
2064 && (( ! FORCE )); then
2065 error "$(gettext "A source package has already been built. (use -f to overwrite)")"
2066 exit 1
2069 # Get back to our src directory so we can begin with sources.
2070 mkdir -p "$srcdir"
2071 chmod a-s "$srcdir"
2072 cd "$srcdir"
2073 if (( ! SKIPINTEG || SOURCEONLY == 2 )); then
2074 download_sources
2076 if (( ! SKIPINTEG )); then
2077 # We can only check checksums if we have all files.
2078 check_checksums
2079 else
2080 warning "$(gettext "Skipping integrity checks.")"
2082 cd "$startdir"
2084 # if we are root or if fakeroot is not enabled, then we don't use it
2085 if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then
2086 create_srcpackage
2087 else
2088 enter_fakeroot
2091 msg "$(gettext "Source package created: %s")" "$pkgbase ($(date))"
2092 exit 0
2095 if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); then
2096 # no warning message needed for nobuild, repkg
2097 if (( NODEPS || ( REPKG && PKGFUNC ) )); then
2098 warning "$(gettext "Skipping dependency checks.")"
2100 elif type -p "${PACMAN%% *}" >/dev/null; then
2101 if (( RMDEPS )); then
2102 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
2104 deperr=0
2106 msg "$(gettext "Checking runtime dependencies...")"
2107 resolve_deps ${depends[@]} || deperr=1
2109 msg "$(gettext "Checking buildtime dependencies...")"
2110 resolve_deps ${makedepends[@]} || deperr=1
2112 if (( CHECKFUNC )); then
2113 resolve_deps ${checkdepends[@]} || deperr=1
2116 if (( RMDEPS )); then
2117 current_pkglist=($(run_pacman -Qq)) # required by remove_deps
2120 if (( deperr )); then
2121 error "$(gettext "Could not resolve all dependencies.")"
2122 exit 1
2124 else
2125 warning "$(gettext "%s was not found in PATH; skipping dependency checks.")" "${PACMAN%% *}"
2128 # ensure we have a sane umask set
2129 umask 0022
2131 # get back to our src directory so we can begin with sources
2132 mkdir -p "$srcdir"
2133 chmod a-s "$srcdir"
2134 cd "$srcdir"
2136 if (( NOEXTRACT )); then
2137 warning "$(gettext "Skipping source retrieval -- using existing src/ tree")"
2138 warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")"
2139 warning "$(gettext "Skipping source extraction -- using existing src/ tree")"
2141 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
2142 error "$(gettext "The source directory is empty, there is nothing to build!")"
2143 plain "$(gettext "Aborting...")"
2144 exit 1
2146 elif (( REPKG )); then
2147 if (( ! PKGFUNC && ! SPLITPKG )) \
2148 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
2149 error "$(gettext "The package directory is empty, there is nothing to repackage!")"
2150 plain "$(gettext "Aborting...")"
2151 exit 1
2153 else
2154 download_sources
2155 if (( ! SKIPINTEG )); then
2156 check_checksums
2157 else
2158 warning "$(gettext "Skipping integrity checks.")"
2160 extract_sources
2163 if (( NOBUILD )); then
2164 msg "$(gettext "Sources are ready.")"
2165 exit 0 #E_OK
2166 else
2167 # check for existing pkg directory; don't remove if we are repackaging
2168 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
2169 msg "$(gettext "Removing existing pkg/ directory...")"
2170 rm -rf "$pkgdir"
2172 mkdir -p "$pkgdir"
2173 chmod a-s "$pkgdir"
2174 cd "$startdir"
2176 # if we are root or if fakeroot is not enabled, then we don't use it
2177 if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then
2178 if (( ! REPKG )); then
2179 devel_update
2180 (( BUILDFUNC )) && run_build
2181 (( CHECKFUNC )) && run_check
2183 if (( ! SPLITPKG )); then
2184 if (( PKGFUNC )); then
2185 run_package
2186 tidy_install
2187 else
2188 if (( ! REPKG )); then
2189 tidy_install
2190 else
2191 warning "$(gettext "Repackaging without the use of a package() function is deprecated.")"
2192 plain "$(gettext "File permissions may not be preserved.")"
2195 create_package
2196 else
2197 run_split_packaging
2199 else
2200 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
2201 devel_update
2202 (( BUILDFUNC )) && run_build
2203 (( CHECKFUNC )) && run_check
2204 cd "$startdir"
2207 enter_fakeroot
2211 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2212 msg "$(gettext "Finished making: %s")" "$pkgbase $fullver ($(date))"
2214 install_package
2216 exit 0 #E_OK
2218 # vim: set ts=2 sw=2 noet: