3 # makepkg - make packages compatable 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 # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, find (findutils),
31 # getopt (util-linux), gettext, grep, gzip, openssl, sed
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
=('pkgdesc' 'license' 'groups' 'depends' 'optdepends' 'provides' \
50 'conflicts' 'replaces' 'backup' 'options' 'install')
51 readonly -a packaging_options other_options splitpkg_overrides
75 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
76 # when dealing with svn/cvs/etc PKGBUILDs.
85 if [ $COLORMSG -eq 1 ]; then
86 printf "\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
88 printf " ${mesg}\n" "$@" >&2
94 if [ $COLORMSG -eq 1 ]; then
95 printf "\033[1;32m==>\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
97 printf "==> ${mesg}\n" "$@" >&2
103 if [ $COLORMSG -eq 1 ]; then
104 printf "\033[1;34m ->\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
106 printf " -> ${mesg}\n" "$@" >&2
112 if [ $COLORMSG -eq 1 ]; then
113 printf "\033[1;33m==> $(gettext "WARNING
:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
115 printf "==> $(gettext "WARNING
:") ${mesg}\n" "$@" >&2
121 if [ $COLORMSG -eq 1 ]; then
122 printf "\033[1;31m==> $(gettext "ERROR
:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
124 printf "==> $(gettext "ERROR
:") ${mesg}\n" "$@" >&2
130 # Special exit call for traps, Don't print any error messages when inside,
131 # the fakeroot call, the error message will be printed by the main call.
134 if [ "$INFAKEROOT" -eq 0 ]; then
143 # Clean up function. Called automatically when the script exits.
148 if [ "$INFAKEROOT" -eq 1 ]; then
149 # Don't clean up when leaving fakeroot, we're not done yet.
153 if [ $EXIT_CODE -eq 0 -a "$CLEANUP" -eq 1 ]; then
154 # If it's a clean exit and -c/--clean has been passed...
155 msg
"$(gettext "Cleaning up...
")"
156 rm -rf "$pkgdir" "$srcdir"
157 if [ -n "$pkgname" ]; then
158 # Can't do this unless the BUILDSCRIPT has been sourced.
159 rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"*
160 if [ "$PKGFUNC" -eq 1 ]; then
161 rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package.log"*
162 elif [ "$SPLITPKG" -eq 1 ]; then
163 for pkg
in ${pkgname[@]}; do
164 rm -f "${pkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"*
178 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
179 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
180 trap 'trap_exit "$(gettext "An unknown error has occured. Exiting...")"' ERR
182 # a source entry can have two forms :
183 # 1) "filename::http://path/to/file"
184 # 2) "http://path/to/file"
186 # extract the filename from a source entry
188 # if a filename is specified, use it
189 local filename
=$
(echo $1 |
sed 's|::.*||')
190 # if it is just an url, we only keep the last component
191 echo "$filename" |
sed 's|^.*://.*/||g'
194 # extract the url from a source entry
196 # strip an eventual filename
197 echo $1 |
sed 's|.*::||'
201 # Checks to see if options are present in makepkg.conf or PKGBUILD;
202 # PKGBUILD options always take precedence.
204 # usage : check_option( $option )
205 # return : y - enabled
210 local ret
=$
(in_opt_array
"$1" ${options[@]})
211 if [ "$ret" != '?' ]; then
216 # fall back to makepkg.conf options
217 ret
=$
(in_opt_array
"$1" ${OPTIONS[@]})
218 if [ "$ret" != '?' ]; then
228 # Check if option is present in BUILDENV
230 # usage : check_buildenv( $option )
231 # return : y - enabled
236 echo $
(in_opt_array
"$1" ${BUILDENV[@]})
241 # usage : in_opt_array( $needle, $haystack )
242 # return : y - enabled
247 local needle
=$
(echo $1 |
tr '[:upper:]' '[:lower:]'); shift
251 opt
=$
(echo $opt |
tr '[:upper:]' '[:lower:]')
252 if [ "$opt" = "$needle" ]; then
255 elif [ "$opt" = "!$needle" ]; then
266 # usage : in_array( $needle, $haystack )
271 local needle
=$1; shift
272 [ -z "$1" ] && return 1 # Not Found
275 [ "$item" = "$needle" ] && return 0 # Found
280 get_downloadclient
() {
281 # $1 = url with valid protocol prefix
283 local proto
=$
(echo "$url" |
sed 's|://.*||')
285 # loop through DOWNLOAD_AGENTS variable looking for protocol
287 for i
in "${DLAGENTS[@]}"; do
288 local handler
=$
(echo $i |
sed 's|::.*||')
289 if [ "$proto" = "$handler" ]; then
290 agent
=$
(echo $i |
sed 's|^.*::||')
295 # if we didn't find an agent, return an error
296 if [ -z "$agent" ]; then
297 error
"$(gettext "There is no agent
set up to handle
%s URLs. Check
%s.
")" "$proto" "$MAKEPKG_CONF"
298 plain
"$(gettext "Aborting...
")"
299 exit 1 # $E_CONFIG_ERROR
302 # ensure specified program is installed
303 local program
="$(echo $agent | awk '{print $1 }')"
304 if [ ! -x "$program" ]; then
305 local baseprog
=$
(basename $program)
306 error
"$(gettext "The download program
%s is not installed.
")" "$baseprog"
307 plain
"$(gettext "Aborting...
")"
308 exit 1 # $E_MISSING_PROGRAM
321 # temporary download file, default to last component of the url
322 local dlfile
=$
(echo "$url" |
sed 's|^.*://.*/||g')
324 # replace %o by the temporary dlfile if it exists
325 if echo "$dlcmd" |
grep -q "%o" ; then
326 dlcmd
=${dlcmd//\%o/$file.part}
329 # add the url, either in place of %u or at the end
330 if echo "$dlcmd" |
grep -q "%u" ; then
331 dlcmd
=${dlcmd//\%u/$url}
338 # rename the temporary download file to the final destination
339 if [ "$dlfile" != "$file" ]; then
340 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
345 [ $# -gt 0 ] ||
return
347 pmout
=$
(pacman
$PACMAN_OPTS -T "$@")
349 if [ $ret -eq 127 ]; then #unresolved deps
351 elif [ $ret -ne 0 ]; then
352 error
"$(gettext "Pacman returned a fatal error
(%i
): %s
")" "$ret" "$pmout"
358 local R_DEPS_SATISFIED
=0
359 local R_DEPS_MISSING
=1
361 [ $# -eq 0 ] && return $R_DEPS_SATISFIED
365 if [ "$DEP_BIN" -eq 0 ]; then
366 return $R_DEPS_MISSING
369 if [ "$DEP_BIN" -eq 1 ]; then
370 # install missing deps from binary packages (using pacman -S)
371 msg
"$(gettext "Installing missing dependencies...
")"
374 if [ "$ASROOT" -eq 0 ]; then
375 sudo pacman
$PACMAN_OPTS -S --asdeps $deplist || ret
=$?
377 pacman
$PACMAN_OPTS -S --asdeps $deplist || ret
=$?
380 if [ $ret -ne 0 ]; then
381 error
"$(gettext "Pacman failed to
install missing dependencies.
")"
382 exit 1 # TODO: error code
386 # we might need the new system environment
387 # set -e can cause problems during sourcing profile scripts
389 source /etc
/profile
&>/dev
/null
392 return $R_DEPS_SATISFIED
396 # $pkgdeps is a GLOBAL variable, used by remove_deps()
397 local R_DEPS_SATISFIED
=0
398 local R_DEPS_MISSING
=1
400 local deplist
="$(check_deps $*)"
401 if [ -z "$deplist" ]; then
402 return $R_DEPS_SATISFIED
405 if handledeps
$deplist; then
406 pkgdeps
="$pkgdeps $deplist"
407 # check deps again to make sure they were resolved
408 deplist
="$(check_deps $*)"
409 [ -z "$deplist" ] && return $R_DEPS_SATISFIED
410 elif [ "$DEP_BIN" -eq 1 ]; then
411 error
"$(gettext "Failed to
install all missing dependencies.
")"
414 msg
"$(gettext "Missing Dependencies
:")"
416 for dep
in $deplist; do
420 return $R_DEPS_MISSING
423 # fix flyspray bug #5923
425 # $pkgdeps is a GLOBAL variable, set by resolve_deps()
426 [ "$RMDEPS" -eq 0 ] && return
427 [ -z "$pkgdeps" ] && return
429 local dep depstrip deplist
431 for dep
in $pkgdeps; do
432 depstrip
=$
(echo $dep |
sed -e 's|=.*$||' -e 's|>.*$||' -e 's|<.*$||')
433 deplist
="$deplist $depstrip"
436 msg
"Removing installed dependencies..."
438 if [ "$ASROOT" -eq 0 ]; then
439 sudo pacman
$PACMAN_OPTS -Rns $deplist || ret
=$?
441 pacman
$PACMAN_OPTS -Rns $deplist || ret
=$?
444 # Fixes FS#10039 - exit cleanly as package has built successfully
445 if [ $ret -ne 0 ]; then
446 warning
"$(gettext "Failed to remove installed dependencies.
")"
452 msg
"$(gettext "Retrieving Sources...
")"
454 if [ ! -w "$SRCDEST" ] ; then
455 error
"$(gettext "You
do not have
write permission to store downloads
in %s.
")" "$SRCDEST"
456 plain
"$(gettext "Aborting...
")"
460 pushd "$SRCDEST" &>/dev
/null
463 for netfile
in "${source[@]}"; do
464 local file=$
(get_filename
"$netfile")
465 local url
=$
(get_url
"$netfile")
466 if [ -f "$startdir/$file" ]; then
467 msg2
"$(gettext "Found
%s
in build dir
")" "$file"
468 rm -f "$srcdir/$file"
469 ln -s "$startdir/$file" "$srcdir/"
471 elif [ -f "$SRCDEST/$file" ]; then
472 msg2
"$(gettext "Using cached copy of
%s
")" "$file"
473 rm -f "$srcdir/$file"
474 ln -s "$SRCDEST/$file" "$srcdir/"
478 # if we get here, check to make sure it was a URL, else fail
479 if [ "$file" = "$url" ]; then
480 error
"$(gettext "%s was not found
in the build directory and is not a URL.
")" "$file"
481 exit 1 # $E_MISSING_FILE
484 # find the client we should use for this URL
485 local dlclient
=$
(get_downloadclient
"$url") ||
exit $?
487 msg2
"$(gettext "Downloading
%s...
")" "$file"
488 # fix flyspray bug #3289
490 download_file
"$dlclient" "$url" "$file" || ret
=$?
491 if [ $ret -gt 0 ]; then
492 error
"$(gettext "Failure
while downloading
%s
")" "$file"
493 plain
"$(gettext "Aborting...
")"
496 rm -f "$srcdir/$file"
497 ln -s "$SRCDEST/$file" "$srcdir/"
503 generate_checksums
() {
504 msg
"$(gettext "Generating checksums
for source files...
")"
507 if [ ! $
(type -p openssl
) ]; then
508 error
"$(gettext "Cannot
find openssl.
")"
509 exit 1 # $E_MISSING_PROGRAM
513 for integ
in ${INTEGRITY_CHECK[@]}; do
514 integ
="$(echo $integ | tr '[:upper:]' '[:lower:]')"
516 md5|sha1|sha256|sha384|sha512
) : ;;
518 error
"$(gettext "Invalid integrity algorithm
'%s' specified.
")" "$integ"
519 exit 1;; # $E_CONFIG_ERROR
523 local numsrc
=${#source[@]}
524 echo -n "${integ}sums=("
528 while [ $i -lt $
((${#integ}+6)) ]; do
534 for netfile
in "${source[@]}"; do
535 local file="$(get_filename "$netfile")"
537 if [ ! -f "$file" ] ; then
538 if [ ! -f "$SRCDEST/$file" ] ; then
539 error
"$(gettext "Unable to
find source file %s to generate checksum.
")" "$file"
540 plain
"$(gettext "Aborting...
")"
543 file="$SRCDEST/$file"
547 local sum="$(openssl dgst -${integ} "$file" | awk '{print $NF}')"
548 [ $ct -gt 0 ] && echo -n "$indent"
551 [ $ct -lt $numsrc ] && echo
559 [ ${#source[@]} -eq 0 ] && return 0
561 if [ ! $
(type -p openssl
) ]; then
562 error
"$(gettext "Cannot
find openssl.
")"
563 exit 1 # $E_MISSING_PROGRAM
568 for integ
in md5 sha1 sha256 sha384 sha512
; do
569 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
570 if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then
571 msg
"$(gettext "Validating
source files with
%s...
")" "${integ}sums"
576 for file in "${source[@]}"; do
578 file="$(get_filename "$file")"
579 echo -n " $file ... " >&2
581 if [ ! -f "$file" ] ; then
582 if [ ! -f "$SRCDEST/$file" ] ; then
583 echo "$(gettext "NOT FOUND
")" >&2
587 file="$SRCDEST/$file"
591 if [ $found -gt 0 ] ; then
592 local expectedsum
="$(echo ${integrity_sums[$idx]} | tr '[A-F]' '[a-f]')"
593 local realsum
="$(openssl dgst -${integ} "$file" | awk '{print $NF}')"
594 if [ "$expectedsum" = "$realsum" ]; then
595 echo "$(gettext "Passed
")" >&2
597 echo "$(gettext "FAILED
")" >&2
605 if [ $errors -gt 0 ]; then
606 error
"$(gettext "One or
more files did not pass the validity check
!")"
607 exit 1 # TODO: error code
609 elif [ ${#integrity_sums[@]} -gt 0 ]; then
610 error
"$(gettext "Integrity checks
(%s
) differ
in size from the
source array.
")" "$integ"
611 exit 1 # TODO: error code
615 if [ $correlation -eq 0 ]; then
616 error
"$(gettext "Integrity checks are missing.
")"
617 exit 1 # TODO: error code
622 msg
"$(gettext "Extracting Sources...
")"
624 for netfile
in "${source[@]}"; do
625 file=$
(get_filename
"$netfile")
626 if in_array
"$file" ${noextract[@]}; then
627 #skip source files in the noextract=() array
628 # these are marked explicitly to NOT be extracted
632 if [ ! -f "$file" ] ; then
633 if [ ! -f "$SRCDEST/$file" ] ; then
634 error
"$(gettext "Unable to
find source file %s
for extraction.
")" "$file"
635 plain
"$(gettext "Aborting...
")"
638 file="$SRCDEST/$file"
643 local file_type
=$
(file -bizL "$file")
646 *application
/x-tar
*|
*application
/zip*|
*application
/x-zip
*|
*application
/x-cpio
*)
647 cmd
="bsdtar -x -f $file" ;;
648 *application
/x-gzip
*)
649 cmd
="gunzip -d -f $file" ;;
650 *application
/x-bzip
*)
651 cmd
="bunzip2 -f $file" ;;
653 cmd
="xz -d -f $file" ;;
655 # Don't know what to use to extract this file,
656 # skip to the next file
663 if [ $ret -ne 0 ]; then
664 error
"$(gettext "Failed to extract
%s
")" "$file"
665 plain
"$(gettext "Aborting...
")"
670 if [ $EUID -eq 0 ]; then
671 # change perms of all source files to root user & root group
672 chown
-R 0:0 "$srcdir"
677 # use distcc if it is requested (check buildenv and PKGBUILD opts)
678 if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then
679 [ -d /usr
/lib
/distcc
/bin
] && export PATH
="/usr/lib/distcc/bin:$PATH"
681 elif [ "$(check_option distcc)" = "n" ]; then
682 # if it is not wanted, clear the makeflags too
686 # use ccache if it is requested (check buildenv and PKGBUILD opts)
687 if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then
688 [ -d /usr
/lib
/ccache
/bin
] && export PATH
="/usr/lib/ccache/bin:$PATH"
691 # clear user-specified makeflags if requested
692 if [ "$(check_option makeflags)" = "n" ]; then
696 msg
"$(gettext "Starting build
()...
")"
699 # ensure all necessary build variables are exported
700 export CFLAGS CXXFLAGS MAKEFLAGS LDFLAGS CHOST
701 # save our shell options so build() can't override what we need
702 local shellopts
=$
(shopt -p)
705 if [ "$LOGGING" -eq 1 ]; then
706 BUILDLOG
="${startdir}/${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"
707 if [ -f "$BUILDLOG" ]; then
710 if [ -f "$BUILDLOG.$i" ]; then
716 mv "$BUILDLOG" "$BUILDLOG.$i"
719 build
2>&1 |
tee "$BUILDLOG"; ret
=${PIPESTATUS[0]}
721 # piping to cat ensures makepkg fails on any build error
722 build
2>&1 |
cat -; ret
=${PIPESTATUS[0]}
725 # reset our shell options
728 if [ $ret -gt 0 ]; then
729 error
"$(gettext "Build Failed.
")"
730 plain
"$(gettext "Aborting...
")"
732 exit 2 # $E_BUILD_FAILED
745 # clear user-specified makeflags if requested
746 if [ "$(check_option makeflags)" = "n" ]; then
750 msg
"$(gettext "Starting
%s
()...
")" "$pkgfunc"
753 # ensure all necessary build variables are exported
754 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
757 if [ "$LOGGING" -eq 1 ]; then
758 BUILDLOG
="${startdir}/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"
759 if [ -f "$BUILDLOG" ]; then
762 if [ -f "$BUILDLOG.$i" ]; then
768 mv "$BUILDLOG" "$BUILDLOG.$i"
771 # ensure overridden package variables suvrive tee with split packages
772 logpipe
=$
(mktemp
-u "$startdir/logpipe.XXXXXXXX")
775 tee "$BUILDLOG" < "$logpipe" &
776 exec 1>"$logpipe" 2>"$logpipe"
777 $pkgfunc 2>&1 |
cat -; ret
=${PIPESTATUS[0]}
782 $pkgfunc 2>&1 |
cat -; ret
=${PIPESTATUS[0]}
785 if [ $ret -gt 0 ]; then
786 error
"$(gettext "Packaging Failed.
")"
787 plain
"$(gettext "Aborting...
")"
789 exit 2 # $E_BUILD_FAILED
795 msg
"$(gettext "Tidying
install...
")"
797 if [ "$(check_option docs)" = "n" -a -n "${DOC_DIRS[*]}" ]; then
798 msg2
"$(gettext "Removing doc files...
")"
799 rm -rf ${DOC_DIRS[@]}
802 if [ "$(check_option purge)" = "y" -a -n "${PURGE_TARGETS[*]}" ]; then
803 msg2
"$(gettext "Purging other files...
")"
805 for pt
in "${PURGE_TARGETS[@]}"; do
806 if [ "${pt}" = "${pt//\/}" ]; then
807 find .
-type f
-name "${pt}" -exec rm -f -- '{}' \
;
814 if [ "$(check_option zipman)" = "y" -a -n "${MAN_DIRS[*]}" ]; then
815 msg2
"$(gettext "Compressing man and info pages...
")"
816 local manpage ext
file link hardlinks hl
817 find ${MAN_DIRS[@]} -type f
2>/dev
/null |
818 while read manpage
; do
819 # check file still exists (potentially compressed with hard link)
820 if [ -f ${manpage} ]; then
822 file="${manpage##*/}"
823 if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then
824 # update symlinks to this manpage
825 find ${MAN_DIRS[@]} -lname "$file" 2>/dev
/null |
828 ln -sf "${file}.gz" "${link}.gz"
830 # find hard links and remove them
831 # the '|| true' part keeps the script from bailing if find returned an
832 # error, such as when one of the man directories doesn't exist
833 hardlinks
="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
834 for hl
in ${hardlinks}; do
837 # compress the original
839 # recreate hard links removed earlier
840 for hl
in ${hardlinks}; do
841 ln "${manpage}.gz" "${hl}.gz"
849 if [ "$(check_option strip)" = "y" -a -n "${STRIP_DIRS[*]}" ]; then
850 msg2
"$(gettext "Stripping debugging symbols from binaries and libraries...
")"
852 find ${STRIP_DIRS[@]} -type f
2>/dev
/null |
while read binary
; do
853 case "$(file -biz "$binary")" in
854 *compressed-encoding
*) # Skip compressed binarys
856 *application
/x-sharedlib
*) # Libraries (.so)
857 /usr
/bin
/strip
-S "$binary";;
858 *application
/x-archive
*) # Libraries (.a)
859 /usr
/bin
/strip
-S "$binary";;
860 *application
/x-executable
*) # Binaries
861 /usr
/bin
/strip
"$binary";;
866 if [ "$(check_option libtool)" = "n" ]; then
867 msg2
"$(gettext "Removing libtool .la files...
")"
868 find .
! -type d
-name "*.la" -exec rm -f -- '{}' \
;
871 if [ "$(check_option emptydirs)" = "n" ]; then
872 msg2
"$(gettext "Removing empty directories...
")"
873 find .
-depth -type d
-empty -delete
878 local builddate
=$
(date -u "+%s")
879 if [ -n "$PACKAGER" ]; then
880 local packager
="$PACKAGER"
882 local packager
="Unknown Packager"
884 local size
=$
(du
-sk |
awk '{print $1 * 1024}')
886 msg2
"$(gettext "Generating .PKGINFO
file...
")"
887 echo "# Generated by makepkg $myver" >.PKGINFO
888 if [ "$INFAKEROOT" -eq 1 ]; then
889 echo "# using $(fakeroot -v)" >>.PKGINFO
891 echo "# $(LC_ALL=C date -u)" >>.PKGINFO
892 echo "pkgname = $1" >>.PKGINFO
893 echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO
894 echo "pkgdesc = $pkgdesc" >>.PKGINFO
895 echo "url = $url" >>.PKGINFO
896 echo "builddate = $builddate" >>.PKGINFO
897 echo "packager = $packager" >>.PKGINFO
898 echo "size = $size" >>.PKGINFO
899 if [ -n "$CARCH" ]; then
900 echo "arch = $CARCH" >>.PKGINFO
902 if [ "$(check_option force)" = "y" ]; then
903 echo "force = true" >> .PKGINFO
907 for it
in "${license[@]}"; do
908 echo "license = $it" >>.PKGINFO
910 for it
in "${replaces[@]}"; do
911 echo "replaces = $it" >>.PKGINFO
913 for it
in "${groups[@]}"; do
914 echo "group = $it" >>.PKGINFO
916 for it
in "${depends[@]}"; do
917 echo "depend = $it" >>.PKGINFO
919 for it
in "${optdepends[@]}"; do
920 echo "optdepend = $it" >>.PKGINFO
922 for it
in "${conflicts[@]}"; do
923 echo "conflict = $it" >>.PKGINFO
925 for it
in "${provides[@]}"; do
926 echo "provides = $it" >>.PKGINFO
928 for it
in "${backup[@]}"; do
929 echo "backup = $it" >>.PKGINFO
931 for it
in "${packaging_options[@]}"; do
932 local ret
="$(check_option $it)"
933 if [ "$ret" != "?" ]; then
934 if [ "$ret" = "y" ]; then
935 echo "makepkgopt = $it" >>.PKGINFO
937 echo "makepkgopt = !$it" >>.PKGINFO
942 # TODO maybe remove this at some point
943 # warn if license array is not present or empty
944 if [ -z "$license" ]; then
945 warning
"$(gettext "Please add a license line to your
%s
!")" "$BUILDSCRIPT"
946 plain
"$(gettext "Example
for GPL
\'ed software
: license
=('GPL').
")"
951 if [ ! -d "$pkgdir" ]; then
952 error
"$(gettext "Missing pkg
/ directory.
")"
953 plain
"$(gettext "Aborting...
")"
954 exit 1 # $E_MISSING_PKGDIR
963 write_pkginfo
$nameofpkg
966 msg
"$(gettext "Creating package...
")"
968 local comp_files
=".PKGINFO"
970 # check for an install script
971 if [ -n "$install" ]; then
972 msg2
"$(gettext "Adding
install script...
")"
973 cp "$startdir/$install" .INSTALL
974 comp_files
="$comp_files .INSTALL"
977 # do we have a changelog?
978 if [ -f "$startdir/ChangeLog" ]; then
979 msg2
"$(gettext "Adding package changelog...
")"
980 cp "$startdir/ChangeLog" .CHANGELOG
981 comp_files
="$comp_files .CHANGELOG"
985 msg2
"$(gettext "Compressing package...
")"
988 *tar.gz
) EXT
=${PKGEXT%.gz} ;;
989 *tar.bz2
) EXT
=${PKGEXT%.bz2} ;;
990 *tar.xz
) EXT
=${PKGEXT%.xz} ;;
991 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
992 "$PKGEXT" ; EXT
=$PKGEXT ;;
994 local pkg_file
="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}${EXT}"
998 # when fileglobbing, we want * in an empty directory to expand to
999 # the null string rather than itself
1001 bsdtar
-cf - $comp_files * > "$pkg_file" || ret
=$?
1004 if [ $ret -eq 0 ]; then
1006 *tar.gz
) gzip -f -n "$pkg_file" ;;
1007 *tar.bz2
) bzip2 -f "$pkg_file" ;;
1008 *tar.xz
) xz
-z -f "$pkg_file" ;;
1013 if [ $ret -ne 0 ]; then
1014 error
"$(gettext "Failed to create package
file.
")"
1015 exit 1 # TODO: error code
1019 create_srcpackage
() {
1022 # Get back to our src directory so we can begin with sources.
1026 # We can only check checksums if we have all files.
1030 msg
"$(gettext "Creating
source package...
")"
1031 local srclinks
="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1032 mkdir
"${srclinks}"/${pkgbase}
1034 msg2
"$(gettext "Adding
%s...
")" "$BUILDSCRIPT"
1035 ln -s "${startdir}/${BUILDSCRIPT}" "${srclinks}/${pkgbase}/"
1037 if [ -n "$install" ]; then
1038 if [ -f $install ]; then
1039 msg2
"$(gettext "Adding
install script...
")"
1040 ln -s "${startdir}/$install" "${srclinks}/${pkgbase}/"
1042 error
"$(gettext "Install
script %s not found.
")" "$install"
1046 if [ -f ChangeLog
]; then
1047 msg2
"$(gettext "Adding
%s...
")" "ChangeLog"
1048 ln -s "${startdir}/ChangeLog" "${srclinks}/${pkgbase}"
1052 for netfile
in "${source[@]}"; do
1053 local file=$
(get_filename
"$netfile")
1054 if [ -f "$netfile" ]; then
1055 msg2
"$(gettext "Adding
%s...
")" "$netfile"
1056 ln -s "${startdir}/$netfile" "${srclinks}/${pkgbase}"
1057 elif [ "$SOURCEONLY" -eq 2 -a -f "$SRCDEST/$file" ]; then
1058 msg2
"$(gettext "Adding
%s...
")" "$file"
1059 ln -s "$SRCDEST/$file" "${srclinks}/${pkgbase}/"
1065 *tar.gz
) TAR_OPT
="z" ;;
1066 *tar.bz2
) TAR_OPT
="j" ;;
1067 *tar.xz
) TAR_OPT
="J" ;;
1068 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
1072 local pkg_file
="$PKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}"
1075 msg2
"$(gettext "Compressing
source package...
")"
1077 if ! bsdtar
-c${TAR_OPT}Lf
"$pkg_file" ${pkgbase}; then
1078 error
"$(gettext "Failed to create
source package
file.
")"
1079 exit 1 # TODO: error code
1082 rm -rf "${srclinks}"
1086 [ "$INSTALL" -eq 0 ] && return
1088 if [ "$SPLITPKG" -eq 0 ]; then
1089 msg
"$(gettext "Installing package
${pkgname} with pacman
-U...
")"
1091 msg
"$(gettext "Installing
${pkgbase} package group with pacman
-U...
")"
1095 for pkg
in ${pkgname[@]}; do
1096 pkglist
="${pkglist} $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
1100 if [ "$ASROOT" -eq 0 ]; then
1101 sudo pacman
$PACMAN_OPTS -U ${pkglist} || ret
=$?
1103 pacman
$PACMAN_OPTS -U ${pkglist} || ret
=$?
1106 if [ $ret -ne 0 ]; then
1107 warning
"$(gettext "Failed to
install built package
(s
).
")"
1113 # check for no-no's in the build script
1114 if [ -z "$pkgname" ]; then
1115 error
"$(gettext "%s is not allowed to be empty.
")" "pkgname"
1118 if [ -z "$pkgver" ]; then
1119 error
"$(gettext "%s is not allowed to be empty.
")" "pkgver"
1122 if [ -z "$pkgrel" ]; then
1123 error
"$(gettext "%s is not allowed to be empty.
")" "pkgrel"
1126 if [ "$pkgver" != "${pkgver//-/}" ]; then
1127 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgver"
1130 if [ "$pkgrel" != "${pkgrel//-/}" ]; then
1131 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgrel"
1135 if [ "$arch" = 'any' ]; then
1139 pkgbase
=${pkgbase:-${pkgname[0]}}
1141 if ! in_array
$CARCH ${arch[@]}; then
1142 if [ "$IGNOREARCH" -eq 0 ]; then
1143 error
"$(gettext "%s is not available
for the
'%s' architecture.
")" "$pkgbase" "$CARCH"
1144 plain
"$(gettext "Note that many packages may need a line added to their
%s
")" "$BUILDSCRIPT"
1145 plain
"$(gettext "such as arch
=('%s').
")" "$CARCH"
1151 for provide
in ${provides[@]}; do
1152 if [ $provide != ${provide//</} -o $provide != ${provide//>/} ]; then
1153 error
"$(gettext "Provides array cannot contain comparison
(< or
>) operators.
")"
1158 if [ "$install" -a ! -f "$install" ]; then
1159 error
"$(gettext "Install scriptlet
(%s
) does not exist.
")" "$install"
1163 local valid_options
=1
1164 local opt known kopt
1165 for opt
in ${options[@]}; do
1167 # check if option matches a known option or its inverse
1168 for kopt
in ${packaging_options[@]} ${other_options[@]}; do
1169 if [ "${opt}" = "${kopt}" -o "${opt}" = "!${kopt}" ]; then
1173 if [ $known -eq 0 ]; then
1174 error
"$(gettext "options array contains unknown option
'%s'")" "$opt"
1178 if [ $valid_options -eq 0 ]; then
1188 # Do not update pkgver if --holdver is set, when building a source package,
1189 # or when reading PKGBUILD from pipe
1190 if [ "$HOLDVER" -eq 1 -o "$SOURCEONLY" -ne 0 -o ! -f "./$BUILDSCRIPT" ]; then
1194 if [ -z "$FORCE_VER" ]; then
1195 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1196 # This will only be used on the first call to makepkg; subsequent
1197 # calls to makepkg via fakeroot will explicitly pass the version
1198 # number to avoid having to determine the version number twice.
1199 # Also do a brief check to make sure we have the VCS tool available.
1201 if [ -n "${_darcstrunk}" -a -n "${_darcsmod}" ] ; then
1202 [ $
(type -p darcs
) ] ||
return 0
1203 msg
"$(gettext "Determining latest darcs revision...
")"
1204 newpkgver
=$
(date +%Y
%m
%d
)
1205 elif [ -n "${_cvsroot}" -a -n "${_cvsmod}" ] ; then
1206 [ $
(type -p cvs
) ] ||
return 0
1207 msg
"$(gettext "Determining latest cvs revision...
")"
1208 newpkgver
=$
(date +%Y
%m
%d
)
1209 elif [ -n "${_gitroot}" -a -n "${_gitname}" ] ; then
1210 [ $
(type -p git
) ] ||
return 0
1211 msg
"$(gettext "Determining latest git revision...
")"
1212 newpkgver
=$
(date +%Y
%m
%d
)
1213 elif [ -n "${_svntrunk}" -a -n "${_svnmod}" ] ; then
1214 [ $
(type -p svn
) ] ||
return 0
1215 msg
"$(gettext "Determining latest svn revision...
")"
1216 newpkgver
=$
(LC_ALL
=C svn info
$_svntrunk |
sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1217 elif [ -n "${_bzrtrunk}" -a -n "${_bzrmod}" ] ; then
1218 [ $
(type -p bzr
) ] ||
return 0
1219 msg
"$(gettext "Determining latest bzr revision...
")"
1220 newpkgver
=$
(bzr revno
${_bzrtrunk})
1221 elif [ -n "${_hgroot}" -a -n "${_hgrepo}" ] ; then
1222 [ $
(type -p hg
) ] ||
return 0
1223 msg
"$(gettext "Determining latest hg revision...
")"
1224 if [ -d .
/src
/$_hgrepo ] ; then
1229 [[ ! -d .
/src
/ ]] && mkdir .
/src
/
1230 hg clone
$_hgroot/$_hgrepo .
/src
/$_hgrepo
1233 newpkgver
=$
(hg tip
--template "{rev}")
1237 if [ -n "$newpkgver" ]; then
1238 msg2
"$(gettext "Version found
: %s
")" "$newpkgver"
1242 # Version number retrieved from fakeroot->makepkg argument
1243 newpkgver
=$FORCE_VER
1248 # This is lame, but if we're wanting to use an updated pkgver for
1249 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1250 # the new pkgver and then re-source it. This is the most robust
1251 # method for dealing with PKGBUILDs that use, e.g.:
1257 if [ -n "$newpkgver" ]; then
1258 if [ "$newpkgver" != "$pkgver" ]; then
1259 if [ -f "./$BUILDSCRIPT" ]; then
1260 @SEDINPLACE@
"s/^pkgver=[^ ]*/pkgver=$newpkgver/" "./$BUILDSCRIPT"
1261 @SEDINPLACE@
"s/^pkgrel=[^ ]*/pkgrel=1/" "./$BUILDSCRIPT"
1262 source "$BUILDSCRIPT"
1268 backup_package_variables
() {
1269 for var
in ${splitpkg_overrides[@]}; do
1270 indirect
="${var}_backup"
1271 eval "${indirect}=(\${$var[@]})"
1275 restore_package_variables
() {
1276 for var
in ${splitpkg_overrides[@]}; do
1277 indirect
="${var}_backup"
1278 if [ -n "${!indirect}" ]; then
1279 eval "${var}=(\${$indirect[@]})"
1285 # pkgdesc gets restored as an array - convert back to a string
1286 local pkgdesc_backup
="${pkgdesc[@]}"
1288 pkgdesc
=${pkgdesc_backup}
1291 # getopt like parser
1293 local short_options
=$1; shift;
1294 local long_options
=$1; shift;
1296 local unused_options
=""
1298 while [ -n "$1" ]; do
1299 if [ ${1:0:2} = '--' ]; then
1300 if [ -n "${1:2}" ]; then
1302 for i
in ${long_options//,/ }; do
1303 if [ ${1:2} = ${i//:} ]; then
1308 if [ -n "$match" ]; then
1309 if [ ${1:2} = $match ]; then
1312 if [ -n "$2" ]; then
1317 echo "makepkg: option '$1' $(gettext "requires an argument
")" >&2
1322 echo "makepkg: $(gettext "unrecognized option
") '$1'" >&2
1329 elif [ ${1:0:1} = '-' ]; then
1330 for ((i
=1; i
<${#1}; i
++)); do
1331 if [[ "$short_options" =~
"${1:i:1}" ]]; then
1332 if [[ "$short_options" =~
"${1:i:1}:" ]]; then
1333 if [ -n "${1:$i+1}" ]; then
1334 printf ' -%s' "${1:i:1}"
1335 printf " '%s'" "${1:$i+1}"
1337 if [ -n "$2" ]; then
1338 printf ' -%s' "${1:i:1}"
1340 printf " '%s'" "${1}"
1342 echo "makepkg: option $(gettext "requires an argument
") -- '${1:i:1}'" >&2
1348 printf ' -%s' "${1:i:1}"
1351 echo "makepkg: $(gettext "invalid option
") -- '${1:i:1}'" >&2
1356 unused_options
="${unused_options} '$1'"
1362 if [ -n "$unused_options" ]; then
1363 for i
in ${unused_options[@]}; do
1367 if [ -n "$1" ]; then
1368 while [ -n "$1" ]; do
1369 printf " '%s'" "${1}"
1379 printf "makepkg (pacman) %s\n" "$myver"
1381 printf "$(gettext "Usage
: %s
[options
]")\n" "$0"
1383 echo "$(gettext "Options
:")"
1384 printf "$(gettext " -A, --ignorearch Ignore incomplete arch field
in %s
")\n" "$BUILDSCRIPT"
1385 echo "$(gettext " -c, --clean Clean up work files after build
")"
1386 echo "$(gettext " -C, --cleancache Clean up
source files from the cache
")"
1387 printf "$(gettext " --config <config
> Use an alternate config
file (instead of
'%s')")\n" "$confdir/makepkg.conf"
1388 echo "$(gettext " -d, --nodeps Skip all dependency checks
")"
1389 echo "$(gettext " -e, --noextract Do not extract
source files
(use existing src
/ dir
)")"
1390 echo "$(gettext " -f, --force Overwrite existing package
")"
1391 echo "$(gettext " -g, --geninteg Generate integrity checks
for source files
")"
1392 echo "$(gettext " -h, --help This
help")"
1393 echo "$(gettext " -i, --install Install package after successful build
")"
1394 echo "$(gettext " -L, --log Log package build process
")"
1395 echo "$(gettext " -m, --nocolor Disable colorized output messages
")"
1396 echo "$(gettext " -o, --nobuild Download and extract files only
")"
1397 printf "$(gettext " -p <buildscript
> Use an alternate build
script (instead of
'%s')")\n" "$BUILDSCRIPT"
1398 echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build
")"
1399 # fix flyspray feature request #2978
1400 echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding
")"
1401 echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman
")"
1402 echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources
")"
1403 echo "$(gettext " --asroot Allow makepkg to run as root user
")"
1404 echo "$(gettext " --holdver Prevent automatic version bumping
for development PKGBUILDs
")"
1405 echo "$(gettext " --source Generate a source-only tarball without downloaded sources
")"
1407 echo "$(gettext "These options can be passed to pacman
:")"
1409 echo "$(gettext " --noconfirm Do not ask
for confirmation when resolving dependencies
")"
1410 echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files
")"
1412 printf "$(gettext "If
-p is not specified
, makepkg will
look for '%s'")\n" "$BUILDSCRIPT"
1417 printf "makepkg (pacman) %s\n" "$myver"
1418 printf "$(gettext "\
1419 Copyright
(c
) 2006-2009 Pacman Development Team
<pacman-dev@archlinux.org
>.
\n\
1420 Copyright
(C
) 2002-2006 Judd Vinet
<jvinet@zeroflux.org
>.
\n\n\
1421 This is free software
; see the
source for copying conditions.
\n\
1422 There is NO WARRANTY
, to the extent permitted by law.
\n")"
1427 # determine whether we have gettext; make it a no-op if we do not
1428 if [ ! $
(type -t gettext) ]; then
1436 # Parse Command Line Options.
1437 OPT_SHORT
="AbcCdefFghiLmop:rRsV"
1438 OPT_LONG
="allsource,asroot,ignorearch,builddeps,clean,cleancache,nodeps"
1439 OPT_LONG
="$OPT_LONG,noextract,force,forcever:,geninteg,help,holdver"
1440 OPT_LONG
="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source"
1441 OPT_LONG
="$OPT_LONG,syncdeps,version,config:"
1443 OPT_LONG
="$OPT_LONG,noconfirm,noprogressbar"
1444 OPT_TEMP
="$(parse_options $OPT_SHORT $OPT_LONG "$@
" || echo 'PARSE_OPTIONS FAILED')"
1445 if echo "$OPT_TEMP" |
grep -q 'PARSE_OPTIONS FAILED'; then
1446 # This is a small hack to stop the script bailing with 'set -e'
1447 echo; usage
; exit 1 # E_INVALID_OPTION;
1449 eval set -- "$OPT_TEMP"
1450 unset OPT_SHORT OPT_LONG OPT_TEMP
1455 --noconfirm) PACMAN_OPTS
="$PACMAN_OPTS --noconfirm" ;;
1456 --noprogressbar) PACMAN_OPTS
="$PACMAN_OPTS --noprogressbar" ;;
1459 --allsource) SOURCEONLY
=2 ;;
1460 --asroot) ASROOT
=1 ;;
1461 -A|
--ignorearch) IGNOREARCH
=1 ;;
1462 -c|
--clean) CLEANUP
=1 ;;
1463 -C|
--cleancache) CLEANCACHE
=1 ;;
1464 --config) shift; MAKEPKG_CONF
=$1 ;;
1465 -d|
--nodeps) NODEPS
=1 ;;
1466 -e|
--noextract) NOEXTRACT
=1 ;;
1467 -f|
--force) FORCE
=1 ;;
1468 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1469 --forcever) shift; FORCE_VER
=$1;;
1471 -g|
--geninteg) GENINTEG
=1 ;;
1472 --holdver) HOLDVER
=1 ;;
1473 -i|
--install) INSTALL
=1 ;;
1474 -L|
--log) LOGGING
=1 ;;
1475 -m|
--nocolor) USE_COLOR
='n' ;;
1476 -o|
--nobuild) NOBUILD
=1 ;;
1477 -p) shift; BUILDSCRIPT
=$1 ;;
1478 -r|
--rmdeps) RMDEPS
=1 ;;
1479 -R|
--repackage) REPKG
=1 ;;
1480 --source) SOURCEONLY
=1 ;;
1481 -s|
--syncdeps) DEP_BIN
=1 ;;
1483 -h|
--help) usage
; exit 0 ;; # E_OK
1484 -V|
--version) version
; exit 0 ;; # E_OK
1486 --) OPT_IND
=0; shift; break;;
1487 *) usage
; exit 1 ;; # E_INVALID_OPTION
1492 #preserve environment variables
1496 # default config is makepkg.conf
1497 MAKEPKG_CONF
=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1499 # Source the config file; fail if it is not found
1500 if [ -r "$MAKEPKG_CONF" ]; then
1501 source "$MAKEPKG_CONF"
1503 error
"$(gettext "%s not found.
")" "$MAKEPKG_CONF"
1504 plain
"$(gettext "Aborting...
")"
1505 exit 1 # $E_CONFIG_ERROR
1508 # Source user-specific makepkg.conf overrides
1509 if [ -r ~
/.makepkg.conf
]; then
1510 source ~
/.makepkg.conf
1513 # check if messages are to be printed using color
1514 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
1518 # override settings with an environment variable for batch processing
1519 PKGDEST
=${_PKGDEST:-$PKGDEST}
1520 PKGDEST
=${PKGDEST:-$startdir} #default to $startdir if undefined
1521 SRCDEST
=${_SRCDEST:-$SRCDEST}
1522 SRCDEST
=${SRCDEST:-$startdir} #default to $startdir if undefined
1525 if [ "$HOLDVER" -eq 1 -a -n "$FORCE_VER" ]; then
1526 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1527 error
"$(gettext "\\0--holdver and
--forcever cannot both be specified
" )"
1531 if [ "$CLEANCACHE" -eq 1 ]; then
1532 #fix flyspray feature request #5223
1533 if [ -n "$SRCDEST" -a "$SRCDEST" != "$startdir" ]; then
1534 msg
"$(gettext "Cleaning up ALL files from
%s.
")" "$SRCDEST"
1535 echo -n "$(gettext " Are you sure you wish to
do this?
")"
1536 echo -n "$(gettext "[Y
/n
]")"
1538 answer
=$
(echo $answer |
tr '[:lower:]' '[:upper:]')
1539 if [ "$answer" = "$(gettext "YES
")" -o "$answer" = "$(gettext "Y
")" ]; then
1541 if [ $?
-ne 0 ]; then
1542 error
"$(gettext "Problem removing files
; you may not have correct permissions
in %s
")" "$SRCDEST"
1546 msg
"$(gettext "Source cache cleaned.
")"
1551 msg
"$(gettext "No files have been removed.
")"
1555 # $SRCDEST is $startdir, two possibilities
1556 error
"$(gettext "Source destination must be defined
in %s.
")" "$MAKEPKG_CONF"
1557 plain
"$(gettext "In addition
, please run makepkg
-C outside of your cache directory.
")"
1562 if [ -z "$BUILDSCRIPT" ]; then
1563 error
"$(gettext "BUILDSCRIPT is undefined
! Ensure you have updated
%s.
")" "$MAKEPKG_CONF"
1567 if [ "$INFAKEROOT" -eq 0 ]; then
1568 if [ $EUID -eq 0 -a "$ASROOT" -eq 0 ]; then
1569 # Warn those who like to live dangerously.
1570 error
"$(gettext "Running makepkg as root is a BAD idea and can cause
")"
1571 plain
"$(gettext "permanent
, catastrophic damage to your system. If you
")"
1572 plain
"$(gettext "wish to run as root
, please use the
--asroot option.
")"
1573 exit 1 # $E_USER_ABORT
1574 elif [ $EUID -gt 0 -a "$ASROOT" -eq 1 ]; then
1575 # Warn those who try to use the --asroot option when they are not root
1576 error
"$(gettext "The
--asroot option is meant
for the root user only.
")"
1577 plain
"$(gettext "Please rerun makepkg without the
--asroot flag.
")"
1578 exit 1 # $E_USER_ABORT
1579 elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then
1580 if [ ! $
(type -p fakeroot
) ]; then
1581 error
"$(gettext "Fakeroot must be installed
if using the
'fakeroot' option
")"
1582 plain
"$(gettext "in the BUILDENV array
in %s.
")" "$MAKEPKG_CONF"
1585 elif [ $EUID -gt 0 ]; then
1586 warning
"$(gettext "Running makepkg as an unprivileged user will result
in non-root
")"
1587 plain
"$(gettext "ownership of the packaged files. Try using the fakeroot environment by
")"
1588 plain
"$(gettext "placing
'fakeroot' in the BUILDENV array
in %s.
")" "$MAKEPKG_CONF"
1592 if [ -z "$FAKEROOTKEY" ]; then
1593 error
"$(gettext "Do not use the
'-F' option. This option is only
for use by makepkg.
")"
1594 exit 1 # TODO: error code
1598 # check for sudo if we will need it during makepkg execution
1599 if [ "$ASROOT" -eq 0 \
1600 -a \
( "$DEP_BIN" -eq 1 -o "$RMDEPS" -eq 1 -o "$INSTALL" -eq 1 \
) ]; then
1601 if [ ! "$(type -p sudo)" ]; then
1602 error
"$(gettext "Cannot
find the sudo binary
! Is sudo installed?
")"
1603 plain
"$(gettext "Missing dependencies cannot be installed or removed as a normal user
")"
1604 plain
"$(gettext "without sudo
; install and configure sudo to auto-resolve dependencies.
")"
1609 unset pkgname pkgbase pkgver pkgrel pkgdesc url license groups provides
1610 unset md5sums replaces depends conflicts backup
source install build
1611 unset makedepends optdepends options noextract
1613 if [ ! -f "$BUILDSCRIPT" ]; then
1615 error
"$(gettext "%s does not exist.
")" "$BUILDSCRIPT"
1618 # PKGBUILD passed through a pipe
1619 BUILDSCRIPT
=/dev
/stdin
1620 source "$BUILDSCRIPT"
1623 crlftest
=$
(file $BUILDSCRIPT |
grep -F 'CRLF' || true
)
1624 if [ -n "$crlftest" ]; then
1625 error
"$(gettext "%s contains CRLF characters and cannot be sourced.
")" "$BUILDSCRIPT"
1629 source .
/"$BUILDSCRIPT"
1632 if [ "$GENINTEG" -eq 1 ]; then
1640 if [ "$(type -t package)" = "function" ]; then
1644 # check the PKGBUILD for some basic requirements
1645 check_sanity ||
exit 1
1647 # We need to run devel_update regardless of whether we are in the fakeroot
1648 # build process so that if the user runs makepkg --forcever manually, we
1649 # 1) output the correct pkgver, and 2) use the correct filename when
1650 # checking if the package file already exists - fixes FS #9194
1654 if [ "${#pkgname[@]}" -gt "1" ]; then
1658 if [ "$SPLITPKG" -eq 0 ]; then
1659 if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \
1660 -a "$FORCE" -eq 0 -a "$SOURCEONLY" -eq 0 -a "$NOBUILD" -eq 0 ]; then
1661 if [ "$INSTALL" -eq 1 ]; then
1662 warning
"$(gettext "A package has already been built
, installing existing package...
")"
1666 error
"$(gettext "A package has already been built.
(use
-f to overwrite
)")"
1673 for pkg
in ${pkgname[@]}; do
1674 if [ -f "$PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" ]; then
1680 if [ "$FORCE" -eq 0 -a "$SOURCEONLY" -eq 0 -a "$NOBUILD" -eq 0 ]; then
1681 if [ "$allpkgbuilt" -eq 1 ]; then
1682 if [ "$INSTALL" -eq 1 ]; then
1683 warning
"$(gettext "The package group has already been built
, installing existing packages...
")"
1687 error
"$(gettext "The package group has already been built.
(use
-f to overwrite
)")"
1691 if [ "$somepkgbuilt" -eq 1 ]; then
1692 error
"$(gettext "Part of the package group has already been built.
(use
-f to overwrite
)")"
1696 unset allpkgbuilt somepkgbuilt
1699 # Run the bare minimum in fakeroot
1700 if [ "$INFAKEROOT" -eq 1 ]; then
1701 if [ "$SPLITPKG" -eq 0 ]; then
1702 if [ "$PKGFUNC" -eq 0 ]; then
1703 if [ "$REPKG" -eq 0 ]; then
1713 for pkg
in ${pkgname[@]}; do
1714 pkgdir
="$pkgdir/$pkg"
1716 backup_package_variables
1720 restore_package_variables
1721 pkgdir
="${pkgdir%/*}"
1725 msg
"$(gettext "Leaving fakeroot environment.
")"
1729 msg
"$(gettext "Making package
: %s
")" "$pkgbase $pkgver-$pkgrel $CARCH ($(date))"
1731 # if we are creating a source-only package, go no further
1732 if [ "$SOURCEONLY" -ne 0 ]; then
1733 if [ -f "$PKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}" \
1734 -a "$FORCE" -eq 0 ]; then
1735 error
"$(gettext "A package has already been built.
(use
-f to overwrite
)")"
1739 msg
"$(gettext "Source package created
: %s
")" "$pkgbase ($(date))"
1743 # fix flyspray bug #5973
1744 if [ "$NODEPS" -eq 1 -o "$NOBUILD" -eq 1 -o "$REPKG" -eq 1 ]; then
1745 # no warning message needed for nobuild, repkg
1746 if [ "$NODEPS" -eq 1 ]; then
1747 warning
"$(gettext "Skipping dependency checks.
")"
1749 elif [ $
(type -p pacman
) ]; then
1750 unset pkgdeps
# Set by resolve_deps() and used by remove_deps()
1753 msg
"$(gettext "Checking Runtime Dependencies...
")"
1754 resolve_deps
${depends[@]} || deperr
=1
1756 msg
"$(gettext "Checking Buildtime Dependencies...
")"
1757 resolve_deps
${makedepends[@]} || deperr
=1
1759 if [ $deperr -eq 1 ]; then
1760 error
"$(gettext "Could not resolve all dependencies.
")"
1764 warning
"$(gettext "pacman was not found
in PATH
; skipping dependency checks.
")"
1767 # ensure we have a sane umask set
1770 # get back to our src directory so we can begin with sources
1774 if [ "$NOEXTRACT" -eq 1 ]; then
1775 warning
"$(gettext "Skipping
source retrieval
-- using existing src
/ tree
")"
1776 warning
"$(gettext "Skipping
source integrity checks
-- using existing src
/ tree
")"
1777 warning
"$(gettext "Skipping
source extraction
-- using existing src
/ tree
")"
1779 if [ "$NOEXTRACT" -eq 1 -a -z "$(ls "$srcdir" 2>/dev/null)" ]; then
1780 error
"$(gettext "The
source directory is empty
, there is nothing to build
!")"
1781 plain
"$(gettext "Aborting...
")"
1784 elif [ "$REPKG" -eq 1 ]; then
1785 if [ "$PKGFUNC" -eq 0 -a "$SPLITPKG" -eq 0 \
1786 -a \
( ! -d "$pkgdir" -o -z "$(ls "$pkgdir" 2>/dev/null)" \
) ]; then
1787 error
"$(gettext "The package directory is empty
, there is nothing to repackage
!")"
1788 plain
"$(gettext "Aborting...
")"
1797 if [ "$NOBUILD" -eq 1 ]; then
1798 msg
"$(gettext "Sources are ready.
")"
1801 # check for existing pkg directory; don't remove if we are repackaging
1803 -a \
( "$REPKG" -eq 0 -o "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \
) ]; then
1804 msg
"$(gettext "Removing existing pkg
/ directory...
")"
1810 # if we are root or if fakeroot is not enabled, then we don't use it
1811 if [ "$(check_buildenv fakeroot)" != "y" -o $EUID -eq 0 ]; then
1812 if [ "$REPKG" -eq 0 ]; then
1816 if [ "$SPLITPKG" -eq 0 ]; then
1817 if [ "$PKGFUNC" -eq 1 ]; then
1820 elif [ "$REPKG" -eq 0 ]; then
1825 for pkg
in ${pkgname[@]}; do
1826 pkgdir
="$pkgdir/$pkg"
1828 backup_package_variables
1832 restore_package_variables
1833 pkgdir
="${pkgdir%/*}"
1837 if [ "$REPKG" -eq 0 -a \
( "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \
) ]; then
1843 msg
"$(gettext "Entering fakeroot environment...
")"
1845 if [ -n "$newpkgver" ]; then
1846 fakeroot
-- $0 --forcever $newpkgver -F $ARGLIST ||
exit $?
1848 fakeroot
-- $0 -F $ARGLIST ||
exit $?
1853 msg
"$(gettext "Finished making
: %s
")" "$pkgbase $pkgver-$pkgrel $CARCH ($(date))"
1859 # vim: set ts=2 sw=2 noet: