makepkg: remove unnecessary tr usage
[pacman-ng.git] / scripts / makepkg.sh.in
blob193a18531b3fa9b6a42b356ba597bccb4c0da68f
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=$1; shift
291 local opt
292 for opt in "$@"; do
293 if [[ $opt = $needle ]]; then
294 echo 'y' # Enabled
295 return
296 elif [[ $opt = "!$needle" ]]; then
297 echo 'n' # Disabled
298 return
300 done
302 echo '?' # Not Found
307 # usage : in_array( $needle, $haystack )
308 # return : 0 - found
309 # 1 - not found
311 in_array() {
312 local needle=$1; shift
313 [[ -z $1 ]] && return 1 # Not Found
314 local item
315 for item in "$@"; do
316 [[ $item = $needle ]] && return 0 # Found
317 done
318 return 1 # Not Found
321 get_downloadclient() {
322 # $1 = URL with valid protocol prefix
323 local url=$1
324 local proto="${url%%://*}"
326 # loop through DOWNLOAD_AGENTS variable looking for protocol
327 local i
328 for i in "${DLAGENTS[@]}"; do
329 local handler="${i%%::*}"
330 if [[ $proto = $handler ]]; then
331 local agent="${i##*::}"
332 break
334 done
336 # if we didn't find an agent, return an error
337 if [[ -z $agent ]]; then
338 error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF"
339 plain "$(gettext "Aborting...")"
340 exit 1 # $E_CONFIG_ERROR
343 # ensure specified program is installed
344 local program="${agent%% *}"
345 if [[ ! -x $program ]]; then
346 local baseprog="${program##*/}"
347 error "$(gettext "The download program %s is not installed.")" "$baseprog"
348 plain "$(gettext "Aborting...")"
349 exit 1 # $E_MISSING_PROGRAM
352 echo "$agent"
355 download_file() {
356 # download command
357 local dlcmd=$1
358 # URL of the file
359 local url=$2
360 # destination file
361 local file=$3
362 # temporary download file, default to last component of the URL
363 local dlfile="${url##*/}"
365 # replace %o by the temporary dlfile if it exists
366 if [[ $dlcmd = *%o* ]]; then
367 dlcmd=${dlcmd//\%o/\"$file.part\"}
368 dlfile="$file.part"
370 # add the URL, either in place of %u or at the end
371 if [[ $dlcmd = *%u* ]]; then
372 dlcmd=${dlcmd//\%u/\"$url\"}
373 else
374 dlcmd="$dlcmd \"$url\""
377 local ret=0
378 eval "$dlcmd || ret=\$?"
379 if (( ret )); then
380 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
381 return $ret
384 # rename the temporary download file to the final destination
385 if [[ $dlfile != $file ]]; then
386 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
390 run_pacman() {
391 local cmd
392 printf -v cmd "%q " "$PACMAN" $PACMAN_OPTS "$@"
393 if (( ! ASROOT )) && [[ ! $1 =~ ^-(T|Qq)$ ]]; then
394 if [ "$(type -p sudo)" ]; then
395 cmd="sudo $cmd"
396 else
397 cmd="su -c '$cmd'"
400 eval "$cmd"
403 check_deps() {
404 (( $# > 0 )) || return 0
406 # Disable error trap in pacman subshell call as this breaks bash-3.2 compatibility
407 # Also, a non-zero return value is not unexpected and we are manually dealing them
408 set +E
409 local ret=0
410 local pmout
411 pmout=$(run_pacman -T "$@") || ret=$?
412 set -E
414 if (( ret == 127 )); then #unresolved deps
415 echo "$pmout"
416 elif (( ret )); then
417 error "$(gettext "'%s' returned a fatal error (%i): %s")" "$PACMAN" "$ret" "$pmout"
418 return "$ret"
422 handle_deps() {
423 local R_DEPS_SATISFIED=0
424 local R_DEPS_MISSING=1
426 (( $# == 0 )) && return $R_DEPS_SATISFIED
428 local deplist="$*"
430 if (( ! DEP_BIN )); then
431 return $R_DEPS_MISSING
434 if (( DEP_BIN )); then
435 # install missing deps from binary packages (using pacman -S)
436 msg "$(gettext "Installing missing dependencies...")"
438 if ! run_pacman -S --asdeps $deplist; then
439 error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN"
440 exit 1 # TODO: error code
444 # we might need the new system environment
445 # avoid triggering the ERR trap
446 local restoretrap=$(trap -p ERR)
447 trap - ERR
448 source /etc/profile &>/dev/null
449 eval $restoretrap
451 return $R_DEPS_SATISFIED
454 resolve_deps() {
455 local R_DEPS_SATISFIED=0
456 local R_DEPS_MISSING=1
458 # deplist cannot be declared like this: local deplist=$(foo)
459 # Otherwise, the return value will depend on the assignment.
460 local deplist
461 deplist="$(set +E; check_deps $*)" || exit 1
462 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
464 if handle_deps $deplist; then
465 # check deps again to make sure they were resolved
466 deplist="$(set +E; check_deps $*)" || exit 1
467 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
470 msg "$(gettext "Missing Dependencies:")"
471 local dep
472 for dep in $deplist; do
473 msg2 "$dep"
474 done
476 return $R_DEPS_MISSING
479 remove_deps() {
480 (( ! RMDEPS )) && return
482 # check for packages removed during dependency install (e.g. due to conflicts)
483 # removing all installed packages is risky in this case
484 if [[ -n $(comm -23 <(printf "%s\n" "${original_pkglist[@]}") \
485 <(printf "%s\n" "${current_pkglist[@]}")) ]]; then
486 warning "$(gettext "Failed to remove installed dependencies.")"
487 return 0
490 local deplist=($(comm -13 <(printf "%s\n" "${original_pkglist[@]}") \
491 <(printf "%s\n" "${current_pkglist[@]}")))
492 (( ${#deplist[@]} == 0 )) && return
494 msg "Removing installed dependencies..."
495 # exit cleanly on failure to remove deps as package has been built successfully
496 if ! run_pacman -Rn ${deplist[@]}; then
497 warning "$(gettext "Failed to remove installed dependencies.")"
498 return 0
502 download_sources() {
503 msg "$(gettext "Retrieving Sources...")"
505 pushd "$SRCDEST" &>/dev/null
507 local netfile
508 for netfile in "${source[@]}"; do
509 local file=$(get_filepath "$netfile" || true)
510 if [[ -n "$file" ]]; then
511 msg2 "$(gettext "Found %s")" "${file##*/}"
512 ln -sf "$file" "$srcdir/"
513 continue
516 file=$(get_filename "$netfile")
517 local url=$(get_url "$netfile")
519 # if we get here, check to make sure it was a URL, else fail
520 if [[ $file = $url ]]; then
521 error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file"
522 exit 1 # $E_MISSING_FILE
525 # find the client we should use for this URL
526 local dlclient=$(get_downloadclient "$url") || exit $?
528 msg2 "$(gettext "Downloading %s...")" "$file"
529 # fix flyspray bug #3289
530 local ret=0
531 download_file "$dlclient" "$url" "$file" || ret=$?
532 if (( ret )); then
533 error "$(gettext "Failure while downloading %s")" "$file"
534 plain "$(gettext "Aborting...")"
535 exit 1
537 rm -f "$srcdir/$file"
538 ln -s "$SRCDEST/$file" "$srcdir/"
539 done
541 popd &>/dev/null
544 get_integlist() {
545 local integ
546 local integlist=()
548 for integ in md5 sha1 sha256 sha384 sha512; do
549 local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
550 if [[ -n "$integrity_sums" ]]; then
551 integlist=(${integlist[@]} $integ)
553 done
555 if (( ${#integlist[@]} > 0 )); then
556 echo ${integlist[@]}
557 else
558 echo ${INTEGRITY_CHECK[@]}
562 generate_checksums() {
563 msg "$(gettext "Generating checksums for source files...")"
564 plain ""
566 if ! type -p openssl >/dev/null; then
567 error "$(gettext "Cannot find openssl.")"
568 exit 1 # $E_MISSING_PROGRAM
571 local integlist
572 if (( $# == 0 )); then
573 integlist=$(get_integlist)
574 else
575 integlist=$@
578 local integ
579 for integ in ${integlist[@]}; do
580 case "$integ" in
581 md5|sha1|sha256|sha384|sha512) : ;;
583 error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
584 exit 1;; # $E_CONFIG_ERROR
585 esac
587 local ct=0
588 local numsrc=${#source[@]}
589 echo -n "${integ}sums=("
591 local i
592 local indent=''
593 for (( i = 0; i < ${#integ} + 6; i++ )); do
594 indent="$indent "
595 done
597 local netfile
598 for netfile in "${source[@]}"; do
599 local file="$(get_filepath "$netfile")" || missing_source_file "$netfile"
600 local sum="$(openssl dgst -${integ} "$file")"
601 sum=${sum##* }
602 (( ct )) && echo -n "$indent"
603 echo -n "'$sum'"
604 ct=$(($ct+1))
605 (( $ct < $numsrc )) && echo
606 done
608 echo ")"
609 done
612 check_checksums() {
613 (( ! ${#source[@]} )) && return 0
615 if ! type -p openssl >/dev/null; then
616 error "$(gettext "Cannot find openssl.")"
617 exit 1 # $E_MISSING_PROGRAM
620 local correlation=0
621 local integ required
622 for integ in md5 sha1 sha256 sha384 sha512; do
623 local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
624 if (( ${#integrity_sums[@]} == ${#source[@]} )); then
625 msg "$(gettext "Validating source files with %s...")" "${integ}sums"
626 correlation=1
627 local errors=0
628 local idx=0
629 local file
630 for file in "${source[@]}"; do
631 local found=1
632 file="$(get_filename "$file")"
633 echo -n " $file ... " >&2
635 if ! file="$(get_filepath "$file")"; then
636 echo "$(gettext "NOT FOUND")" >&2
637 errors=1
638 found=0
641 if (( $found )) ; then
642 local expectedsum=$(tr '[:upper:]' '[:lower:]' <<< "${integrity_sums[$idx]}")
643 local realsum="$(openssl dgst -${integ} "$file")"
644 realsum="${realsum##* }"
645 if [[ $expectedsum = $realsum ]]; then
646 echo "$(gettext "Passed")" >&2
647 else
648 echo "$(gettext "FAILED")" >&2
649 errors=1
653 idx=$((idx + 1))
654 done
656 if (( errors )); then
657 error "$(gettext "One or more files did not pass the validity check!")"
658 exit 1 # TODO: error code
660 elif (( ${#integrity_sums[@]} )); then
661 error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
662 exit 1 # TODO: error code
664 done
666 if (( ! correlation )); then
667 error "$(gettext "Integrity checks are missing.")"
668 exit 1 # TODO: error code
672 extract_sources() {
673 msg "$(gettext "Extracting Sources...")"
674 local netfile
675 for netfile in "${source[@]}"; do
676 local file=$(get_filename "$netfile")
677 if in_array "$file" ${noextract[@]}; then
678 #skip source files in the noextract=() array
679 # these are marked explicitly to NOT be extracted
680 continue
684 # fix flyspray #6246
685 local file_type=$(file -bizL "$file")
686 local ext=${file##*.}
687 local cmd=''
688 case "$file_type" in
689 *application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*)
690 cmd="bsdtar" ;;
691 *application/x-gzip*)
692 case "$ext" in
693 gz|z|Z) cmd="gzip" ;;
694 *) continue;;
695 esac ;;
696 *application/x-bzip*)
697 case "$ext" in
698 bz2|bz) cmd="bzip2" ;;
699 *) continue;;
700 esac ;;
701 *application/x-xz*)
702 case "$ext" in
703 xz) cmd="xz" ;;
704 *) continue;;
705 esac ;;
707 # See if bsdtar can recognize the file
708 if bsdtar -tf "$file" -q '*' &>/dev/null; then
709 cmd="bsdtar"
710 else
711 continue
712 fi ;;
713 esac
715 local ret=0
716 msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd"
717 if [[ $cmd = bsdtar ]]; then
718 $cmd -xf "$file" || ret=$?
719 else
720 rm -f "${file%.*}"
721 $cmd -dcf "$file" > "${file%.*}" || ret=$?
723 if (( ret )); then
724 error "$(gettext "Failed to extract %s")" "$file"
725 plain "$(gettext "Aborting...")"
726 exit 1
728 done
730 if (( EUID == 0 )); then
731 # change perms of all source files to root user & root group
732 chown -R 0:0 "$srcdir"
736 error_function() {
737 if [[ -p $logpipe ]]; then
738 rm "$logpipe"
740 # first exit all subshells, then print the error
741 if (( ! BASH_SUBSHELL )); then
742 error "$(gettext "A failure occurred in %s().")" "$1"
743 plain "$(gettext "Aborting...")"
744 remove_deps
746 exit 2 # $E_BUILD_FAILED
749 run_function() {
750 if [[ -z $1 ]]; then
751 return 1
753 local pkgfunc="$1"
755 # clear user-specified buildflags if requested
756 if [[ $(check_option buildflags) = "n" ]]; then
757 CFLAGS=""
758 CXXFLAGS=""
759 LDFLAGS=""
762 # clear user-specified makeflags if requested
763 if [[ $(check_option makeflags) = "n" ]]; then
764 MAKEFLAGS=""
767 msg "$(gettext "Starting %s()...")" "$pkgfunc"
768 cd "$srcdir"
770 # ensure all necessary build variables are exported
771 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
772 # save our shell options so pkgfunc() can't override what we need
773 local shellopts=$(shopt -p)
775 local ret=0
776 local restoretrap
777 if (( LOGGING )); then
778 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
779 local BUILDLOG="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
780 if [[ -f $BUILDLOG ]]; then
781 local i=1
782 while true; do
783 if [[ -f $BUILDLOG.$i ]]; then
784 i=$(($i +1))
785 else
786 break
788 done
789 mv "$BUILDLOG" "$BUILDLOG.$i"
792 # ensure overridden package variables survive tee with split packages
793 logpipe=$(mktemp -u "$startdir/logpipe.XXXXXXXX")
794 mkfifo "$logpipe"
795 tee "$BUILDLOG" < "$logpipe" &
796 local teepid=$!
798 restoretrap=$(trap -p ERR)
799 trap 'error_function $pkgfunc' ERR
800 $pkgfunc &>"$logpipe"
801 eval $restoretrap
803 wait $teepid
804 rm "$logpipe"
805 else
806 restoretrap=$(trap -p ERR)
807 trap 'error_function $pkgfunc' ERR
808 $pkgfunc 2>&1
809 eval $restoretrap
811 # reset our shell options
812 eval "$shellopts"
815 run_build() {
816 # use distcc if it is requested (check buildenv and PKGBUILD opts)
817 if [[ $(check_buildenv distcc) = "y" && $(check_option distcc) != "n" ]]; then
818 [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH"
819 export DISTCC_HOSTS
820 elif [[ $(check_option distcc) = "n" ]]; then
821 # if it is not wanted, clear the makeflags too
822 MAKEFLAGS=""
825 # use ccache if it is requested (check buildenv and PKGBUILD opts)
826 if [[ $(check_buildenv ccache) = "y" && $(check_option ccache) != "n" ]]; then
827 [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH"
830 run_function "build"
833 run_check() {
834 run_function "check"
837 run_package() {
838 local pkgfunc
839 if [[ -z $1 ]]; then
840 pkgfunc="package"
841 else
842 pkgfunc="package_$1"
845 run_function "$pkgfunc"
848 tidy_install() {
849 cd "$pkgdir"
850 msg "$(gettext "Tidying install...")"
852 if [[ $(check_option docs) = "n" && -n ${DOC_DIRS[*]} ]]; then
853 msg2 "$(gettext "Removing doc files...")"
854 rm -rf ${DOC_DIRS[@]}
857 if [[ $(check_option purge) = "y" && -n ${PURGE_TARGETS[*]} ]]; then
858 msg2 "$(gettext "Purging other files...")"
859 local pt
860 for pt in "${PURGE_TARGETS[@]}"; do
861 if [[ ${pt} = ${pt//\/} ]]; then
862 find . -type f -name "${pt}" -exec rm -f -- '{}' \;
863 else
864 rm -f ${pt}
866 done
869 if [[ $(check_option zipman) = "y" && -n ${MAN_DIRS[*]} ]]; then
870 msg2 "$(gettext "Compressing man and info pages...")"
871 local manpage ext file link hardlinks hl
872 find ${MAN_DIRS[@]} -type f 2>/dev/null |
873 while read manpage ; do
874 ext="${manpage##*.}"
875 file="${manpage##*/}"
876 if [[ $ext != gz && $ext != bz2 ]]; then
877 # update symlinks to this manpage
878 find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null |
879 while read link ; do
880 rm -f "$link"
881 ln -sf "${file}.gz" "${link}.gz"
882 done
884 # check file still exists (potentially already compressed due to hardlink)
885 if [[ -f ${manpage} ]]; then
886 # find hard links and remove them
887 # the '|| true' part keeps the script from bailing if find returned an
888 # error, such as when one of the man directories doesn't exist
889 hardlinks="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
890 for hl in ${hardlinks}; do
891 rm -f "${hl}";
892 done
893 # compress the original
894 gzip -9 "$manpage"
895 # recreate hard links removed earlier
896 for hl in ${hardlinks}; do
897 ln "${manpage}.gz" "${hl}.gz"
898 chmod 644 ${hl}.gz
899 done
902 done
905 if [[ $(check_option strip) = y ]]; then
906 msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")"
907 # make sure library stripping variables are defined to prevent excess stripping
908 [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S"
909 [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S"
910 local binary
911 find . -type f -perm -u+w 2>/dev/null | while read binary ; do
912 case "$(file -bi "$binary")" in
913 *application/x-sharedlib*) # Libraries (.so)
914 /usr/bin/strip $STRIP_SHARED "$binary";;
915 *application/x-archive*) # Libraries (.a)
916 /usr/bin/strip $STRIP_STATIC "$binary";;
917 *application/x-executable*) # Binaries
918 /usr/bin/strip $STRIP_BINARIES "$binary";;
919 esac
920 done
923 if [[ $(check_option libtool) = "n" ]]; then
924 msg2 "$(gettext "Removing libtool .la files...")"
925 find . ! -type d -name "*.la" -exec rm -f -- '{}' \;
928 if [[ $(check_option emptydirs) = "n" ]]; then
929 msg2 "$(gettext "Removing empty directories...")"
930 find . -depth -type d -empty -delete
934 write_pkginfo() {
935 local builddate=$(date -u "+%s")
936 if [[ -n $PACKAGER ]]; then
937 local packager="$PACKAGER"
938 else
939 local packager="Unknown Packager"
941 local size="$(@DUPATH@ -sk)"
942 size="$(( ${size%%[^0-9]*} * 1024 ))"
944 msg2 "$(gettext "Generating .PKGINFO file...")"
945 echo "# Generated by makepkg $myver"
946 if (( INFAKEROOT )); then
947 echo "# using $(fakeroot -v)"
949 echo "# $(LC_ALL=C date -u)"
950 echo "pkgname = $1"
951 (( SPLITPKG )) && echo pkgbase = $pkgbase
952 echo "pkgver = $(get_full_version $epoch $pkgver $pkgrel)"
953 echo "pkgdesc = $pkgdesc"
954 echo "url = $url"
955 echo "builddate = $builddate"
956 echo "packager = $packager"
957 echo "size = $size"
958 echo "arch = $PKGARCH"
960 [[ $license ]] && printf "license = %s\n" "${license[@]}"
961 [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
962 [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
963 [[ $depends ]] && printf "depend = %s\n" "${depends[@]}"
964 [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]}"
965 [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
966 [[ $provides ]] && printf "provides = %s\n" "${provides[@]}"
967 [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
969 local it
970 for it in "${packaging_options[@]}"; do
971 local ret="$(check_option $it)"
972 if [[ $ret != "?" ]]; then
973 if [[ $ret = y ]]; then
974 echo "makepkgopt = $it"
975 else
976 echo "makepkgopt = !$it"
979 done
981 # TODO maybe remove this at some point
982 # warn if license array is not present or empty
983 if [[ -z $license ]]; then
984 warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT"
985 plain "$(gettext "Example for GPL\'ed software: license=('GPL').")"
989 check_package() {
990 cd "$pkgdir"
992 # check existence of backup files
993 local file
994 for file in "${backup[@]}"; do
995 if [[ ! -f $file ]]; then
996 warning "$(gettext "Backup entry file not in package : %s")" "$file"
998 done
1000 # check for references to the build and package directory
1001 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${srcdir}" ; then
1002 warning "$(gettext "Package contains reference to %s")" "\$srcdir"
1004 if find "${pkgdir}" -type f -print0 | xargs -0 grep -q -I "${pkgdir}" ; then
1005 warning "$(gettext "Package contains reference to %s")" "\$pkgdir"
1010 create_package() {
1011 if [[ ! -d $pkgdir ]]; then
1012 error "$(gettext "Missing pkg/ directory.")"
1013 plain "$(gettext "Aborting...")"
1014 exit 1 # $E_MISSING_PKGDIR
1017 check_package
1019 cd "$pkgdir"
1020 msg "$(gettext "Creating package...")"
1022 local nameofpkg
1023 if [[ -z $1 ]]; then
1024 nameofpkg="$pkgname"
1025 else
1026 nameofpkg="$1"
1029 if [[ $arch = "any" ]]; then
1030 PKGARCH="any"
1031 else
1032 PKGARCH=$CARCH
1035 write_pkginfo $nameofpkg > .PKGINFO
1037 local comp_files=".PKGINFO"
1039 # check for changelog/install files
1040 for i in 'changelog/.CHANGELOG' 'install/.INSTALL'; do
1041 IFS='/' read -r orig dest <<< "$i"
1043 if [[ -n ${!orig} ]]; then
1044 msg2 "$(gettext "Adding %s file...")" "$orig"
1045 cp "$startdir/${!orig}" "$dest"
1046 chmod 644 "$dest"
1047 comp_files+=" $dest"
1049 done
1051 # tar it up
1052 msg2 "$(gettext "Compressing package...")"
1054 local EXT
1055 case "$PKGEXT" in
1056 *tar.gz) EXT=${PKGEXT%.gz} ;;
1057 *tar.bz2) EXT=${PKGEXT%.bz2} ;;
1058 *tar.xz) EXT=${PKGEXT%.xz} ;;
1059 *tar) EXT=${PKGEXT} ;;
1060 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1061 "$PKGEXT" ; EXT=$PKGEXT ;;
1062 esac
1064 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1065 local pkg_file="$PKGDEST/${nameofpkg}-${fullver}-${PKGARCH}${PKGEXT}"
1066 local ret=0
1068 # when fileglobbing, we want * in an empty directory to expand to
1069 # the null string rather than itself
1070 shopt -s nullglob
1071 # TODO: Maybe this can be set globally for robustness
1072 shopt -s -o pipefail
1073 bsdtar -cf - $comp_files * |
1074 case "$PKGEXT" in
1075 *tar.gz) gzip -c -f -n ;;
1076 *tar.bz2) bzip2 -c -f ;;
1077 *tar.xz) xz -c -z - ;;
1078 *tar) cat ;;
1079 esac > ${pkg_file} || ret=$?
1081 shopt -u nullglob
1082 shopt -u -o pipefail
1084 if (( ret )); then
1085 error "$(gettext "Failed to create package file.")"
1086 exit 1 # TODO: error code
1089 if (( ! ret )) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
1090 ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1091 ret=$?
1094 if (( ret )); then
1095 warning "$(gettext "Failed to create symlink to package file.")"
1099 create_srcpackage() {
1100 cd "$startdir"
1102 # Get back to our src directory so we can begin with sources.
1103 mkdir -p "$srcdir"
1104 chmod a-s "$srcdir"
1105 cd "$srcdir"
1106 if (( ! SKIPINTEG || SOURCEONLY == 2 )); then
1107 download_sources
1109 if (( ! SKIPINTEG )); then
1110 # We can only check checksums if we have all files.
1111 check_checksums
1112 else
1113 warning "$(gettext "Skipping integrity checks.")"
1115 cd "$startdir"
1117 msg "$(gettext "Creating source package...")"
1118 local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1119 mkdir "${srclinks}"/${pkgbase}
1121 msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
1122 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1124 local file
1125 for file in "${source[@]}"; do
1126 if [[ -f $file ]]; then
1127 msg2 "$(gettext "Adding %s...")" "$file"
1128 ln -s "${startdir}/$file" "$srclinks/$pkgbase"
1129 elif (( SOURCEONLY == 2 )); then
1130 local absfile=$(get_filepath "$file") || missing_source_file "$file"
1131 msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
1132 ln -s "$absfile" "$srclinks/$pkgbase"
1134 done
1136 local i
1137 for i in 'changelog' 'install'; do
1138 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDSCRIPT")
1139 local file
1140 for file in $filelist; do
1141 # evaluate any bash variables used
1142 eval file=${file}
1143 if [[ ! -f "${srclinks}/${pkgbase}/$file" ]]; then
1144 msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}"
1145 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
1147 done
1148 done
1150 local TAR_OPT
1151 case "$SRCEXT" in
1152 *tar.gz) TAR_OPT="z" ;;
1153 *tar.bz2) TAR_OPT="j" ;;
1154 *tar.xz) TAR_OPT="J" ;;
1155 *tar) TAR_OPT="" ;;
1156 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1157 "$SRCEXT" ;;
1158 esac
1160 local fullver=$(get_full_version $epoch $pkgver $pkgrel)
1161 local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
1163 # tar it up
1164 msg2 "$(gettext "Compressing source package...")"
1165 cd "${srclinks}"
1166 if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgbase}; then
1167 error "$(gettext "Failed to create source package file.")"
1168 exit 1 # TODO: error code
1171 if (( ! ret )) && [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
1172 ln -sf "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
1173 ret=$?
1176 if (( ret )); then
1177 warning "$(gettext "Failed to create symlink to source package file.")"
1180 cd "${startdir}"
1181 rm -rf "${srclinks}"
1184 install_package() {
1185 (( ! INSTALL )) && return
1187 if (( ! SPLITPKG )); then
1188 msg "$(gettext "Installing package %s with %s -U...")" "$pkgname" "$PACMAN"
1189 else
1190 msg "$(gettext "Installing %s package group with %s -U...")" "$pkgbase" "$PACMAN"
1193 local fullver pkg pkglist
1194 for pkg in ${pkgname[@]}; do
1195 # TODO: this wasn't properly fixed in commit 2020e629
1196 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1197 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} ]]; then
1198 pkglist+=" $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT}"
1199 else
1200 pkglist+=" $PKGDEST/${pkg}-${fullver}-any${PKGEXT}"
1202 done
1204 if ! run_pacman -U $pkglist; then
1205 warning "$(gettext "Failed to install built package(s).")"
1206 return 0
1210 check_sanity() {
1211 # check for no-no's in the build script
1212 local i
1213 local ret=0
1214 for i in 'pkgname' 'pkgrel' 'pkgver'; do
1215 if [[ -z ${!i} ]]; then
1216 error "$(gettext "%s is not allowed to be empty.")" "$i"
1217 ret=1
1219 done
1221 for i in "${pkgname[@]}"; do
1222 if [[ ${i:0:1} = "-" ]]; then
1223 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname"
1224 ret=1
1226 done
1228 if [[ ${pkgbase:0:1} = "-" ]]; then
1229 error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgbase"
1230 ret=1
1232 if [[ $pkgver =~ [:-] ]]; then
1233 error "$(gettext "%s is not allowed to contain colons or hyphens.")" "pkgver"
1234 ret=1
1236 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1237 error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
1238 ret=1
1241 if [[ ! $epoch =~ ^[0-9]*$ ]]; then
1242 error "$(gettext "%s must be an integer.")" "epoch"
1243 ret=1
1246 if [[ $arch != 'any' ]]; then
1247 if ! in_array $CARCH ${arch[@]}; then
1248 if (( ! IGNOREARCH )); then
1249 error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH"
1250 plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
1251 plain "$(gettext "such as arch=('%s').")" "$CARCH"
1252 ret=1
1257 local provides_list=()
1258 eval $(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \
1259 sed -e "s/provides=/provides_list+=/" -e "s/#.*//")
1260 for i in ${provides_list[@]}; do
1261 if [[ $i != ${i//</} || $i != ${i//>/} ]]; then
1262 error "$(gettext "Provides array cannot contain comparison (< or >) operators.")"
1263 ret=1
1265 done
1267 local backup_list=()
1268 eval $(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \
1269 sed -e "s/backup=/backup_list+=/" -e "s/#.*//")
1270 for i in "${backup_list[@]}"; do
1271 if [[ ${i:0:1} = "/" ]]; then
1272 error "$(gettext "Backup entry should not contain leading slash : %s")" "$i"
1273 ret=1
1275 done
1277 local optdepends_list=()
1278 eval $(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(|#.*)$/' "$BUILDFILE" | \
1279 sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//")
1280 for i in "${optdepends_list[@]}"; do
1281 local pkg=${i%%:*}
1282 if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]+$ ]]; then
1283 error "$(gettext "Invalid syntax for optdepend : '%s'")" "$i"
1284 ret=1
1286 done
1288 for i in 'changelog' 'install'; do
1289 local filelist=$(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1290 local file
1291 for file in $filelist; do
1292 # evaluate any bash variables used
1293 eval file=${file}
1294 if [[ ! -f $file ]]; then
1295 error "$(gettext "%s file (%s) does not exist.")" "$i" "$file"
1296 ret=1
1298 done
1299 done
1301 local valid_options=1
1302 local known kopt options_list
1303 eval $(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \
1304 sed -e "s/options=/options_list+=/" -e "s/#.*//")
1305 for i in ${options_list[@]}; do
1306 known=0
1307 # check if option matches a known option or its inverse
1308 for kopt in ${packaging_options[@]} ${other_options[@]}; do
1309 if [[ ${i} = ${kopt} || ${i} = "!${kopt}" ]]; then
1310 known=1
1312 done
1313 if (( ! known )); then
1314 error "$(gettext "options array contains unknown option '%s'")" "$i"
1315 valid_options=0
1317 done
1318 if (( ! valid_options )); then
1319 ret=1
1322 if (( ${#pkgname[@]} > 1 )); then
1323 for i in ${pkgname[@]}; do
1324 if ! declare -f package_${i} >/dev/null; then
1325 error "$(gettext "missing package function for split package '%s'")" "$i"
1326 ret=1
1328 done
1331 for i in ${PKGLIST[@]}; do
1332 if ! in_array $i ${pkgname[@]}; then
1333 error "$(gettext "requested package %s is not provided in %s")" "$i" "$BUILDFILE"
1334 ret=1
1336 done
1338 return $ret
1341 devel_check() {
1342 newpkgver=""
1344 # Do not update pkgver if --holdver is set, when building a source package, repackaging,
1345 # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1346 if (( HOLDVER || SOURCEONLY || REPKG )) \
1347 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1348 return
1351 if [[ -z $FORCE_VER ]]; then
1352 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1353 # This will only be used on the first call to makepkg; subsequent
1354 # calls to makepkg via fakeroot will explicitly pass the version
1355 # number to avoid having to determine the version number twice.
1356 # Also do a brief check to make sure we have the VCS tool available.
1357 oldpkgver=$pkgver
1358 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1359 type -p darcs >/dev/null || return 0
1360 msg "$(gettext "Determining latest %s revision...")" 'darcs'
1361 newpkgver=$(date +%Y%m%d)
1362 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1363 type -p cvs >/dev/null || return 0
1364 msg "$(gettext "Determining latest %s revision...")" 'cvs'
1365 newpkgver=$(date +%Y%m%d)
1366 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1367 type -p git >/dev/null || return 0
1368 msg "$(gettext "Determining latest %s revision...")" 'git'
1369 newpkgver=$(date +%Y%m%d)
1370 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1371 type -p svn >/dev/null || return 0
1372 msg "$(gettext "Determining latest %s revision...")" 'svn'
1373 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1374 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1375 type -p bzr >/dev/null || return 0
1376 msg "$(gettext "Determining latest %s revision...")" 'bzr'
1377 newpkgver=$(bzr revno ${_bzrtrunk})
1378 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1379 type -p hg >/dev/null || return 0
1380 msg "$(gettext "Determining latest %s revision...")" 'hg'
1381 if [[ -d ./src/$_hgrepo ]] ; then
1382 cd ./src/$_hgrepo
1383 hg pull
1384 hg update
1385 else
1386 [[ ! -d ./src/ ]] && mkdir ./src/
1387 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1388 cd ./src/$_hgrepo
1390 newpkgver=$(hg tip --template "{rev}")
1391 cd ../../
1394 if [[ -n $newpkgver ]]; then
1395 msg2 "$(gettext "Version found: %s")" "$newpkgver"
1398 else
1399 # Version number retrieved from fakeroot->makepkg argument
1400 newpkgver=$FORCE_VER
1404 devel_update() {
1405 # This is lame, but if we're wanting to use an updated pkgver for
1406 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1407 # the new pkgver and then re-source it. This is the most robust
1408 # method for dealing with PKGBUILDs that use, e.g.:
1410 # pkgver=23
1411 # ...
1412 # _foo=pkgver
1414 if [[ -n $newpkgver ]]; then
1415 if [[ $newpkgver != $pkgver ]]; then
1416 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1417 @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE"
1418 @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE"
1419 source "$BUILDFILE"
1425 backup_package_variables() {
1426 local var
1427 for var in ${splitpkg_overrides[@]}; do
1428 local indirect="${var}_backup"
1429 eval "${indirect}=(\"\${$var[@]}\")"
1430 done
1433 restore_package_variables() {
1434 local var
1435 for var in ${splitpkg_overrides[@]}; do
1436 local indirect="${var}_backup"
1437 if [[ -n ${!indirect} ]]; then
1438 eval "${var}=(\"\${$indirect[@]}\")"
1439 else
1440 unset ${var}
1442 done
1445 run_split_packaging() {
1446 local pkgname_backup=${pkgname[@]}
1447 for pkgname in ${pkgname_backup[@]}; do
1448 pkgdir="$pkgdir/$pkgname"
1449 mkdir -p "$pkgdir"
1450 chmod a-s "$pkgdir"
1451 backup_package_variables
1452 run_package $pkgname
1453 tidy_install
1454 create_package $pkgname
1455 restore_package_variables
1456 pkgdir="${pkgdir%/*}"
1457 done
1458 pkgname=${pkgname_backup[@]}
1461 # Canonicalize a directory path if it exists
1462 canonicalize_path() {
1463 local path="$1";
1465 if [[ -d $path ]]; then
1467 cd "$path"
1468 pwd -P
1470 else
1471 echo "$path"
1475 # getopt like parser
1476 parse_options() {
1477 local short_options=$1; shift;
1478 local long_options=$1; shift;
1479 local ret=0;
1480 local unused_options=""
1481 local i
1483 while [[ -n $1 ]]; do
1484 if [[ ${1:0:2} = '--' ]]; then
1485 if [[ -n ${1:2} ]]; then
1486 local match=""
1487 for i in ${long_options//,/ }; do
1488 if [[ ${1:2} = ${i//:} ]]; then
1489 match=$i
1490 break
1492 done
1493 if [[ -n $match ]]; then
1494 if [[ ${1:2} = $match ]]; then
1495 printf ' %s' "$1"
1496 else
1497 if [[ -n $2 ]]; then
1498 printf ' %s' "$1"
1499 shift
1500 printf " '%s'" "$1"
1501 else
1502 echo "makepkg: option '$1' $(gettext "requires an argument")" >&2
1503 ret=1
1506 else
1507 echo "makepkg: $(gettext "unrecognized option") '$1'" >&2
1508 ret=1
1510 else
1511 shift
1512 break
1514 elif [[ ${1:0:1} = '-' ]]; then
1515 for ((i=1; i<${#1}; i++)); do
1516 if [[ $short_options =~ ${1:i:1} ]]; then
1517 if [[ $short_options =~ ${1:i:1}: ]]; then
1518 if [[ -n ${1:$i+1} ]]; then
1519 printf ' -%s' "${1:i:1}"
1520 printf " '%s'" "${1:$i+1}"
1521 else
1522 if [[ -n $2 ]]; then
1523 printf ' -%s' "${1:i:1}"
1524 shift
1525 printf " '%s'" "${1}"
1526 else
1527 echo "makepkg: option $(gettext "requires an argument") -- '${1:i:1}'" >&2
1528 ret=1
1531 break
1532 else
1533 printf ' -%s' "${1:i:1}"
1535 else
1536 echo "makepkg: $(gettext "invalid option") -- '${1:i:1}'" >&2
1537 ret=1
1539 done
1540 else
1541 unused_options="${unused_options} '$1'"
1543 shift
1544 done
1546 printf " --"
1547 if [[ -n $unused_options ]]; then
1548 for i in ${unused_options[@]}; do
1549 printf ' %s' "$i"
1550 done
1552 if [[ -n $1 ]]; then
1553 while [[ -n $1 ]]; do
1554 printf " '%s'" "${1}"
1555 shift
1556 done
1558 printf "\n"
1560 return $ret
1563 usage() {
1564 printf "makepkg (pacman) %s\n" "$myver"
1565 echo
1566 printf "$(gettext "Usage: %s [options]")\n" "$0"
1567 echo
1568 echo "$(gettext "Options:")"
1569 printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
1570 echo "$(gettext " -c, --clean Clean up work files after build")"
1571 echo "$(gettext " -C, --cleancache Clean up source files from the cache")"
1572 echo "$(gettext " -d, --nodeps Skip all dependency checks")"
1573 echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
1574 echo "$(gettext " -f, --force Overwrite existing package")"
1575 echo "$(gettext " -g, --geninteg Generate integrity checks for source files")"
1576 echo "$(gettext " -h, --help This help")"
1577 echo "$(gettext " -i, --install Install package after successful build")"
1578 echo "$(gettext " -L, --log Log package build process")"
1579 echo "$(gettext " -m, --nocolor Disable colorized output messages")"
1580 echo "$(gettext " -o, --nobuild Download and extract files only")"
1581 printf "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1582 echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1583 echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1584 echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")"
1585 echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1586 echo "$(gettext " --asroot Allow makepkg to run as root user")"
1587 printf "$(gettext " --check Run the check() function in the %s")\n" "$BUILDSCRIPT"
1588 printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf"
1589 printf "$(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT"
1590 printf "$(gettext " --nocheck Do not run the check() function in the %s")\n" "$BUILDSCRIPT"
1591 echo "$(gettext " --pkg <list> Only build listed packages from a split package")"
1592 echo "$(gettext " --skipinteg Do not fail when integrity checks are missing")"
1593 echo "$(gettext " --source Generate a source-only tarball without downloaded sources")"
1594 echo
1595 echo "$(gettext "These options can be passed to pacman:")"
1596 echo
1597 echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1598 echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1599 echo
1600 printf "$(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1601 echo
1604 version() {
1605 printf "makepkg (pacman) %s\n" "$myver"
1606 printf "$(gettext "\
1607 Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1608 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1609 This is free software; see the source for copying conditions.\n\
1610 There is NO WARRANTY, to the extent permitted by law.\n")"
1613 # PROGRAM START
1615 # determine whether we have gettext; make it a no-op if we do not
1616 if ! type -p gettext >/dev/null; then
1617 gettext() {
1618 echo "$@"
1622 ARGLIST=("$@")
1624 # Parse Command Line Options.
1625 OPT_SHORT="AcCdefFghiLmop:rRsV"
1626 OPT_LONG="allsource,asroot,ignorearch,check,clean,cleancache,nodeps"
1627 OPT_LONG+=",noextract,force,forcever:,geninteg,help,holdver"
1628 OPT_LONG+=",install,log,nocolor,nobuild,nocheck,pkg:,rmdeps"
1629 OPT_LONG+=",repackage,skipinteg,source,syncdeps,version,config:"
1630 # Pacman Options
1631 OPT_LONG+=",noconfirm,noprogressbar"
1632 OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')"
1633 if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then
1634 # This is a small hack to stop the script bailing with 'set -e'
1635 echo; usage; exit 1 # E_INVALID_OPTION;
1637 eval set -- "$OPT_TEMP"
1638 unset OPT_SHORT OPT_LONG OPT_TEMP
1640 while true; do
1641 case "$1" in
1642 # Pacman Options
1643 --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
1644 --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
1646 # Makepkg Options
1647 --allsource) SOURCEONLY=2 ;;
1648 --asroot) ASROOT=1 ;;
1649 -A|--ignorearch) IGNOREARCH=1 ;;
1650 -c|--clean) CLEANUP=1 ;;
1651 -C|--cleancache) CLEANCACHE=1 ;;
1652 --check) RUN_CHECK='y' ;;
1653 --config) shift; MAKEPKG_CONF=$1 ;;
1654 -d|--nodeps) NODEPS=1 ;;
1655 -e|--noextract) NOEXTRACT=1 ;;
1656 -f|--force) FORCE=1 ;;
1657 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1658 --forcever) shift; FORCE_VER=$1;;
1659 -F) INFAKEROOT=1 ;;
1660 -g|--geninteg) GENINTEG=1 ;;
1661 --holdver) HOLDVER=1 ;;
1662 -i|--install) INSTALL=1 ;;
1663 -L|--log) LOGGING=1 ;;
1664 -m|--nocolor) USE_COLOR='n' ;;
1665 --nocheck) RUN_CHECK='n' ;;
1666 -o|--nobuild) NOBUILD=1 ;;
1667 -p) shift; BUILDFILE=$1 ;;
1668 --pkg) shift; PKGLIST=($1) ;;
1669 -r|--rmdeps) RMDEPS=1 ;;
1670 -R|--repackage) REPKG=1 ;;
1671 --skipinteg) SKIPINTEG=1 ;;
1672 --source) SOURCEONLY=1 ;;
1673 -s|--syncdeps) DEP_BIN=1 ;;
1675 -h|--help) usage; exit 0 ;; # E_OK
1676 -V|--version) version; exit 0 ;; # E_OK
1678 --) OPT_IND=0; shift; break;;
1679 *) usage; exit 1 ;; # E_INVALID_OPTION
1680 esac
1681 shift
1682 done
1684 # preserve environment variables and canonicalize path
1685 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
1686 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
1687 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
1689 # default config is makepkg.conf
1690 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1692 # Source the config file; fail if it is not found
1693 if [[ -r $MAKEPKG_CONF ]]; then
1694 source "$MAKEPKG_CONF"
1695 else
1696 error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
1697 plain "$(gettext "Aborting...")"
1698 exit 1 # $E_CONFIG_ERROR
1701 # Source user-specific makepkg.conf overrides
1702 if [[ -r ~/.makepkg.conf ]]; then
1703 source ~/.makepkg.conf
1706 # set pacman command if not already defined
1707 PACMAN=${PACMAN:-pacman}
1709 # check if messages are to be printed using color
1710 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1711 if [[ -t 2 && ! $USE_COLOR = "n" && $(check_buildenv color) = "y" ]]; then
1712 # prefer terminal safe colored and bold text when tput is supported
1713 if tput setaf 0 &>/dev/null; then
1714 ALL_OFF="$(tput sgr0)"
1715 BOLD="$(tput bold)"
1716 BLUE="${BOLD}$(tput setaf 4)"
1717 GREEN="${BOLD}$(tput setaf 2)"
1718 RED="${BOLD}$(tput setaf 1)"
1719 YELLOW="${BOLD}$(tput setaf 3)"
1720 else
1721 ALL_OFF="\e[1;0m"
1722 BOLD="\e[1;1m"
1723 BLUE="${BOLD}\e[1;34m"
1724 GREEN="${BOLD}\e[1;32m"
1725 RED="${BOLD}\e[1;31m"
1726 YELLOW="${BOLD}\e[1;33m"
1729 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1731 # override settings with an environment variable for batch processing
1732 PKGDEST=${_PKGDEST:-$PKGDEST}
1733 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1734 if [[ ! -w $PKGDEST ]]; then
1735 error "$(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
1736 plain "$(gettext "Aborting...")"
1737 exit 1
1740 SRCDEST=${_SRCDEST:-$SRCDEST}
1741 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1742 if [[ ! -w $SRCDEST ]] ; then
1743 error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
1744 plain "$(gettext "Aborting...")"
1745 exit 1
1748 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
1749 SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
1752 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1753 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1754 error "$(gettext "\\0--holdver and --forcever cannot both be specified" )"
1755 exit 1
1758 if (( CLEANCACHE )); then
1759 #fix flyspray feature request #5223
1760 if [[ -n $SRCDEST && ! $SRCDEST -ef "${startdir}" ]]; then
1761 msg "$(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1762 echo -n "$(gettext " Are you sure you wish to do this? ")"
1763 echo -n "$(gettext "[y/N]")"
1764 read answer
1765 answer=$(tr '[:lower:]' '[:upper:]' <<< "$answer")
1766 if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then
1767 rm "$SRCDEST"/*
1768 if (( $? )); then
1769 error "$(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1770 exit 1
1771 else
1772 # removal worked
1773 msg "$(gettext "Source cache cleaned.")"
1774 exit 0
1776 else
1777 # answer = no
1778 msg "$(gettext "No files have been removed.")"
1779 exit 0
1781 else
1782 # $SRCDEST is $startdir, two possibilities
1783 error "$(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
1784 plain "$(gettext "In addition, please run makepkg -C outside of your cache directory.")"
1785 exit 1
1789 if (( ! INFAKEROOT )); then
1790 if (( EUID == 0 && ! ASROOT )); then
1791 # Warn those who like to live dangerously.
1792 error "$(gettext "Running makepkg as root is a BAD idea and can cause")"
1793 plain "$(gettext "permanent, catastrophic damage to your system. If you")"
1794 plain "$(gettext "wish to run as root, please use the --asroot option.")"
1795 exit 1 # $E_USER_ABORT
1796 elif (( EUID > 0 && ASROOT )); then
1797 # Warn those who try to use the --asroot option when they are not root
1798 error "$(gettext "The --asroot option is meant for the root user only.")"
1799 plain "$(gettext "Please rerun makepkg without the --asroot flag.")"
1800 exit 1 # $E_USER_ABORT
1801 elif [[ $(check_buildenv fakeroot) = "y" ]] && (( EUID > 0 )); then
1802 if ! type -p fakeroot >/dev/null; then
1803 error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
1804 plain "$(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1805 exit 1
1807 elif (( EUID > 0 )); then
1808 warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")"
1809 plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
1810 plain "$(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1811 sleep 1
1813 else
1814 if [[ -z $FAKEROOTKEY ]]; then
1815 error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
1816 exit 1 # TODO: error code
1820 # check for sudo if we will need it during makepkg execution
1821 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1822 if ! type -p sudo >/dev/null; then
1823 warning "$(gettext "Sudo can not be found. Will use su to acquire root privileges.")"
1827 unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
1828 unset md5sums replaces depends conflicts backup source install changelog build
1829 unset makedepends optdepends options noextract
1831 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1832 if [[ ! -f $BUILDFILE ]]; then
1833 if [[ -t 0 ]]; then
1834 error "$(gettext "%s does not exist.")" "$BUILDFILE"
1835 exit 1
1836 else
1837 # PKGBUILD passed through a pipe
1838 BUILDFILE=/dev/stdin
1839 source "$BUILDFILE"
1841 else
1842 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1843 if [[ -n $crlftest ]]; then
1844 error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE"
1845 exit 1
1848 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1849 BUILDFILE="$startdir/$BUILDFILE"
1851 source "$BUILDFILE"
1854 # set defaults if they weren't specified in buildfile
1855 pkgbase=${pkgbase:-${pkgname[0]}}
1856 epoch=${epoch:-0}
1858 if (( GENINTEG )); then
1859 mkdir -p "$srcdir"
1860 chmod a-s "$srcdir"
1861 cd "$srcdir"
1862 download_sources
1863 generate_checksums
1864 exit 0 # $E_OK
1867 # check the PKGBUILD for some basic requirements
1868 check_sanity || exit 1
1870 # We need to run devel_update regardless of whether we are in the fakeroot
1871 # build process so that if the user runs makepkg --forcever manually, we
1872 # 1) output the correct pkgver, and 2) use the correct filename when
1873 # checking if the package file already exists - fixes FS #9194
1874 devel_check
1875 devel_update
1877 if (( ${#pkgname[@]} > 1 )); then
1878 SPLITPKG=1
1881 # test for available PKGBUILD functions
1882 if declare -f build >/dev/null; then
1883 BUILDFUNC=1
1885 if declare -f check >/dev/null; then
1886 # "Hide" check() function if not going to be run
1887 if [[ $RUN_CHECK = 'y' || (! $(check_buildenv check) = "n" && ! $RUN_CHECK = "n") ]]; then
1888 CHECKFUNC=1
1891 if declare -f package >/dev/null; then
1892 PKGFUNC=1
1893 elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then
1894 SPLITPKG=1
1897 if [[ -n "${PKGLIST[@]}" ]]; then
1898 unset pkgname
1899 pkgname=("${PKGLIST[@]}")
1902 if (( ! SPLITPKG )); then
1903 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1904 if [[ -f $PKGDEST/${pkgname}-${fullver}-${CARCH}${PKGEXT} \
1905 || -f $PKGDEST/${pkgname}-${fullver}-any${PKGEXT} ]] \
1906 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
1907 if (( INSTALL )); then
1908 warning "$(gettext "A package has already been built, installing existing package...")"
1909 install_package
1910 exit $?
1911 else
1912 error "$(gettext "A package has already been built. (use -f to overwrite)")"
1913 exit 1
1916 else
1917 allpkgbuilt=1
1918 somepkgbuilt=0
1919 for pkg in ${pkgname[@]}; do
1920 # TODO: this wasn't properly fixed in commit 2020e629
1921 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1922 if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} \
1923 || -f $PKGDEST/${pkg}-${fullver}-any${PKGEXT} ]]; then
1924 somepkgbuilt=1
1925 else
1926 allpkgbuilt=0
1928 done
1929 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
1930 if (( allpkgbuilt )); then
1931 if (( INSTALL )); then
1932 warning "$(gettext "The package group has already been built, installing existing packages...")"
1933 install_package
1934 exit $?
1935 else
1936 error "$(gettext "The package group has already been built. (use -f to overwrite)")"
1937 exit 1
1940 if (( somepkgbuilt )); then
1941 error "$(gettext "Part of the package group has already been built. (use -f to overwrite)")"
1942 exit 1
1945 unset allpkgbuilt somepkgbuilt
1948 # Run the bare minimum in fakeroot
1949 if (( INFAKEROOT )); then
1950 if (( ! SPLITPKG )); then
1951 if (( ! PKGFUNC )); then
1952 if (( ! REPKG )); then
1953 if (( BUILDFUNC )); then
1954 run_build
1955 (( CHECKFUNC )) && run_check
1956 tidy_install
1958 else
1959 warning "$(gettext "Repackaging without the use of a package() function is deprecated.")"
1960 plain "$(gettext "File permissions may not be preserved.")"
1962 else
1963 run_package
1964 tidy_install
1966 create_package
1967 else
1968 run_split_packaging
1971 msg "$(gettext "Leaving fakeroot environment.")"
1972 exit 0 # $E_OK
1975 fullver=$(get_full_version $epoch $pkgver $pkgrel)
1976 msg "$(gettext "Making package: %s")" "$pkgbase $fullver ($(date))"
1978 # if we are creating a source-only package, go no further
1979 if (( SOURCEONLY )); then
1980 if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \
1981 && (( ! FORCE )); then
1982 error "$(gettext "A source package has already been built. (use -f to overwrite)")"
1983 exit 1
1985 create_srcpackage
1986 msg "$(gettext "Source package created: %s")" "$pkgbase ($(date))"
1987 exit 0
1990 if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); then
1991 # no warning message needed for nobuild, repkg
1992 if (( NODEPS || ( REPKG && PKGFUNC ) )); then
1993 warning "$(gettext "Skipping dependency checks.")"
1995 elif type -p "${PACMAN%% *}" >/dev/null; then
1996 if (( RMDEPS )); then
1997 original_pkglist=($(run_pacman -Qq)) # required by remove_dep
1999 deperr=0
2001 msg "$(gettext "Checking runtime dependencies...")"
2002 resolve_deps ${depends[@]} || deperr=1
2004 msg "$(gettext "Checking buildtime dependencies...")"
2005 resolve_deps ${makedepends[@]} || deperr=1
2007 if (( CHECKFUNC )); then
2008 resolve_deps ${checkdepends[@]} || deperr=1
2011 if (( RMDEPS )); then
2012 current_pkglist=($(run_pacman -Qq)) # required by remove_deps
2015 if (( deperr )); then
2016 error "$(gettext "Could not resolve all dependencies.")"
2017 exit 1
2019 else
2020 warning "$(gettext "%s was not found in PATH; skipping dependency checks.")" "${PACMAN%% *}"
2023 # ensure we have a sane umask set
2024 umask 0022
2026 # get back to our src directory so we can begin with sources
2027 mkdir -p "$srcdir"
2028 chmod a-s "$srcdir"
2029 cd "$srcdir"
2031 if (( NOEXTRACT )); then
2032 warning "$(gettext "Skipping source retrieval -- using existing src/ tree")"
2033 warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")"
2034 warning "$(gettext "Skipping source extraction -- using existing src/ tree")"
2036 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
2037 error "$(gettext "The source directory is empty, there is nothing to build!")"
2038 plain "$(gettext "Aborting...")"
2039 exit 1
2041 elif (( REPKG )); then
2042 if (( ! PKGFUNC && ! SPLITPKG )) \
2043 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
2044 error "$(gettext "The package directory is empty, there is nothing to repackage!")"
2045 plain "$(gettext "Aborting...")"
2046 exit 1
2048 else
2049 download_sources
2050 if (( ! SKIPINTEG )); then
2051 check_checksums
2052 else
2053 warning "$(gettext "Skipping integrity checks.")"
2055 extract_sources
2058 if (( NOBUILD )); then
2059 msg "$(gettext "Sources are ready.")"
2060 exit 0 #E_OK
2061 else
2062 # check for existing pkg directory; don't remove if we are repackaging
2063 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
2064 msg "$(gettext "Removing existing pkg/ directory...")"
2065 rm -rf "$pkgdir"
2067 mkdir -p "$pkgdir"
2068 chmod a-s "$pkgdir"
2069 cd "$startdir"
2071 # if we are root or if fakeroot is not enabled, then we don't use it
2072 if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then
2073 if (( ! REPKG )); then
2074 devel_update
2075 (( BUILDFUNC )) && run_build
2076 (( CHECKFUNC )) && run_check
2078 if (( ! SPLITPKG )); then
2079 if (( PKGFUNC )); then
2080 run_package
2081 tidy_install
2082 else
2083 if (( ! REPKG )); then
2084 tidy_install
2085 else
2086 warning "$(gettext "Repackaging without the use of a package() function is deprecated.")"
2087 plain "$(gettext "File permissions may not be preserved.")"
2090 create_package
2091 else
2092 run_split_packaging
2094 else
2095 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
2096 devel_update
2097 (( BUILDFUNC )) && run_build
2098 (( CHECKFUNC )) && run_check
2099 cd "$startdir"
2102 msg "$(gettext "Entering fakeroot environment...")"
2104 if [[ -n $newpkgver ]]; then
2105 fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $?
2106 else
2107 fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
2112 fullver=$(get_full_version $epoch $pkgver $pkgrel)
2113 msg "$(gettext "Finished making: %s")" "$pkgbase $fullver ($(date))"
2115 install_package
2117 exit 0 #E_OK
2119 # vim: set ts=2 sw=2 noet: