Merge branch 'maint'
[pacman-ng.git] / scripts / makepkg.sh.in
blob93cf566246fed5768f6237948c9eae647be9ff50
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, 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"
44 srcdir="$startdir/src"
45 pkgdir="$startdir/pkg"
47 packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge')
48 other_options=('ccache' 'distcc' 'buildflags' 'makeflags')
49 splitpkg_overrides=('pkgver' 'pkgrel' 'pkgdesc' 'arch' 'license' 'groups' \
50 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' \
51 'backup' 'options' 'install' 'changelog')
52 readonly -a packaging_options other_options splitpkg_overrides
54 # Options
55 ASROOT=0
56 CLEANUP=0
57 CLEANCACHE=0
58 DEP_BIN=0
59 FORCE=0
60 INFAKEROOT=0
61 GENINTEG=0
62 SKIPINTEG=0
63 INSTALL=0
64 NOBUILD=0
65 NODEPS=0
66 NOEXTRACT=0
67 RMDEPS=0
68 REPKG=0
69 LOGGING=0
70 SOURCEONLY=0
71 IGNOREARCH=0
72 HOLDVER=0
73 BUILDFUNC=0
74 CHECKFUNC=0
75 PKGFUNC=0
76 SPLITPKG=0
77 PKGLIST=()
79 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
80 # when dealing with svn/cvs/etc PKGBUILDs.
81 FORCE_VER=""
83 PACMAN_OPTS=
85 ### SUBROUTINES ###
87 plain() {
88 local mesg=$1; shift
89 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
92 msg() {
93 local mesg=$1; shift
94 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
97 msg2() {
98 local mesg=$1; shift
99 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
102 warning() {
103 local mesg=$1; shift
104 printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
107 error() {
108 local mesg=$1; shift
109 printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
114 # Special exit call for traps, Don't print any error messages when inside,
115 # the fakeroot call, the error message will be printed by the main call.
117 trap_exit() {
118 if (( ! INFAKEROOT )); then
119 echo
120 error "$@"
122 [[ -n $srclinks ]] && rm -rf "$srclinks"
123 exit 1
128 # Clean up function. Called automatically when the script exits.
130 clean_up() {
131 local EXIT_CODE=$?
133 if (( INFAKEROOT )); then
134 # Don't clean up when leaving fakeroot, we're not done yet.
135 return
138 if (( ! EXIT_CODE && CLEANUP )); then
139 local pkg file
141 # If it's a clean exit and -c/--clean has been passed...
142 msg "$(gettext "Cleaning up...")"
143 rm -rf "$pkgdir" "$srcdir"
144 if [[ -n $pkgbase ]]; then
145 # TODO: this wasn't properly fixed in commit 2020e629
146 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
147 # Can't do this unless the BUILDSCRIPT has been sourced.
148 if (( BUILDFUNC )); then
149 rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
151 if (( CHECKFUNC )); then
152 rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"*
154 if (( PKGFUNC )); then
155 rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"*
156 elif (( SPLITPKG )); then
157 for pkg in ${pkgname[@]}; do
158 rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"*
159 done
162 # clean up dangling symlinks to packages
163 for pkg in ${pkgname[@]}; do
164 for file in ${pkg}-*-*-${CARCH}{${PKGEXT},${SRCEXT}}; do
165 if [[ -h $file && ! -e $file ]]; then
166 rm -f $file
168 done
169 done
173 remove_deps
178 # Signal Traps
180 set -E
181 trap 'clean_up' 0
182 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
183 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
184 trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
186 # a source entry can have two forms :
187 # 1) "filename::http://path/to/file"
188 # 2) "http://path/to/file"
190 # Return the absolute filename of a source entry
192 # This function accepts a source entry or the already extracted filename of a
193 # source entry as input
194 get_filepath() {
195 local file="$(get_filename "$1")"
197 if [[ -f "$startdir/$file" ]]; then
198 file="$startdir/$file"
199 elif [[ -f "$SRCDEST/$file" ]]; then
200 file="$SRCDEST/$file"
201 else
202 return 1
205 echo "$file"
208 # Print 'source not found' error message and exit makepkg
209 missing_source_file() {
210 error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")"
211 plain "$(gettext "Aborting...")"
212 exit 1 # $E_MISSING_FILE
215 # extract the filename from a source entry
216 get_filename() {
217 # if a filename is specified, use it
218 local filename="${1%%::*}"
219 # if it is just an URL, we only keep the last component
220 echo "${filename##*/}"
223 # extract the URL from a source entry
224 get_url() {
225 # strip an eventual filename
226 echo "${1#*::}"
230 # usage : get_full_version( $epoch, $pkgver, $pkgrel )
231 # return : full version spec, including epoch (if necessary), pkgver, pkgrel
233 get_full_version() {
234 if [[ $1 -eq 0 ]]; then
235 # zero epoch case, don't include it in version
236 echo $2-$3
237 else
238 echo $1:$2-$3
243 # Checks to see if options are present in makepkg.conf or PKGBUILD;
244 # PKGBUILD options always take precedence.
246 # usage : check_option( $option )
247 # return : y - enabled
248 # n - disabled
249 # ? - not found
251 check_option() {
252 local ret=$(in_opt_array "$1" ${options[@]})
253 if [[ $ret != '?' ]]; then
254 echo $ret
255 return
258 # fall back to makepkg.conf options
259 ret=$(in_opt_array "$1" ${OPTIONS[@]})
260 if [[ $ret != '?' ]]; then
261 echo $ret
262 return
265 echo '?' # Not Found
270 # Check if option is present in BUILDENV
272 # usage : check_buildenv( $option )
273 # return : y - enabled
274 # n - disabled
275 # ? - not found
277 check_buildenv() {
278 echo $(in_opt_array "$1" ${BUILDENV[@]})
283 # usage : in_opt_array( $needle, $haystack )
284 # return : y - enabled
285 # n - disabled
286 # ? - not found
288 in_opt_array() {
289 local needle=$(tr '[:upper:]' '[:lower:]' <<< $1); shift
291 local opt
292 for opt in "$@"; do
293 opt=$(tr '[:upper:]' '[:lower:]' <<< $opt)
294 if [[ $opt = $needle ]]; then
295 echo 'y' # Enabled
296 return
297 elif [[ $opt = "!$needle" ]]; then
298 echo 'n' # Disabled
299 return
301 done
303 echo '?' # Not Found
308 # usage : in_array( $needle, $haystack )
309 # return : 0 - found
310 # 1 - not found
312 in_array() {
313 local needle=$1; shift
314 [[ -z $1 ]] && return 1 # Not Found
315 local item
316 for item in "$@"; do
317 [[ $item = $needle ]] && return 0 # Found
318 done
319 return 1 # Not Found
322 get_downloadclient() {
323 # $1 = URL with valid protocol prefix
324 local url=$1
325 local proto="${url%%://*}"
327 # loop through DOWNLOAD_AGENTS variable looking for protocol
328 local i
329 for i in "${DLAGENTS[@]}"; do
330 local handler="${i%%::*}"
331 if [[ $proto = $handler ]]; then
332 local agent="${i##*::}"
333 break
335 done
337 # if we didn't find an agent, return an error
338 if [[ -z $agent ]]; then
339 error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF"
340 plain "$(gettext "Aborting...")"
341 exit 1 # $E_CONFIG_ERROR
344 # ensure specified program is installed
345 local program="${agent%% *}"
346 if [[ ! -x $program ]]; then
347 local baseprog="${program##*/}"
348 error "$(gettext "The download program %s is not installed.")" "$baseprog"
349 plain "$(gettext "Aborting...")"
350 exit 1 # $E_MISSING_PROGRAM
353 echo "$agent"
356 download_file() {
357 # download command
358 local dlcmd=$1
359 # URL of the file
360 local url=$2
361 # destination file
362 local file=$3
363 # temporary download file, default to last component of the URL
364 local dlfile="${url##*/}"
366 # replace %o by the temporary dlfile if it exists
367 if [[ $dlcmd = *%o* ]]; then
368 dlcmd=${dlcmd//\%o/\"$file.part\"}
369 dlfile="$file.part"
371 # add the URL, either in place of %u or at the end
372 if [[ $dlcmd = *%u* ]]; then
373 dlcmd=${dlcmd//\%u/\"$url\"}
374 else
375 dlcmd="$dlcmd \"$url\""
378 local ret=0
379 eval "$dlcmd || ret=\$?"
380 if (( ret )); then
381 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
382 return $ret
385 # rename the temporary download file to the final destination
386 if [[ $dlfile != $file ]]; then
387 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
391 run_pacman() {
392 local cmd
393 printf -v cmd "%q " "$PACMAN" $PACMAN_OPTS "$@"
394 if (( ! ASROOT )) && [[ ! $1 =~ ^-(T|Qq)$ ]]; then
395 if [ "$(type -p sudo)" ]; then
396 cmd="sudo $cmd"
397 else
398 cmd="su -c '$cmd'"
401 eval "$cmd"
404 check_deps() {
405 (( $# > 0 )) || return 0
407 # Disable error trap in pacman subshell call as this breaks bash-3.2 compatibility
408 # Also, a non-zero return value is not unexpected and we are manually dealing them
409 set +E
410 local ret=0
411 local pmout
412 pmout=$(run_pacman -T "$@") || ret=$?
413 set -E
415 if (( ret == 127 )); then #unresolved deps
416 echo "$pmout"
417 elif (( ret )); then
418 error "$(gettext "'%s' returned a fatal error (%i): %s")" "$PACMAN" "$ret" "$pmout"
419 return "$ret"
423 handle_deps() {
424 local R_DEPS_SATISFIED=0
425 local R_DEPS_MISSING=1
427 (( $# == 0 )) && return $R_DEPS_SATISFIED
429 local deplist="$*"
431 if (( ! DEP_BIN )); then
432 return $R_DEPS_MISSING
435 if (( DEP_BIN )); then
436 # install missing deps from binary packages (using pacman -S)
437 msg "$(gettext "Installing missing dependencies...")"
439 if ! run_pacman -S --asdeps $deplist; then
440 error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN"
441 exit 1 # TODO: error code
445 # we might need the new system environment
446 # avoid triggering the ERR trap
447 local restoretrap=$(trap -p ERR)
448 trap - ERR
449 source /etc/profile &>/dev/null
450 eval $restoretrap
452 return $R_DEPS_SATISFIED
455 resolve_deps() {
456 local R_DEPS_SATISFIED=0
457 local R_DEPS_MISSING=1
459 # deplist cannot be declared like this: local deplist=$(foo)
460 # Otherwise, the return value will depend on the assignment.
461 local deplist
462 deplist="$(set +E; check_deps $*)" || exit 1
463 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
465 if handle_deps $deplist; then
466 # check deps again to make sure they were resolved
467 deplist="$(set +E; check_deps $*)" || exit 1
468 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
471 msg "$(gettext "Missing Dependencies:")"
472 local dep
473 for dep in $deplist; do
474 msg2 "$dep"
475 done
477 return $R_DEPS_MISSING
480 remove_deps() {
481 (( ! RMDEPS )) && return
483 # check for packages removed during dependency install (e.g. due to conflicts)
484 # removing all installed packages is risky in this case
485 if [[ -n $(comm -23 <(printf "%s\n" "${original_pkglist[@]}") \
486 <(printf "%s\n" "${current_pkglist[@]}")) ]]; then
487 warning "$(gettext "Failed to remove installed dependencies.")"
488 return 0
491 local deplist=($(comm -13 <(printf "%s\n" "${original_pkglist[@]}") \
492 <(printf "%s\n" "${current_pkglist[@]}")))
493 (( ${#deplist[@]} == 0 )) && return
495 msg "Removing installed dependencies..."
496 # exit cleanly on failure to remove deps as package has been built successfully
497 if ! run_pacman -Rn ${deplist[@]}; then
498 warning "$(gettext "Failed to remove installed dependencies.")"
499 return 0
503 download_sources() {
504 msg "$(gettext "Retrieving Sources...")"
506 pushd "$SRCDEST" &>/dev/null
508 local netfile
509 for netfile in "${source[@]}"; do
510 local file=$(get_filepath "$netfile" || true)
511 if [[ -n "$file" ]]; then
512 msg2 "$(gettext "Found %s")" "${file##*/}"
513 ln -sf "$file" "$srcdir/"
514 continue
517 file=$(get_filename "$netfile")
518 local url=$(get_url "$netfile")
520 # if we get here, check to make sure it was a URL, else fail
521 if [[ $file = $url ]]; then
522 error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file"
523 exit 1 # $E_MISSING_FILE
526 # find the client we should use for this URL
527 local dlclient=$(get_downloadclient "$url") || exit $?
529 msg2 "$(gettext "Downloading %s...")" "$file"
530 # fix flyspray bug #3289
531 local ret=0
532 download_file "$dlclient" "$url" "$file" || ret=$?
533 if (( ret )); then
534 error "$(gettext "Failure while downloading %s")" "$file"
535 plain "$(gettext "Aborting...")"
536 exit 1
538 rm -f "$srcdir/$file"
539 ln -s "$SRCDEST/$file" "$srcdir/"
540 done
542 popd &>/dev/null
545 get_integlist() {
546 local integ
547 local integlist=()
549 for integ in md5 sha1 sha256 sha384 sha512; do
550 local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
551 if [[ -n "$integrity_sums" ]]; then
552 integlist=(${integlist[@]} $integ)
554 done
556 if (( ${#integlist[@]} > 0 )); then
557 echo ${integlist[@]}
558 else
559 echo ${INTEGRITY_CHECK[@]}
563 generate_checksums() {
564 msg "$(gettext "Generating checksums for source files...")"
565 plain ""
567 if ! type -p openssl >/dev/null; then
568 error "$(gettext "Cannot find openssl.")"
569 exit 1 # $E_MISSING_PROGRAM
572 local integlist
573 if (( $# == 0 )); then
574 integlist=$(get_integlist)
575 else
576 integlist=$@
579 local integ
580 for integ in ${integlist[@]}; do
581 integ=$(tr '[:upper:]' '[:lower:]' <<< "$integ")
582 case "$integ" in
583 md5|sha1|sha256|sha384|sha512) : ;;
585 error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
586 exit 1;; # $E_CONFIG_ERROR
587 esac
589 local ct=0
590 local numsrc=${#source[@]}
591 echo -n "${integ}sums=("
593 local i
594 local indent=''
595 for (( i = 0; i < ${#integ} + 6; i++ )); do
596 indent="$indent "
597 done
599 local netfile
600 for netfile in "${source[@]}"; do
601 local file="$(get_filepath "$netfile")" || missing_source_file "$netfile"
602 local sum="$(openssl dgst -${integ} "$file")"
603 sum=${sum##* }
604 (( ct )) && echo -n "$indent"
605 echo -n "'$sum'"
606 ct=$(($ct+1))
607 (( $ct < $numsrc )) && echo
608 done
610 echo ")"
611 done
614 check_checksums() {
615 (( ! ${#source[@]} )) && return 0
617 if ! type -p openssl >/dev/null; then
618 error "$(gettext "Cannot find openssl.")"
619 exit 1 # $E_MISSING_PROGRAM
622 local correlation=0
623 local integ required
624 for integ in md5 sha1 sha256 sha384 sha512; do
625 local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
626 if (( ${#integrity_sums[@]} == ${#source[@]} )); then
627 msg "$(gettext "Validating source files with %s...")" "${integ}sums"
628 correlation=1
629 local errors=0
630 local idx=0
631 local file
632 for file in "${source[@]}"; do
633 local found=1
634 file="$(get_filename "$file")"
635 echo -n " $file ... " >&2
637 if ! file="$(get_filepath "$file")"; then
638 echo "$(gettext "NOT FOUND")" >&2
639 errors=1
640 found=0
643 if (( $found )) ; then
644 local expectedsum=$(tr '[:upper:]' '[:lower:]' <<< "${integrity_sums[$idx]}")
645 local realsum="$(openssl dgst -${integ} "$file")"
646 realsum="${realsum##* }"
647 if [[ $expectedsum = $realsum ]]; then
648 echo "$(gettext "Passed")" >&2
649 else
650 echo "$(gettext "FAILED")" >&2
651 errors=1
655 idx=$((idx + 1))
656 done
658 if (( errors )); then
659 error "$(gettext "One or more files did not pass the validity check!")"
660 exit 1 # TODO: error code
662 elif (( ${#integrity_sums[@]} )); then
663 error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
664 exit 1 # TODO: error code
666 done
668 if (( ! correlation )); then
669 error "$(gettext "Integrity checks are missing.")"
670 exit 1 # TODO: error code
674 extract_sources() {
675 msg "$(gettext "Extracting Sources...")"
676 local netfile
677 for netfile in "${source[@]}"; do
678 local file=$(get_filename "$netfile")
679 if in_array "$file" ${noextract[@]}; then
680 #skip source files in the noextract=() array
681 # these are marked explicitly to NOT be extracted
682 continue
686 # fix flyspray #6246
687 local file_type=$(file -bizL "$file")
688 local ext=${file##*.}
689 local cmd=''
690 case "$file_type" in
691 *application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*)
692 cmd="bsdtar" ;;
693 *application/x-gzip*)
694 case "$ext" in
695 gz|z|Z) cmd="gzip" ;;
696 *) continue;;
697 esac ;;
698 *application/x-bzip*)
699 case "$ext" in
700 bz2|bz) cmd="bzip2" ;;
701 *) continue;;
702 esac ;;
703 *application/x-xz*)
704 case "$ext" in
705 xz) cmd="xz" ;;
706 *) continue;;
707 esac ;;
709 # See if bsdtar can recognize the file
710 if bsdtar -tf "$file" -q '*' &>/dev/null; then
711 cmd="bsdtar"
712 else
713 continue
714 fi ;;
715 esac
717 local ret=0
718 msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd"
719 if [[ $cmd = bsdtar ]]; then
720 $cmd -xf "$file" || ret=$?
721 else
722 rm -f "${file%.*}"
723 $cmd -dcf "$file" > "${file%.*}" || ret=$?
725 if (( ret )); then
726 error "$(gettext "Failed to extract %s")" "$file"
727 plain "$(gettext "Aborting...")"
728 exit 1
730 done
732 if (( EUID == 0 )); then
733 # change perms of all source files to root user & root group
734 chown -R 0:0 "$srcdir"
738 error_function() {
739 if [[ -p $logpipe ]]; then
740 rm "$logpipe"
742 # first exit all subshells, then print the error
743 if (( ! BASH_SUBSHELL )); then
744 error "$(gettext "A failure occurred in %s().")" "$1"
745 plain "$(gettext "Aborting...")"
746 remove_deps
748 exit 2 # $E_BUILD_FAILED
751 run_function() {
752 if [[ -z $1 ]]; then
753 return 1
755 local pkgfunc="$1"
757 # clear user-specified buildflags if requested
758 if [[ $(check_option buildflags) = "n" ]]; then
759 CFLAGS=""
760 CXXFLAGS=""
761 LDFLAGS=""
764 # clear user-specified makeflags if requested
765 if [[ $(check_option makeflags) = "n" ]]; then
766 MAKEFLAGS=""
769 msg "$(gettext "Starting %s()...")" "$pkgfunc"
770 cd "$srcdir"
772 # ensure all necessary build variables are exported
773 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
774 # save our shell options so pkgfunc() can't override what we need
775 local shellopts=$(shopt -p)
777 local ret=0
778 local restoretrap
779 if (( LOGGING )); then
780 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
781 local BUILDLOG="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
782 if [[ -f $BUILDLOG ]]; then
783 local i=1
784 while true; do
785 if [[ -f $BUILDLOG.$i ]]; then
786 i=$(($i +1))
787 else
788 break
790 done
791 mv "$BUILDLOG" "$BUILDLOG.$i"
794 # ensure overridden package variables survive tee with split packages
795 logpipe=$(mktemp -u "$startdir/logpipe.XXXXXXXX")
796 mkfifo "$logpipe"
797 tee "$BUILDLOG" < "$logpipe" &
798 local teepid=$!
800 restoretrap=$(trap -p ERR)
801 trap 'error_function $pkgfunc' ERR
802 $pkgfunc &>"$logpipe"
803 eval $restoretrap
805 wait $teepid
806 rm "$logpipe"
807 else
808 restoretrap=$(trap -p ERR)
809 trap 'error_function $pkgfunc' ERR
810 $pkgfunc 2>&1
811 eval $restoretrap
813 # reset our shell options
814 eval "$shellopts"
817 run_build() {
818 # use distcc if it is requested (check buildenv and PKGBUILD opts)
819 if [[ $(check_buildenv distcc) = "y" && $(check_option distcc) != "n" ]]; then
820 [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH"
821 export DISTCC_HOSTS
822 elif [[ $(check_option distcc) = "n" ]]; then
823 # if it is not wanted, clear the makeflags too
824 MAKEFLAGS=""
827 # use ccache if it is requested (check buildenv and PKGBUILD opts)
828 if [[ $(check_buildenv ccache) = "y" && $(check_option ccache) != "n" ]]; then
829 [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH"
832 run_function "build"
835 run_check() {
836 run_function "check"
839 run_package() {
840 local pkgfunc
841 if [[ -z $1 ]]; then
842 pkgfunc="package"
843 else
844 pkgfunc="package_$1"
847 run_function "$pkgfunc"
850 tidy_install() {
851 cd "$pkgdir"
852 msg "$(gettext "Tidying install...")"
854 if [[ $(check_option docs) = "n" && -n ${DOC_DIRS[*]} ]]; then
855 msg2 "$(gettext "Removing doc files...")"
856 rm -rf ${DOC_DIRS[@]}
859 if [[ $(check_option purge) = "y" && -n ${PURGE_TARGETS[*]} ]]; then
860 msg2 "$(gettext "Purging other files...")"
861 local pt
862 for pt in "${PURGE_TARGETS[@]}"; do
863 if [[ ${pt} = ${pt//\/} ]]; then
864 find . -type f -name "${pt}" -exec rm -f -- '{}' \;
865 else
866 rm -f ${pt}
868 done
871 if [[ $(check_option zipman) = "y" && -n ${MAN_DIRS[*]} ]]; then
872 msg2 "$(gettext "Compressing man and info pages...")"
873 local manpage ext file link hardlinks hl
874 find ${MAN_DIRS[@]} -type f 2>/dev/null |
875 while read manpage ; do
876 ext="${manpage##*.}"
877 file="${manpage##*/}"
878 if [[ $ext != gz && $ext != bz2 ]]; then
879 # update symlinks to this manpage
880 find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null |
881 while read link ; do
882 rm -f "$link"
883 ln -sf "${file}.gz" "${link}.gz"
884 done
886 # check file still exists (potentially already compressed due to hardlink)
887 if [[ -f ${manpage} ]]; then
888 # find hard links and remove them
889 # the '|| true' part keeps the script from bailing if find returned an
890 # error, such as when one of the man directories doesn't exist
891 hardlinks="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
892 for hl in ${hardlinks}; do
893 rm -f "${hl}";
894 done
895 # compress the original
896 gzip -9 "$manpage"
897 # recreate hard links removed earlier
898 for hl in ${hardlinks}; do
899 ln "${manpage}.gz" "${hl}.gz"
900 chmod 644 ${hl}.gz
901 done
904 done
907 if [[ $(check_option strip) = y ]]; then
908 msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")"
909 # make sure library stripping variables are defined to prevent excess stripping
910 [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S"
911 [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S"
912 local binary
913 find . -type f -perm -u+w 2>/dev/null | while read binary ; do
914 case "$(file -bi "$binary")" in
915 *application/x-sharedlib*) # Libraries (.so)
916 /usr/bin/strip $STRIP_SHARED "$binary";;
917 *application/x-archive*) # Libraries (.a)
918 /usr/bin/strip $STRIP_STATIC "$binary";;
919 *application/x-executable*) # Binaries
920 /usr/bin/strip $STRIP_BINARIES "$binary";;
921 esac
922 done
925 if [[ $(check_option libtool) = "n" ]]; then
926 msg2 "$(gettext "Removing libtool .la files...")"
927 find . ! -type d -name "*.la" -exec rm -f -- '{}' \;
930 if [[ $(check_option emptydirs) = "n" ]]; then
931 msg2 "$(gettext "Removing empty directories...")"
932 find . -depth -type d -empty -delete
936 write_pkginfo() {
937 local builddate=$(date -u "+%s")
938 if [[ -n $PACKAGER ]]; then
939 local packager="$PACKAGER"
940 else
941 local packager="Unknown Packager"
943 local size="$(@DUPATH@ -sk)"
944 size="$(( ${size%%[^0-9]*} * 1024 ))"
946 msg2 "$(gettext "Generating .PKGINFO file...")"
947 echo "# Generated by makepkg $myver"
948 if (( INFAKEROOT )); then
949 echo "# using $(fakeroot -v)"
951 echo "# $(LC_ALL=C date -u)"
952 echo "pkgname = $1"
953 (( SPLITPKG )) && echo pkgbase = $pkgbase
954 echo "pkgver = $(get_full_version $epoch $pkgver $pkgrel)"
955 echo "pkgdesc = $pkgdesc"
956 echo "url = $url"
957 echo "builddate = $builddate"
958 echo "packager = $packager"
959 echo "size = $size"
960 echo "arch = $PKGARCH"
962 [[ $license ]] && printf "license = %s\n" "${license[@]}"
963 [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
964 [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
965 [[ $depends ]] && printf "depend = %s\n" "${depends[@]}"
966 [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]}"
967 [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
968 [[ $provides ]] && printf "provides = %s\n" "${provides[@]}"
969 [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
971 local it
972 for it in "${packaging_options[@]}"; do
973 local ret="$(check_option $it)"
974 if [[ $ret != "?" ]]; then
975 if [[ $ret = y ]]; then
976 echo "makepkgopt = $it"
977 else
978 echo "makepkgopt = !$it"
981 done
983 # TODO maybe remove this at some point
984 # warn if license array is not present or empty
985 if [[ -z $license ]]; then
986 warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT"
987 plain "$(gettext "Example for GPL\'ed software: license=('GPL').")"
991 check_package() {
992 cd "$pkgdir"
994 # check existence of backup files
995 local file
996 for file in "${backup[@]}"; do
997 if [[ ! -f $file ]]; then
998 warning "$(gettext "Backup entry file not in package : %s")" "$file"
1000 done
1002 # check for references to the build and package directory
1003 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${srcdir}" ; then
1004 warning "$(gettext "Package contains reference to %s")" "\$srcdir"
1006 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${pkgdir}" ; then
1007 warning "$(gettext "Package contains reference to %s")" "\$pkgdir"
1012 create_package() {
1013 if [[ ! -d $pkgdir ]]; then
1014 error "$(gettext "Missing pkg/ directory.")"
1015 plain "$(gettext "Aborting...")"
1016 exit 1 # $E_MISSING_PKGDIR
1019 check_package
1021 cd "$pkgdir"
1022 msg "$(gettext "Creating package...")"
1024 local nameofpkg
1025 if [[ -z $1 ]]; then
1026 nameofpkg="$pkgname"
1027 else
1028 nameofpkg="$1"
1031 if [[ $arch = "any" ]]; then
1032 PKGARCH="any"
1033 else
1034 PKGARCH=$CARCH
1037 write_pkginfo $nameofpkg > .PKGINFO
1039 local comp_files=".PKGINFO"
1041 # check for changelog/install files
1042 for i in 'changelog' 'install'; do
1043 orig=${!i}
1044 dest=$(tr '[:lower:]' '[:upper:]' <<<".$i")
1046 if [[ -n $orig ]]; then
1047 msg2 "$(gettext "Adding %s file...")" "$i"
1048 cp "$startdir/$orig" "$dest"
1049 chmod 644 "$dest"
1050 comp_files+=" $dest"
1052 done
1054 # tar it up
1055 msg2 "$(gettext "Compressing package...")"
1057 local EXT
1058 case "$PKGEXT" in
1059 *tar.gz) EXT=${PKGEXT%.gz} ;;
1060 *tar.bz2) EXT=${PKGEXT%.bz2} ;;
1061 *tar.xz) EXT=${PKGEXT%.xz} ;;
1062 *tar) EXT=${PKGEXT} ;;
1063 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1064 "$PKGEXT" ; EXT=$PKGEXT ;;
1065 esac
1067 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1068 local pkg_file="$PKGDEST/${nameofpkg}-${fullver}-${PKGARCH}${PKGEXT}"
1069 local ret=0
1071 [[ -f $pkg_file ]] && rm -f "$pkg_file"
1072 [[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig"
1074 # when fileglobbing, we want * in an empty directory to expand to
1075 # the null string rather than itself
1076 shopt -s nullglob
1077 # TODO: Maybe this can be set globally for robustness
1078 shopt -s -o pipefail
1079 bsdtar -cf - $comp_files * |
1080 case "$PKGEXT" in
1081 *tar.gz) gzip -c -f -n ;;
1082 *tar.bz2) bzip2 -c -f ;;
1083 *tar.xz) xz -c -z - ;;
1084 *tar) cat ;;
1085 esac > ${pkg_file} || ret=$?
1087 shopt -u nullglob
1088 shopt -u -o pipefail
1090 if (( ret )); then
1091 error "$(gettext "Failed to create package file.")"
1092 exit 1 # TODO: error code
1095 create_signature "$pkg_file"
1097 if (( ! ret )) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
1098 ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1099 ret=$?
1100 [[ -f $pkg_file.sig ]] && ln -sf "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
1103 if (( ret )); then
1104 warning "$(gettext "Failed to create symlink to package file.")"
1108 create_signature() {
1109 if [[ $(check_buildenv sign) != "y" ]]; then
1110 return
1112 local ret=0
1113 local filename="$1"
1114 msg "$(gettext "Signing package...")"
1115 if [ ! $(type -p "gpg") ]; then
1116 error "$(gettext "Cannot find the gpg binary! Is gnupg installed?")"
1117 exit 1 # $E_MISSING_PROGRAM
1119 gpg --detach-sign --use-agent "$filename" || ret=$?
1120 if (( ! ret )); then
1121 msg2 "$(gettext "Created signature file %s.")" "$filename.sig"
1122 else
1123 warning "$(gettext "Failed to sign package file.")"
1127 create_srcpackage() {
1128 cd "$startdir"
1130 # Get back to our src directory so we can begin with sources.
1131 mkdir -p "$srcdir"
1132 chmod a-s "$srcdir"
1133 cd "$srcdir"
1134 if (( ! SKIPINTEG || SOURCEONLY == 2 )); then
1135 download_sources
1137 if (( ! SKIPINTEG )); then
1138 # We can only check checksums if we have all files.
1139 check_checksums
1140 else
1141 warning "$(gettext "Skipping integrity checks.")"
1143 cd "$startdir"
1145 msg "$(gettext "Creating source package...")"
1146 local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1147 mkdir "${srclinks}"/${pkgbase}
1149 msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
1150 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1152 local file
1153 for file in "${source[@]}"; do
1154 if [[ -f $file ]]; then
1155 msg2 "$(gettext "Adding %s...")" "$file"
1156 ln -s "${startdir}/$file" "$srclinks/$pkgbase"
1157 elif (( SOURCEONLY == 2 )); then
1158 local absfile=$(get_filepath "$file") || missing_source_file "$file"
1159 msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
1160 ln -s "$absfile" "$srclinks/$pkgbase"
1162 done
1164 local i
1165 for i in 'changelog' 'install'; do
1166 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDSCRIPT")
1167 local file
1168 for file in $filelist; do
1169 # evaluate any bash variables used
1170 eval file=${file}
1171 if [[ ! -f "${srclinks}/${pkgbase}/$file" ]]; then
1172 msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}"
1173 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
1175 done
1176 done
1178 local TAR_OPT
1179 case "$SRCEXT" in
1180 *tar.gz) TAR_OPT="z" ;;
1181 *tar.bz2) TAR_OPT="j" ;;
1182 *tar.xz) TAR_OPT="J" ;;
1183 *tar) TAR_OPT="" ;;
1184 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1185 "$SRCEXT" ;;
1186 esac
1188 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1189 local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
1191 # tar it up
1192 msg2 "$(gettext "Compressing source package...")"
1193 cd "${srclinks}"
1194 if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgbase}; then
1195 error "$(gettext "Failed to create source package file.")"
1196 exit 1 # TODO: error code
1199 if (( ! ret )) && [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
1200 ln -sf "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
1201 ret=$?
1204 if (( ret )); then
1205 warning "$(gettext "Failed to create symlink to source package file.")"
1208 cd "${startdir}"
1209 rm -rf "${srclinks}"
1212 install_package() {
1213 (( ! INSTALL )) && return
1215 if (( ! SPLITPKG )); then
1216 msg "$(gettext "Installing package %s with %s -U...")" "$pkgname" "$PACMAN"
1217 else
1218 msg "$(gettext "Installing %s package group with %s -U...")" "$pkgbase" "$PACMAN"
1221 local fullver pkg pkglist
1222 for pkg in ${pkgname[@]}; do
1223 # TODO: this wasn't properly fixed in commit 2020e629
1224 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1225 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} ]]; then
1226 pkglist+=" $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT}"
1227 else
1228 pkglist+=" $PKGDEST/${pkg}-${fullver}-any${PKGEXT}"
1230 done
1232 if ! run_pacman -U $pkglist; then
1233 warning "$(gettext "Failed to install built package(s).")"
1234 return 0
1238 check_sanity() {
1239 # check for no-no's in the build script
1240 local i
1241 local ret=0
1242 for i in 'pkgname' 'pkgrel' 'pkgver'; do
1243 if [[ -z ${!i} ]]; then
1244 error "$(gettext "%s is not allowed to be empty.")" "$i"
1245 ret=1
1247 done
1249 for i in "${pkgname[@]}"; do
1250 if [[ ${i:0:1} = "-" ]]; then
1251 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname"
1252 ret=1
1254 done
1256 if [[ ${pkgbase:0:1} = "-" ]]; then
1257 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgbase"
1258 ret=1
1260 if [[ $pkgver =~ [:-] ]]; then
1261 error "$(gettext "%s is not allowed to contain colons or hyphens.")" "pkgver"
1262 ret=1
1264 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1265 error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
1266 ret=1
1269 if [[ ! $epoch =~ ^[0-9]*$ ]]; then
1270 error "$(gettext "%s must be an integer.")" "epoch"
1271 ret=1
1274 if [[ $arch != 'any' ]]; then
1275 if ! in_array $CARCH ${arch[@]}; then
1276 if (( ! IGNOREARCH )); then
1277 error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH"
1278 plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
1279 plain "$(gettext "such as arch=('%s').")" "$CARCH"
1280 ret=1
1285 local provides_list=()
1286 eval $(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \
1287 sed -e "s/provides=/provides_list+=/" -e "s/#.*//")
1288 for i in ${provides_list[@]}; do
1289 if [[ $i != ${i//</} || $i != ${i//>/} ]]; then
1290 error "$(gettext "Provides array cannot contain comparison (< or >) operators.")"
1291 ret=1
1293 done
1295 local backup_list=()
1296 eval $(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \
1297 sed -e "s/backup=/backup_list+=/" -e "s/#.*//")
1298 for i in "${backup_list[@]}"; do
1299 if [[ ${i:0:1} = "/" ]]; then
1300 error "$(gettext "Backup entry should not contain leading slash : %s")" "$i"
1301 ret=1
1303 done
1305 local optdepends_list=()
1306 eval $(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(|#.*)$/' "$BUILDFILE" | \
1307 sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//")
1308 for i in "${optdepends_list[@]}"; do
1309 local pkg=${i%%:*}
1310 if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]+$ ]]; then
1311 error "$(gettext "Invalid syntax for optdepend : '%s'")" "$i"
1312 ret=1
1314 done
1316 for i in 'changelog' 'install'; do
1317 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1318 local file
1319 for file in $filelist; do
1320 # evaluate any bash variables used
1321 eval file=${file}
1322 if [[ ! -f $file ]]; then
1323 error "$(gettext "%s file (%s) does not exist.")" "$i" "$file"
1324 ret=1
1326 done
1327 done
1329 local valid_options=1
1330 local known kopt options_list
1331 eval $(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \
1332 sed -e "s/options=/options_list+=/" -e "s/#.*//")
1333 for i in ${options_list[@]}; do
1334 known=0
1335 # check if option matches a known option or its inverse
1336 for kopt in ${packaging_options[@]} ${other_options[@]}; do
1337 if [[ ${i} = ${kopt} || ${i} = "!${kopt}" ]]; then
1338 known=1
1340 done
1341 if (( ! known )); then
1342 error "$(gettext "options array contains unknown option '%s'")" "$i"
1343 valid_options=0
1345 done
1346 if (( ! valid_options )); then
1347 ret=1
1350 if (( ${#pkgname[@]} > 1 )); then
1351 for i in ${pkgname[@]}; do
1352 if ! declare -f package_${i} >/dev/null; then
1353 error "$(gettext "missing package function for split package '%s'")" "$i"
1354 ret=1
1356 done
1359 for i in ${PKGLIST[@]}; do
1360 if ! in_array $i ${pkgname[@]}; then
1361 error "$(gettext "requested package %s is not provided in %s")" "$i" "$BUILDFILE"
1362 ret=1
1364 done
1366 return $ret
1369 devel_check() {
1370 newpkgver=""
1372 # Do not update pkgver if --holdver is set, when building a source package, repackaging,
1373 # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1374 if (( HOLDVER || SOURCEONLY || REPKG )) \
1375 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1376 return
1379 if [[ -z $FORCE_VER ]]; then
1380 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1381 # This will only be used on the first call to makepkg; subsequent
1382 # calls to makepkg via fakeroot will explicitly pass the version
1383 # number to avoid having to determine the version number twice.
1384 # Also do a brief check to make sure we have the VCS tool available.
1385 oldpkgver=$pkgver
1386 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1387 type -p darcs >/dev/null || return 0
1388 msg "$(gettext "Determining latest %s revision...")" 'darcs'
1389 newpkgver=$(date +%Y%m%d)
1390 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1391 type -p cvs >/dev/null || return 0
1392 msg "$(gettext "Determining latest %s revision...")" 'cvs'
1393 newpkgver=$(date +%Y%m%d)
1394 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1395 type -p git >/dev/null || return 0
1396 msg "$(gettext "Determining latest %s revision...")" 'git'
1397 newpkgver=$(date +%Y%m%d)
1398 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1399 type -p svn >/dev/null || return 0
1400 msg "$(gettext "Determining latest %s revision...")" 'svn'
1401 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1402 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1403 type -p bzr >/dev/null || return 0
1404 msg "$(gettext "Determining latest %s revision...")" 'bzr'
1405 newpkgver=$(bzr revno ${_bzrtrunk})
1406 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1407 type -p hg >/dev/null || return 0
1408 msg "$(gettext "Determining latest %s revision...")" 'hg'
1409 if [[ -d ./src/$_hgrepo ]] ; then
1410 cd ./src/$_hgrepo
1411 hg pull
1412 hg update
1413 else
1414 [[ ! -d ./src/ ]] && mkdir ./src/
1415 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1416 cd ./src/$_hgrepo
1418 newpkgver=$(hg tip --template "{rev}")
1419 cd ../../
1422 if [[ -n $newpkgver ]]; then
1423 msg2 "$(gettext "Version found: %s")" "$newpkgver"
1426 else
1427 # Version number retrieved from fakeroot->makepkg argument
1428 newpkgver=$FORCE_VER
1432 devel_update() {
1433 # This is lame, but if we're wanting to use an updated pkgver for
1434 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1435 # the new pkgver and then re-source it. This is the most robust
1436 # method for dealing with PKGBUILDs that use, e.g.:
1438 # pkgver=23
1439 # ...
1440 # _foo=pkgver
1442 if [[ -n $newpkgver ]]; then
1443 if [[ $newpkgver != $pkgver ]]; then
1444 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1445 @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE"
1446 @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE"
1447 source "$BUILDFILE"
1453 backup_package_variables() {
1454 local var
1455 for var in ${splitpkg_overrides[@]}; do
1456 local indirect="${var}_backup"
1457 eval "${indirect}=(\"\${$var[@]}\")"
1458 done
1461 restore_package_variables() {
1462 local var
1463 for var in ${splitpkg_overrides[@]}; do
1464 local indirect="${var}_backup"
1465 if [[ -n ${!indirect} ]]; then
1466 eval "${var}=(\"\${$indirect[@]}\")"
1467 else
1468 unset ${var}
1470 done
1473 run_split_packaging() {
1474 local pkgname_backup=${pkgname[@]}
1475 for pkgname in ${pkgname_backup[@]}; do
1476 pkgdir="$pkgdir/$pkgname"
1477 mkdir -p "$pkgdir"
1478 chmod a-s "$pkgdir"
1479 backup_package_variables
1480 run_package $pkgname
1481 tidy_install
1482 create_package $pkgname
1483 restore_package_variables
1484 pkgdir="${pkgdir%/*}"
1485 done
1486 pkgname=${pkgname_backup[@]}
1489 # Canonicalize a directory path if it exists
1490 canonicalize_path() {
1491 local path="$1";
1493 if [[ -d $path ]]; then
1495 cd "$path"
1496 pwd -P
1498 else
1499 echo "$path"
1503 # getopt like parser
1504 parse_options() {
1505 local short_options=$1; shift;
1506 local long_options=$1; shift;
1507 local ret=0;
1508 local unused_options=""
1509 local i
1511 while [[ -n $1 ]]; do
1512 if [[ ${1:0:2} = '--' ]]; then
1513 if [[ -n ${1:2} ]]; then
1514 local match=""
1515 for i in ${long_options//,/ }; do
1516 if [[ ${1:2} = ${i//:} ]]; then
1517 match=$i
1518 break
1520 done
1521 if [[ -n $match ]]; then
1522 if [[ ${1:2} = $match ]]; then
1523 printf ' %s' "$1"
1524 else
1525 if [[ -n $2 ]]; then
1526 printf ' %s' "$1"
1527 shift
1528 printf " '%s'" "$1"
1529 else
1530 echo "makepkg: option '$1' $(gettext "requires an argument")" >&2
1531 ret=1
1534 else
1535 echo "makepkg: $(gettext "unrecognized option") '$1'" >&2
1536 ret=1
1538 else
1539 shift
1540 break
1542 elif [[ ${1:0:1} = '-' ]]; then
1543 for ((i=1; i<${#1}; i++)); do
1544 if [[ $short_options =~ ${1:i:1} ]]; then
1545 if [[ $short_options =~ ${1:i:1}: ]]; then
1546 if [[ -n ${1:$i+1} ]]; then
1547 printf ' -%s' "${1:i:1}"
1548 printf " '%s'" "${1:$i+1}"
1549 else
1550 if [[ -n $2 ]]; then
1551 printf ' -%s' "${1:i:1}"
1552 shift
1553 printf " '%s'" "${1}"
1554 else
1555 echo "makepkg: option $(gettext "requires an argument") -- '${1:i:1}'" >&2
1556 ret=1
1559 break
1560 else
1561 printf ' -%s' "${1:i:1}"
1563 else
1564 echo "makepkg: $(gettext "invalid option") -- '${1:i:1}'" >&2
1565 ret=1
1567 done
1568 else
1569 unused_options="${unused_options} '$1'"
1571 shift
1572 done
1574 printf " --"
1575 if [[ -n $unused_options ]]; then
1576 for i in ${unused_options[@]}; do
1577 printf ' %s' "$i"
1578 done
1580 if [[ -n $1 ]]; then
1581 while [[ -n $1 ]]; do
1582 printf " '%s'" "${1}"
1583 shift
1584 done
1586 printf "\n"
1588 return $ret
1591 usage() {
1592 printf "makepkg (pacman) %s\n" "$myver"
1593 echo
1594 printf "$(gettext "Usage: %s [options]")\n" "$0"
1595 echo
1596 echo "$(gettext "Options:")"
1597 printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
1598 echo "$(gettext " -c, --clean Clean up work files after build")"
1599 echo "$(gettext " -C, --cleancache Clean up source files from the cache")"
1600 echo "$(gettext " -d, --nodeps Skip all dependency checks")"
1601 echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
1602 echo "$(gettext " -f, --force Overwrite existing package")"
1603 echo "$(gettext " -g, --geninteg Generate integrity checks for source files")"
1604 echo "$(gettext " -h, --help This help")"
1605 echo "$(gettext " -i, --install Install package after successful build")"
1606 echo "$(gettext " -L, --log Log package build process")"
1607 echo "$(gettext " -m, --nocolor Disable colorized output messages")"
1608 echo "$(gettext " -o, --nobuild Download and extract files only")"
1609 printf "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1610 echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1611 echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1612 echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")"
1613 echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1614 echo "$(gettext " --asroot Allow makepkg to run as root user")"
1615 printf "$(gettext " --check Run the check() function in the %s")\n" "$BUILDSCRIPT"
1616 printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf"
1617 printf "$(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT"
1618 printf "$(gettext " --nocheck Do not run the check() function in the %s")\n" "$BUILDSCRIPT"
1619 echo "$(gettext " --pkg <list> Only build listed packages from a split package")"
1620 echo "$(gettext " --skipinteg Do not fail when integrity checks are missing")"
1621 echo "$(gettext " --source Generate a source-only tarball without downloaded sources")"
1622 echo
1623 echo "$(gettext "These options can be passed to pacman:")"
1624 echo
1625 echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1626 echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1627 echo
1628 printf "$(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1629 echo
1632 version() {
1633 printf "makepkg (pacman) %s\n" "$myver"
1634 printf "$(gettext "\
1635 Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1636 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1637 This is free software; see the source for copying conditions.\n\
1638 There is NO WARRANTY, to the extent permitted by law.\n")"
1641 # PROGRAM START
1643 # determine whether we have gettext; make it a no-op if we do not
1644 if ! type -p gettext >/dev/null; then
1645 gettext() {
1646 echo "$@"
1650 ARGLIST=("$@")
1652 # Parse Command Line Options.
1653 OPT_SHORT="AcCdefFghiLmop:rRsV"
1654 OPT_LONG="allsource,asroot,ignorearch,check,clean,cleancache,nodeps"
1655 OPT_LONG+=",noextract,force,forcever:,geninteg,help,holdver"
1656 OPT_LONG+=",install,log,nocolor,nobuild,nocheck,pkg:,rmdeps"
1657 OPT_LONG+=",repackage,skipinteg,source,syncdeps,version,config:"
1658 # Pacman Options
1659 OPT_LONG+=",noconfirm,noprogressbar"
1660 OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')"
1661 if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then
1662 # This is a small hack to stop the script bailing with 'set -e'
1663 echo; usage; exit 1 # E_INVALID_OPTION;
1665 eval set -- "$OPT_TEMP"
1666 unset OPT_SHORT OPT_LONG OPT_TEMP
1668 while true; do
1669 case "$1" in
1670 # Pacman Options
1671 --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
1672 --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
1674 # Makepkg Options
1675 --allsource) SOURCEONLY=2 ;;
1676 --asroot) ASROOT=1 ;;
1677 -A|--ignorearch) IGNOREARCH=1 ;;
1678 -c|--clean) CLEANUP=1 ;;
1679 -C|--cleancache) CLEANCACHE=1 ;;
1680 --check) RUN_CHECK='y' ;;
1681 --config) shift; MAKEPKG_CONF=$1 ;;
1682 -d|--nodeps) NODEPS=1 ;;
1683 -e|--noextract) NOEXTRACT=1 ;;
1684 -f|--force) FORCE=1 ;;
1685 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1686 --forcever) shift; FORCE_VER=$1;;
1687 -F) INFAKEROOT=1 ;;
1688 -g|--geninteg) GENINTEG=1 ;;
1689 --holdver) HOLDVER=1 ;;
1690 -i|--install) INSTALL=1 ;;
1691 -L|--log) LOGGING=1 ;;
1692 -m|--nocolor) USE_COLOR='n' ;;
1693 --nocheck) RUN_CHECK='n' ;;
1694 -o|--nobuild) NOBUILD=1 ;;
1695 -p) shift; BUILDFILE=$1 ;;
1696 --pkg) shift; PKGLIST=($1) ;;
1697 -r|--rmdeps) RMDEPS=1 ;;
1698 -R|--repackage) REPKG=1 ;;
1699 --skipinteg) SKIPINTEG=1 ;;
1700 --source) SOURCEONLY=1 ;;
1701 -s|--syncdeps) DEP_BIN=1 ;;
1703 -h|--help) usage; exit 0 ;; # E_OK
1704 -V|--version) version; exit 0 ;; # E_OK
1706 --) OPT_IND=0; shift; break;;
1707 *) usage; exit 1 ;; # E_INVALID_OPTION
1708 esac
1709 shift
1710 done
1712 # preserve environment variables and canonicalize path
1713 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
1714 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
1715 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
1717 # default config is makepkg.conf
1718 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1720 # Source the config file; fail if it is not found
1721 if [[ -r $MAKEPKG_CONF ]]; then
1722 source "$MAKEPKG_CONF"
1723 else
1724 error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
1725 plain "$(gettext "Aborting...")"
1726 exit 1 # $E_CONFIG_ERROR
1729 # Source user-specific makepkg.conf overrides
1730 if [[ -r ~/.makepkg.conf ]]; then
1731 source ~/.makepkg.conf
1734 # set pacman command if not already defined
1735 PACMAN=${PACMAN:-pacman}
1737 # check if messages are to be printed using color
1738 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1739 if [[ -t 2 && ! $USE_COLOR = "n" && $(check_buildenv color) = "y" ]]; then
1740 # prefer terminal safe colored and bold text when tput is supported
1741 if tput setaf 0 &>/dev/null; then
1742 ALL_OFF="$(tput sgr0)"
1743 BOLD="$(tput bold)"
1744 BLUE="${BOLD}$(tput setaf 4)"
1745 GREEN="${BOLD}$(tput setaf 2)"
1746 RED="${BOLD}$(tput setaf 1)"
1747 YELLOW="${BOLD}$(tput setaf 3)"
1748 else
1749 ALL_OFF="\e[1;0m"
1750 BOLD="\e[1;1m"
1751 BLUE="${BOLD}\e[1;34m"
1752 GREEN="${BOLD}\e[1;32m"
1753 RED="${BOLD}\e[1;31m"
1754 YELLOW="${BOLD}\e[1;33m"
1757 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1759 # override settings with an environment variable for batch processing
1760 PKGDEST=${_PKGDEST:-$PKGDEST}
1761 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1762 if [[ ! -w $PKGDEST ]]; then
1763 error "$(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
1764 plain "$(gettext "Aborting...")"
1765 exit 1
1768 SRCDEST=${_SRCDEST:-$SRCDEST}
1769 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1770 if [[ ! -w $SRCDEST ]] ; then
1771 error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
1772 plain "$(gettext "Aborting...")"
1773 exit 1
1776 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
1777 SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
1780 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1781 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1782 error "$(gettext "\\0--holdver and --forcever cannot both be specified" )"
1783 exit 1
1786 if (( CLEANCACHE )); then
1787 #fix flyspray feature request #5223
1788 if [[ -n $SRCDEST && ! $SRCDEST -ef "${startdir}" ]]; then
1789 msg "$(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1790 echo -n "$(gettext " Are you sure you wish to do this? ")"
1791 echo -n "$(gettext "[y/N]")"
1792 read answer
1793 answer=$(tr '[:lower:]' '[:upper:]' <<< "$answer")
1794 if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then
1795 rm "$SRCDEST"/*
1796 if (( $? )); then
1797 error "$(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1798 exit 1
1799 else
1800 # removal worked
1801 msg "$(gettext "Source cache cleaned.")"
1802 exit 0
1804 else
1805 # answer = no
1806 msg "$(gettext "No files have been removed.")"
1807 exit 0
1809 else
1810 # $SRCDEST is $startdir, two possibilities
1811 error "$(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
1812 plain "$(gettext "In addition, please run makepkg -C outside of your cache directory.")"
1813 exit 1
1817 if (( ! INFAKEROOT )); then
1818 if (( EUID == 0 && ! ASROOT )); then
1819 # Warn those who like to live dangerously.
1820 error "$(gettext "Running makepkg as root is a BAD idea and can cause")"
1821 plain "$(gettext "permanent, catastrophic damage to your system. If you")"
1822 plain "$(gettext "wish to run as root, please use the --asroot option.")"
1823 exit 1 # $E_USER_ABORT
1824 elif (( EUID > 0 && ASROOT )); then
1825 # Warn those who try to use the --asroot option when they are not root
1826 error "$(gettext "The --asroot option is meant for the root user only.")"
1827 plain "$(gettext "Please rerun makepkg without the --asroot flag.")"
1828 exit 1 # $E_USER_ABORT
1829 elif [[ $(check_buildenv fakeroot) = "y" ]] && (( EUID > 0 )); then
1830 if ! type -p fakeroot >/dev/null; then
1831 error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
1832 plain "$(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1833 exit 1
1835 elif (( EUID > 0 )); then
1836 warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")"
1837 plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
1838 plain "$(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1839 sleep 1
1841 else
1842 if [[ -z $FAKEROOTKEY ]]; then
1843 error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
1844 exit 1 # TODO: error code
1848 # check for sudo if we will need it during makepkg execution
1849 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1850 if ! type -p sudo >/dev/null; then
1851 warning "$(gettext "Sudo can not be found. Will use su to acquire root privileges.")"
1855 unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
1856 unset md5sums replaces depends conflicts backup source install changelog build
1857 unset makedepends optdepends options noextract
1859 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1860 if [[ ! -f $BUILDFILE ]]; then
1861 if [[ -t 0 ]]; then
1862 error "$(gettext "%s does not exist.")" "$BUILDFILE"
1863 exit 1
1864 else
1865 # PKGBUILD passed through a pipe
1866 BUILDFILE=/dev/stdin
1867 source "$BUILDFILE"
1869 else
1870 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1871 if [[ -n $crlftest ]]; then
1872 error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE"
1873 exit 1
1876 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1877 BUILDFILE="$startdir/$BUILDFILE"
1879 source "$BUILDFILE"
1882 # set defaults if they weren't specified in buildfile
1883 pkgbase=${pkgbase:-${pkgname[0]}}
1884 epoch=${epoch:-0}
1886 if (( GENINTEG )); then
1887 mkdir -p "$srcdir"
1888 chmod a-s "$srcdir"
1889 cd "$srcdir"
1890 download_sources
1891 generate_checksums
1892 exit 0 # $E_OK
1895 # check the PKGBUILD for some basic requirements
1896 check_sanity || exit 1
1898 # We need to run devel_update regardless of whether we are in the fakeroot
1899 # build process so that if the user runs makepkg --forcever manually, we
1900 # 1) output the correct pkgver, and 2) use the correct filename when
1901 # checking if the package file already exists - fixes FS #9194
1902 devel_check
1903 devel_update
1905 if (( ${#pkgname[@]} > 1 )); then
1906 SPLITPKG=1
1909 # test for available PKGBUILD functions
1910 if declare -f build >/dev/null; then
1911 BUILDFUNC=1
1913 if declare -f check >/dev/null; then
1914 # "Hide" check() function if not going to be run
1915 if [[ $RUN_CHECK = 'y' || (! $(check_buildenv check) = "n" && ! $RUN_CHECK = "n") ]]; then
1916 CHECKFUNC=1
1919 if declare -f package >/dev/null; then
1920 PKGFUNC=1
1921 elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then
1922 SPLITPKG=1
1925 if [[ -n "${PKGLIST[@]}" ]]; then
1926 unset pkgname
1927 pkgname=("${PKGLIST[@]}")
1930 if (( ! SPLITPKG )); then
1931 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1932 if [[ -f $PKGDEST/${pkgname}-${fullver}-${CARCH}${PKGEXT} \
1933 || -f $PKGDEST/${pkgname}-${fullver}-any${PKGEXT} ]] \
1934 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
1935 if (( INSTALL )); then
1936 warning "$(gettext "A package has already been built, installing existing package...")"
1937 install_package
1938 exit $?
1939 else
1940 error "$(gettext "A package has already been built. (use -f to overwrite)")"
1941 exit 1
1944 else
1945 allpkgbuilt=1
1946 somepkgbuilt=0
1947 for pkg in ${pkgname[@]}; do
1948 # TODO: this wasn't properly fixed in commit 2020e629
1949 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1950 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} \
1951 || -f $PKGDEST/${pkg}-${fullver}-any${PKGEXT} ]]; then
1952 somepkgbuilt=1
1953 else
1954 allpkgbuilt=0
1956 done
1957 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
1958 if (( allpkgbuilt )); then
1959 if (( INSTALL )); then
1960 warning "$(gettext "The package group has already been built, installing existing packages...")"
1961 install_package
1962 exit $?
1963 else
1964 error "$(gettext "The package group has already been built. (use -f to overwrite)")"
1965 exit 1
1968 if (( somepkgbuilt )); then
1969 error "$(gettext "Part of the package group has already been built. (use -f to overwrite)")"
1970 exit 1
1973 unset allpkgbuilt somepkgbuilt
1976 # Run the bare minimum in fakeroot
1977 if (( INFAKEROOT )); then
1978 if (( ! SPLITPKG )); then
1979 if (( ! PKGFUNC )); then
1980 if (( ! REPKG )); then
1981 if (( BUILDFUNC )); then
1982 run_build
1983 (( CHECKFUNC )) && run_check
1984 tidy_install
1986 else
1987 warning "$(gettext "Repackaging without the use of a package() function is deprecated.")"
1988 plain "$(gettext "File permissions may not be preserved.")"
1990 else
1991 run_package
1992 tidy_install
1994 create_package
1995 else
1996 run_split_packaging
1999 msg "$(gettext "Leaving fakeroot environment.")"
2000 exit 0 # $E_OK
2003 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2004 msg "$(gettext "Making package: %s")" "$pkgbase $fullver ($(date))"
2006 # if we are creating a source-only package, go no further
2007 if (( SOURCEONLY )); then
2008 if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \
2009 && (( ! FORCE )); then
2010 error "$(gettext "A source package has already been built. (use -f to overwrite)")"
2011 exit 1
2013 create_srcpackage
2014 msg "$(gettext "Source package created: %s")" "$pkgbase ($(date))"
2015 exit 0
2018 if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); then
2019 # no warning message needed for nobuild, repkg
2020 if (( NODEPS || ( REPKG && PKGFUNC ) )); then
2021 warning "$(gettext "Skipping dependency checks.")"
2023 elif type -p "${PACMAN%% *}" >/dev/null; then
2024 if (( RMDEPS )); then
2025 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
2027 deperr=0
2029 msg "$(gettext "Checking runtime dependencies...")"
2030 resolve_deps ${depends[@]} || deperr=1
2032 msg "$(gettext "Checking buildtime dependencies...")"
2033 resolve_deps ${makedepends[@]} || deperr=1
2035 if (( CHECKFUNC )); then
2036 resolve_deps ${checkdepends[@]} || deperr=1
2039 if (( RMDEPS )); then
2040 current_pkglist=($(run_pacman -Qq)) # required by remove_deps
2043 if (( deperr )); then
2044 error "$(gettext "Could not resolve all dependencies.")"
2045 exit 1
2047 else
2048 warning "$(gettext "%s was not found in PATH; skipping dependency checks.")" "${PACMAN%% *}"
2051 # ensure we have a sane umask set
2052 umask 0022
2054 # get back to our src directory so we can begin with sources
2055 mkdir -p "$srcdir"
2056 chmod a-s "$srcdir"
2057 cd "$srcdir"
2059 if (( NOEXTRACT )); then
2060 warning "$(gettext "Skipping source retrieval -- using existing src/ tree")"
2061 warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")"
2062 warning "$(gettext "Skipping source extraction -- using existing src/ tree")"
2064 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
2065 error "$(gettext "The source directory is empty, there is nothing to build!")"
2066 plain "$(gettext "Aborting...")"
2067 exit 1
2069 elif (( REPKG )); then
2070 if (( ! PKGFUNC && ! SPLITPKG )) \
2071 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
2072 error "$(gettext "The package directory is empty, there is nothing to repackage!")"
2073 plain "$(gettext "Aborting...")"
2074 exit 1
2076 else
2077 download_sources
2078 if (( ! SKIPINTEG )); then
2079 check_checksums
2080 else
2081 warning "$(gettext "Skipping integrity checks.")"
2083 extract_sources
2086 if (( NOBUILD )); then
2087 msg "$(gettext "Sources are ready.")"
2088 exit 0 #E_OK
2089 else
2090 # check for existing pkg directory; don't remove if we are repackaging
2091 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
2092 msg "$(gettext "Removing existing pkg/ directory...")"
2093 rm -rf "$pkgdir"
2095 mkdir -p "$pkgdir"
2096 chmod a-s "$pkgdir"
2097 cd "$startdir"
2099 # if we are root or if fakeroot is not enabled, then we don't use it
2100 if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then
2101 if (( ! REPKG )); then
2102 devel_update
2103 (( BUILDFUNC )) && run_build
2104 (( CHECKFUNC )) && run_check
2106 if (( ! SPLITPKG )); then
2107 if (( PKGFUNC )); then
2108 run_package
2109 tidy_install
2110 else
2111 if (( ! REPKG )); then
2112 tidy_install
2113 else
2114 warning "$(gettext "Repackaging without the use of a package() function is deprecated.")"
2115 plain "$(gettext "File permissions may not be preserved.")"
2118 create_package
2119 else
2120 run_split_packaging
2122 else
2123 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
2124 devel_update
2125 (( BUILDFUNC )) && run_build
2126 (( CHECKFUNC )) && run_check
2127 cd "$startdir"
2130 msg "$(gettext "Entering fakeroot environment...")"
2132 if [[ -n $newpkgver ]]; then
2133 fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $?
2134 else
2135 fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
2140 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2141 msg "$(gettext "Finished making: %s")" "$pkgbase $fullver ($(date))"
2143 install_package
2145 exit 0 #E_OK
2147 # vim: set ts=2 sw=2 noet: