3 # makepkg - make packages compatible for use with pacman
4 # Generated from makepkg.in; do not edit by hand.
6 # Copyright (c) 2006-2010 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 # gettext, grep, gzip, openssl, sed, tput (ncurses), xz
33 # gettext initialization
34 export TEXTDOMAIN
='pacman'
35 export TEXTDOMAINDIR
='/usr/share/locale'
37 # file -i does not work on Mac OSX unless legacy mode is set
38 export COMMAND_MODE
='legacy'
42 BUILDSCRIPT
='PKGBUILD'
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
121 [[ -n $srclinks ]] && rm -rf "$srclinks"
127 # Clean up function. Called automatically when the script exits.
132 if (( INFAKEROOT
)); then
133 # Don't clean up when leaving fakeroot, we're not done yet.
137 if (( ! EXIT_CODE
&& CLEANUP
)); then
138 # If it's a clean exit and -c/--clean has been passed...
139 msg
"$(gettext "Cleaning up...
")"
140 rm -rf "$pkgdir" "$srcdir"
141 if [[ -n $pkgbase ]]; then
142 # Can't do this unless the BUILDSCRIPT has been sourced.
143 if (( BUILDFUNC
)); then
144 rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"*
146 if (( PKGFUNC
)); then
147 rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package.log"*
148 elif (( SPLITPKG
)); then
149 for pkg
in ${pkgname[@]}; do
150 rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package_${pkg}.log"*
154 # clean up dangling symlinks to packages
155 for pkg
in ${pkgname[@]}; do
156 for file in ${pkg}-*-*-${CARCH}${PKGEXT}; do
157 if [[ -h $file && ! -e $file ]]; then
174 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
175 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
176 trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
178 # a source entry can have two forms :
179 # 1) "filename::http://path/to/file"
180 # 2) "http://path/to/file"
182 # Return the absolute filename of a source entry
184 # This function accepts a source entry or the already extracted filename of a
185 # source entry as input
187 local file="$(get_filename "$1")"
189 if [[ -f "$startdir/$file" ]]; then
190 file="$startdir/$file"
191 elif [[ -f "$SRCDEST/$file" ]]; then
192 file="$SRCDEST/$file"
200 # Print 'source not found' error message and exit makepkg
201 missing_source_file
() {
202 error
"$(gettext "Unable to
find source file %s.
")" "$(get_filename "$1")"
203 plain
"$(gettext "Aborting...
")"
204 exit 1 # $E_MISSING_FILE
207 # extract the filename from a source entry
209 # if a filename is specified, use it
210 local filename
="${1%%::*}"
211 # if it is just an URL, we only keep the last component
212 echo "${filename##*/}"
215 # extract the URL from a source entry
217 # strip an eventual filename
222 # Checks to see if options are present in makepkg.conf or PKGBUILD;
223 # PKGBUILD options always take precedence.
225 # usage : check_option( $option )
226 # return : y - enabled
231 local ret
=$
(in_opt_array
"$1" ${options[@]})
232 if [[ $ret != '?' ]]; then
237 # fall back to makepkg.conf options
238 ret
=$
(in_opt_array
"$1" ${OPTIONS[@]})
239 if [[ $ret != '?' ]]; then
249 # Check if option is present in BUILDENV
251 # usage : check_buildenv( $option )
252 # return : y - enabled
257 echo $
(in_opt_array
"$1" ${BUILDENV[@]})
262 # usage : in_opt_array( $needle, $haystack )
263 # return : y - enabled
268 local needle
="${1,,}"; shift
273 if [[ $opt = $needle ]]; then
276 elif [[ $opt = "!$needle" ]]; then
287 # usage : in_array( $needle, $haystack )
292 local needle
=$1; shift
293 [[ -z $1 ]] && return 1 # Not Found
296 [[ $item = $needle ]] && return 0 # Found
301 get_downloadclient
() {
302 # $1 = URL with valid protocol prefix
304 local proto
="${url%%://*}"
306 # loop through DOWNLOAD_AGENTS variable looking for protocol
308 for i
in "${DLAGENTS[@]}"; do
309 local handler
="${i%%::*}"
310 if [[ $proto = $handler ]]; then
316 # if we didn't find an agent, return an error
317 if [[ -z $agent ]]; then
318 error
"$(gettext "There is no agent
set up to handle
%s URLs. Check
%s.
")" "$proto" "$MAKEPKG_CONF"
319 plain
"$(gettext "Aborting...
")"
320 exit 1 # $E_CONFIG_ERROR
323 # ensure specified program is installed
324 local program
="${agent%% *}"
325 if [[ ! -x $program ]]; then
326 local baseprog
=$
(basename $program)
327 error
"$(gettext "The download program
%s is not installed.
")" "$baseprog"
328 plain
"$(gettext "Aborting...
")"
329 exit 1 # $E_MISSING_PROGRAM
342 # temporary download file, default to last component of the URL
343 local dlfile
="${url##*/}"
345 # replace %o by the temporary dlfile if it exists
346 if [[ $dlcmd = *%o
* ]]; then
347 dlcmd
=${dlcmd//\%o/\"$file.part\"}
350 # add the URL, either in place of %u or at the end
351 if [[ $dlcmd = *%u
* ]]; then
352 dlcmd
=${dlcmd//\%u/\"$url\"}
354 dlcmd
="$dlcmd \"$url\""
358 eval "$dlcmd || ret=\$?"
360 [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
364 # rename the temporary download file to the final destination
365 if [[ $dlfile != $file ]]; then
366 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
372 if (( ! ASROOT
)) && [[ $1 != "-T" && $1 != "-Qq" ]]; then
373 if [ "$(type -p sudo)" ] && sudo
-l $PACMAN &>/dev
/null
; then
374 sudo
$PACMAN $PACMAN_OPTS "$@" || ret
=$?
376 su
-c "$PACMAN $PACMAN_OPTS $*" || ret
=$?
379 $PACMAN $PACMAN_OPTS "$@" || ret
=$?
385 (( $# > 0 )) ||
return
388 pmout
=$
(run_pacman
-T "$@")
390 if (( ret
== 127 )); then #unresolved deps
393 error
"$(gettext "'%s' returned a fatal error
(%i
): %s
")" "$PACMAN" "$ret" "$pmout"
399 local R_DEPS_SATISFIED
=0
400 local R_DEPS_MISSING
=1
402 (( $# == 0 )) && return $R_DEPS_SATISFIED
406 if (( ! DEP_BIN
)); then
407 return $R_DEPS_MISSING
410 if (( DEP_BIN
)); then
411 # install missing deps from binary packages (using pacman -S)
412 msg
"$(gettext "Installing missing dependencies...
")"
414 if ! run_pacman
-S --asdeps $deplist; then
415 error
"$(gettext "'%s' failed to
install missing dependencies.
")" "$PACMAN"
416 exit 1 # TODO: error code
420 # we might need the new system environment
421 # avoid triggering the ERR trap
422 local restoretrap
=$
(trap -p ERR
)
424 source /etc
/profile
&>/dev
/null
427 return $R_DEPS_SATISFIED
431 local R_DEPS_SATISFIED
=0
432 local R_DEPS_MISSING
=1
434 local deplist
="$(check_deps $*)"
435 if [[ -z $deplist ]]; then
436 return $R_DEPS_SATISFIED
439 if handle_deps
$deplist; then
440 # check deps again to make sure they were resolved
441 deplist
="$(check_deps $*)"
442 [[ -z $deplist ]] && return $R_DEPS_SATISFIED
443 elif (( DEP_BIN
)); then
444 error
"$(gettext "Failed to
install all missing dependencies.
")"
447 msg
"$(gettext "Missing Dependencies
:")"
449 for dep
in $deplist; do
453 return $R_DEPS_MISSING
457 (( ! RMDEPS
)) && return
459 # check for packages removed during dependency install (e.g. due to conflicts)
460 # removing all installed packages is risky in this case
461 if [[ -n $
(comm -23 <(printf "%s\n" "${original_pkglist[@]}") \
462 <(printf "%s\n" "${current_pkglist[@]}")) ]]; then
463 warning
"$(gettext "Failed to remove installed dependencies.
")"
467 local deplist
=($
(comm -13 <(printf "%s\n" "${original_pkglist[@]}") \
468 <(printf "%s\n" "${current_pkglist[@]}")))
469 (( ${#deplist[@]} == 0 )) && return
471 msg
"Removing installed dependencies..."
472 # exit cleanly on failure to remove deps as package has been built successfully
473 if ! run_pacman
-Rn ${deplist[@]}; then
474 warning
"$(gettext "Failed to remove installed dependencies.
")"
480 msg
"$(gettext "Retrieving Sources...
")"
482 pushd "$SRCDEST" &>/dev
/null
485 for netfile
in "${source[@]}"; do
487 if file=$
(get_filepath
"$netfile"); then
488 msg2
"$(gettext "Found
%s
")" "${file##*/}"
489 ln -sf "$file" "$srcdir/"
493 file=$
(get_filename
"$netfile")
494 local url
=$
(get_url
"$netfile")
496 # if we get here, check to make sure it was a URL, else fail
497 if [[ $file = $url ]]; then
498 error
"$(gettext "%s was not found
in the build directory and is not a URL.
")" "$file"
499 exit 1 # $E_MISSING_FILE
502 # find the client we should use for this URL
503 local dlclient
=$
(get_downloadclient
"$url") ||
exit $?
505 msg2
"$(gettext "Downloading
%s...
")" "$file"
506 # fix flyspray bug #3289
508 download_file
"$dlclient" "$url" "$file" || ret
=$?
510 error
"$(gettext "Failure
while downloading
%s
")" "$file"
511 plain
"$(gettext "Aborting...
")"
514 rm -f "$srcdir/$file"
515 ln -s "$SRCDEST/$file" "$srcdir/"
525 for integ
in md5 sha1 sha256 sha384 sha512
; do
526 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
527 if [[ -n "$integrity_sums" ]]; then
528 integlist
=(${integlist[@]} $integ)
532 if (( ${#integlist[@]} > 0 )); then
535 echo ${INTEGRITY_CHECK[@]}
539 generate_checksums
() {
540 msg
"$(gettext "Generating checksums
for source files...
")"
543 if [ ! $
(type -p openssl
) ]; then
544 error
"$(gettext "Cannot
find openssl.
")"
545 exit 1 # $E_MISSING_PROGRAM
549 if (( $# == 0 )); then
550 integlist
=$
(get_integlist
)
556 for integ
in ${integlist[@]}; do
559 md5|sha1|sha256|sha384|sha512
) : ;;
561 error
"$(gettext "Invalid integrity algorithm
'%s' specified.
")" "$integ"
562 exit 1;; # $E_CONFIG_ERROR
566 local numsrc
=${#source[@]}
567 echo -n "${integ}sums=("
571 for (( i
= 0; i
< ${#integ} + 6; i
++ )); do
576 for netfile
in "${source[@]}"; do
577 local file="$(get_filepath "$netfile")" || missing_source_file
"$netfile"
578 local sum="$(openssl dgst -${integ} "$file")"
580 (( ct
)) && echo -n "$indent"
583 (( $ct < $numsrc )) && echo
591 (( ! ${#source[@]} )) && return 0
593 if [ ! $
(type -p openssl
) ]; then
594 error
"$(gettext "Cannot
find openssl.
")"
595 exit 1 # $E_MISSING_PROGRAM
600 for integ
in md5 sha1 sha256 sha384 sha512
; do
601 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
602 if (( ${#integrity_sums[@]} == ${#source[@]} )); then
603 msg
"$(gettext "Validating
source files with
%s...
")" "${integ}sums"
608 for file in "${source[@]}"; do
610 file="$(get_filename "$file")"
611 echo -n " $file ... " >&2
613 if ! file="$(get_filepath "$file")"; then
614 echo "$(gettext "NOT FOUND
")" >&2
619 if (( $found )) ; then
620 local expectedsum
="${integrity_sums[$idx],,}"
621 local realsum
="$(openssl dgst -${integ} "$file")"
622 realsum
="${realsum##* }"
623 if [[ $expectedsum = $realsum ]]; then
624 echo "$(gettext "Passed
")" >&2
626 echo "$(gettext "FAILED
")" >&2
634 if (( errors
)); then
635 error
"$(gettext "One or
more files did not pass the validity check
!")"
636 exit 1 # TODO: error code
638 elif (( ${#integrity_sums[@]} )); then
639 error
"$(gettext "Integrity checks
(%s
) differ
in size from the
source array.
")" "$integ"
640 exit 1 # TODO: error code
644 if (( ! correlation
)); then
645 error
"$(gettext "Integrity checks are missing.
")"
646 exit 1 # TODO: error code
651 msg
"$(gettext "Extracting Sources...
")"
653 for netfile
in "${source[@]}"; do
654 file=$
(get_filename
"$netfile")
655 if in_array
"$file" ${noextract[@]}; then
656 #skip source files in the noextract=() array
657 # these are marked explicitly to NOT be extracted
663 local file_type
=$
(file -bizL "$file")
664 local ext
=${file##*.}
667 *application
/x-tar
*|
*application
/zip*|
*application
/x-zip
*|
*application
/x-cpio
*)
669 *application
/x-gzip
*)
671 gz|z|Z
) cmd
="gzip" ;;
674 *application
/x-bzip
*)
676 bz2|bz
) cmd
="bzip2" ;;
685 # Don't know what to use to extract this file,
686 # skip to the next file
691 msg2
"$(gettext "Extracting
%s with
%s
")" "$file" "$cmd"
692 if [[ $cmd = bsdtar
]]; then
693 $cmd -xf "$file" || ret
=$?
696 $cmd -dcf "$file" > "${file%.*}" || ret
=$?
699 error
"$(gettext "Failed to extract
%s
")" "$file"
700 plain
"$(gettext "Aborting...
")"
705 if (( EUID
== 0 )); then
706 # change perms of all source files to root user & root group
707 chown
-R 0:0 "$srcdir"
712 if [[ -p $logpipe ]]; then
715 # first exit all subshells, then print the error
716 if (( ! BASH_SUBSHELL
)); then
717 plain
"$(gettext "Aborting...
")"
720 exit 2 # $E_BUILD_FAILED
729 # clear user-specified makeflags if requested
730 if [[ $
(check_option makeflags
) = "n" ]]; then
734 msg
"$(gettext "Starting
%s
()...
")" "$pkgfunc"
737 # ensure all necessary build variables are exported
738 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
739 # save our shell options so pkgfunc() can't override what we need
740 local shellopts
=$
(shopt -p)
743 if (( LOGGING
)); then
744 BUILDLOG
="${startdir}/${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-$pkgfunc.log"
745 if [[ -f $BUILDLOG ]]; then
748 if [[ -f $BUILDLOG.
$i ]]; then
754 mv "$BUILDLOG" "$BUILDLOG.$i"
757 # ensure overridden package variables survive tee with split packages
758 logpipe
=$
(mktemp
-u "$startdir/logpipe.XXXXXXXX")
761 tee "$BUILDLOG" < "$logpipe" &
762 exec 1>"$logpipe" 2>"$logpipe"
763 restoretrap
=$
(trap -p ERR
)
764 trap 'error_function' ERR
771 restoretrap
=$
(trap -p ERR
)
772 trap 'error_function' ERR
776 # reset our shell options
781 # use distcc if it is requested (check buildenv and PKGBUILD opts)
782 if [[ $
(check_buildenv distcc
) = "y" && $
(check_option distcc
) != "n" ]]; then
783 [[ -d /usr
/lib
/distcc
/bin
]] && export PATH
="/usr/lib/distcc/bin:$PATH"
785 elif [[ $
(check_option distcc
) = "n" ]]; then
786 # if it is not wanted, clear the makeflags too
790 # use ccache if it is requested (check buildenv and PKGBUILD opts)
791 if [[ $
(check_buildenv ccache
) = "y" && $
(check_option ccache
) != "n" ]]; then
792 [[ -d /usr
/lib
/ccache
/bin
]] && export PATH
="/usr/lib/ccache/bin:$PATH"
805 run_function
"$pkgfunc"
810 msg
"$(gettext "Tidying
install...
")"
812 if [[ $
(check_option docs
) = "n" && -n ${DOC_DIRS[*]} ]]; then
813 msg2
"$(gettext "Removing doc files...
")"
814 rm -rf ${DOC_DIRS[@]}
817 if [[ $
(check_option purge
) = "y" && -n ${PURGE_TARGETS[*]} ]]; then
818 msg2
"$(gettext "Purging other files...
")"
820 for pt
in "${PURGE_TARGETS[@]}"; do
821 if [[ ${pt} = ${pt//\/} ]]; then
822 find .
-type f
-name "${pt}" -exec rm -f -- '{}' \
;
829 if [[ $
(check_option zipman
) = "y" && -n ${MAN_DIRS[*]} ]]; then
830 msg2
"$(gettext "Compressing man and info pages...
")"
831 local manpage ext
file link hardlinks hl
832 find ${MAN_DIRS[@]} -type f
2>/dev
/null |
833 while read manpage
; do
835 file="${manpage##*/}"
836 if [[ $ext != gz
&& $ext != bz2
]]; then
837 # update symlinks to this manpage
838 find ${MAN_DIRS[@]} -lname "$file" 2>/dev
/null |
841 ln -sf "${file}.gz" "${link}.gz"
844 # check file still exists (potentially already compressed due to hardlink)
845 if [[ -f ${manpage} ]]; then
846 # find hard links and remove them
847 # the '|| true' part keeps the script from bailing if find returned an
848 # error, such as when one of the man directories doesn't exist
849 hardlinks
="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
850 for hl
in ${hardlinks}; do
853 # compress the original
855 # recreate hard links removed earlier
856 for hl
in ${hardlinks}; do
857 ln "${manpage}.gz" "${hl}.gz"
865 if [[ $
(check_option strip
) = y
&& -n ${STRIP_DIRS[*]} ]]; then
866 msg2
"$(gettext "Stripping unneeded symbols from binaries and libraries...
")"
867 # make sure library stripping variables are defined to prevent excess stripping
868 [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED
="-S"
869 [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC
="-S"
871 find ${STRIP_DIRS[@]} -type f
-perm -u+w
2>/dev
/null |
while read binary
; do
872 case "$(file -bi "$binary")" in
873 *application
/x-sharedlib
*) # Libraries (.so)
874 /usr
/bin
/strip
$STRIP_SHARED "$binary";;
875 *application
/x-archive
*) # Libraries (.a)
876 /usr
/bin
/strip
$STRIP_STATIC "$binary";;
877 *application
/x-executable
*) # Binaries
878 /usr
/bin
/strip
$STRIP_BINARIES "$binary";;
883 if [[ $
(check_option libtool
) = "n" ]]; then
884 msg2
"$(gettext "Removing libtool .la files...
")"
885 find .
! -type d
-name "*.la" -exec rm -f -- '{}' \
;
888 if [[ $
(check_option emptydirs
) = "n" ]]; then
889 msg2
"$(gettext "Removing empty directories...
")"
890 find .
-depth -type d
-empty -delete
895 local builddate
=$
(date -u "+%s")
896 if [[ -n $PACKAGER ]]; then
897 local packager
="$PACKAGER"
899 local packager
="Unknown Packager"
901 local size
="$(du -sk)"
902 size
="$(( ${size%%[^0-9]*} * 1024 ))"
904 msg2
"$(gettext "Generating .PKGINFO
file...
")"
905 echo "# Generated by makepkg $myver" >.PKGINFO
906 if (( INFAKEROOT
)); then
907 echo "# using $(fakeroot -v)" >>.PKGINFO
909 echo "# $(LC_ALL=C date -u)" >>.PKGINFO
910 echo "pkgname = $1" >>.PKGINFO
911 (( SPLITPKG
)) && echo pkgbase
= $pkgbase >>.PKGINFO
912 echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO
913 echo "pkgdesc = $pkgdesc" >>.PKGINFO
914 echo "url = $url" >>.PKGINFO
915 echo "builddate = $builddate" >>.PKGINFO
916 echo "packager = $packager" >>.PKGINFO
917 echo "size = $size" >>.PKGINFO
918 echo "arch = $PKGARCH" >>.PKGINFO
919 if [[ $
(check_option force
) = "y" ]]; then
920 echo "force = true" >> .PKGINFO
924 for it
in "${license[@]}"; do
925 echo "license = $it" >>.PKGINFO
927 for it
in "${replaces[@]}"; do
928 echo "replaces = $it" >>.PKGINFO
930 for it
in "${groups[@]}"; do
931 echo "group = $it" >>.PKGINFO
933 for it
in "${depends[@]}"; do
934 echo "depend = $it" >>.PKGINFO
936 for it
in "${optdepends[@]}"; do
937 echo "optdepend = $it" >>.PKGINFO
939 for it
in "${conflicts[@]}"; do
940 echo "conflict = $it" >>.PKGINFO
942 for it
in "${provides[@]}"; do
943 echo "provides = $it" >>.PKGINFO
945 for it
in "${backup[@]}"; do
946 echo "backup = $it" >>.PKGINFO
948 for it
in "${packaging_options[@]}"; do
949 local ret
="$(check_option $it)"
950 if [[ $ret != "?" ]]; then
951 if [[ $ret = y
]]; then
952 echo "makepkgopt = $it" >>.PKGINFO
954 echo "makepkgopt = !$it" >>.PKGINFO
959 # TODO maybe remove this at some point
960 # warn if license array is not present or empty
961 if [[ -z $license ]]; then
962 warning
"$(gettext "Please add a license line to your
%s
!")" "$BUILDSCRIPT"
963 plain
"$(gettext "Example
for GPL
\'ed software
: license
=('GPL').
")"
970 # check existence of backup files
972 for file in "${backup[@]}"; do
973 if [[ ! -f $file ]]; then
974 warning
"$(gettext "Invalid backup entry
: %s
")" "$file"
978 # check for references to the build directory
979 if grep -R "${srcdir}" "${pkgdir}" &>/dev
/null
; then
980 warning
"$(gettext "Package contains reference to
%s
")" "\$srcdir"
985 if [[ ! -d $pkgdir ]]; then
986 error
"$(gettext "Missing pkg
/ directory.
")"
987 plain
"$(gettext "Aborting...
")"
988 exit 1 # $E_MISSING_PKGDIR
994 msg
"$(gettext "Creating package...
")"
1002 if [[ $arch = "any" ]]; then
1008 write_pkginfo
$nameofpkg
1010 local comp_files
=".PKGINFO"
1012 # check for an install script
1013 if [[ -n $install ]]; then
1014 msg2
"$(gettext "Adding
install script...
")"
1015 cp "$startdir/$install" .INSTALL
1017 comp_files
="$comp_files .INSTALL"
1020 # do we have a changelog?
1021 if [[ -n $changelog ]]; then
1022 msg2
"$(gettext "Adding package changelog...
")"
1023 cp "$startdir/$changelog" .CHANGELOG
1024 chmod 644 .CHANGELOG
1025 comp_files
="$comp_files .CHANGELOG"
1029 msg2
"$(gettext "Compressing package...
")"
1032 *tar.gz
) EXT
=${PKGEXT%.gz} ;;
1033 *tar.bz2
) EXT
=${PKGEXT%.bz2} ;;
1034 *tar.xz
) EXT
=${PKGEXT%.xz} ;;
1035 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
1036 "$PKGEXT" ; EXT
=$PKGEXT ;;
1038 local tar_file
="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${PKGARCH}${EXT}"
1039 local pkg_file
="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${PKGARCH}${PKGEXT}"
1043 # when fileglobbing, we want * in an empty directory to expand to
1044 # the null string rather than itself
1046 bsdtar
-cf - $comp_files * > "$tar_file" || ret
=$?
1049 if (( ! ret
)); then
1051 *tar.gz
) gzip -f -n "$tar_file" ;;
1052 *tar.bz2
) bzip2 -f "$tar_file" ;;
1053 *tar.xz
) xz
-z -f "$tar_file" ;;
1059 error
"$(gettext "Failed to create package
file.
")"
1060 exit 1 # TODO: error code
1063 if (( ! ret
)) && [[ "$PKGDEST" != "${startdir}" ]]; then
1064 ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
1069 warning
"$(gettext "Failed to create symlink to package
file.
")"
1073 create_srcpackage
() {
1076 # Get back to our src directory so we can begin with sources.
1080 if (( ! SKIPINTEG || SOURCEONLY
== 2 )); then
1083 if (( ! SKIPINTEG
)); then
1084 # We can only check checksums if we have all files.
1087 warning
"$(gettext "Skipping integrity checks.
")"
1091 msg
"$(gettext "Creating
source package...
")"
1092 local srclinks
="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1093 mkdir
"${srclinks}"/${pkgbase}
1095 msg2
"$(gettext "Adding
%s...
")" "$BUILDSCRIPT"
1096 ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
1099 for file in "${source[@]}"; do
1100 if [[ -f $file ]]; then
1101 msg2
"$(gettext "Adding
%s...
")" "$file"
1102 ln -s "${startdir}/$file" "$srclinks/$pkgbase"
1103 elif (( SOURCEONLY
== 2 )); then
1104 local absfile
=$
(get_filepath
"$file") || missing_source_file
"$file"
1105 msg2
"$(gettext "Adding
%s...
")" "${absfile##*/}"
1106 ln -s "$absfile" "$srclinks/$pkgbase"
1111 for i
in 'changelog' 'install'; do
1112 local filelist
=$
(sed -n "s/^[[:space:]]*$i=//p" "$BUILDSCRIPT")
1114 for file in $filelist; do
1115 # evaluate any bash variables used
1117 if [[ ! -f "${srclinks}/${pkgbase}/$file" ]]; then
1118 msg2
"$(gettext "Adding
%s
file (%s
)...
")" "$i" "${file}"
1119 ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
1126 *tar.gz
) TAR_OPT
="z" ;;
1127 *tar.bz2
) TAR_OPT
="j" ;;
1128 *tar.xz
) TAR_OPT
="J" ;;
1129 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
1133 local pkg_file
="$SRCPKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}"
1136 msg2
"$(gettext "Compressing
source package...
")"
1138 if ! bsdtar
-c${TAR_OPT}Lf
"$pkg_file" ${pkgbase}; then
1139 error
"$(gettext "Failed to create
source package
file.
")"
1140 exit 1 # TODO: error code
1143 rm -rf "${srclinks}"
1147 (( ! INSTALL
)) && return
1149 if (( ! SPLITPKG
)); then
1150 msg
"$(gettext "Installing package
%s with
%s
-U...
")" "$pkgname" "$PACMAN"
1152 msg
"$(gettext "Installing
%s package group with
%s
-U...
")" "$pkgbase" "$PACMAN"
1156 for pkg
in ${pkgname[@]}; do
1157 if [[ -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} ]]; then
1158 pkglist
="${pkglist} $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
1160 pkglist
="${pkglist} $PKGDEST/${pkg}-${pkgver}-${pkgrel}-any${PKGEXT}"
1164 if ! run_pacman
-U $pkglist; then
1165 warning
"$(gettext "Failed to
install built package
(s
).
")"
1171 # check for no-no's in the build script
1172 if [[ -z $pkgname ]]; then
1173 error
"$(gettext "%s is not allowed to be empty.
")" "pkgname"
1176 if [[ -z $pkgver ]]; then
1177 error
"$(gettext "%s is not allowed to be empty.
")" "pkgver"
1180 if [[ -z $pkgrel ]]; then
1181 error
"$(gettext "%s is not allowed to be empty.
")" "pkgrel"
1186 for name
in "${pkgname[@]}"; do
1187 if [[ ${name:0:1} = "-" ]]; then
1188 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgname"
1193 if [[ ${pkgbase:0:1} = "-" ]]; then
1194 error
"$(gettext "%s is not allowed to start with a hyphen.
")" "pkgbase"
1197 if [[ $pkgver != ${pkgver//-/} ]]; then
1198 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgver"
1201 if [[ $pkgrel != ${pkgrel//-/} ]]; then
1202 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgrel"
1206 if [[ $arch != 'any' ]]; then
1207 if ! in_array
$CARCH ${arch[@]}; then
1208 if (( ! IGNOREARCH
)); then
1209 error
"$(gettext "%s is not available
for the
'%s' architecture.
")" "$pkgbase" "$CARCH"
1210 plain
"$(gettext "Note that many packages may need a line added to their
%s
")" "$BUILDSCRIPT"
1211 plain
"$(gettext "such as arch
=('%s').
")" "$CARCH"
1218 for provide
in ${provides[@]}; do
1219 if [[ $provide != ${provide//</} ||
$provide != ${provide//>/} ]]; then
1220 error
"$(gettext "Provides array cannot contain comparison
(< or
>) operators.
")"
1226 for file in "${backup[@]}"; do
1227 if [[ ${file:0:1} = "/" ]]; then
1228 error
"$(gettext "Invalid backup entry
: %s
")" "$file"
1234 for optdepend
in "${optdepends[@]}"; do
1235 pkg
=${optdepend%%:*}
1236 if [[ ! $pkg =~ ^
[[:alnum
:]\
>\
<\
=\.\
+\_\
-]*$
]]; then
1237 error
"$(gettext "Invalid syntax
for optdepend
: '%s'")" "$optdepend"
1242 for i
in 'changelog' 'install'; do
1243 local filelist
=$
(sed -n "s/^[[:space:]]*$i=//p" "$BUILDFILE")
1245 for file in $filelist; do
1246 # evaluate any bash variables used
1248 if [[ ! -f $file ]]; then
1249 error
"$(gettext "%s
file (%s
) does not exist.
")" "${i^}" "$file"
1255 local valid_options
=1
1256 local opt known kopt
1257 for opt
in ${options[@]}; do
1259 # check if option matches a known option or its inverse
1260 for kopt
in ${packaging_options[@]} ${other_options[@]}; do
1261 if [[ ${opt} = ${kopt} || ${opt} = "!${kopt}" ]]; then
1265 if (( ! known )); then
1266 error "$
(gettext "options array contains unknown option '%s'")" "$opt"
1270 if (( ! valid_options )); then
1274 if (( ${#pkgname[@]} > 1 )); then
1275 for pkg in ${pkgname[@]}; do
1276 if [ "$
(type -t package_
${pkg})" != "function" ]; then
1277 error "$
(gettext "missing package function for split package '%s'")" "$pkg"
1283 if [[ -n "${PKGLIST[@]}" ]]; then
1284 for pkg in ${PKGLIST[@]}; do
1285 if ! in_array $pkg ${pkgname[@]}; then
1286 error "$
(gettext "requested package %s is not provided in %s")" "$pkg" "$BUILDFILE"
1298 # Do not update pkgver if --holdver is set, when building a source package, repackaging,
1299 # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w)
1300 if (( HOLDVER || SOURCEONLY || REPKG )) \
1301 || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then
1305 if [[ -z $FORCE_VER ]]; then
1306 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1307 # This will only be used on the first call to makepkg; subsequent
1308 # calls to makepkg via fakeroot will explicitly pass the version
1309 # number to avoid having to determine the version number twice.
1310 # Also do a brief check to make sure we have the VCS tool available.
1312 if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
1313 [ $(type -p darcs) ] || return 0
1314 msg "$
(gettext "Determining latest darcs revision...")"
1315 newpkgver=$(date +%Y%m%d)
1316 elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
1317 [ $(type -p cvs) ] || return 0
1318 msg "$
(gettext "Determining latest cvs revision...")"
1319 newpkgver=$(date +%Y%m%d)
1320 elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
1321 [ $(type -p git) ] || return 0
1322 msg "$
(gettext "Determining latest git revision...")"
1323 newpkgver=$(date +%Y%m%d)
1324 elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
1325 [ $(type -p svn) ] || return 0
1326 msg "$
(gettext "Determining latest svn revision...")"
1327 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1328 elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
1329 [ $(type -p bzr) ] || return 0
1330 msg "$
(gettext "Determining latest bzr revision...")"
1331 newpkgver=$(bzr revno ${_bzrtrunk})
1332 elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
1333 [ $(type -p hg) ] || return 0
1334 msg "$
(gettext "Determining latest hg revision...")"
1335 if [[ -d ./src/$_hgrepo ]] ; then
1340 [[ ! -d ./src/ ]] && mkdir ./src/
1341 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1344 newpkgver=$(hg tip --template "{rev}")
1348 if [[ -n $newpkgver ]]; then
1349 msg2 "$
(gettext "Version found: %s")" "$newpkgver"
1353 # Version number retrieved from fakeroot->makepkg argument
1354 newpkgver=$FORCE_VER
1359 # This is lame, but if we're wanting to use an updated pkgver for
1360 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1361 # the new pkgver and then re-source it. This is the most robust
1362 # method for dealing with PKGBUILDs that use, e.g.:
1368 if [[ -n $newpkgver ]]; then
1369 if [[ $newpkgver != $pkgver ]]; then
1370 if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
1371 sed -i "s
/^pkgver
=[^
]*/pkgver
=$newpkgver/" "$BUILDFILE"
1372 sed -i "s
/^pkgrel
=[^
]*/pkgrel
=1/" "$BUILDFILE"
1379 backup_package_variables() {
1380 for var in ${splitpkg_overrides[@]}; do
1381 indirect="${var}_backup
"
1382 eval "${indirect}=(\"\
${$var[@]}\")"
1386 restore_package_variables() {
1387 for var in ${splitpkg_overrides[@]}; do
1388 indirect="${var}_backup
"
1389 if [[ -n ${!indirect} ]]; then
1390 eval "${var}=(\"\
${$indirect[@]}\")"
1397 # getopt like parser
1399 local short_options=$1; shift;
1400 local long_options=$1; shift;
1402 local unused_options=""
1404 while [[ -n $1 ]]; do
1405 if [[ ${1:0:2} = '--' ]]; then
1406 if [[ -n ${1:2} ]]; then
1408 for i in ${long_options//,/ }; do
1409 if [[ ${1:2} = ${i//:} ]]; then
1414 if [[ -n $match ]]; then
1415 if [[ ${1:2} = $match ]]; then
1418 if [[ -n $2 ]]; then
1423 echo "makepkg
: option
'$1' $
(gettext "requires an argument")" >&2
1428 echo "makepkg
: $
(gettext "unrecognized option") '$1'" >&2
1435 elif [[ ${1:0:1} = '-' ]]; then
1436 for ((i=1; i<${#1}; i++)); do
1437 if [[ $short_options =~ ${1:i:1} ]]; then
1438 if [[ $short_options =~ "${1:i:1}:" ]]; then
1439 if [[ -n ${1:$i+1} ]]; then
1440 printf ' -%s' "${1:i:1}"
1441 printf " '%s'" "${1:$i+1}"
1443 if [[ -n $2 ]]; then
1444 printf ' -%s' "${1:i:1}"
1446 printf " '%s'" "${1}"
1448 echo "makepkg
: option $
(gettext "requires an argument") -- '${1:i:1}'" >&2
1454 printf ' -%s' "${1:i:1}"
1457 echo "makepkg
: $
(gettext "invalid option") -- '${1:i:1}'" >&2
1462 unused_options="${unused_options} '$1'"
1468 if [[ -n $unused_options ]]; then
1469 for i in ${unused_options[@]}; do
1473 if [[ -n $1 ]]; then
1474 while [[ -n $1 ]]; do
1475 printf " '%s'" "${1}"
1485 printf "makepkg
(pacman
) %s
\n" "$myver"
1487 printf "$
(gettext "Usage: %s [options]")\n" "$0"
1489 echo "$
(gettext "Options:")"
1490 printf "$
(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
1491 echo "$
(gettext " -c, --clean Clean up work files after build")"
1492 echo "$
(gettext " -C, --cleancache Clean up source files from the cache")"
1493 echo "$
(gettext " -d, --nodeps Skip all dependency checks")"
1494 echo "$
(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
1495 echo "$
(gettext " -f, --force Overwrite existing package")"
1496 echo "$
(gettext " -g, --geninteg Generate integrity checks for source files")"
1497 echo "$
(gettext " -h, --help This help")"
1498 echo "$
(gettext " -i, --install Install package after successful build")"
1499 echo "$
(gettext " -L, --log Log package build process")"
1500 echo "$
(gettext " -m, --nocolor Disable colorized output messages")"
1501 echo "$
(gettext " -o, --nobuild Download and extract files only")"
1502 printf "$
(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1503 echo "$
(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1504 echo "$
(gettext " -R, --repackage Repackage contents of the package without rebuilding")"
1505 echo "$
(gettext " -s, --syncdeps Install missing dependencies with pacman")"
1506 echo "$
(gettext " --allsource Generate a source-only tarball including downloaded sources")"
1507 echo "$
(gettext " --asroot Allow makepkg to run as root user")"
1508 printf "$
(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf
"
1509 echo "$
(gettext " --holdver Prevent automatic version bumping for development PKGBUILDs")"
1510 echo "$
(gettext " --pkg <list> Only build listed packages from a split package")"
1511 echo "$
(gettext " --skipinteg Do not fail when integrity checks are missing")"
1512 echo "$
(gettext " --source Generate a source-only tarball without downloaded sources")"
1514 echo "$
(gettext "These options can be passed to pacman:")"
1516 echo "$
(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1517 echo "$
(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1519 printf "$
(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1524 printf "makepkg
(pacman
) %s
\n" "$myver"
1525 printf "$
(gettext "\
1526 Copyright (c) 2006-2010 Pacman Development Team <pacman-dev@archlinux.org>.\n\
1527 Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1528 This is free software; see the source for copying conditions.\n\
1529 There is NO WARRANTY, to the extent permitted by law.\n")"
1534 # determine whether we have gettext; make it a no-op if we do not
1535 if [ ! $(type -t gettext) ]; then
1543 # Parse Command Line Options.
1544 OPT_SHORT="AcCdefFghiLmop
:rRsV
"
1545 OPT_LONG="allsource
,asroot
,ignorearch
,clean
,cleancache
,nodeps
"
1546 OPT_LONG="$OPT_LONG,noextract
,force
,forcever
:,geninteg
,help,holdver
"
1547 OPT_LONG="$OPT_LONG,install,log
,nocolor
,nobuild
,pkg
:,rmdeps
,repackage
,skipinteg
"
1548 OPT_LONG="$OPT_LONG,source,syncdeps
,version
,config
:"
1550 OPT_LONG="$OPT_LONG,noconfirm
,noprogressbar
"
1551 OPT_TEMP="$
(parse_options
$OPT_SHORT $OPT_LONG "$@" ||
echo 'PARSE_OPTIONS FAILED')"
1552 if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then
1553 # This is a small hack to stop the script bailing with 'set -e'
1554 echo; usage; exit 1 # E_INVALID_OPTION;
1556 eval set -- "$OPT_TEMP"
1557 unset OPT_SHORT OPT_LONG OPT_TEMP
1562 --noconfirm) PACMAN_OPTS="$PACMAN_OPTS --noconfirm" ;;
1563 --noprogressbar) PACMAN_OPTS="$PACMAN_OPTS --noprogressbar" ;;
1566 --allsource) SOURCEONLY=2 ;;
1567 --asroot) ASROOT=1 ;;
1568 -A|--ignorearch) IGNOREARCH=1 ;;
1569 -c|--clean) CLEANUP=1 ;;
1570 -C|--cleancache) CLEANCACHE=1 ;;
1571 --config) shift; MAKEPKG_CONF=$1 ;;
1572 -d|--nodeps) NODEPS=1 ;;
1573 -e|--noextract) NOEXTRACT=1 ;;
1574 -f|--force) FORCE=1 ;;
1575 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1576 --forcever) shift; FORCE_VER=$1;;
1578 -g|--geninteg) GENINTEG=1 ;;
1579 --holdver) HOLDVER=1 ;;
1580 -i|--install) INSTALL=1 ;;
1581 -L|--log) LOGGING=1 ;;
1582 -m|--nocolor) USE_COLOR='n' ;;
1583 -o|--nobuild) NOBUILD=1 ;;
1584 -p) shift; BUILDFILE=$1 ;;
1585 --pkg) shift; PKGLIST=$1 ;;
1586 -r|--rmdeps) RMDEPS=1 ;;
1587 -R|--repackage) REPKG=1 ;;
1588 --skipinteg) SKIPINTEG=1 ;;
1589 --source) SOURCEONLY=1 ;;
1590 -s|--syncdeps) DEP_BIN=1 ;;
1592 -h|--help) usage; exit 0 ;; # E_OK
1593 -V|--version) version; exit 0 ;; # E_OK
1595 --) OPT_IND=0; shift; break;;
1596 *) usage; exit 1 ;; # E_INVALID_OPTION
1601 #preserve environment variables
1604 _SRCPKGDEST=${SRCPKGDEST}
1606 # default config is makepkg.conf
1607 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1609 # Source the config file; fail if it is not found
1610 if [[ -r $MAKEPKG_CONF ]]; then
1611 source "$MAKEPKG_CONF"
1613 error "$
(gettext "%s not found.")" "$MAKEPKG_CONF"
1614 plain "$
(gettext "Aborting...")"
1615 exit 1 # $E_CONFIG_ERROR
1618 # Source user-specific makepkg.conf overrides
1619 if [[ -r ~/.makepkg.conf ]]; then
1620 source ~/.makepkg.conf
1623 # set pacman command if not already defined
1624 PACMAN=${PACMAN:-pacman}
1626 # check if messages are to be printed using color
1627 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
1628 if [[ -t 2 && ! $USE_COLOR = "n
" && $(check_buildenv color) = "y
" ]]; then
1629 ALL_OFF="$
(tput sgr0
)"
1631 BLUE="${BOLD}$
(tput setaf
4)"
1632 GREEN="${BOLD}$
(tput setaf
2)"
1633 RED="${BOLD}$
(tput setaf
1)"
1634 YELLOW="${BOLD}$
(tput setaf
3)"
1636 readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
1638 # override settings with an environment variable for batch processing
1639 PKGDEST=${_PKGDEST:-$PKGDEST}
1640 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1641 if [[ ! -w $PKGDEST ]]; then
1642 error "$
(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
1643 plain "$
(gettext "Aborting...")"
1647 SRCDEST=${_SRCDEST:-$SRCDEST}
1648 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1649 if [[ ! -w $SRCDEST ]] ; then
1650 error "$
(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
1651 plain "$
(gettext "Aborting...")"
1655 SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
1656 SRCPKGDEST=${SRCPKGDEST:-$PKGDEST} #default to $PKGDEST if undefined
1659 if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
1660 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1661 error "$
(gettext "\\0--holdver and --forcever cannot both be specified" )"
1665 if (( CLEANCACHE )); then
1666 #fix flyspray feature request #5223
1667 if [[ -n $SRCDEST && $SRCDEST != $startdir ]]; then
1668 msg "$
(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1669 echo -n "$
(gettext " Are you sure you wish to do this? ")"
1670 echo -n "$
(gettext "[y/N]")"
1672 answer="${answer^^}"
1673 if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then
1676 error "$
(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1680 msg "$
(gettext "Source cache cleaned.")"
1685 msg "$
(gettext "No files have been removed.")"
1689 # $SRCDEST is $startdir, two possibilities
1690 error "$
(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
1691 plain "$
(gettext "In addition, please run makepkg -C outside of your cache directory.")"
1696 if (( ! INFAKEROOT )); then
1697 if (( EUID == 0 && ! ASROOT )); then
1698 # Warn those who like to live dangerously.
1699 error "$
(gettext "Running makepkg as root is a BAD idea and can cause")"
1700 plain "$
(gettext "permanent, catastrophic damage to your system. If you")"
1701 plain "$
(gettext "wish to run as root, please use the --asroot option.")"
1702 exit 1 # $E_USER_ABORT
1703 elif (( EUID > 0 && ASROOT )); then
1704 # Warn those who try to use the --asroot option when they are not root
1705 error "$
(gettext "The --asroot option is meant for the root user only.")"
1706 plain "$
(gettext "Please rerun makepkg without the --asroot flag.")"
1707 exit 1 # $E_USER_ABORT
1708 elif [[ $(check_buildenv fakeroot) = "y
" ]] && (( EUID > 0 )); then
1709 if [ ! $(type -p fakeroot) ]; then
1710 error "$
(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
1711 plain "$
(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1714 elif (( EUID > 0 )); then
1715 warning "$
(gettext "Running makepkg as an unprivileged user will result in non-root")"
1716 plain "$
(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
1717 plain "$
(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
1721 if [[ -z $FAKEROOTKEY ]]; then
1722 error "$
(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
1723 exit 1 # TODO: error code
1727 # check for sudo if we will need it during makepkg execution
1728 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
1729 if [ ! "$
(type -p sudo
)" ]; then
1730 warning "$
(gettext "Sudo can not be found. Will use su to acquire root privileges.")"
1734 unset pkgname pkgbase pkgver pkgrel pkgdesc url license groups provides
1735 unset md5sums replaces depends conflicts backup source install changelog build
1736 unset makedepends optdepends options noextract
1738 BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
1739 if [[ ! -f $BUILDFILE ]]; then
1741 error "$
(gettext "%s does not exist.")" "$BUILDFILE"
1744 # PKGBUILD passed through a pipe
1745 BUILDFILE=/dev/stdin
1749 crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true)
1750 if [[ -n $crlftest ]]; then
1751 error "$
(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE"
1755 if [[ ${BUILDFILE:0:1} != "/" ]]; then
1756 BUILDFILE="$startdir/$BUILDFILE"
1761 if (( GENINTEG )); then
1770 # check the PKGBUILD for some basic requirements
1771 check_sanity || exit 1
1773 # We need to run devel_update regardless of whether we are in the fakeroot
1774 # build process so that if the user runs makepkg --forcever manually, we
1775 # 1) output the correct pkgver, and 2) use the correct filename when
1776 # checking if the package file already exists - fixes FS #9194
1780 if (( ${#pkgname[@]} > 1 )); then
1784 # test for available PKGBUILD functions
1785 # The exclamation mark is required here to avoid triggering the ERR trap when
1786 # a tested function does not exist.
1787 if [[ $(! type -t build) = "function" ]]; then
1790 if [ "$
(type -t package
)" = "function" ]; then
1792 elif [ $SPLITPKG -eq 0 -a "$
(type -t package_
${pkgname})" = "function" ]; then
1796 pkgbase=${pkgbase:-${pkgname[0]}}
1798 if [[ -n "${PKGLIST[@]}" ]]; then
1800 pkgname="${PKGLIST[@]}"
1803 if (( ! SPLITPKG )); then
1804 if [[ -f $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} \
1805 || -f $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-any${PKGEXT} ]] \
1806 && ! (( FORCE || SOURCEONLY || NOBUILD )); then
1807 if (( INSTALL )); then
1808 warning "$
(gettext "A package has already been built, installing existing package...")"
1812 error "$
(gettext "A package has already been built. (use -f to overwrite)")"
1819 for pkg in ${pkgname[@]}; do
1820 if [[ -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} \
1821 || -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-any${PKGEXT} ]]; then
1827 if ! (( FORCE || SOURCEONLY || NOBUILD )); then
1828 if (( allpkgbuilt )); then
1829 if (( INSTALL )); then
1830 warning "$
(gettext "The package group has already been built, installing existing packages...")"
1834 error "$
(gettext "The package group has already been built. (use -f to overwrite)")"
1838 if (( somepkgbuilt )); then
1839 error "$
(gettext "Part of the package group has already been built. (use -f to overwrite)")"
1843 unset allpkgbuilt somepkgbuilt
1846 # Run the bare minimum in fakeroot
1847 if (( INFAKEROOT )); then
1848 if (( ! SPLITPKG )); then
1849 if (( ! PKGFUNC )); then
1850 if (( ! REPKG )); then
1851 if (( BUILDFUNC )); then
1856 warning "$
(gettext "Repackaging without the use of a package() function is deprecated.")"
1857 plain "$
(gettext "File permissions may not be preserved.")"
1865 for pkg in ${pkgname[@]}; do
1866 pkgdir="$pkgdir/$pkg"
1869 backup_package_variables
1873 restore_package_variables
1874 pkgdir="${pkgdir%/*}"
1878 msg "$
(gettext "Leaving fakeroot environment.")"
1882 msg "$
(gettext "Making package: %s")" "$pkgbase $pkgver-$pkgrel ($
(date))"
1884 # if we are creating a source-only package, go no further
1885 if (( SOURCEONLY )); then
1886 if [[ -f $SRCPKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT} ]] \
1887 && (( ! FORCE )); then
1888 error "$
(gettext "A source package has already been built. (use -f to overwrite)")"
1892 msg "$
(gettext "Source package created: %s")" "$pkgbase ($
(date))"
1896 if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); then
1897 # no warning message needed for nobuild, repkg
1898 if (( NODEPS || ( REPKG && PKGFUNC ) )); then
1899 warning "$
(gettext "Skipping dependency checks.")"
1901 elif [ $(type -p "${PACMAN%% *}") ]; then
1902 if (( RMDEPS )); then
1903 original_pkglist=($(run_pacman -Qq | sort)) # required by remove_dep
1907 msg "$
(gettext "Checking Runtime Dependencies...")"
1908 resolve_deps ${depends[@]} || deperr=1
1910 msg "$
(gettext "Checking Buildtime Dependencies...")"
1911 resolve_deps ${makedepends[@]} || deperr=1
1913 if (( RMDEPS )); then
1914 current_pkglist=($(run_pacman -Qq | sort)) # required by remove_deps
1917 if (( deperr )); then
1918 error "$
(gettext "Could not resolve all dependencies.")"
1922 warning "$
(gettext "%s was not found in PATH; skipping dependency checks.")" "${PACMAN%% *}"
1925 # ensure we have a sane umask set
1928 # get back to our src directory so we can begin with sources
1933 if (( NOEXTRACT )); then
1934 warning "$
(gettext "Skipping source retrieval -- using existing src/ tree")"
1935 warning "$
(gettext "Skipping source integrity checks -- using existing src/ tree")"
1936 warning "$
(gettext "Skipping source extraction -- using existing src/ tree")"
1938 if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then
1939 error "$
(gettext "The source directory is empty, there is nothing to build!")"
1940 plain "$
(gettext "Aborting...")"
1943 elif (( REPKG )); then
1944 if (( ! PKGFUNC && ! SPLITPKG )) \
1945 && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then
1946 error "$
(gettext "The package directory is empty, there is nothing to repackage!")"
1947 plain "$
(gettext "Aborting...")"
1952 if (( ! SKIPINTEG )); then
1955 warning "$
(gettext "Skipping integrity checks.")"
1960 if (( NOBUILD )); then
1961 msg "$
(gettext "Sources are ready.")"
1964 # check for existing pkg directory; don't remove if we are repackaging
1965 if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then
1966 msg "$
(gettext "Removing existing pkg/ directory...")"
1973 # if we are root or if fakeroot is not enabled, then we don't use it
1974 if [[ $(check_buildenv fakeroot) != "y
" ]] || (( EUID == 0 )); then
1975 if (( ! REPKG )); then
1977 (( BUILDFUNC )) && run_build
1979 if (( ! SPLITPKG )); then
1980 if (( PKGFUNC )); then
1984 if (( ! REPKG )); then
1987 warning "$
(gettext "Repackaging without the use of a package() function is deprecated.")"
1988 plain "$
(gettext "File permissions may not be preserved.")"
1993 for pkg in ${pkgname[@]}; do
1994 pkgdir="$pkgdir/$pkg"
1997 backup_package_variables
2001 restore_package_variables
2002 pkgdir="${pkgdir%/*}"
2006 if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then
2008 (( BUILDFUNC )) && run_build
2012 msg "$
(gettext "Entering fakeroot environment...")"
2014 if [[ -n $newpkgver ]]; then
2015 fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $?
2017 fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
2022 msg "$
(gettext "Finished making: %s")" "$pkgbase $pkgver-$pkgrel ($
(date))"
2028 # vim: set ts=2 sw=2 noet: