3 # makepkg - make packages compatible for use with pacman
6 # Copyright (c) 2006-2009 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 # bsdtar (libarchive), bzip2, coreutils, fakeroot, find (findutils),
31 # getopt (util-linux), gettext, grep, gzip, openssl, sed, tput (ncurses)
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@'
44 srcdir
="$startdir/src"
45 pkgdir
="$startdir/pkg"
47 packaging_options
=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge')
48 other_options
=('ccache' 'distcc' 'makeflags' 'force')
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
78 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
79 # when dealing with svn/cvs/etc PKGBUILDs.
88 printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
93 printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
98 printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
103 printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
108 printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
113 # Special exit call for traps, Don't print any error messages when inside,
114 # the fakeroot call, the error message will be printed by the main call.
117 if (( ! INFAKEROOT
)); then
126 # Clean up function. Called automatically when the script exits.
131 if (( INFAKEROOT
)); then
132 # Don't clean up when leaving fakeroot, we're not done yet.
136 if (( ! EXIT_CODE
&& CLEANUP
)); then
137 # If it's a clean exit and -c/--clean has been passed...
138 msg
"$(gettext "Cleaning up...
")"
139 rm -rf "$pkgdir" "$srcdir"
140 if [[ -n $pkgbase ]]; then
141 # Can't do this unless the BUILDSCRIPT has been sourced.
142 if (( BUILDFUNC
)); then
143 rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"*
145 if (( PKGFUNC
)); then
146 rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package.log"*
147 elif (( SPLITPKG
)); then
148 for pkg
in ${pkgname[@]}; do
149 rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package_${pkg}.log"*
153 # clean up dangling symlinks to packages
154 for pkg
in ${pkgname[@]}; do
155 for file in ${pkg}-*-*-${CARCH}${PKGEXT}; do
156 if [[ -h $file && ! -e $file ]]; then
173 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
174 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
175 trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
177 # a source entry can have two forms :
178 # 1) "filename::http://path/to/file"
179 # 2) "http://path/to/file"
181 # extract the filename from a source entry
183 # if a filename is specified, use it
184 local filename
="${1%%::*}"
185 # if it is just an URL, we only keep the last component
186 echo "${filename##*/}"
189 # extract the URL from a source entry
191 # strip an eventual filename
196 # Checks to see if options are present in makepkg.conf or PKGBUILD;
197 # PKGBUILD options always take precedence.
199 # usage : check_option( $option )
200 # return : y - enabled
205 local ret
=$
(in_opt_array
"$1" ${options[@]})
206 if [[ $ret != '?' ]]; then
211 # fall back to makepkg.conf options
212 ret
=$
(in_opt_array
"$1" ${OPTIONS[@]})
213 if [[ $ret != '?' ]]; then
223 # Check if option is present in BUILDENV
225 # usage : check_buildenv( $option )
226 # return : y - enabled
231 echo $
(in_opt_array
"$1" ${BUILDENV[@]})
236 # usage : in_opt_array( $needle, $haystack )
237 # return : y - enabled
242 local needle
="${1,,}"; shift
247 if [[ $opt = $needle ]]; then
250 elif [[ $opt = "!$needle" ]]; then
261 # usage : in_array( $needle, $haystack )
266 local needle
=$1; shift
267 [[ -z $1 ]] && return 1 # Not Found
270 [[ $item = $needle ]] && return 0 # Found
275 get_downloadclient
() {
276 # $1 = URL with valid protocol prefix
278 local proto
="${url%%://*}"
280 # loop through DOWNLOAD_AGENTS variable looking for protocol
282 for i
in "${DLAGENTS[@]}"; do
283 local handler
="${i%%::*}"
284 if [[ $proto = $handler ]]; then
290 # if we didn't find an agent, return an error
291 if [[ -z $agent ]]; then
292 error
"$(gettext "There is no agent
set up to handle
%s URLs. Check
%s.
")" "$proto" "$MAKEPKG_CONF"
293 plain
"$(gettext "Aborting...
")"
294 exit 1 # $E_CONFIG_ERROR
297 # ensure specified program is installed
298 local program
="${agent%% *}"
299 if [[ ! -x $program ]]; then
300 local baseprog
=$
(basename $program)
301 error
"$(gettext "The download program
%s is not installed.
")" "$baseprog"
302 plain
"$(gettext "Aborting...
")"
303 exit 1 # $E_MISSING_PROGRAM
316 # temporary download file, default to last component of the URL
317 local dlfile
="${url##*/}"
319 # replace %o by the temporary dlfile if it exists
320 if echo "$dlcmd" |
grep -q "%o" ; then
321 dlcmd
=${dlcmd//\%o/\"$file.part\"}
324 # add the URL, either in place of %u or at the end
325 if echo "$dlcmd" |
grep -q "%u" ; then
326 dlcmd
=${dlcmd//\%u/\"$url\"}
328 dlcmd
="$dlcmd \"$url\""
332 eval "$dlcmd || ret=\$?"
334 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
338 # rename the temporary download file to the final destination
339 if [[ $dlfile != $file ]]; then
340 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
346 if (( ! ASROOT
)) && [[ $1 != "-T" ]]; then
347 sudo
$PACMAN $PACMAN_OPTS "$@" || ret
=$?
349 $PACMAN $PACMAN_OPTS "$@" || ret
=$?
355 (( $# > 0 )) ||
return
358 pmout
=$
(run_pacman
-T "$@")
360 if (( ret
== 127 )); then #unresolved deps
363 error
"$(gettext "'%s' returned a fatal error
(%i
): %s
")" "$PACMAN" "$ret" "$pmout"
369 local R_DEPS_SATISFIED
=0
370 local R_DEPS_MISSING
=1
372 (( $# == 0 )) && return $R_DEPS_SATISFIED
376 if (( ! DEP_BIN
)); then
377 return $R_DEPS_MISSING
380 if (( DEP_BIN
)); then
381 # install missing deps from binary packages (using pacman -S)
382 msg
"$(gettext "Installing missing dependencies...
")"
384 if ! run_pacman
-S --asdeps $deplist; then
385 error
"$(gettext "'%s' failed to
install missing dependencies.
")" "$PACMAN"
386 exit 1 # TODO: error code
390 # we might need the new system environment
391 # avoid triggering the ERR trap
392 local restoretrap
=$
(trap -p ERR
)
394 source /etc
/profile
&>/dev
/null
397 return $R_DEPS_SATISFIED
401 # $pkgdeps is a GLOBAL variable, used by remove_deps()
402 local R_DEPS_SATISFIED
=0
403 local R_DEPS_MISSING
=1
405 local deplist
="$(check_deps $*)"
406 if [[ -z $deplist ]]; then
407 return $R_DEPS_SATISFIED
410 if handle_deps
$deplist; then
411 pkgdeps
="$pkgdeps $deplist"
412 # check deps again to make sure they were resolved
413 deplist
="$(check_deps $*)"
414 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
415 elif (( DEP_BIN
)); then
416 error
"$(gettext "Failed to
install all missing dependencies.
")"
419 msg
"$(gettext "Missing Dependencies
:")"
421 for dep
in $deplist; do
425 return $R_DEPS_MISSING
428 # fix flyspray bug #5923
430 # $pkgdeps is a GLOBAL variable, set by resolve_deps()
431 (( ! RMDEPS
)) && return
432 [[ -z $pkgdeps ]] && return
434 local dep depstrip deplist
436 for dep
in $pkgdeps; do
437 depstrip
="${dep%%[<=>]*}"
438 deplist
="$deplist $depstrip"
441 msg
"Removing installed dependencies..."
443 # exit cleanly on failure to remove deps as package has been built successfully
444 if ! run_pacman
-Rns $deplist; then
445 warning
"$(gettext "Failed to remove installed dependencies.
")"
451 msg
"$(gettext "Retrieving Sources...
")"
453 if [[ ! -w $SRCDEST ]] ; then
454 error
"$(gettext "You
do not have
write permission to store downloads
in %s.
")" "$SRCDEST"
455 plain
"$(gettext "Aborting...
")"
459 pushd "$SRCDEST" &>/dev
/null
462 for netfile
in "${source[@]}"; do
463 local file=$
(get_filename
"$netfile")
464 local url
=$
(get_url
"$netfile")
465 if [[ -f $startdir/$file ]]; then
466 msg2
"$(gettext "Found
%s
in build dir
")" "$file"
467 rm -f "$srcdir/$file"
468 ln -s "$startdir/$file" "$srcdir/"
470 elif [[ -f $SRCDEST/$file ]]; then
471 msg2
"$(gettext "Using cached copy of
%s
")" "$file"
472 rm -f "$srcdir/$file"
473 ln -s "$SRCDEST/$file" "$srcdir/"
477 # if we get here, check to make sure it was a URL, else fail
478 if [[ $file = $url ]]; then
479 error
"$(gettext "%s was not found
in the build directory and is not a URL.
")" "$file"
480 exit 1 # $E_MISSING_FILE
483 # find the client we should use for this URL
484 local dlclient
=$
(get_downloadclient
"$url") ||
exit $?
486 msg2
"$(gettext "Downloading
%s...
")" "$file"
487 # fix flyspray bug #3289
489 download_file
"$dlclient" "$url" "$file" || ret
=$?
491 error
"$(gettext "Failure
while downloading
%s
")" "$file"
492 plain
"$(gettext "Aborting...
")"
495 rm -f "$srcdir/$file"
496 ln -s "$SRCDEST/$file" "$srcdir/"
502 generate_checksums
() {
503 msg
"$(gettext "Generating checksums
for source files...
")"
506 if [ ! $
(type -p openssl
) ]; then
507 error
"$(gettext "Cannot
find openssl.
")"
508 exit 1 # $E_MISSING_PROGRAM
512 for integ
in ${INTEGRITY_CHECK[@]}; do
515 md5|sha1|sha256|sha384|sha512
) : ;;
517 error
"$(gettext "Invalid integrity algorithm
'%s' specified.
")" "$integ"
518 exit 1;; # $E_CONFIG_ERROR
522 local numsrc
=${#source[@]}
523 echo -n "${integ}sums=("
527 for (( i
= 0; i
< ${#integ} + 6; i
++ )); do
532 for netfile
in "${source[@]}"; do
533 local file="$(get_filename "$netfile")"
535 if [[ ! -f $file ]] ; then
536 if [[ ! -f $SRCDEST/$file ]] ; then
537 error
"$(gettext "Unable to
find source file %s to generate checksum.
")" "$file"
538 plain
"$(gettext "Aborting...
")"
541 file="$SRCDEST/$file"
545 local sum="$(openssl dgst -${integ} "$file")"
547 (( ct
)) && echo -n "$indent"
550 (( $ct < $numsrc )) && echo
558 (( ! ${#source[@]} )) && return 0
560 if [ ! $
(type -p openssl
) ]; then
561 error
"$(gettext "Cannot
find openssl.
")"
562 exit 1 # $E_MISSING_PROGRAM
567 for integ
in md5 sha1 sha256 sha384 sha512
; do
568 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
569 if (( ${#integrity_sums[@]} == ${#source[@]} )); then
570 msg
"$(gettext "Validating
source files with
%s...
")" "${integ}sums"
575 for file in "${source[@]}"; do
577 file="$(get_filename "$file")"
578 echo -n " $file ... " >&2
580 if [[ ! -f $file ]] ; then
581 if [[ ! -f $SRCDEST/$file ]] ; then
582 echo "$(gettext "NOT FOUND
")" >&2
586 file="$SRCDEST/$file"
590 if (( $found )) ; then
591 local expectedsum
="${integrity_sums[$idx],,}"
592 local realsum
="$(openssl dgst -${integ} "$file")"
593 realsum
="${realsum##* }"
594 if [[ $expectedsum = $realsum ]]; then
595 echo "$(gettext "Passed
")" >&2
597 echo "$(gettext "FAILED
")" >&2
605 if (( errors
)); then
606 error
"$(gettext "One or
more files did not pass the validity check
!")"
607 exit 1 # TODO: error code
609 elif (( ${#integrity_sums[@]} )); then
610 error
"$(gettext "Integrity checks
(%s
) differ
in size from the
source array.
")" "$integ"
611 exit 1 # TODO: error code
615 if (( ! correlation
)); then
616 if (( SKIPINTEG
)); then
617 warning
"$(gettext "Integrity checks are missing.
")"
619 error
"$(gettext "Integrity checks are missing.
")"
620 exit 1 # TODO: error code
626 msg
"$(gettext "Extracting Sources...
")"
628 for netfile
in "${source[@]}"; do
629 file=$
(get_filename
"$netfile")
630 if in_array
"$file" ${noextract[@]}; then
631 #skip source files in the noextract=() array
632 # these are marked explicitly to NOT be extracted
636 if [[ ! -f $file ]] ; then
637 if [[ ! -f $SRCDEST/$file ]] ; then
638 error
"$(gettext "Unable to
find source file %s
for extraction.
")" "$file"
639 plain
"$(gettext "Aborting...
")"
642 file="$SRCDEST/$file"
647 local file_type
=$
(file -bizL "$file")
648 local ext
=${file##*.}
651 *application
/x-tar
*|
*application
/zip*|
*application
/x-zip
*|
*application
/x-cpio
*)
653 *application
/x-gzip
*)
655 gz|z|Z
) cmd
="gzip" ;;
658 *application
/x-bzip
*)
660 bz2|bz
) cmd
="bzip2" ;;
669 # Don't know what to use to extract this file,
670 # skip to the next file
675 msg2
"$(gettext "Extracting
%s with
%s
")" "$file" "$cmd"
676 if [[ $cmd = bsdtar
]]; then
677 $cmd -xf "$file" || ret
=?
680 $cmd -dcf "$file" > "${file%.*}" || ret
=?
683 error
"$(gettext "Failed to extract
%s
")" "$file"
684 plain
"$(gettext "Aborting...
")"
689 if (( EUID
== 0 )); then
690 # change perms of all source files to root user & root group
691 chown
-R 0:0 "$srcdir"
696 if [[ -p $logpipe ]]; then
699 # first exit all subshells, then print the error
700 if (( ! BASH_SUBSHELL
)); then
701 plain
"$(gettext "Aborting...
")"
704 exit 2 # $E_BUILD_FAILED
713 # clear user-specified makeflags if requested
714 if [[ $
(check_option makeflags
) = "n" ]]; then
718 msg
"$(gettext "Starting
%s
()...
")" "$pkgfunc"
721 # ensure all necessary build variables are exported
722 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
723 # save our shell options so pkgfunc() can't override what we need
724 local shellopts
=$
(shopt -p)
727 if (( LOGGING
)); then
728 BUILDLOG
="${startdir}/${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-$pkgfunc.log"
729 if [[ -f $BUILDLOG ]]; then
732 if [[ -f $BUILDLOG.
$i ]]; then
738 mv "$BUILDLOG" "$BUILDLOG.$i"
741 # ensure overridden package variables survive tee with split packages
742 logpipe
=$
(mktemp
-u "$startdir/logpipe.XXXXXXXX")
745 tee "$BUILDLOG" < "$logpipe" &
746 exec 1>"$logpipe" 2>"$logpipe"
747 restoretrap
=$
(trap -p ERR
)
748 trap 'error_function' ERR
755 restoretrap
=$
(trap -p ERR
)
756 trap 'error_function' ERR
760 # reset our shell options
765 # use distcc if it is requested (check buildenv and PKGBUILD opts)
766 if [[ $
(check_buildenv distcc
) = "y" && $
(check_option distcc
) != "n" ]]; then
767 [[ -d /usr
/lib
/distcc
/bin
]] && export PATH
="/usr/lib/distcc/bin:$PATH"
769 elif [[ $
(check_option distcc
) = "n" ]]; then
770 # if it is not wanted, clear the makeflags too
774 # use ccache if it is requested (check buildenv and PKGBUILD opts)
775 if [[ $
(check_buildenv ccache
) = "y" && $
(check_option ccache
) != "n" ]]; then
776 [[ -d /usr
/lib
/ccache
/bin
]] && export PATH
="/usr/lib/ccache/bin:$PATH"
789 run_function
"$pkgfunc"
794 msg
"$(gettext "Tidying
install...
")"
796 if [[ $
(check_option docs
) = "n" && -n ${DOC_DIRS[*]} ]]; then
797 msg2
"$(gettext "Removing doc files...
")"
798 rm -rf ${DOC_DIRS[@]}
801 if [[ $
(check_option purge
) = "y" && -n ${PURGE_TARGETS[*]} ]]; then
802 msg2
"$(gettext "Purging other files...
")"
804 for pt
in "${PURGE_TARGETS[@]}"; do
805 if [[ ${pt} = ${pt//\/} ]]; then
806 find .
-type f
-name "${pt}" -exec rm -f -- '{}' \
;
813 if [[ $
(check_option zipman
) = "y" && -n ${MAN_DIRS[*]} ]]; then
814 msg2
"$(gettext "Compressing man and info pages...
")"
815 local manpage ext
file link hardlinks hl
816 find ${MAN_DIRS[@]} -type f
2>/dev
/null |
817 while read manpage
; do
818 # check file still exists (potentially compressed with hard link)
819 if [[ -f ${manpage} ]]; then
821 file="${manpage##*/}"
822 if [[ $ext != gz
&& $ext != bz2
]]; then
823 # update symlinks to this manpage
824 find ${MAN_DIRS[@]} -lname "$file" 2>/dev
/null |
827 ln -sf "${file}.gz" "${link}.gz"
829 # find hard links and remove them
830 # the '|| true' part keeps the script from bailing if find returned an
831 # error, such as when one of the man directories doesn't exist
832 hardlinks
="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
833 for hl
in ${hardlinks}; do
836 # compress the original
838 # recreate hard links removed earlier
839 for hl
in ${hardlinks}; do
840 ln "${manpage}.gz" "${hl}.gz"
848 if [[ $
(check_option strip
) = y
&& -n ${STRIP_DIRS[*]} ]]; then
849 msg2
"$(gettext "Stripping debugging symbols from binaries and libraries...
")"
851 find ${STRIP_DIRS[@]} -type f
2>/dev
/null |
while read binary
; do
852 case "$(file -biz "$binary")" in
853 *compressed-encoding
*) # Skip compressed binaries
855 *application
/x-sharedlib
*) # Libraries (.so)
856 /usr
/bin
/strip
-S "$binary";;
857 *application
/x-archive
*) # Libraries (.a)
858 /usr
/bin
/strip
-S "$binary";;
859 *application
/x-executable
*) # Binaries
860 /usr
/bin
/strip
"$binary";;
865 if [[ $
(check_option libtool
) = "n" ]]; then
866 msg2
"$(gettext "Removing libtool .la files...
")"
867 find .
! -type d
-name "*.la" -exec rm -f -- '{}' \
;
870 if [[ $
(check_option emptydirs
) = "n" ]]; then
871 msg2
"$(gettext "Removing empty directories...
")"
872 find .
-depth -type d
-empty -delete
877 local builddate
=$
(date -u "+%s")
878 if [[ -n $PACKAGER ]]; then
879 local packager
="$PACKAGER"
881 local packager
="Unknown Packager"
883 local size
="$(du -sk)"
884 size
="$(( ${size%%[^0-9]*} * 1024 ))"
886 msg2
"$(gettext "Generating .PKGINFO
file...
")"
887 echo "# Generated by makepkg $myver" >.PKGINFO
888 if (( INFAKEROOT
)); then
889 echo "# using $(fakeroot -v)" >>.PKGINFO
891 echo "# $(LC_ALL=C date -u)" >>.PKGINFO
892 echo "pkgname = $1" >>.PKGINFO
893 (( SPLITPKG
)) && echo pkgbase
= $pkgbase >>.PKGINFO
894 echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO
895 echo "pkgdesc = $pkgdesc" >>.PKGINFO
896 echo "url = $url" >>.PKGINFO
897 echo "builddate = $builddate" >>.PKGINFO
898 echo "packager = $packager" >>.PKGINFO
899 echo "size = $size" >>.PKGINFO
900 echo "arch = $PKGARCH" >>.PKGINFO
901 if [[ $
(check_option force
) = "y" ]]; then
902 echo "force = true" >> .PKGINFO
906 for it
in "${license[@]}"; do
907 echo "license = $it" >>.PKGINFO
909 for it
in "${replaces[@]}"; do
910 echo "replaces = $it" >>.PKGINFO
912 for it
in "${groups[@]}"; do
913 echo "group = $it" >>.PKGINFO
915 for it
in "${depends[@]}"; do
916 echo "depend = $it" >>.PKGINFO
918 for it
in "${optdepends[@]}"; do
919 echo "optdepend = $it" >>.PKGINFO
921 for it
in "${conflicts[@]}"; do
922 echo "conflict = $it" >>.PKGINFO
924 for it
in "${provides[@]}"; do
925 echo "provides = $it" >>.PKGINFO
927 for it
in "${backup[@]}"; do
928 echo "backup = $it" >>.PKGINFO
930 for it
in "${packaging_options[@]}"; do
931 local ret
="$(check_option $it)"
932 if [[ $ret != "?" ]]; then
933 if [[ $ret = y
]]; then
934 echo "makepkgopt = $it" >>.PKGINFO
936 echo "makepkgopt = !$it" >>.PKGINFO
941 # TODO maybe remove this at some point
942 # warn if license array is not present or empty
943 if [[ -z $license ]]; then
944 warning
"$(gettext "Please add a license line to your
%s
!")" "$BUILDSCRIPT"
945 plain
"$(gettext "Example
for GPL
\'ed software
: license
=('GPL').
")"
952 # check existence of backup files
954 for file in "${backup[@]}"; do
955 if [[ ! -f $file ]]; then
956 warning
"$(gettext "Invalid backup entry
: %s
")" "$file"
960 # check for references to the build directory
961 if grep -R "${srcdir}" "${pkgdir}" &>/dev
/null
; then
962 warning
"$(gettext "Package contains reference to
%s
")" "\$srcdir"
967 if [[ ! -d $pkgdir ]]; then
968 error
"$(gettext "Missing pkg
/ directory.
")"
969 plain
"$(gettext "Aborting...
")"
970 exit 1 # $E_MISSING_PKGDIR
976 msg
"$(gettext "Creating package...
")"
984 if [[ $arch = "any" ]]; then
990 write_pkginfo
$nameofpkg
992 local comp_files
=".PKGINFO"
994 # check for an install script
995 if [[ -n $install ]]; then
996 msg2
"$(gettext "Adding
install script...
")"
997 cp "$startdir/$install" .INSTALL
998 comp_files
="$comp_files .INSTALL"
1001 # do we have a changelog?
1002 if [[ -n $changelog ]]; then
1003 msg2
"$(gettext "Adding package changelog...
")"
1004 cp "$startdir/$changelog" .CHANGELOG
1005 comp_files
="$comp_files .CHANGELOG"
1009 msg2
"$(gettext "Compressing package...
")"
1012 *tar.gz
) EXT
=${PKGEXT%.gz} ;;
1013 *tar.bz2
) EXT
=${PKGEXT%.bz2} ;;
1014 *tar.xz
) EXT
=${PKGEXT%.xz} ;;
1015 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
1016 "$PKGEXT" ; EXT
=$PKGEXT ;;
1018 local tar_file
="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${PKGARCH}${EXT}"
1019 local pkg_file
="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${PKGARCH}${PKGEXT}"
1023 # when fileglobbing, we want * in an empty directory to expand to
1024 # the null string rather than itself
1026 bsdtar
-cf - $comp_files * > "$tar_file" || ret
=$?
1029 if (( ! ret
)); then
1031 *tar.gz
) gzip -f -n "$tar_file" ;;
1032 *tar.bz2
) bzip2 -f "$tar_file" ;;
1033 *tar.xz
) xz
-z -f "$tar_file" ;;
1039 error
"$(gettext "Failed to create package
file.
")"
1040 exit 1 # TODO: error code
1043 if (( ! ret
)) && [[ "$PKGDEST" != "${startdir}" ]]; then
1044 ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1049 warning
"$(gettext "Failed to create symlink to package
file.
")"
1053 create_srcpackage
() {
1056 # Get back to our src directory so we can begin with sources.
1060 # We can only check checksums if we have all files.
1064 msg
"$(gettext "Creating
source package...
")"
1065 local srclinks
="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1066 mkdir
"${srclinks}"/${pkgbase}
1068 msg2
"$(gettext "Adding
%s...
")" "$BUILDSCRIPT"
1069 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1071 if [[ -n $install ]]; then
1072 if [[ -f $install ]]; then
1073 msg2
"$(gettext "Adding
install script...
")"
1074 ln -s "${startdir}/$install" "${srclinks}/${pkgbase}/"
1076 error
"$(gettext "Install scriptlet
(%s
) does not exist.
")" "$install"
1080 if [[ -n $changelog ]]; then
1081 if [[ -f $changelog ]]; then
1082 msg2
"$(gettext "Adding package changelog...
")"
1083 ln -s "${startdir}/$changelog" "${srclinks}/${pkgbase}/"
1085 error
"$(gettext "Changelog
file (%s
) does not exist.
")" "$changelog"
1090 for netfile
in "${source[@]}"; do
1091 local file=$
(get_filename
"$netfile")
1092 if [[ -f $netfile ]]; then
1093 msg2
"$(gettext "Adding
%s...
")" "$netfile"
1094 ln -s "${startdir}/$netfile" "${srclinks}/${pkgbase}"
1095 elif (( SOURCEONLY
== 2 )) && [[ -f $SRCDEST/$file ]]; then
1096 msg2
"$(gettext "Adding
%s...
")" "$file"
1097 ln -s "$SRCDEST/$file" "${srclinks}/${pkgbase}/"
1103 *tar.gz
) TAR_OPT
="z" ;;
1104 *tar.bz2
) TAR_OPT
="j" ;;
1105 *tar.xz
) TAR_OPT
="J" ;;
1106 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
1110 local pkg_file
="$PKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}"
1113 msg2
"$(gettext "Compressing
source package...
")"
1115 if ! bsdtar
-c${TAR_OPT}Lf
"$pkg_file" ${pkgbase}; then
1116 error
"$(gettext "Failed to create
source package
file.
")"
1117 exit 1 # TODO: error code
1120 rm -rf "${srclinks}"
1124 (( ! INSTALL
)) && return
1126 if (( ! SPLITPKG
)); then
1127 msg
"$(gettext "Installing package
%s with
%s
-U...
")" "$pkgname" "$PACMAN"
1129 msg
"$(gettext "Installing
%s package group with
%s
-U...
")" "$pkgbase" "$PACMAN"
1133 for pkg
in ${pkgname[@]}; do
1134 if [[ -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} ]]; then
1135 pkglist
="${pkglist} $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
1137 pkglist
="${pkglist} $PKGDEST/${pkg}-${pkgver}-${pkgrel}-any${PKGEXT}"
1141 if ! run_pacman
-U $pkglist; then
1142 warning
"$(gettext "Failed to
install built package
(s
).
")"
1148 # check for no-no's in the build script
1149 if [[ -z $pkgname ]]; then
1150 error
"$(gettext "%s is not allowed to be empty.
")" "pkgname"
1153 if [[ -z $pkgver ]]; then
1154 error
"$(gettext "%s is not allowed to be empty.
")" "pkgver"
1157 if [[ -z $pkgrel ]]; then
1158 error
"$(gettext "%s is not allowed to be empty.
")" "pkgrel"
1163 for name
in "${pkgname[@]}"; do
1164 if [[ ${name:0:1} = "-" ]]; then
1165 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgname"
1170 if [[ ${pkgbase:0:1} = "-" ]]; then
1171 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgbase"
1174 if [[ $pkgver != ${pkgver//-/} ]]; then
1175 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgver"
1178 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1179 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgrel"
1183 if [[ $arch != 'any' ]]; then
1184 if ! in_array
$CARCH ${arch[@]}; then
1185 if (( ! IGNOREARCH
)); then
1186 error
"$(gettext "%s is not available
for the
'%s' architecture.
")" "$pkgbase" "$CARCH"
1187 plain
"$(gettext "Note that many packages may need a line added to their
%s
")" "$BUILDSCRIPT"
1188 plain
"$(gettext "such as arch
=('%s').
")" "$CARCH"
1195 for provide
in ${provides[@]}; do
1196 if [[ $provide != ${provide//</} ||
$provide != ${provide//>/} ]]; then
1197 error
"$(gettext "Provides array cannot contain comparison
(< or
>) operators.
")"
1203 for file in "${backup[@]}"; do
1204 if [[ ${file:0:1} = "/" ]]; then
1205 error
"$(gettext "Invalid backup entry
: %s
")" "$file"
1211 for optdepend
in "${optdepends[@]}"; do
1212 pkg
=${optdepend%%:*}
1213 if [[ ! $pkg =~ ^
[[:alnum
:]\
>\
<\
=\.\
+\_\
-]*$
]]; then
1214 error
"$(gettext "Invalid syntax
for optdepend
: '%s'")" "$optdepend"
1218 if [[ $install && ! -f $install ]]; then
1219 error
"$(gettext "Install scriptlet
(%s
) does not exist.
")" "$install"
1223 if [[ -n $changelog && ! -f $changelog ]]; then
1224 error
"$(gettext "Changelog
file (%s
) does not exist.
")" "$changelog"
1228 local valid_options
=1
1229 local opt known kopt
1230 for opt
in ${options[@]}; do
1232 # check if option matches a known option or its inverse
1233 for kopt
in ${packaging_options[@]} ${other_options[@]}; do
1234 if [[ ${opt} = ${kopt} || ${opt} = "!${kopt}" ]]; then
1238 if (( ! known )); then
1239 error "$
(gettext "options array contains unknown option '%s'")" "$opt"
1243 if (( ! valid_options )); then
1247 if (( ${#pkgname[@]} > 1 )); then
1248 for pkg in ${pkgname[@]}; do
1249 if [ "$
(type -t package_
${pkg})" != "function" ]; then
1250 error "$
(gettext "missing package function for split package '%s'")" "$pkg"
1256 if [[ -n "${PKGLIST[@]}" ]]; then
1257 for pkg in ${PKGLIST[@]}; do
1258 if ! in_array $pkg ${pkgname[@]}; then
1259 error "$
(gettext "requested package %s is not provided in %s")" "$pkg" "$BUILDSCRIPT"
1271 # Do not update pkgver if --holdver is set, when building a source package,
1272 # when reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1273 if (( HOLDVER || SOURCEONLY )) \
1274 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1278 if [[ -z $FORCE_VER ]]; then
1279 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1280 # This will only be used on the first call to makepkg; subsequent
1281 # calls to makepkg via fakeroot will explicitly pass the version
1282 # number to avoid having to determine the version number twice.
1283 # Also do a brief check to make sure we have the VCS tool available.
1285 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1286 [ $(type -p darcs) ] || return 0
1287 msg "$
(gettext "Determining latest darcs revision...")"
1288 newpkgver=$(date +%Y%m%d)
1289 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1290 [ $(type -p cvs) ] || return 0
1291 msg "$
(gettext "Determining latest cvs revision...")"
1292 newpkgver=$(date +%Y%m%d)
1293 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1294 [ $(type -p git) ] || return 0
1295 msg "$
(gettext "Determining latest git revision...")"
1296 newpkgver=$(date +%Y%m%d)
1297 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1298 [ $(type -p svn) ] || return 0
1299 msg "$
(gettext "Determining latest svn revision...")"
1300 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1301 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1302 [ $(type -p bzr) ] || return 0
1303 msg "$
(gettext "Determining latest bzr revision...")"
1304 newpkgver=$(bzr revno ${_bzrtrunk})
1305 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1306 [ $(type -p hg) ] || return 0
1307 msg "$
(gettext "Determining latest hg revision...")"
1308 if [[ -d ./src/$_hgrepo ]] ; then
1313 [[ ! -d ./src/ ]] && mkdir ./src/
1314 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1317 newpkgver=$(hg tip --template "{rev}")
1321 if [[ -n $newpkgver ]]; then
1322 msg2 "$
(gettext "Version found: %s")" "$newpkgver"
1326 # Version number retrieved from fakeroot->makepkg argument
1327 newpkgver=$FORCE_VER
1332 # This is lame, but if we're wanting to use an updated pkgver for
1333 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1334 # the new pkgver and then re-source it. This is the most robust
1335 # method for dealing with PKGBUILDs that use, e.g.:
1341 if [[ -n $newpkgver ]]; then
1342 if [[ $newpkgver != $pkgver ]]; then
1343 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1344 @SEDINPLACE@ "s
/^pkgver
=[^
]*/pkgver
=$newpkgver/" "$BUILDFILE"
1345 @SEDINPLACE@ "s
/^pkgrel
=[^
]*/pkgrel
=1/" "$BUILDFILE"
1352 backup_package_variables() {
1353 for var in ${splitpkg_overrides[@]}; do
1354 indirect="${var}_backup
"
1355 eval "${indirect}=(\"\
${$var[@]}\")"
1359 restore_package_variables() {
1360 for var in ${splitpkg_overrides[@]}; do
1361 indirect="${var}_backup
"
1362 if [[ -n ${!indirect} ]]; then
1363 eval "${var}=(\"\
${$indirect[@]}\")"
1370 # getopt like parser
1372 local short_options=$1; shift;
1373 local long_options=$1; shift;
1375 local unused_options=""
1377 while [[ -n $1 ]]; do
1378 if [[ ${1:0:2} = '--' ]]; then
1379 if [[ -n ${1:2} ]]; then
1381 for i in ${long_options//,/ }; do
1382 if [[ ${1:2} = ${i//:} ]]; then
1387 if [[ -n $match ]]; then
1388 if [[ ${1:2} = $match ]]; then
1391 if [[ -n $2 ]]; then
1396 echo "makepkg
: option
'$1' $
(gettext "requires an argument")" >&2
1401 echo "makepkg
: $
(gettext "unrecognized option") '$1'" >&2
1408 elif [[ ${1:0:1} = '-' ]]; then
1409 for ((i=1; i<${#1}; i++)); do
1410 if [[ $short_options =~ ${1:i:1} ]]; then
1411 if [[ $short_options =~ "${1:i:1}:" ]]; then
1412 if [[ -n ${1:$i+1} ]]; then
1413 printf ' -%s' "${1:i:1}"
1414 printf " '%s'" "${1:$i+1}"
1416 if [[ -n $2 ]]; then
1417 printf ' -%s' "${1:i:1}"
1419 printf " '%s'" "${1}"
1421 echo "makepkg
: option $
(gettext "requires an argument") -- '${1:i:1}'" >&2
1427 printf ' -%s' "${1:i:1}"
1430 echo "makepkg
: $
(gettext "invalid option") -- '${1:i:1}'" >&2
1435 unused_options="${unused_options} '$1'"
1441 if [[ -n $unused_options ]]; then
1442 for i in ${unused_options[@]}; do
1446 if [[ -n $1 ]]; then
1447 while [[ -n $1 ]]; do
1448 printf " '%s'" "${1}"
1458 printf "makepkg
(pacman
) %s
\n" "$myver"
1460 printf "$
(gettext "Usage: %s [options]")\n" "$0"
1462 echo "$
(gettext "Options:")"
1463 printf "$
(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
1464 echo "$
(gettext " -c, --clean Clean up work files after build")"
1465 echo "$
(gettext " -C, --cleancache Clean up source files from the cache")"
1466 echo "$
(gettext " -d, --nodeps Skip all dependency checks")"
1467 echo "$
(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
1468 echo "$
(gettext " -f, --force Overwrite existing package")"
1469 echo "$
(gettext " -g, --geninteg Generate integrity checks for source files")"
1470 echo "$
(gettext " -h, --help This help")"
1471 echo "$
(gettext " -i, --install Install package after successful build")"
1472 echo "$
(gettext " -L, --log Log package build process")"
1473 echo "$
(gettext " -m, --nocolor Disable colorized output messages")"
1474 echo "$
(gettext " -o, --nobuild Download and extract files only")"
1475 printf "$
(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1476 echo "$
(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1477 echo "$
(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1478 echo "$
(gettext " -s, --syncdeps Install missing dependencies with pacman")"
1479 echo "$
(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1480 echo "$
(gettext " --asroot Allow makepkg to run as root user")"
1481 printf "$
(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf
"
1482 echo "$
(gettext " --holdver Prevent automatic version bumping for development PKGBUILDs")"
1483 echo "$
(gettext " --pkg <list> Only build listed packages from a split package")"
1484 echo "$
(gettext " --skipinteg Do not fail when integrity checks are missing")"
1485 echo "$
(gettext " --source Generate a source-only tarball without downloaded sources")"
1487 echo "$
(gettext "These options can be passed to pacman:")"
1489 echo "$
(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1490 echo "$
(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1492 printf "$
(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1497 printf "makepkg
(pacman
) %s
\n" "$myver"
1498 printf "$
(gettext "\
1499 Copyright (c) 2006-2009 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1500 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1501 This is free software; see the source for copying conditions.\n\
1502 There is NO WARRANTY, to the extent permitted by law.\n")"
1507 # determine whether we have gettext; make it a no-op if we do not
1508 if [ ! $(type -t gettext) ]; then
1516 # Parse Command Line Options.
1517 OPT_SHORT="AcCdefFghiLmop
:rRsV
"
1518 OPT_LONG="allsource
,asroot
,ignorearch
,clean
,cleancache
,nodeps
"
1519 OPT_LONG="$OPT_LONG,noextract
,force
,forcever
:,geninteg
,help,holdver
"
1520 OPT_LONG="$OPT_LONG,install,log
,nocolor
,nobuild
,pkg
:,rmdeps
,repackage
,skipinteg
"
1521 OPT_LONG="$OPT_LONG,source,syncdeps
,version
,config
:"
1523 OPT_LONG="$OPT_LONG,noconfirm
,noprogressbar
"
1524 OPT_TEMP="$
(parse_options
$OPT_SHORT $OPT_LONG "$@" ||
echo 'PARSE_OPTIONS FAILED')"
1525 if echo "$OPT_TEMP" | grep -q 'PARSE_OPTIONS FAILED'; then
1526 # This is a small hack to stop the script bailing with 'set -e'
1527 echo; usage; exit 1 # E_INVALID_OPTION;
1529 eval set -- "$OPT_TEMP"
1530 unset OPT_SHORT OPT_LONG OPT_TEMP
1535 --noconfirm) PACMAN_OPTS="$PACMAN_OPTS --noconfirm" ;;
1536 --noprogressbar) PACMAN_OPTS="$PACMAN_OPTS --noprogressbar" ;;
1539 --allsource) SOURCEONLY=2 ;;
1540 --asroot) ASROOT=1 ;;
1541 -A|--ignorearch) IGNOREARCH=1 ;;
1542 -c|--clean) CLEANUP=1 ;;
1543 -C|--cleancache) CLEANCACHE=1 ;;
1544 --config) shift; MAKEPKG_CONF=$1 ;;
1545 -d|--nodeps) NODEPS=1 ;;
1546 -e|--noextract) NOEXTRACT=1 ;;
1547 -f|--force) FORCE=1 ;;
1548 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1549 --forcever) shift; FORCE_VER=$1;;
1551 -g|--geninteg) GENINTEG=1 ;;
1552 --holdver) HOLDVER=1 ;;
1553 -i|--install) INSTALL=1 ;;
1554 -L|--log) LOGGING=1 ;;
1555 -m|--nocolor) USE_COLOR='n' ;;
1556 -o|--nobuild) NOBUILD=1 ;;
1557 -p) shift; BUILDFILE=$1 ;;
1558 --pkg) shift; PKGLIST=$1 ;;
1559 -r|--rmdeps) RMDEPS=1 ;;
1560 -R|--repackage) REPKG=1 ;;
1561 --skipinteg) SKIPINTEG=1 ;;
1562 --source) SOURCEONLY=1 ;;
1563 -s|--syncdeps) DEP_BIN=1 ;;
1565 -h|--help) usage; exit 0 ;; # E_OK
1566 -V|--version) version; exit 0 ;; # E_OK
1568 --) OPT_IND=0; shift; break;;
1569 *) usage; exit 1 ;; # E_INVALID_OPTION
1574 #preserve environment variables
1578 # default config is makepkg.conf
1579 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1581 # Source the config file; fail if it is not found
1582 if [[ -r $MAKEPKG_CONF ]]; then
1583 source "$MAKEPKG_CONF"
1585 error "$
(gettext "%s not found.")" "$MAKEPKG_CONF"
1586 plain "$
(gettext "Aborting...")"
1587 exit 1 # $E_CONFIG_ERROR
1590 # Source user-specific makepkg.conf overrides
1591 if [[ -r ~/.makepkg.conf ]]; then
1592 source ~/.makepkg.conf
1595 # set pacman command if not already defined
1596 PACMAN=${PACMAN:-pacman}
1598 # check if messages are to be printed using color
1599 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1600 if [[ -t 2 && ! $USE_COLOR = "n
" && $(check_buildenv color) = "y
" ]]; then
1601 ALL_OFF="$
(tput sgr0
)"
1603 BLUE="${BOLD}$
(tput setaf
4)"
1604 GREEN="${BOLD}$
(tput setaf
2)"
1605 RED="${BOLD}$
(tput setaf
1)"
1606 YELLOW="${BOLD}$
(tput setaf
3)"
1608 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1610 # override settings with an environment variable for batch processing
1611 PKGDEST=${_PKGDEST:-$PKGDEST}
1612 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1613 SRCDEST=${_SRCDEST:-$SRCDEST}
1614 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1617 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1618 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1619 error "$
(gettext "\\0--holdver and --forcever cannot both be specified" )"
1623 if (( CLEANCACHE )); then
1624 #fix flyspray feature request #5223
1625 if [[ -n $SRCDEST && $SRCDEST != $startdir ]]; then
1626 msg "$
(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1627 echo -n "$
(gettext " Are you sure you wish to do this? ")"
1628 echo -n "$
(gettext "[y/N]")"
1630 answer="${answer^^}"
1631 if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then
1634 error "$
(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1638 msg "$
(gettext "Source cache cleaned.")"
1643 msg "$
(gettext "No files have been removed.")"
1647 # $SRCDEST is $startdir, two possibilities
1648 error "$
(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
1649 plain "$
(gettext "In addition, please run makepkg -C outside of your cache directory.")"
1654 if (( ! INFAKEROOT )); then
1655 if (( EUID == 0 && ! ASROOT )); then
1656 # Warn those who like to live dangerously.
1657 error "$
(gettext "Running makepkg as root is a BAD idea and can cause")"
1658 plain "$
(gettext "permanent, catastrophic damage to your system. If you")"
1659 plain "$
(gettext "wish to run as root, please use the --asroot option.")"
1660 exit 1 # $E_USER_ABORT
1661 elif (( EUID > 0 && ASROOT )); then
1662 # Warn those who try to use the --asroot option when they are not root
1663 error "$
(gettext "The --asroot option is meant for the root user only.")"
1664 plain "$
(gettext "Please rerun makepkg without the --asroot flag.")"
1665 exit 1 # $E_USER_ABORT
1666 elif [[ $(check_buildenv fakeroot) = "y
" ]] && (( EUID > 0 )); then
1667 if [ ! $(type -p fakeroot) ]; then
1668 error "$
(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
1669 plain "$
(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1672 elif (( EUID > 0 )); then
1673 warning "$
(gettext "Running makepkg as an unprivileged user will result in non-root")"
1674 plain "$
(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
1675 plain "$
(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1679 if [[ -z $FAKEROOTKEY ]]; then
1680 error "$
(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
1681 exit 1 # TODO: error code
1685 # check for sudo if we will need it during makepkg execution
1686 if (( ! ASROOT && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1687 if [ ! "$
(type -p sudo
)" ]; then
1688 error "$
(gettext "Cannot find the sudo binary! Is sudo installed?")"
1689 plain "$
(gettext "Missing dependencies cannot be installed or removed as a normal user")"
1690 plain "$
(gettext "without sudo; install and configure sudo to auto-resolve dependencies.")"
1695 unset pkgname pkgbase pkgver pkgrel pkgdesc url license groups provides
1696 unset md5sums replaces depends conflicts backup source install changelog build
1697 unset makedepends optdepends options noextract
1699 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1700 if [[ ! -f $BUILDFILE ]]; then
1702 error "$
(gettext "%s does not exist.")" "$BUILDFILE"
1705 # PKGBUILD passed through a pipe
1706 BUILDFILE=/dev/stdin
1710 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1711 if [[ -n $crlftest ]]; then
1712 error "$
(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE"
1716 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1717 BUILDFILE="$startdir/$BUILDFILE"
1722 if (( GENINTEG )); then
1730 # check the PKGBUILD for some basic requirements
1731 check_sanity || exit 1
1733 # We need to run devel_update regardless of whether we are in the fakeroot
1734 # build process so that if the user runs makepkg --forcever manually, we
1735 # 1) output the correct pkgver, and 2) use the correct filename when
1736 # checking if the package file already exists - fixes FS #9194
1740 if (( ${#pkgname[@]} > 1 )); then
1744 # test for available PKGBUILD functions
1745 # The exclamation mark is required here to avoid triggering the ERR trap when
1746 # a tested function does not exist.
1747 if [[ $(! type -t build) = "function" ]]; then
1750 if [ "$
(type -t package
)" = "function" ]; then
1752 elif [ $SPLITPKG -eq 0 -a "$
(type -t package_
${pkgname})" = "function" ]; then
1756 pkgbase=${pkgbase:-${pkgname[0]}}
1758 if [[ -n "${PKGLIST[@]}" ]]; then
1760 pkgname="${PKGLIST[@]}"
1763 if (( ! SPLITPKG )); then
1764 if [[ -f $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} \
1765 || -f $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-any${PKGEXT} ]] \
1766 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
1767 if (( INSTALL )); then
1768 warning "$
(gettext "A package has already been built, installing existing package...")"
1772 error "$
(gettext "A package has already been built. (use -f to overwrite)")"
1779 for pkg in ${pkgname[@]}; do
1780 if [[ -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} \
1781 || -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-any${PKGEXT} ]]; then
1787 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
1788 if (( allpkgbuilt )); then
1789 if (( INSTALL )); then
1790 warning "$
(gettext "The package group has already been built, installing existing packages...")"
1794 error "$
(gettext "The package group has already been built. (use -f to overwrite)")"
1798 if (( somepkgbuilt )); then
1799 error "$
(gettext "Part of the package group has already been built. (use -f to overwrite)")"
1803 unset allpkgbuilt somepkgbuilt
1806 # Run the bare minimum in fakeroot
1807 if (( INFAKEROOT )); then
1808 if (( ! SPLITPKG )); then
1809 if (( ! PKGFUNC )); then
1810 if (( BUILDFUNC && ! REPKG )); then
1820 for pkg in ${pkgname[@]}; do
1821 pkgdir="$pkgdir/$pkg"
1823 backup_package_variables
1827 restore_package_variables
1828 pkgdir="${pkgdir%/*}"
1832 msg "$
(gettext "Leaving fakeroot environment.")"
1836 msg "$
(gettext "Making package: %s")" "$pkgbase $pkgver-$pkgrel ($
(date))"
1838 # if we are creating a source-only package, go no further
1839 if (( SOURCEONLY )); then
1840 if [[ -f $PKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT} ]] \
1841 && (( ! FORCE )); then
1842 error "$
(gettext "A source package has already been built. (use -f to overwrite)")"
1846 msg "$
(gettext "Source package created: %s")" "$pkgbase ($
(date))"
1850 # fix flyspray bug #5973
1851 if (( NODEPS || NOBUILD || REPKG )); then
1852 # no warning message needed for nobuild, repkg
1853 if (( NODEPS )); then
1854 warning "$
(gettext "Skipping dependency checks.")"
1856 elif [ $(type -p "${PACMAN%% *}") ]; then
1857 unset pkgdeps # Set by resolve_deps() and used by remove_deps()
1860 msg "$
(gettext "Checking Runtime Dependencies...")"
1861 resolve_deps ${depends[@]} || deperr=1
1863 msg "$
(gettext "Checking Buildtime Dependencies...")"
1864 resolve_deps ${makedepends[@]} || deperr=1
1866 if (( deperr )); then
1867 error "$
(gettext "Could not resolve all dependencies.")"
1871 warning "$
(gettext "%s was not found in PATH; skipping dependency checks.")" "${PACMAN%% *}"
1874 # ensure we have a sane umask set
1877 # get back to our src directory so we can begin with sources
1881 if (( NOEXTRACT )); then
1882 warning "$
(gettext "Skipping source retrieval -- using existing src/ tree")"
1883 warning "$
(gettext "Skipping source integrity checks -- using existing src/ tree")"
1884 warning "$
(gettext "Skipping source extraction -- using existing src/ tree")"
1886 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
1887 error "$
(gettext "The source directory is empty, there is nothing to build!")"
1888 plain "$
(gettext "Aborting...")"
1891 elif (( REPKG )); then
1892 if (( ! PKGFUNC && ! SPLITPKG )) \
1893 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
1894 error "$
(gettext "The package directory is empty, there is nothing to repackage!")"
1895 plain "$
(gettext "Aborting...")"
1904 if (( NOBUILD )); then
1905 msg "$
(gettext "Sources are ready.")"
1908 # check for existing pkg directory; don't remove if we are repackaging
1909 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
1910 msg "$
(gettext "Removing existing pkg/ directory...")"
1916 # if we are root or if fakeroot is not enabled, then we don't use it
1917 if [[ $(check_buildenv fakeroot) != "y
" ]] || (( EUID == 0 )); then
1918 if (( ! REPKG )); then
1920 (( BUILDFUNC )) && run_build
1922 if (( ! SPLITPKG )); then
1923 if (( PKGFUNC )); then
1926 elif (( ! REPKG )); then
1931 for pkg in ${pkgname[@]}; do
1932 pkgdir="$pkgdir/$pkg"
1934 backup_package_variables
1938 restore_package_variables
1939 pkgdir="${pkgdir%/*}"
1943 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
1945 (( BUILDFUNC )) && run_build
1949 msg "$
(gettext "Entering fakeroot environment...")"
1951 if [[ -n $newpkgver ]]; then
1952 fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $?
1954 fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
1959 msg "$
(gettext "Finished making: %s")" "$pkgbase $pkgver-$pkgrel ($
(date))"
1965 # vim: set ts=2 sw=2 noet: