3 # makepkg - make packages compatable for use with pacman
6 # Copyright (c) 2002-2008 by Judd Vinet <jvinet@zeroflux.org>
7 # Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
8 # Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
9 # Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
10 # Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk>
11 # Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org>
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 # makepkg uses quite a few external programs during its execution. You
28 # need to have at least the following installed for makepkg to function:
29 # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, find (findutils),
30 # getopt (util-linux), gettext, grep, gzip, openssl, sed
32 # gettext initialization
33 export TEXTDOMAIN
='pacman'
34 export TEXTDOMAINDIR
='@localedir@'
36 # file -i does not work on Mac OSX unless legacy mode is set
37 export COMMAND_MODE
='legacy'
39 myver
='@PACKAGE_VERSION@'
40 confdir
='@sysconfdir@'
41 BUILDSCRIPT
='@BUILDSCRIPT@'
43 srcdir
="$startdir/src"
44 pkgdir
="$startdir/pkg"
46 packaging_options
=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge')
47 other_options
=('ccache' 'distcc' 'makeflags' 'force')
48 splitpkg_overrides
=('pkgdesc' 'license' 'groups' 'depends' 'optdepends' 'provides' \
49 'conflicts' 'replaces' 'backup' 'options' 'install')
50 readonly -a packaging_options other_options splitpkg_overrides
74 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
75 # when dealing with svn/cvs/etc PKGBUILDs.
84 if [ $COLORMSG -eq 1 ]; then
85 printf "\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
87 printf " ${mesg}\n" "$@" >&2
93 if [ $COLORMSG -eq 1 ]; then
94 printf "\033[1;32m==>\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
96 printf "==> ${mesg}\n" "$@" >&2
102 if [ $COLORMSG -eq 1 ]; then
103 printf "\033[1;34m ->\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
105 printf " -> ${mesg}\n" "$@" >&2
111 if [ $COLORMSG -eq 1 ]; then
112 printf "\033[1;33m==> $(gettext "WARNING
:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
114 printf "==> $(gettext "WARNING
:") ${mesg}\n" "$@" >&2
120 if [ $COLORMSG -eq 1 ]; then
121 printf "\033[1;31m==> $(gettext "ERROR
:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
123 printf "==> $(gettext "ERROR
:") ${mesg}\n" "$@" >&2
129 # Special exit call for traps, Don't print any error messages when inside,
130 # the fakeroot call, the error message will be printed by the main call.
133 if [ "$INFAKEROOT" -eq 0 ]; then
142 # Clean up function. Called automatically when the script exits.
147 if [ "$INFAKEROOT" -eq 1 ]; then
148 # Don't clean up when leaving fakeroot, we're not done yet.
152 if [ $EXIT_CODE -eq 0 -a "$CLEANUP" -eq 1 ]; then
153 # If it's a clean exit and -c/--clean has been passed...
154 msg
"$(gettext "Cleaning up...
")"
155 rm -rf "$pkgdir" "$srcdir"
156 if [ -n "$pkgname" ]; then
157 # Can't do this unless the BUILDSCRIPT has been sourced.
158 rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"*
159 if [ "$PKGFUNC" -eq 1 ]; then
160 rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package.log"*
161 elif [ "$SPLITPKG" -eq 1 ]; then
162 for pkg
in ${pkgname[@]}; do
163 rm -f "${pkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"*
177 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
178 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
179 trap 'trap_exit "$(gettext "An unknown error has occured. Exiting...")"' ERR
181 # a source entry can have two forms :
182 # 1) "filename::http://path/to/file"
183 # 2) "http://path/to/file"
185 # extract the filename from a source entry
187 # if a filename is specified, use it
188 local filename
=$
(echo $1 |
sed 's|::.*||')
189 # if it is just an url, we only keep the last component
190 echo "$filename" |
sed 's|^.*://.*/||g'
193 # extract the url from a source entry
195 # strip an eventual filename
196 echo $1 |
sed 's|.*::||'
200 # Checks to see if options are present in makepkg.conf or PKGBUILD;
201 # PKGBUILD options always take precedence.
203 # usage : check_option( $option )
204 # return : y - enabled
209 local ret
=$
(in_opt_array
"$1" ${options[@]})
210 if [ "$ret" != '?' ]; then
215 # fall back to makepkg.conf options
216 ret
=$
(in_opt_array
"$1" ${OPTIONS[@]})
217 if [ "$ret" != '?' ]; then
227 # Check if option is present in BUILDENV
229 # usage : check_buildenv( $option )
230 # return : y - enabled
235 echo $
(in_opt_array
"$1" ${BUILDENV[@]})
240 # usage : in_opt_array( $needle, $haystack )
241 # return : y - enabled
246 local needle
=$
(echo $1 |
tr '[:upper:]' '[:lower:]'); shift
250 opt
=$
(echo $opt |
tr '[:upper:]' '[:lower:]')
251 if [ "$opt" = "$needle" ]; then
254 elif [ "$opt" = "!$needle" ]; then
265 # usage : in_array( $needle, $haystack )
270 local needle
=$1; shift
271 [ -z "$1" ] && return 1 # Not Found
274 [ "$item" = "$needle" ] && return 0 # Found
279 get_downloadclient
() {
280 # $1 = url with valid protocol prefix
282 local proto
=$
(echo "$url" |
sed 's|://.*||')
284 # loop through DOWNLOAD_AGENTS variable looking for protocol
286 for i
in "${DLAGENTS[@]}"; do
287 local handler
=$
(echo $i |
sed 's|::.*||')
288 if [ "$proto" = "$handler" ]; then
289 agent
=$
(echo $i |
sed 's|^.*::||')
294 # if we didn't find an agent, return an error
295 if [ -z "$agent" ]; then
296 error
"$(gettext "There is no agent
set up to handle
%s URLs. Check
%s.
")" "$proto" "$MAKEPKG_CONF"
297 plain
"$(gettext "Aborting...
")"
298 exit 1 # $E_CONFIG_ERROR
301 # ensure specified program is installed
302 local program
="$(echo $agent | awk '{print $1 }')"
303 if [ ! -x "$program" ]; then
304 local baseprog
=$
(basename $program)
305 error
"$(gettext "The download program
%s is not installed.
")" "$baseprog"
306 plain
"$(gettext "Aborting...
")"
307 exit 1 # $E_MISSING_PROGRAM
320 # temporary download file, default to last component of the url
321 local dlfile
=$
(echo "$url" |
sed 's|^.*://.*/||g')
323 # replace %o by the temporary dlfile if it exists
324 if echo "$dlcmd" |
grep -q "%o" ; then
325 dlcmd
=${dlcmd//\%o/$file.part}
328 # add the url, either in place of %u or at the end
329 if echo "$dlcmd" |
grep -q "%u" ; then
330 dlcmd
=${dlcmd//\%u/$url}
337 # rename the temporary download file to the final destination
338 if [ "$dlfile" != "$file" ]; then
339 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
344 [ $# -gt 0 ] ||
return
346 pmout
=$
(pacman
$PACMAN_OPTS -T "$@")
348 if [ $ret -eq 127 ]; then #unresolved deps
350 elif [ $ret -ne 0 ]; then
351 error
"$(gettext "Pacman returned a fatal error
(%i
): %s
")" "$ret" "$pmout"
357 local R_DEPS_SATISFIED
=0
358 local R_DEPS_MISSING
=1
360 [ $# -eq 0 ] && return $R_DEPS_SATISFIED
364 if [ "$DEP_BIN" -eq 0 ]; then
365 return $R_DEPS_MISSING
368 if [ "$DEP_BIN" -eq 1 ]; then
369 # install missing deps from binary packages (using pacman -S)
370 msg
"$(gettext "Installing missing dependencies...
")"
373 if [ "$ASROOT" -eq 0 ]; then
374 sudo pacman
$PACMAN_OPTS -S --asdeps $deplist || ret
=$?
376 pacman
$PACMAN_OPTS -S --asdeps $deplist || ret
=$?
379 if [ $ret -ne 0 ]; then
380 error
"$(gettext "Pacman failed to
install missing dependencies.
")"
381 exit 1 # TODO: error code
385 # we might need the new system environment
386 # set -e can cause problems during sourcing profile scripts
388 source /etc
/profile
&>/dev
/null
391 return $R_DEPS_SATISFIED
395 # $pkgdeps is a GLOBAL variable, used by remove_deps()
396 local R_DEPS_SATISFIED
=0
397 local R_DEPS_MISSING
=1
399 local deplist
="$(check_deps $*)"
400 if [ -z "$deplist" ]; then
401 return $R_DEPS_SATISFIED
404 if handledeps
$deplist; then
405 pkgdeps
="$pkgdeps $deplist"
406 # check deps again to make sure they were resolved
407 deplist
="$(check_deps $*)"
408 [ -z "$deplist" ] && return $R_DEPS_SATISFIED
409 elif [ "$DEP_BIN" -eq 1 ]; then
410 error
"$(gettext "Failed to
install all missing dependencies.
")"
413 msg
"$(gettext "Missing Dependencies
:")"
415 for dep
in $deplist; do
419 return $R_DEPS_MISSING
422 # fix flyspray bug #5923
424 # $pkgdeps is a GLOBAL variable, set by resolve_deps()
425 [ "$RMDEPS" -eq 0 ] && return
426 [ -z "$pkgdeps" ] && return
428 local dep depstrip deplist
430 for dep
in $pkgdeps; do
431 depstrip
=$
(echo $dep |
sed -e 's|=.*$||' -e 's|>.*$||' -e 's|<.*$||')
432 deplist
="$deplist $depstrip"
435 msg
"Removing installed dependencies..."
437 if [ "$ASROOT" -eq 0 ]; then
438 sudo pacman
$PACMAN_OPTS -Rns $deplist || ret
=$?
440 pacman
$PACMAN_OPTS -Rns $deplist || ret
=$?
443 # Fixes FS#10039 - exit cleanly as package has built successfully
444 if [ $ret -ne 0 ]; then
445 warning
"$(gettext "Failed to remove installed dependencies.
")"
451 msg
"$(gettext "Retrieving Sources...
")"
453 if [ ! -w "$SRCDEST" ] ; then
454 error
"$(gettext "You
do not have
write permission to store downloads
in %s.
")" "$SRCDEST"
455 plain
"$(gettext "Aborting...
")"
459 pushd "$SRCDEST" &>/dev
/null
462 for netfile
in "${source[@]}"; do
463 local file=$
(get_filename
"$netfile")
464 local url
=$
(get_url
"$netfile")
465 if [ -f "$startdir/$file" ]; then
466 msg2
"$(gettext "Found
%s
in build dir
")" "$file"
467 rm -f "$srcdir/$file"
468 ln -s "$startdir/$file" "$srcdir/"
470 elif [ -f "$SRCDEST/$file" ]; then
471 msg2
"$(gettext "Using cached copy of
%s
")" "$file"
472 rm -f "$srcdir/$file"
473 ln -s "$SRCDEST/$file" "$srcdir/"
477 # if we get here, check to make sure it was a URL, else fail
478 if [ "$file" = "$url" ]; then
479 error
"$(gettext "%s was not found
in the build directory and is not a URL.
")" "$file"
480 exit 1 # $E_MISSING_FILE
483 # find the client we should use for this URL
484 local dlclient
=$
(get_downloadclient
"$url") ||
exit $?
486 msg2
"$(gettext "Downloading
%s...
")" "$file"
487 # fix flyspray bug #3289
489 download_file
"$dlclient" "$url" "$file" || ret
=$?
490 if [ $ret -gt 0 ]; then
491 error
"$(gettext "Failure
while downloading
%s
")" "$file"
492 plain
"$(gettext "Aborting...
")"
495 rm -f "$srcdir/$file"
496 ln -s "$SRCDEST/$file" "$srcdir/"
502 generate_checksums
() {
503 msg
"$(gettext "Generating checksums
for source files...
")"
506 if [ ! $
(type -p openssl
) ]; then
507 error
"$(gettext "Cannot
find openssl.
")"
508 exit 1 # $E_MISSING_PROGRAM
512 for integ
in ${INTEGRITY_CHECK[@]}; do
513 integ
="$(echo $integ | tr '[:upper:]' '[:lower:]')"
515 md5|sha1|sha256|sha384|sha512
) : ;;
517 error
"$(gettext "Invalid integrity algorithm
'%s' specified.
")" "$integ"
518 exit 1;; # $E_CONFIG_ERROR
522 local numsrc
=${#source[@]}
523 echo -n "${integ}sums=("
527 while [ $i -lt $
((${#integ}+6)) ]; do
533 for netfile
in "${source[@]}"; do
534 local file="$(get_filename "$netfile")"
536 if [ ! -f "$file" ] ; then
537 if [ ! -f "$SRCDEST/$file" ] ; then
538 error
"$(gettext "Unable to
find source file %s to generate checksum.
")" "$file"
539 plain
"$(gettext "Aborting...
")"
542 file="$SRCDEST/$file"
546 local sum="$(openssl dgst -${integ} "$file" | awk '{print $NF}')"
547 [ $ct -gt 0 ] && echo -n "$indent"
550 [ $ct -lt $numsrc ] && echo
558 [ ${#source[@]} -eq 0 ] && return 0
560 if [ ! $
(type -p openssl
) ]; then
561 error
"$(gettext "Cannot
find openssl.
")"
562 exit 1 # $E_MISSING_PROGRAM
567 for integ
in md5 sha1 sha256 sha384 sha512
; do
568 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
569 if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then
570 msg
"$(gettext "Validating
source files with
%s...
")" "${integ}sums"
575 for file in "${source[@]}"; do
577 file="$(get_filename "$file")"
578 echo -n " $file ... " >&2
580 if [ ! -f "$file" ] ; then
581 if [ ! -f "$SRCDEST/$file" ] ; then
582 echo "$(gettext "NOT FOUND
")" >&2
586 file="$SRCDEST/$file"
590 if [ $found -gt 0 ] ; then
591 local expectedsum
="$(echo ${integrity_sums[$idx]} | tr '[A-F]' '[a-f]')"
592 local realsum
="$(openssl dgst -${integ} "$file" | awk '{print $NF}')"
593 if [ "$expectedsum" = "$realsum" ]; then
594 echo "$(gettext "Passed
")" >&2
596 echo "$(gettext "FAILED
")" >&2
604 if [ $errors -gt 0 ]; then
605 error
"$(gettext "One or
more files did not pass the validity check
!")"
606 exit 1 # TODO: error code
608 elif [ ${#integrity_sums[@]} -gt 0 ]; then
609 error
"$(gettext "Integrity checks
(%s
) differ
in size from the
source array.
")" "$integ"
610 exit 1 # TODO: error code
614 if [ $correlation -eq 0 ]; then
615 error
"$(gettext "Integrity checks are missing.
")"
616 exit 1 # TODO: error code
621 msg
"$(gettext "Extracting Sources...
")"
623 for netfile
in "${source[@]}"; do
624 file=$
(get_filename
"$netfile")
625 if in_array
"$file" ${noextract[@]}; then
626 #skip source files in the noextract=() array
627 # these are marked explicitly to NOT be extracted
631 if [ ! -f "$file" ] ; then
632 if [ ! -f "$SRCDEST/$file" ] ; then
633 error
"$(gettext "Unable to
find source file %s
for extraction.
")" "$file"
634 plain
"$(gettext "Aborting...
")"
637 file="$SRCDEST/$file"
642 local file_type
=$
(file -bizL "$file")
645 *application
/x-tar
*|
*application
/zip*|
*application
/x-zip
*|
*application
/x-cpio
*)
646 cmd
="bsdtar -x -f $file" ;;
647 *application
/x-gzip
*)
648 cmd
="gunzip -d -f $file" ;;
649 *application
/x-bzip
*)
650 cmd
="bunzip2 -f $file" ;;
652 cmd
="xz -d -f $file" ;;
654 # Don't know what to use to extract this file,
655 # skip to the next file
662 if [ $ret -ne 0 ]; then
663 error
"$(gettext "Failed to extract
%s
")" "$file"
664 plain
"$(gettext "Aborting...
")"
669 if [ $EUID -eq 0 ]; then
670 # change perms of all source files to root user & root group
671 chown
-R 0:0 "$srcdir"
676 # use distcc if it is requested (check buildenv and PKGBUILD opts)
677 if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then
678 [ -d /usr
/lib
/distcc
/bin
] && export PATH
="/usr/lib/distcc/bin:$PATH"
680 elif [ "$(check_option distcc)" = "n" ]; then
681 # if it is not wanted, clear the makeflags too
685 # use ccache if it is requested (check buildenv and PKGBUILD opts)
686 if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then
687 [ -d /usr
/lib
/ccache
/bin
] && export PATH
="/usr/lib/ccache/bin:$PATH"
690 # clear user-specified makeflags if requested
691 if [ "$(check_option makeflags)" = "n" ]; then
695 msg
"$(gettext "Starting build
()...
")"
698 # ensure all necessary build variables are exported
699 export CFLAGS CXXFLAGS MAKEFLAGS LDFLAGS CHOST
700 # save our shell options so build() can't override what we need
701 local shellopts
=$
(shopt -p)
704 if [ "$LOGGING" -eq 1 ]; then
705 BUILDLOG
="${startdir}/${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"
706 if [ -f "$BUILDLOG" ]; then
709 if [ -f "$BUILDLOG.$i" ]; then
715 mv "$BUILDLOG" "$BUILDLOG.$i"
718 build
2>&1 |
tee "$BUILDLOG"; ret
=${PIPESTATUS[0]}
722 # reset our shell options
725 if [ $ret -gt 0 ]; then
726 error
"$(gettext "Build Failed.
")"
727 plain
"$(gettext "Aborting...
")"
729 exit 2 # $E_BUILD_FAILED
742 # clear user-specified makeflags if requested
743 if [ "$(check_option makeflags)" = "n" ]; then
747 msg
"$(gettext "Starting
%s
()...
")" "$pkgfunc"
750 # ensure all necessary build variables are exported
751 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
754 if [ "$LOGGING" -eq 1 ]; then
755 BUILDLOG
="${startdir}/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"
756 if [ -f "$BUILDLOG" ]; then
759 if [ -f "$BUILDLOG.$i" ]; then
765 mv "$BUILDLOG" "$BUILDLOG.$i"
768 # ensure overridden package variables suvrive tee with split packages
769 logpipe
=$
(mktemp
-u "$startdir/logpipe.XXXXXXXX")
772 tee "$BUILDLOG" < "$logpipe" &
773 exec 1>"$logpipe" 2>"$logpipe"
774 $pkgfunc 2>&1 || ret
=$?
779 $pkgfunc 2>&1 || ret
=$?
782 if [ $ret -gt 0 ]; then
783 error
"$(gettext "Packaging Failed.
")"
784 plain
"$(gettext "Aborting...
")"
786 exit 2 # $E_BUILD_FAILED
792 msg
"$(gettext "Tidying
install...
")"
794 if [ "$(check_option docs)" = "n" -a -n "${DOC_DIRS[*]}" ]; then
795 msg2
"$(gettext "Removing doc files...
")"
796 rm -rf ${DOC_DIRS[@]}
799 if [ "$(check_option purge)" = "y" -a -n "${PURGE_TARGETS[*]}" ]; then
800 msg2
"$(gettext "Purging other files...
")"
802 for pt
in "${PURGE_TARGETS[@]}"; do
803 if [ "${pt}" = "${pt//\/}" ]; then
804 find .
-type f
-name "${pt}" -exec rm -f -- '{}' \
;
811 if [ "$(check_option zipman)" = "y" -a -n "${MAN_DIRS[*]}" ]; then
812 msg2
"$(gettext "Compressing man and info pages...
")"
813 local manpage ext
file link hardlinks hl
814 find ${MAN_DIRS[@]} -type f
2>/dev
/null |
815 while read manpage
; do
816 # check file still exists (potentially compressed with hard link)
817 if [ -f ${manpage} ]; then
819 file="${manpage##*/}"
820 if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then
821 # update symlinks to this manpage
822 find ${MAN_DIRS[@]} -lname "$file" 2>/dev
/null |
825 ln -sf "${file}.gz" "${link}.gz"
827 # find hard links and remove them
828 # the '|| true' part keeps the script from bailing if find returned an
829 # error, such as when one of the man directories doesn't exist
830 hardlinks
="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
831 for hl
in ${hardlinks}; do
834 # compress the original
836 # recreate hard links removed earlier
837 for hl
in ${hardlinks}; do
838 ln "${manpage}.gz" "${hl}.gz"
846 if [ "$(check_option strip)" = "y" -a -n "${STRIP_DIRS[*]}" ]; then
847 msg2
"$(gettext "Stripping debugging symbols from binaries and libraries...
")"
849 find ${STRIP_DIRS[@]} -type f
2>/dev
/null |
while read binary
; do
850 case "$(file -biz "$binary")" in
851 *compressed-encoding
*) # Skip compressed binarys
853 *application
/x-sharedlib
*) # Libraries (.so)
854 /usr
/bin
/strip
-S "$binary";;
855 *application
/x-archive
*) # Libraries (.a)
856 /usr
/bin
/strip
-S "$binary";;
857 *application
/x-executable
*) # Binaries
858 /usr
/bin
/strip
"$binary";;
863 if [ "$(check_option libtool)" = "n" ]; then
864 msg2
"$(gettext "Removing libtool .la files...
")"
865 find .
! -type d
-name "*.la" -exec rm -f -- '{}' \
;
868 if [ "$(check_option emptydirs)" = "n" ]; then
869 msg2
"$(gettext "Removing empty directories...
")"
870 find .
-depth -type d
-empty -delete
875 local builddate
=$
(date -u "+%s")
876 if [ -n "$PACKAGER" ]; then
877 local packager
="$PACKAGER"
879 local packager
="Unknown Packager"
881 local size
=$
(du
-sk |
awk '{print $1 * 1024}')
883 # write the .PKGINFO file
884 msg2
"$(gettext "Generating .PKGINFO
file...
")"
885 echo "# Generated by makepkg $myver" >.PKGINFO
886 if [ "$INFAKEROOT" -eq 1 ]; then
887 echo "# using $(fakeroot -v)" >>.PKGINFO
889 echo "# $(LC_ALL=C date -u)" >>.PKGINFO
890 echo "pkgname = $nameofpkg" >>.PKGINFO
891 echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO
892 echo "pkgdesc = $pkgdesc" >>.PKGINFO
893 echo "url = $url" >>.PKGINFO
894 echo "builddate = $builddate" >>.PKGINFO
895 echo "packager = $packager" >>.PKGINFO
896 echo "size = $size" >>.PKGINFO
897 if [ -n "$CARCH" ]; then
898 echo "arch = $CARCH" >>.PKGINFO
900 if [ "$(check_option force)" = "y" ]; then
901 echo "force = true" >> .PKGINFO
905 for it
in "${license[@]}"; do
906 echo "license = $it" >>.PKGINFO
908 for it
in "${replaces[@]}"; do
909 echo "replaces = $it" >>.PKGINFO
911 for it
in "${groups[@]}"; do
912 echo "group = $it" >>.PKGINFO
914 for it
in "${depends[@]}"; do
915 echo "depend = $it" >>.PKGINFO
917 for it
in "${optdepends[@]}"; do
918 echo "optdepend = $it" >>.PKGINFO
920 for it
in "${conflicts[@]}"; do
921 echo "conflict = $it" >>.PKGINFO
923 for it
in "${provides[@]}"; do
924 echo "provides = $it" >>.PKGINFO
926 for it
in "${backup[@]}"; do
927 echo "backup = $it" >>.PKGINFO
929 for it
in "${packaging_options[@]}"; do
930 local ret
="$(check_option $it)"
931 if [ "$ret" != "?" ]; then
932 if [ "$ret" = "y" ]; then
933 echo "makepkgopt = $it" >>.PKGINFO
935 echo "makepkgopt = !$it" >>.PKGINFO
940 # TODO maybe remove this at some point
941 # warn if license array is not present or empty
942 if [ -z "$license" ]; then
943 warning
"$(gettext "Please add a license line to your
%s
!")" "$BUILDSCRIPT"
944 plain
"$(gettext "Example
for GPL
\'ed software
: license
=('GPL').
")"
949 if [ ! -d "$pkgdir" ]; then
950 error
"$(gettext "Missing pkg
/ directory.
")"
951 plain
"$(gettext "Aborting...
")"
952 exit 1 # $E_MISSING_PKGDIR
961 write_pkginfo
$nameofpkg
964 msg
"$(gettext "Creating package...
")"
966 local comp_files
=".PKGINFO"
968 # check for an install script
969 if [ -n "$install" ]; then
970 msg2
"$(gettext "Adding
install script...
")"
971 cp "$startdir/$install" .INSTALL
972 comp_files
="$comp_files .INSTALL"
975 # do we have a changelog?
976 if [ -f "$startdir/ChangeLog" ]; then
977 msg2
"$(gettext "Adding package changelog...
")"
978 cp "$startdir/ChangeLog" .CHANGELOG
979 comp_files
="$comp_files .CHANGELOG"
983 msg2
"$(gettext "Compressing package...
")"
986 *tar.gz
) EXT
=${PKGEXT%.gz} ;;
987 *tar.bz2
) EXT
=${PKGEXT%.bz2} ;;
988 *tar.xz
) EXT
=${PKGEXT%.xz} ;;
989 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
990 "$PKGEXT" ; EXT
=$PKGEXT ;;
992 local pkg_file
="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}${EXT}"
996 # when fileglobbing, we want * in an empty directory to expand to
997 # the null string rather than itself
999 bsdtar
-cf - $comp_files * > "$pkg_file" || ret
=$?
1002 if [ $ret -eq 0 ]; then
1004 *tar.gz
) gzip -f -n "$pkg_file" ;;
1005 *tar.bz2
) bzip2 -f "$pkg_file" ;;
1006 *tar.xz
) xz
-z -f "$pkg_file" ;;
1011 if [ $ret -ne 0 ]; then
1012 error
"$(gettext "Failed to create package
file.
")"
1013 exit 1 # TODO: error code
1017 create_srcpackage
() {
1020 # Get back to our src directory so we can begin with sources.
1024 # We can only check checksums if we have all files.
1028 msg
"$(gettext "Creating
source package...
")"
1029 local srclinks
="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1030 mkdir
"${srclinks}"/${pkgbase}
1032 msg2
"$(gettext "Adding
%s...
")" "$BUILDSCRIPT"
1033 ln -s "${startdir}/${BUILDSCRIPT}" "${srclinks}/${pkgbase}/"
1035 if [ -n "$install" ]; then
1036 if [ -f $install ]; then
1037 msg2
"$(gettext "Adding
install script...
")"
1038 ln -s "${startdir}/$install" "${srclinks}/${pkgbase}/"
1040 error
"$(gettext "Install
script %s not found.
")" "$install"
1044 if [ -f ChangeLog
]; then
1045 msg2
"$(gettext "Adding
%s...
")" "ChangeLog"
1046 ln -s "${startdir}/ChangeLog" "${srclinks}/${pkgbase}"
1050 for netfile
in "${source[@]}"; do
1051 local file=$
(get_filename
"$netfile")
1052 if [ -f "$netfile" ]; then
1053 msg2
"$(gettext "Adding
%s...
")" "$netfile"
1054 ln -s "${startdir}/$netfile" "${srclinks}/${pkgbase}"
1055 elif [ "$SOURCEONLY" -eq 2 -a -f "$SRCDEST/$file" ]; then
1056 msg2
"$(gettext "Adding
%s...
")" "$file"
1057 ln -s "$SRCDEST/$file" "${srclinks}/${pkgbase}/"
1063 *tar.gz
) TAR_OPT
="z" ;;
1064 *tar.bz2
) TAR_OPT
="j" ;;
1065 *tar.xz
) TAR_OPT
="J" ;;
1066 *) warning
"$(gettext "'%s' is not a valid archive extension.
")" \
1070 local pkg_file
="$PKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}"
1073 msg2
"$(gettext "Compressing
source package...
")"
1075 if ! bsdtar
-c${TAR_OPT}Lf
"$pkg_file" ${pkgbase}; then
1076 error
"$(gettext "Failed to create
source package
file.
")"
1077 exit 1 # TODO: error code
1080 rm -rf "${srclinks}"
1084 [ "$INSTALL" -eq 0 ] && return
1086 if [ "$SPLITPKG" -eq 0 ]; then
1087 msg
"$(gettext "Installing package
${pkgname} with pacman
-U...
")"
1089 msg
"$(gettext "Installing
${pkgbase} package group with pacman
-U...
")"
1093 for pkg
in ${pkgname[@]}; do
1094 pkglist
="${pkglist} $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
1098 if [ "$ASROOT" -eq 0 ]; then
1099 sudo pacman
$PACMAN_OPTS -U ${pkglist} || ret
=$?
1101 pacman
$PACMAN_OPTS -U ${pkglist} || ret
=$?
1104 if [ $ret -ne 0 ]; then
1105 warning
"$(gettext "Failed to
install built package
(s
).
")"
1111 # check for no-no's in the build script
1112 if [ -z "$pkgname" ]; then
1113 error
"$(gettext "%s is not allowed to be empty.
")" "pkgname"
1116 if [ -z "$pkgver" ]; then
1117 error
"$(gettext "%s is not allowed to be empty.
")" "pkgver"
1120 if [ -z "$pkgrel" ]; then
1121 error
"$(gettext "%s is not allowed to be empty.
")" "pkgrel"
1124 if [ "$pkgver" != "${pkgver//-/}" ]; then
1125 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgver"
1128 if [ "$pkgrel" != "${pkgrel//-/}" ]; then
1129 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgrel"
1133 if [ "$arch" = 'any' ]; then
1137 pkgbase
=${pkgbase:-${pkgname[0]}}
1139 if ! in_array
$CARCH ${arch[@]}; then
1140 if [ "$IGNOREARCH" -eq 0 ]; then
1141 error
"$(gettext "%s is not available
for the
'%s' architecture.
")" "$pkgbase" "$CARCH"
1142 plain
"$(gettext "Note that many packages may need a line added to their
%s
")" "$BUILDSCRIPT"
1143 plain
"$(gettext "such as arch
=('%s').
")" "$CARCH"
1149 for provide
in ${provides[@]}; do
1150 if [ $provide != ${provide//</} -o $provide != ${provide//>/} ]; then
1151 error
"$(gettext "Provides array cannot contain comparison
(< or
>) operators.
")"
1156 if [ "$install" -a ! -f "$install" ]; then
1157 error
"$(gettext "Install scriptlet
(%s
) does not exist.
")" "$install"
1161 local valid_options
=1
1162 local opt known kopt
1163 for opt
in ${options[@]}; do
1165 # check if option matches a known option or its inverse
1166 for kopt
in ${packaging_options[@]} ${other_options[@]}; do
1167 if [ "${opt}" = "${kopt}" -o "${opt}" = "!${kopt}" ]; then
1171 if [ $known -eq 0 ]; then
1172 error
"$(gettext "options array contains unknown option
'%s'")" "$opt"
1176 if [ $valid_options -eq 0 ]; then
1186 # Do not update pkgver if --holdver is set, when building a source package,
1187 # or when reading PKGBUILD from pipe
1188 if [ "$HOLDVER" -eq 1 -o "$SOURCEONLY" -ne 0 -o ! -f "./$BUILDSCRIPT" ]; then
1192 if [ -z "$FORCE_VER" ]; then
1193 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1194 # This will only be used on the first call to makepkg; subsequent
1195 # calls to makepkg via fakeroot will explicitly pass the version
1196 # number to avoid having to determine the version number twice.
1197 # Also do a brief check to make sure we have the VCS tool available.
1199 if [ -n "${_darcstrunk}" -a -n "${_darcsmod}" ] ; then
1200 [ $
(type -p darcs
) ] ||
return 0
1201 msg
"$(gettext "Determining latest darcs revision...
")"
1202 newpkgver
=$
(date +%Y
%m
%d
)
1203 elif [ -n "${_cvsroot}" -a -n "${_cvsmod}" ] ; then
1204 [ $
(type -p cvs
) ] ||
return 0
1205 msg
"$(gettext "Determining latest cvs revision...
")"
1206 newpkgver
=$
(date +%Y
%m
%d
)
1207 elif [ -n "${_gitroot}" -a -n "${_gitname}" ] ; then
1208 [ $
(type -p git
) ] ||
return 0
1209 msg
"$(gettext "Determining latest git revision...
")"
1210 newpkgver
=$
(date +%Y
%m
%d
)
1211 elif [ -n "${_svntrunk}" -a -n "${_svnmod}" ] ; then
1212 [ $
(type -p svn
) ] ||
return 0
1213 msg
"$(gettext "Determining latest svn revision...
")"
1214 newpkgver
=$
(LC_ALL
=C svn info
$_svntrunk |
sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p')
1215 elif [ -n "${_bzrtrunk}" -a -n "${_bzrmod}" ] ; then
1216 [ $
(type -p bzr
) ] ||
return 0
1217 msg
"$(gettext "Determining latest bzr revision...
")"
1218 newpkgver
=$
(bzr revno
${_bzrtrunk})
1219 elif [ -n "${_hgroot}" -a -n "${_hgrepo}" ] ; then
1220 [ $
(type -p hg
) ] ||
return 0
1221 msg
"$(gettext "Determining latest hg revision...
")"
1222 if [ -d .
/src
/$_hgrepo ] ; then
1227 [[ ! -d .
/src
/ ]] && mkdir .
/src
/
1228 hg clone
$_hgroot/$_hgrepo .
/src
/$_hgrepo
1231 newpkgver
=$
(hg tip
--template "{rev}")
1235 if [ -n "$newpkgver" ]; then
1236 msg2
"$(gettext "Version found
: %s
")" "$newpkgver"
1240 # Version number retrieved from fakeroot->makepkg argument
1241 newpkgver
=$FORCE_VER
1246 # This is lame, but if we're wanting to use an updated pkgver for
1247 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1248 # the new pkgver and then re-source it. This is the most robust
1249 # method for dealing with PKGBUILDs that use, e.g.:
1255 if [ -n "$newpkgver" ]; then
1256 if [ "$newpkgver" != "$pkgver" ]; then
1257 if [ -f "./$BUILDSCRIPT" ]; then
1258 @SEDINPLACE@
"s/^pkgver=[^ ]*/pkgver=$newpkgver/" "./$BUILDSCRIPT"
1259 @SEDINPLACE@
"s/^pkgrel=[^ ]*/pkgrel=1/" "./$BUILDSCRIPT"
1260 source "$BUILDSCRIPT"
1266 backup_package_variables
() {
1267 for var
in ${splitpkg_overrides[@]}; do
1268 indirect
="${var}_backup"
1269 eval "${indirect}=(\${$var[@]})"
1273 restore_package_variables
() {
1274 for var
in ${splitpkg_overrides[@]}; do
1275 indirect
="${var}_backup"
1276 if [ -n "${!indirect}" ]; then
1277 eval "${var}=(\${$indirect[@]})"
1284 # getopt like parser
1286 local short_options
=$1; shift;
1287 local long_options
=$1; shift;
1289 local unused_options
=""
1291 while [ -n "$1" ]; do
1292 if [ ${1:0:2} = '--' ]; then
1293 if [ -n "${1:2}" ]; then
1295 for i
in ${long_options//,/ }; do
1296 if [ ${1:2} = ${i//:} ]; then
1301 if [ -n "$match" ]; then
1302 if [ ${1:2} = $match ]; then
1305 if [ -n "$2" ]; then
1310 echo "makepkg: option '$1' $(gettext "requires an argument
")" >&2
1315 echo "makepkg: $(gettext "unrecognized option
") '$1'" >&2
1322 elif [ ${1:0:1} = '-' ]; then
1323 for ((i
=1; i
<${#1}; i
++)); do
1324 if [[ "$short_options" =~
"${1:i:1}" ]]; then
1325 if [[ "$short_options" =~
"${1:i:1}:" ]]; then
1326 if [ -n "${1:$i+1}" ]; then
1327 printf ' -%s' "${1:i:1}"
1328 printf " '%s'" "${1:$i+1}"
1330 if [ -n "$2" ]; then
1331 printf ' -%s' "${1:i:1}"
1333 printf " '%s'" "${1}"
1335 echo "makepkg: option $(gettext "requires an argument
") -- '${1:i:1}'" >&2
1341 printf ' -%s' "${1:i:1}"
1344 echo "makepkg: $(gettext "invalid option
") -- '${1:i:1}'" >&2
1349 unused_options
="${unused_options} '$1'"
1355 if [ -n "$unused_options" ]; then
1356 for i
in ${unused_options[@]}; do
1360 if [ -n "$1" ]; then
1361 while [ -n "$1" ]; do
1362 printf " '%s'" "${1}"
1372 printf "makepkg (pacman) %s\n" "$myver"
1374 printf "$(gettext "Usage
: %s
[options
]")\n" "$0"
1376 echo "$(gettext "Options
:")"
1377 printf "$(gettext " -A, --ignorearch Ignore incomplete arch field
in %s
")\n" "$BUILDSCRIPT"
1378 echo "$(gettext " -c, --clean Clean up work files after build
")"
1379 echo "$(gettext " -C, --cleancache Clean up
source files from the cache
")"
1380 printf "$(gettext " --config <config
> Use an alternate config
file (instead of
'%s')")\n" "$confdir/makepkg.conf"
1381 echo "$(gettext " -d, --nodeps Skip all dependency checks
")"
1382 echo "$(gettext " -e, --noextract Do not extract
source files
(use existing src
/ dir
)")"
1383 echo "$(gettext " -f, --force Overwrite existing package
")"
1384 echo "$(gettext " -g, --geninteg Generate integrity checks
for source files
")"
1385 echo "$(gettext " -h, --help This
help")"
1386 echo "$(gettext " -i, --install Install package after successful build
")"
1387 echo "$(gettext " -L, --log Log package build process
")"
1388 echo "$(gettext " -m, --nocolor Disable colorized output messages
")"
1389 echo "$(gettext " -o, --nobuild Download and extract files only
")"
1390 printf "$(gettext " -p <buildscript
> Use an alternate build
script (instead of
'%s')")\n" "$BUILDSCRIPT"
1391 echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build
")"
1392 # fix flyspray feature request #2978
1393 echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding
")"
1394 echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman
")"
1395 echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources
")"
1396 echo "$(gettext " --asroot Allow makepkg to run as root user
")"
1397 echo "$(gettext " --holdver Prevent automatic version bumping
for development PKGBUILDs
")"
1398 echo "$(gettext " --source Generate a source-only tarball without downloaded sources
")"
1400 echo "$(gettext "These options can be passed to pacman
:")"
1402 echo "$(gettext " --noconfirm Do not ask
for confirmation when resolving dependencies
")"
1403 echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files
")"
1405 printf "$(gettext "If
-p is not specified
, makepkg will
look for '%s'")\n" "$BUILDSCRIPT"
1410 printf "makepkg (pacman) %s\n" "$myver"
1411 printf "$(gettext "\
1412 Copyright
(C
) 2002-2007 Judd Vinet
<jvinet@zeroflux.org
>.
\n\n\
1413 This is free software
; see the
source for copying conditions.
\n\
1414 There is NO WARRANTY
, to the extent permitted by law.
\n")"
1419 # determine whether we have gettext; make it a no-op if we do not
1420 if [ ! $
(type -t gettext) ]; then
1428 # Parse Command Line Options.
1429 OPT_SHORT
="AbcCdefFghiLmop:rRsV"
1430 OPT_LONG
="allsource,asroot,ignorearch,builddeps,clean,cleancache,nodeps"
1431 OPT_LONG
="$OPT_LONG,noextract,force,forcever:,geninteg,help,holdver"
1432 OPT_LONG
="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source"
1433 OPT_LONG
="$OPT_LONG,syncdeps,version,config:"
1435 OPT_LONG
="$OPT_LONG,noconfirm,noprogressbar"
1436 OPT_TEMP
="$(parse_options $OPT_SHORT $OPT_LONG "$@
" || echo 'PARSE_OPTIONS FAILED')"
1437 if echo "$OPT_TEMP" |
grep -q 'PARSE_OPTIONS FAILED'; then
1438 # This is a small hack to stop the script bailing with 'set -e'
1439 echo; usage
; exit 1 # E_INVALID_OPTION;
1441 eval set -- "$OPT_TEMP"
1442 unset OPT_SHORT OPT_LONG OPT_TEMP
1447 --noconfirm) PACMAN_OPTS
="$PACMAN_OPTS --noconfirm" ;;
1448 --noprogressbar) PACMAN_OPTS
="$PACMAN_OPTS --noprogressbar" ;;
1451 --allsource) SOURCEONLY
=2 ;;
1452 --asroot) ASROOT
=1 ;;
1453 -A|
--ignorearch) IGNOREARCH
=1 ;;
1454 -c|
--clean) CLEANUP
=1 ;;
1455 -C|
--cleancache) CLEANCACHE
=1 ;;
1456 --config) shift; MAKEPKG_CONF
=$1 ;;
1457 -d|
--nodeps) NODEPS
=1 ;;
1458 -e|
--noextract) NOEXTRACT
=1 ;;
1459 -f|
--force) FORCE
=1 ;;
1460 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1461 --forcever) shift; FORCE_VER
=$1;;
1463 -g|
--geninteg) GENINTEG
=1 ;;
1464 --holdver) HOLDVER
=1 ;;
1465 -i|
--install) INSTALL
=1 ;;
1466 -L|
--log) LOGGING
=1 ;;
1467 -m|
--nocolor) USE_COLOR
='n' ;;
1468 -o|
--nobuild) NOBUILD
=1 ;;
1469 -p) shift; BUILDSCRIPT
=$1 ;;
1470 -r|
--rmdeps) RMDEPS
=1 ;;
1471 -R|
--repackage) REPKG
=1 ;;
1472 --source) SOURCEONLY
=1 ;;
1473 -s|
--syncdeps) DEP_BIN
=1 ;;
1475 -h|
--help) usage
; exit 0 ;; # E_OK
1476 -V|
--version) version
; exit 0 ;; # E_OK
1478 --) OPT_IND
=0; shift; break;;
1479 *) usage
; exit 1 ;; # E_INVALID_OPTION
1484 #preserve environment variables
1488 # default config is makepkg.conf
1489 MAKEPKG_CONF
=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1491 # Source the config file; fail if it is not found
1492 if [ -r "$MAKEPKG_CONF" ]; then
1493 source "$MAKEPKG_CONF"
1495 error
"$(gettext "%s not found.
")" "$MAKEPKG_CONF"
1496 plain
"$(gettext "Aborting...
")"
1497 exit 1 # $E_CONFIG_ERROR
1500 # Source user-specific makepkg.conf overrides
1501 if [ -r ~
/.makepkg.conf
]; then
1502 source ~
/.makepkg.conf
1505 # check if messages are to be printed using color
1506 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
1510 # override settings with an environment variable for batch processing
1511 PKGDEST
=${_PKGDEST:-$PKGDEST}
1512 PKGDEST
=${PKGDEST:-$startdir} #default to $startdir if undefined
1513 SRCDEST
=${_SRCDEST:-$SRCDEST}
1514 SRCDEST
=${SRCDEST:-$startdir} #default to $startdir if undefined
1517 if [ "$HOLDVER" -eq 1 -a -n "$FORCE_VER" ]; then
1518 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1519 error
"$(gettext "\\0--holdver and
--forcever cannot both be specified
" )"
1523 if [ "$CLEANCACHE" -eq 1 ]; then
1524 #fix flyspray feature request #5223
1525 if [ -n "$SRCDEST" -a "$SRCDEST" != "$startdir" ]; then
1526 msg
"$(gettext "Cleaning up ALL files from
%s.
")" "$SRCDEST"
1527 echo -n "$(gettext " Are you sure you wish to
do this?
")"
1528 echo -n "$(gettext "[Y
/n
]")"
1530 answer
=$
(echo $answer |
tr '[:lower:]' '[:upper:]')
1531 if [ "$answer" = "$(gettext "YES
")" -o "$answer" = "$(gettext "Y
")" ]; then
1533 if [ $?
-ne 0 ]; then
1534 error
"$(gettext "Problem removing files
; you may not have correct permissions
in %s
")" "$SRCDEST"
1538 msg
"$(gettext "Source cache cleaned.
")"
1543 msg
"$(gettext "No files have been removed.
")"
1547 # $SRCDEST is $startdir, two possibilities
1548 error
"$(gettext "Source destination must be defined
in %s.
")" "$MAKEPKG_CONF"
1549 plain
"$(gettext "In addition
, please run makepkg
-C outside of your cache directory.
")"
1554 if [ -z "$BUILDSCRIPT" ]; then
1555 error
"$(gettext "BUILDSCRIPT is undefined
! Ensure you have updated
%s.
")" "$MAKEPKG_CONF"
1559 if [ "$INFAKEROOT" -eq 0 ]; then
1560 if [ $EUID -eq 0 -a "$ASROOT" -eq 0 ]; then
1561 # Warn those who like to live dangerously.
1562 error
"$(gettext "Running makepkg as root is a BAD idea and can cause
")"
1563 plain
"$(gettext "permanent
, catastrophic damage to your system. If you
")"
1564 plain
"$(gettext "wish to run as root
, please use the
--asroot option.
")"
1565 exit 1 # $E_USER_ABORT
1566 elif [ $EUID -gt 0 -a "$ASROOT" -eq 1 ]; then
1567 # Warn those who try to use the --asroot option when they are not root
1568 error
"$(gettext "The
--asroot option is meant
for the root user only.
")"
1569 plain
"$(gettext "Please rerun makepkg without the
--asroot flag.
")"
1570 exit 1 # $E_USER_ABORT
1571 elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then
1572 if [ ! $
(type -p fakeroot
) ]; then
1573 error
"$(gettext "Fakeroot must be installed
if using the
'fakeroot' option
")"
1574 plain
"$(gettext "in the BUILDENV array
in %s.
")" "$MAKEPKG_CONF"
1577 elif [ $EUID -gt 0 ]; then
1578 warning
"$(gettext "Running makepkg as an unprivileged user will result
in non-root
")"
1579 plain
"$(gettext "ownership of the packaged files. Try using the fakeroot environment by
")"
1580 plain
"$(gettext "placing
'fakeroot' in the BUILDENV array
in %s.
")" "$MAKEPKG_CONF"
1584 if [ -z "$FAKEROOTKEY" ]; then
1585 error
"$(gettext "Do not use the
'-F' option. This option is only
for use by makepkg.
")"
1586 exit 1 # TODO: error code
1590 # check for sudo if we will need it during makepkg execution
1591 if [ "$ASROOT" -eq 0 \
1592 -a \
( "$DEP_BIN" -eq 1 -o "$RMDEPS" -eq 1 -o "$INSTALL" -eq 1 \
) ]; then
1593 if [ ! "$(type -p sudo)" ]; then
1594 error
"$(gettext "Cannot
find the sudo binary
! Is sudo installed?
")"
1595 plain
"$(gettext "Missing dependencies cannot be installed or removed as a normal user
")"
1596 plain
"$(gettext "without sudo
; install and configure sudo to auto-resolve dependencies.
")"
1601 unset pkgname pkgbase pkgver pkgrel pkgdesc url license groups provides
1602 unset md5sums replaces depends conflicts backup
source install build
1603 unset makedepends optdepends options noextract
1605 if [ ! -f "$BUILDSCRIPT" ]; then
1607 error
"$(gettext "%s does not exist.
")" "$BUILDSCRIPT"
1610 # PKGBUILD passed through a pipe
1611 BUILDSCRIPT
=/dev
/stdin
1612 source "$BUILDSCRIPT"
1615 crlftest
=$
(file $BUILDSCRIPT |
grep -F 'CRLF' || true
)
1616 if [ -n "$crlftest" ]; then
1617 error
"$(gettext "%s contains CRLF characters and cannot be sourced.
")" "$BUILDSCRIPT"
1621 source .
/"$BUILDSCRIPT"
1624 if [ "$GENINTEG" -eq 1 ]; then
1632 if [ "$(type -t package)" = "function" ]; then
1636 # check the PKGBUILD for some basic requirements
1637 check_sanity ||
exit 1
1639 # We need to run devel_update regardless of whether we are in the fakeroot
1640 # build process so that if the user runs makepkg --forcever manually, we
1641 # 1) output the correct pkgver, and 2) use the correct filename when
1642 # checking if the package file already exists - fixes FS #9194
1646 if [ "${#pkgname[@]}" -gt "1" ]; then
1650 if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \
1651 -a "$FORCE" -eq 0 -a "$SOURCEONLY" -eq 0 -a "$NOBUILD" -eq 0 ]; then
1652 if [ "$INSTALL" -eq 1 ]; then
1653 warning
"$(gettext "A package has already been built
, installing existing package...
")"
1657 error
"$(gettext "A package has already been built.
(use
-f to overwrite
)")"
1662 # Run the bare minimum in fakeroot
1663 if [ "$INFAKEROOT" -eq 1 ]; then
1664 if [ "$SPLITPKG" -eq 0 ]; then
1665 if [ "$PKGFUNC" -eq 0 ]; then
1666 if [ "$REPKG" -eq 0 ]; then
1676 for pkg
in ${pkgname[@]}; do
1677 pkgdir
="$pkgdir/$pkg"
1679 backup_package_variables
1683 restore_package_variables
1684 pkgdir
="${pkgdir%/*}"
1688 msg
"$(gettext "Leaving fakeroot environment.
")"
1692 msg
"$(gettext "Making package
: %s
")" "$pkgbase $pkgver-$pkgrel $CARCH ($(date))"
1694 # if we are creating a source-only package, go no further
1695 if [ "$SOURCEONLY" -ne 0 ]; then
1696 if [ -f "$PKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}" \
1697 -a "$FORCE" -eq 0 ]; then
1698 error
"$(gettext "A package has already been built.
(use
-f to overwrite
)")"
1702 msg
"$(gettext "Source package created
: %s
")" "$pkgbase ($(date))"
1706 # fix flyspray bug #5973
1707 if [ "$NODEPS" -eq 1 -o "$NOBUILD" -eq 1 -o "$REPKG" -eq 1 ]; then
1708 # no warning message needed for nobuild, repkg
1709 if [ "$NODEPS" -eq 1 ]; then
1710 warning
"$(gettext "Skipping dependency checks.
")"
1712 elif [ $
(type -p pacman
) ]; then
1713 unset pkgdeps
# Set by resolve_deps() and used by remove_deps()
1716 msg
"$(gettext "Checking Runtime Dependencies...
")"
1717 resolve_deps
${depends[@]} || deperr
=1
1719 msg
"$(gettext "Checking Buildtime Dependencies...
")"
1720 resolve_deps
${makedepends[@]} || deperr
=1
1722 if [ $deperr -eq 1 ]; then
1723 error
"$(gettext "Could not resolve all dependencies.
")"
1727 warning
"$(gettext "pacman was not found
in PATH
; skipping dependency checks.
")"
1730 # ensure we have a sane umask set
1733 # get back to our src directory so we can begin with sources
1737 if [ "$NOEXTRACT" -eq 1 ]; then
1738 warning
"$(gettext "Skipping
source retrieval
-- using existing src
/ tree
")"
1739 warning
"$(gettext "Skipping
source integrity checks
-- using existing src
/ tree
")"
1740 warning
"$(gettext "Skipping
source extraction
-- using existing src
/ tree
")"
1742 if [ "$NOEXTRACT" -eq 1 -a -z "$(ls "$srcdir" 2>/dev/null)" ]; then
1743 error
"$(gettext "The
source directory is empty
, there is nothing to build
!")"
1744 plain
"$(gettext "Aborting...
")"
1747 elif [ "$REPKG" -eq 1 ]; then
1748 if [ "$PKGFUNC" -eq 0 -a "$SPLITPKG" -eq 0 \
1749 -a \
( ! -d "$pkgdir" -o -z "$(ls "$pkgdir" 2>/dev/null)" \
) ]; then
1750 error
"$(gettext "The package directory is empty
, there is nothing to repackage
!")"
1751 plain
"$(gettext "Aborting...
")"
1760 if [ "$NOBUILD" -eq 1 ]; then
1761 msg
"$(gettext "Sources are ready.
")"
1764 # check for existing pkg directory; don't remove if we are repackaging
1766 -a \
( "$REPKG" -eq 0 -o "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \
) ]; then
1767 msg
"$(gettext "Removing existing pkg
/ directory...
")"
1773 # if we are root or if fakeroot is not enabled, then we don't use it
1774 if [ "$(check_buildenv fakeroot)" != "y" -o $EUID -eq 0 ]; then
1775 if [ "$REPKG" -eq 0 ]; then
1779 if [ "$SPLITPKG" -eq 0 ]; then
1780 if [ "$PKGFUNC" -eq 1 ]; then
1783 elif [ "$REPKG" -eq 0 ]; then
1788 for pkg
in ${pkgname[@]}; do
1789 pkgdir
="$pkgdir/$pkg"
1791 backup_package_variables
1795 restore_package_variables
1796 pkgdir
="${pkgdir%/*}"
1800 if [ "$REPKG" -eq 0 -a \
( "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \
) ]; then
1806 msg
"$(gettext "Entering fakeroot environment...
")"
1808 if [ -n "$newpkgver" ]; then
1809 fakeroot
-- $0 --forcever $newpkgver -F $ARGLIST ||
exit $?
1811 fakeroot
-- $0 -F $ARGLIST ||
exit $?
1816 msg
"$(gettext "Finished making
: %s
")" "$pkgbase $pkgver-$pkgrel $CARCH ($(date))"
1822 # vim: set ts=2 sw=2 noet: