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
71 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
72 # when dealing with svn/cvs/etc PKGBUILDs.
81 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
82 printf "\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
84 printf " ${mesg}\n" "$@" >&2
90 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
91 printf "\033[1;32m==>\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
93 printf "==> ${mesg}\n" "$@" >&2
99 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
100 printf "\033[1;34m ->\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
102 printf " -> ${mesg}\n" "$@" >&2
108 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
109 printf "\033[1;33m==> $(gettext "WARNING
:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
111 printf "==> $(gettext "WARNING
:") ${mesg}\n" "$@" >&2
117 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
118 printf "\033[1;31m==> $(gettext "ERROR
:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
120 printf "==> $(gettext "ERROR
:") ${mesg}\n" "$@" >&2
126 # Special exit call for traps, Don't print any error messages when inside,
127 # the fakeroot call, the error message will be printed by the main call.
130 if [ "$INFAKEROOT" = "0" ]; then
139 # Clean up function. Called automatically when the script exits.
144 if [ "$INFAKEROOT" = "1" ]; then
145 # Don't clean up when leaving fakeroot, we're not done yet.
149 if [ $EXIT_CODE -eq 0 -a "$CLEANUP" = "1" ]; then
150 # If it's a clean exit and -c/--clean has been passed...
151 msg
"$(gettext "Cleaning up...
")"
152 rm -rf "$pkgdir" "$srcdir"
153 if [ "$pkgname" != "" ]; then
154 # Can't do this unless the BUILDSCRIPT has been sourced.
155 rm -f "${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log*"
167 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
168 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
169 trap 'trap_exit "$(gettext "An unknown error has occured. Exiting...")"' ERR
171 # a source entry can have two forms :
172 # 1) "filename::http://path/to/file"
173 # 2) "http://path/to/file"
175 # extract the filename from a source entry
177 # if a filename is specified, use it
178 local filename
=$
(echo $1 |
sed 's|::.*||')
179 # if it is just an url, we only keep the last component
180 echo "$filename" |
sed 's|^.*://.*/||g'
183 # extract the url from a source entry
185 # strip an eventual filename
186 echo $1 |
sed 's|.*::||'
190 # Checks to see if options are present in makepkg.conf or PKGBUILD;
191 # PKGBUILD options always take precedence.
193 # usage : check_option( $option )
194 # return : y - enabled
199 local ret
=$
(in_opt_array
"$1" ${options[@]})
200 if [ "$ret" != '?' ]; then
205 # fall back to makepkg.conf options
206 ret
=$
(in_opt_array
"$1" ${OPTIONS[@]})
207 if [ "$ret" != '?' ]; then
217 # Check if option is present in BUILDENV
219 # usage : check_buildenv( $option )
220 # return : y - enabled
225 echo $
(in_opt_array
"$1" ${BUILDENV[@]})
230 # usage : in_opt_array( $needle, $haystack )
231 # return : y - enabled
236 local needle
=$
(echo $1 |
tr '[:upper:]' '[:lower:]'); shift
240 opt
=$
(echo $opt |
tr '[:upper:]' '[:lower:]')
241 if [ "$opt" = "$needle" ]; then
244 elif [ "$opt" = "!$needle" ]; then
255 # usage : in_array( $needle, $haystack )
260 local needle
=$1; shift
261 [ -z "$1" ] && return 1 # Not Found
264 [ "$item" = "$needle" ] && return 0 # Found
269 get_downloadclient
() {
270 # $1 = url with valid protocol prefix
272 local proto
=$
(echo "$url" |
sed 's|://.*||')
274 # loop through DOWNLOAD_AGENTS variable looking for protocol
276 for i
in "${DLAGENTS[@]}"; do
277 local handler
=$
(echo $i |
sed 's|::.*||')
278 if [ "$proto" == "$handler" ]; then
279 agent
=$
(echo $i |
sed 's|^.*::||')
284 # if we didn't find an agent, return an error
285 if [ -z "$agent" ]; then
286 error
"$(gettext "There is no agent
set up to handle
%s URLs. Check
%s.
")" "$proto" "$MAKEPKG_CONF"
287 plain
"$(gettext "Aborting...
")"
288 exit 1 # $E_CONFIG_ERROR
291 # ensure specified program is installed
292 local program
="$(echo $agent | awk '{print $1 }')"
293 if [ ! -x "$program" ]; then
294 local baseprog
=$
(basename $program)
295 error
"$(gettext "The download program
%s is not installed.
")" "$baseprog"
296 plain
"$(gettext "Aborting...
")"
297 exit 1 # $E_MISSING_PROGRAM
310 # temporary download file, default to last component of the url
311 local dlfile
=$
(echo "$url" |
sed 's|^.*://.*/||g')
313 # replace %o by the temporary dlfile if it exists
314 if echo "$dlcmd" |
grep -q "%o" ; then
315 dlcmd
=${dlcmd//\%o/$file.part}
318 # add the url, either in place of %u or at the end
319 if echo "$dlcmd" |
grep -q "%u" ; then
320 dlcmd
=${dlcmd//\%u/$url}
327 # rename the temporary download file to the final destination
328 if [ "$dlfile" != "$file" ]; then
329 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
334 [ $# -gt 0 ] ||
return
336 pmout
=$
(pacman
$PACMAN_OPTS -T "$@")
338 if [ $ret -eq 127 ]; then #unresolved deps
340 elif [ $ret -ne 0 ]; then
341 error
"$(gettext "Pacman returned a fatal error
(%i
): %s
")" "$ret" "$pmout"
347 local R_DEPS_SATISFIED
=0
348 local R_DEPS_MISSING
=1
350 [ $# -eq 0 ] && return $R_DEPS_SATISFIED
354 if [ "$DEP_BIN" = "0" ]; then
355 return $R_DEPS_MISSING
358 if [ "$DEP_BIN" = "1" ]; then
359 # install missing deps from binary packages (using pacman -S)
360 msg
"$(gettext "Installing missing dependencies...
")"
363 if [ "$ASROOT" = 0 ]; then
364 sudo pacman
$PACMAN_OPTS -S --asdeps $deplist || ret
=$?
366 pacman
$PACMAN_OPTS -S --asdeps $deplist || ret
=$?
369 if [ $ret -ne 0 ]; then
370 error
"$(gettext "Pacman failed to
install missing dependencies.
")"
371 exit 1 # TODO: error code
375 # we might need the new system environment
376 # set -e can cause problems during sourcing profile scripts
378 source /etc
/profile
&>/dev
/null
381 return $R_DEPS_SATISFIED
385 # $pkgdeps is a GLOBAL variable, used by remove_deps()
386 local R_DEPS_SATISFIED
=0
387 local R_DEPS_MISSING
=1
389 local deplist
="$(check_deps $*)"
390 if [ "$deplist" = "" ]; then
391 return $R_DEPS_SATISFIED
394 if handledeps
$deplist; then
395 pkgdeps
="$pkgdeps $deplist"
396 # check deps again to make sure they were resolved
397 deplist
="$(check_deps $*)"
398 [ "$deplist" = "" ] && return $R_DEPS_SATISFIED
399 elif [ "$DEP_BIN" = "1" ]; then
400 error
"$(gettext "Failed to
install all missing dependencies.
")"
403 msg
"$(gettext "Missing Dependencies
:")"
405 for dep
in $deplist; do
409 return $R_DEPS_MISSING
412 # fix flyspray bug #5923
414 # $pkgdeps is a GLOBAL variable, set by resolve_deps()
415 [ "$RMDEPS" = "0" ] && return
416 [ "$pkgdeps" = "" ] && return
418 local dep depstrip deplist
420 for dep
in $pkgdeps; do
421 depstrip
=$
(echo $dep |
sed -e 's|=.*$||' -e 's|>.*$||' -e 's|<.*$||')
422 deplist
="$deplist $depstrip"
425 msg
"Removing installed dependencies..."
427 if [ "$ASROOT" = "0" ]; then
428 sudo pacman
$PACMAN_OPTS -Rns $deplist || ret
=$?
430 pacman
$PACMAN_OPTS -Rns $deplist || ret
=$?
433 # Fixes FS#10039 - exit cleanly as package has built successfully
434 if [ $ret -ne 0 ]; then
435 warning
"$(gettext "Failed to remove installed dependencies.
")"
441 msg
"$(gettext "Retrieving Sources...
")"
443 if [ ! -w "$SRCDEST" ] ; then
444 error
"$(gettext "You
do not have
write permission to store downloads
in %s.
")" "$SRCDEST"
445 plain
"$(gettext "Aborting...
")"
449 pushd "$SRCDEST" &>/dev
/null
452 for netfile
in "${source[@]}"; do
453 local file=$
(get_filename
"$netfile")
454 local url
=$
(get_url
"$netfile")
455 if [ -f "$startdir/$file" ]; then
456 msg2
"$(gettext "Found
%s
in build dir
")" "$file"
457 rm -f "$srcdir/$file"
458 ln -s "$startdir/$file" "$srcdir/"
460 elif [ -f "$SRCDEST/$file" ]; then
461 msg2
"$(gettext "Using cached copy of
%s
")" "$file"
462 rm -f "$srcdir/$file"
463 ln -s "$SRCDEST/$file" "$srcdir/"
467 # if we get here, check to make sure it was a URL, else fail
468 if [ "$file" = "$url" ]; then
469 error
"$(gettext "%s was not found
in the build directory and is not a URL.
")" "$file"
470 exit 1 # $E_MISSING_FILE
473 # find the client we should use for this URL
474 local dlclient
=$
(get_downloadclient
"$url") ||
exit $?
476 msg2
"$(gettext "Downloading
%s...
")" "$file"
477 # fix flyspray bug #3289
479 download_file
"$dlclient" "$url" "$file" || ret
=$?
480 if [ $ret -gt 0 ]; then
481 error
"$(gettext "Failure
while downloading
%s
")" "$file"
482 plain
"$(gettext "Aborting...
")"
485 rm -f "$srcdir/$file"
486 ln -s "$SRCDEST/$file" "$srcdir/"
492 generate_checksums
() {
493 msg
"$(gettext "Generating checksums
for source files...
")"
496 if [ ! $
(type -p openssl
) ]; then
497 error
"$(gettext "Cannot
find openssl.
")"
498 exit 1 # $E_MISSING_PROGRAM
502 for integ
in ${INTEGRITY_CHECK[@]}; do
503 integ
="$(echo $integ | tr '[:upper:]' '[:lower:]')"
505 md5|sha1|sha256|sha384|sha512
) : ;;
507 error
"$(gettext "Invalid integrity algorithm
'%s' specified.
")" "$integ"
508 exit 1;; # $E_CONFIG_ERROR
512 local numsrc
=${#source[@]}
513 echo -n "${integ}sums=("
517 while [ $i -lt $
((${#integ}+6)) ]; do
523 for netfile
in "${source[@]}"; do
524 local file="$(get_filename "$netfile")"
526 if [ ! -f "$file" ] ; then
527 if [ ! -f "$SRCDEST/$file" ] ; then
528 error
"$(gettext "Unable to
find source file %s to generate checksum.
")" "$file"
529 plain
"$(gettext "Aborting...
")"
532 file="$SRCDEST/$file"
536 local sum="$(openssl dgst -${integ} "$file" | awk '{print $NF}')"
537 [ $ct -gt 0 ] && echo -n "$indent"
540 [ $ct -lt $numsrc ] && echo
548 if [ ! $
(type -p openssl
) ]; then
549 error
"$(gettext "Cannot
find openssl.
")"
550 exit 1 # $E_MISSING_PROGRAM
555 for integ
in md5 sha1 sha256 sha384 sha512
; do
556 local integrity_sums
=($
(eval echo "\${${integ}sums[@]}"))
557 if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then
558 msg
"$(gettext "Validating
source files with
%s...
")" "${integ}sums"
563 for file in "${source[@]}"; do
564 file="$(get_filename "$file")"
565 echo -n " $file ... " >&2
567 if [ ! -f "$file" ] ; then
568 if [ ! -f "$file" ] ; then
569 echo "$(gettext "NOT FOUND
")" >&2
573 file="$SRCDEST/$file"
577 local expectedsum
="$(echo ${integrity_sums[$idx]} | tr '[A-F]' '[a-f]')"
578 local realsum
="$(openssl dgst -${integ} "$file" | awk '{print $NF}')"
579 if [ "$expectedsum" = "$realsum" ]; then
580 echo "$(gettext "Passed
")" >&2
582 echo "$(gettext "FAILED
")" >&2
589 if [ $errors -gt 0 ]; then
590 error
"$(gettext "One or
more files did not pass the validity check
!")"
591 exit 1 # TODO: error code
593 elif [ ${#integrity_sums[@]} -gt 0 ]; then
594 error
"$(gettext "Integrity checks
(%s
) differ
in size from the
source array.
")" "$integ"
595 exit 1 # TODO: error code
599 if [ $correlation -eq 0 ]; then
600 error
"$(gettext "Integrity checks are missing.
")"
601 exit 1 # TODO: error code
606 msg
"$(gettext "Extracting Sources...
")"
608 for netfile
in "${source[@]}"; do
609 file=$
(get_filename
"$netfile")
610 if in_array
"$file" ${noextract[@]}; then
611 #skip source files in the noextract=() array
612 # these are marked explicitly to NOT be extracted
616 if [ ! -f "$file" ] ; then
617 if [ ! -f "$SRCDEST/$file" ] ; then
618 error
"$(gettext "Unable to
find source file %s
for extraction.
")" "$file"
619 plain
"$(gettext "Aborting...
")"
622 file="$SRCDEST/$file"
627 local file_type
=$
(file -bizL "$file")
630 *application
/x-tar
*|
*application
/zip*|
*application
/x-zip
*|
*application
/x-cpio
*)
631 cmd
="bsdtar -x -f $file" ;;
632 *application
/x-gzip
*)
633 cmd
="gunzip -d -f $file" ;;
634 *application
/x-bzip
*)
635 cmd
="bunzip2 -f $file" ;;
637 # Don't know what to use to extract this file,
638 # skip to the next file
645 if [ $ret -ne 0 ]; then
646 error
"$(gettext "Failed to extract
%s
")" "$file"
647 plain
"$(gettext "Aborting...
")"
652 if [ $EUID -eq 0 ]; then
653 # change perms of all source files to root user & root group
654 chown
-R 0:0 "$srcdir"
659 # use distcc if it is requested (check buildenv and PKGBUILD opts)
660 if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then
661 [ -d /usr
/lib
/distcc
/bin
] && export PATH
="/usr/lib/distcc/bin:$PATH"
663 elif [ "$(check_option distcc)" = "n" ]; then
664 # if it is not wanted, clear the makeflags too
668 # use ccache if it is requested (check buildenv and PKGBUILD opts)
669 if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then
670 [ -d /usr
/lib
/ccache
/bin
] && export PATH
="/usr/lib/ccache/bin:$PATH"
673 # clear user-specified makeflags if requested
674 if [ "$(check_option makeflags)" = "n" ]; then
678 msg
"$(gettext "Starting build
()...
")"
681 # ensure all necessary build variables are exported
682 export CFLAGS CXXFLAGS MAKEFLAGS LDFLAGS CHOST
683 # save our shell options so build() can't override what we need
684 local shellopts
=$
(shopt -p)
687 if [ "$LOGGING" = "1" ]; then
688 BUILDLOG
="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-build.log"
689 if [ -f "$BUILDLOG" ]; then
692 if [ -f "$BUILDLOG.$i" ]; then
698 mv "$BUILDLOG" "$BUILDLOG.$i"
701 build
2>&1 |
tee "$BUILDLOG"; ret
=${PIPESTATUS[0]}
705 # reset our shell options
708 if [ $ret -gt 0 ]; then
709 error
"$(gettext "Build Failed.
")"
710 plain
"$(gettext "Aborting...
")"
712 exit 2 # $E_BUILD_FAILED
717 # clear user-specified makeflags if requested
718 if [ "$(check_option makeflags)" = "n" ]; then
722 msg
"$(gettext "Starting package
()...
")"
725 # ensure all necessary build variables are exported
726 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
729 if [ "$LOGGING" = "1" ]; then
730 BUILDLOG
="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-package.log"
731 if [ -f "$BUILDLOG" ]; then
734 if [ -f "$BUILDLOG.$i" ]; then
740 mv "$BUILDLOG" "$BUILDLOG.$i"
743 package
2>&1 |
tee "$BUILDLOG"; ret
=${PIPESTATUS[0]}
745 package
2>&1 || ret
=$?
748 if [ $ret -gt 0 ]; then
749 error
"$(gettext "Packaging Failed.
")"
750 plain
"$(gettext "Aborting...
")"
752 exit 2 # $E_BUILD_FAILED
758 msg
"$(gettext "Tidying
install...
")"
760 if [ "$(check_option docs)" = "n" -a -n "${DOC_DIRS[*]}" ]; then
761 msg2
"$(gettext "Removing doc files...
")"
762 rm -rf ${DOC_DIRS[@]}
765 if [ "$(check_option purge)" = "y" -a -n "${PURGE_TARGETS[*]}" ]; then
766 msg2
"$(gettext "Purging other files...
")"
768 for pt
in "${PURGE_TARGETS[@]}"; do
769 if [ "${pt}" == "${pt//\/}" ]; then
770 find .
-type f
-name "${pt}" -exec rm -f -- '{}' \
;
777 if [ "$(check_option zipman)" = "y" -a -n "${MAN_DIRS[*]}" ]; then
778 msg2
"$(gettext "Compressing man and info pages...
")"
779 local manpage ext
file link hardlinks hl
780 find ${MAN_DIRS[@]} -type f
2>/dev
/null |
781 while read manpage
; do
782 # check file still exists (potentially compressed with hard link)
783 if [ -f ${manpage} ]; then
785 file="${manpage##*/}"
786 if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then
787 # update symlinks to this manpage
788 find ${MAN_DIRS[@]} -lname "$file" 2>/dev
/null |
791 ln -sf "${file}.gz" "${link}.gz"
793 # find hard links and remove them
794 # the '|| true' part keeps the script from bailing if find returned an
795 # error, such as when one of the man directories doesn't exist
796 hardlinks
="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
797 for hl
in ${hardlinks}; do
800 # compress the original
802 # recreate hard links removed earlier
803 for hl
in ${hardlinks}; do
804 ln "${manpage}.gz" "${hl}.gz"
812 if [ "$(check_option strip)" = "y" -a -n "${STRIP_DIRS[*]}" ]; then
813 msg2
"$(gettext "Stripping debugging symbols from binaries and libraries...
")"
815 find ${STRIP_DIRS[@]} -type f
2>/dev
/null |
while read binary
; do
816 case "$(file -biz "$binary")" in
817 *application
/x-sharedlib
*) # Libraries (.so)
818 /usr
/bin
/strip
--strip-debug "$binary";;
819 *application
/x-archive
*) # Libraries (.a)
820 /usr
/bin
/strip
--strip-debug "$binary";;
821 *application
/x-executable
*) # Binaries
822 /usr
/bin
/strip
"$binary";;
827 if [ "$(check_option libtool)" = "n" ]; then
828 msg2
"$(gettext "Removing libtool .la files...
")"
829 find .
! -type d
-name "*.la" -exec rm -f -- '{}' \
;
832 if [ "$(check_option emptydirs)" = "n" ]; then
833 msg2
"$(gettext "Removing empty directories...
")"
834 find .
-depth -type d
-empty -delete
839 if [ ! -d "$pkgdir" ]; then
840 error
"$(gettext "Missing pkg
/ directory.
")"
841 plain
"$(gettext "Aborting...
")"
842 exit 1 # $E_MISSING_PKGDIR
846 msg
"$(gettext "Creating package...
")"
848 local builddate
=$
(date -u "+%s")
849 if [ "$PACKAGER" != "" ]; then
850 local packager
="$PACKAGER"
852 local packager
="Unknown Packager"
854 local size
=$
(du
-sk |
awk '{print $1 * 1024}')
856 # write the .PKGINFO file
857 msg2
"$(gettext "Generating .PKGINFO
file...
")"
858 echo "# Generated by makepkg $myver" >.PKGINFO
859 if [ "$INFAKEROOT" = "1" ]; then
860 echo "# using $(fakeroot -v)" >>.PKGINFO
862 echo "# $(LC_ALL=C date -u)" >>.PKGINFO
863 echo "pkgname = $pkgname" >>.PKGINFO
864 echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO
865 echo "pkgdesc = $pkgdesc" >>.PKGINFO
866 echo "url = $url" >>.PKGINFO
867 echo "builddate = $builddate" >>.PKGINFO
868 echo "packager = $packager" >>.PKGINFO
869 echo "size = $size" >>.PKGINFO
870 if [ "$CARCH" != "" ]; then
871 echo "arch = $CARCH" >>.PKGINFO
873 if [ "$(check_option force)" = "y" ]; then
874 echo "force = true" >> .PKGINFO
878 for it
in "${license[@]}"; do
879 echo "license = $it" >>.PKGINFO
881 for it
in "${replaces[@]}"; do
882 echo "replaces = $it" >>.PKGINFO
884 for it
in "${groups[@]}"; do
885 echo "group = $it" >>.PKGINFO
887 for it
in "${depends[@]}"; do
888 echo "depend = $it" >>.PKGINFO
890 for it
in "${optdepends[@]}"; do
891 echo "optdepend = $it" >>.PKGINFO
893 for it
in "${conflicts[@]}"; do
894 echo "conflict = $it" >>.PKGINFO
896 for it
in "${provides[@]}"; do
897 echo "provides = $it" >>.PKGINFO
899 for it
in "${backup[@]}"; do
900 echo "backup = $it" >>.PKGINFO
902 for it
in "${packaging_options[@]}"; do
903 local ret
="$(check_option $it)"
904 if [ "$ret" != "?" ]; then
905 if [ "$ret" = "y" ]; then
906 echo "makepkgopt = $it" >>.PKGINFO
908 echo "makepkgopt = !$it" >>.PKGINFO
913 # TODO maybe remove this at some point
914 # warn if license array is not present or empty
915 if [ "$license" = "" ]; then
916 warning
"$(gettext "Please add a license line to your
%s
!")" "$BUILDSCRIPT"
917 plain
"$(gettext "Example
for GPL
'ed software: license=('GPL
').")"
920 local comp_files=".PKGINFO"
922 # check for an install script
923 if [ "$install" != "" ]; then
924 msg2 "$(gettext "Adding install script...")"
925 cp "$startdir/$install" .INSTALL
926 comp_files="$comp_files .INSTALL"
929 # do we have a changelog?
930 if [ -f "$startdir/ChangeLog" ]; then
931 msg2 "$(gettext "Adding package changelog...")"
932 cp "$startdir/ChangeLog" .CHANGELOG
933 comp_files="$comp_files .CHANGELOG"
937 msg2 "$(gettext "Compressing package...")"
941 *tar.gz) TAR_OPT="z" ;;
942 *tar.bz2) TAR_OPT="j" ;;
943 *) warning "$(gettext "'%s
' is not a valid archive extension.")" \
947 local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
949 # when fileglobbing, we want * in an empty directory to expand to
950 # the null string rather than itself
953 if ! bsdtar -c${TAR_OPT}f "$pkg_file" $comp_files *; then
954 error "$(gettext "Failed to create package file.")"
955 exit 1 # TODO: error code
961 if [ "$(check_buildenv xdelta)" != "y" ]; then
963 elif [ ! "$(type -p xdelta)" ]; then
964 error "$(gettext "Cannot find the xdelta binary! Is xdelta installed?")"
969 local cache_dir="/var/cache/pacman/pkg" # TODO: autoconf me
970 local pkginfo="$(mktemp "$startdir"/xdelta-pkginfo.XXXXXXXXX)"
972 local old_file old_version
973 for old_file in $(ls {"$cache_dir","$PKGDEST"}/${pkgname}-*-*{,-$CARCH}$PKGEXT 2>/dev/null); do
974 bsdtar -xOf "$old_file" .PKGINFO > "$pkginfo" || continue
975 if [ "$(cat "$pkginfo" | grep '^pkgname
= ')" != "pkgname = $pkgname" ]; then
976 continue # Package name does not match.
977 elif [ "$(cat "$pkginfo" | grep '^arch
= ')" != "arch = $CARCH" ] ; then
978 continue # Not same arch.
981 old_version="$(cat "$pkginfo" | grep '^pkgver
= ' | sed 's
/^pkgver
= //')"
983 # old_version may include the target package, only use the old versions
984 local vercmp=$(vercmp "$old_version" "$latest_version")
985 if [ "$old_version" != "$pkgver-$pkgrel" -a $vercmp -gt 0 ]; then
986 local latest_version=$old_version
987 local base_file=$old_file
993 if [ "$base_file" != "" ]; then
994 msg "$(gettext "Making delta from version %s...")" "$latest_version"
995 local delta_file="$PKGDEST/$pkgname-${latest_version}_to_$pkgver-$pkgrel-$CARCH.delta"
998 # xdelta will decompress base_file & pkg_file into TMP_DIR (or /tmp if
999 # TMP_DIR is unset) then perform the delta on the resulting tars
1000 xdelta delta "$base_file" "$pkg_file" "$delta_file" || ret=$?
1002 if [ $ret -eq 0 -o $ret -eq 1 ]; then
1003 # Generate the final gz using xdelta for compression. xdelta will be our
1004 # common denominator compression utility between the packager and the
1005 # users. makepkg and pacman must use the same compression algorithm or
1006 # the delta generated package may not match, producing md5 checksum
1008 msg2 "$(gettext "Recreating package tarball from delta to match md5 signatures")"
1009 msg2 "$(gettext "NOTE: the delta should ONLY be distributed with this tarball")"
1011 xdelta patch "$delta_file" "$base_file" "$pkg_file" || ret=$?
1012 if [ $ret -ne 0 ]; then
1013 error "$(gettext "Could not generate the package from the delta.")"
1017 warning "$(gettext "Delta was not able to be created.")"
1020 warning "$(gettext "No previous version found, skipping xdelta.")"
1024 create_srcpackage() {
1026 if [ "$SOURCEONLY" = "2" ]; then
1027 # get back to our src directory so we can begin with sources
1031 # we can only check checksums if we have all files
1035 msg "$(gettext "Creating source package...")"
1036 local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
1037 mkdir "${srclinks}"/${pkgname}
1039 msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
1040 ln -s "${startdir}/${BUILDSCRIPT}" "${srclinks}/${pkgname}/"
1042 if [ "$install" != "" ]; then
1043 if [ -f $install ]; then
1044 msg2 "$(gettext "Adding install script...")"
1045 ln -s "${startdir}/$install" "${srclinks}/${pkgname}/"
1047 error "$(gettext "Install script %s not found.")" "$install"
1051 if [ -f ChangeLog ]; then
1052 msg2 "$(gettext "Adding %s...")" "ChangeLog"
1053 ln -s "${startdir}/ChangeLog" "${srclinks}/${pkgname}"
1057 for netfile in "${source[@]}"; do
1058 local file=$(get_filename "$netfile")
1059 if [ -f "$netfile" ]; then
1060 msg2 "$(gettext "Adding %s...")" "$netfile"
1061 ln -s "${startdir}/$netfile" "${srclinks}/${pkgname}"
1062 elif [ "$SOURCEONLY" = "2" -a -f "$SRCDEST/$file" ]; then
1063 msg2 "$(gettext "Adding %s...")" "$file"
1064 ln -s "$SRCDEST/$file" "${srclinks}/${pkgname}/"
1070 *tar.gz) TAR_OPT="z" ;;
1071 *tar.bz2) TAR_OPT="j" ;;
1072 *) warning "$(gettext "'%s
' is not a valid archive extension.")" \
1076 local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}${SRCEXT}"
1079 msg2 "$(gettext "Compressing source package...")"
1081 if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgname}; then
1082 error "$(gettext "Failed to create source package file.")"
1083 exit 1 # TODO: error code
1086 rm -rf "${srclinks}"
1090 [ "$INSTALL" = "0" ] && return
1091 msg "$(gettext "Installing package ${pkgname} with pacman -U...")"
1092 if [ "$ASROOT" = "0" ]; then
1093 sudo pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} || exit $?
1095 pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} || exit $?
1101 # Only update pkgver if --holdver is not set
1102 if [ "$HOLDVER" = "1" ]; then
1105 # Cannot update pkgver/pkgrel if reading PKGBUILD from pipe
1106 if [ ! -f "./$BUILDSCRIPT" ]; then
1109 if [ "$FORCE_VER" = "" ]; then
1110 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
1111 # This will only be used on the first call to makepkg; subsequent
1112 # calls to makepkg via fakeroot will explicitly pass the version
1113 # number to avoid having to determine the version number twice.
1114 # Also do a brief check to make sure we have the VCS tool available.
1116 if [ -n "${_darcstrunk}" -a -n "${_darcsmod}" ] ; then
1117 [ $(type -p darcs) ] || return 0
1118 msg "$(gettext "Determining latest darcs revision...")"
1119 newpkgver=$(date +%Y%m%d)
1120 elif [ -n "${_cvsroot}" -a -n "${_cvsmod}" ] ; then
1121 [ $(type -p cvs) ] || return 0
1122 msg "$(gettext "Determining latest cvs revision...")"
1123 newpkgver=$(date +%Y%m%d)
1124 elif [ -n "${_gitroot}" -a -n "${_gitname}" ] ; then
1125 [ $(type -p git) ] || return 0
1126 msg "$(gettext "Determining latest git revision...")"
1127 newpkgver=$(date +%Y%m%d)
1128 elif [ -n "${_svntrunk}" -a -n "${_svnmod}" ] ; then
1129 [ $(type -p svn) ] || return 0
1130 msg "$(gettext "Determining latest svn revision...")"
1131 newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's
/^Last Changed Rev
: \
([0-9]*\
)$
/\
1/p
')
1132 elif [ -n "${_bzrtrunk}" -a -n "${_bzrmod}" ] ; then
1133 [ $(type -p bzr) ] || return 0
1134 msg "$(gettext "Determining latest bzr revision...")"
1135 newpkgver=$(bzr revno ${_bzrtrunk})
1136 elif [ -n "${_hgroot}" -a -n "${_hgrepo}" ] ; then
1137 [ $(type -p hg) ] || return 0
1138 msg "$(gettext "Determining latest hg revision...")"
1139 if [ -d ./src/$_hgrepo ] ; then
1144 [[ ! -d ./src/ ]] && mkdir ./src/
1145 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1148 newpkgver=$(hg tip --template "{rev}")
1152 if [ "$newpkgver" != "" ]; then
1153 msg2 "$(gettext "Version found: %s")" "$newpkgver"
1159 # Version number retrieved from fakeroot->makepkg argument
1160 newpkgver=$FORCE_VER
1165 # This is lame, but if we're wanting to use an updated pkgver
for
1166 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1167 # the new pkgver and then re-source it. This is the most robust
1168 # method for dealing with PKGBUILDs that use, e.g.:
1174 if [ "$newpkgver" != "" ]; then
1175 if [ "$newpkgver" != "$pkgver" ]; then
1176 if [ -f "./$BUILDSCRIPT" ]; then
1177 sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "./$BUILDSCRIPT"
1178 sed -i "s/^pkgrel=[^ ]*/pkgrel=1/" "./$BUILDSCRIPT"
1179 source "$BUILDSCRIPT"
1185 backup_package_variables
() {
1186 for var
in ${splitpkg_overrides[@]}; do
1187 indirect
="${var}_backup"
1188 eval "${indirect}=\"${!var}\""
1192 restore_package_variables
() {
1193 for var
in ${splitpkg_overrides[@]}; do
1194 indirect
="${var}_backup"
1195 if [ -n "${!indirect}" ]; then
1196 eval "${var}=\"${!indirect}\""
1203 # getopt like parser
1205 local short_options
=$1; shift;
1206 local long_options
=$1; shift;
1208 local unused_options
=""
1210 while [ -n "$1" ]; do
1211 if [ ${1:0:2} = '--' ]; then
1212 if [ -n "${1:2}" ]; then
1214 for i
in ${long_options//,/ }; do
1215 if [ ${1:2} = ${i//:} ]; then
1220 if [ -n "$match" ]; then
1221 if [ ${1:2} = $match ]; then
1224 if [ -n "$2" ]; then
1229 echo "makepkg: option '$1' $(gettext "requires an argument
")" >&2
1234 echo "makepkg: $(gettext "unrecognized option
") '$1'" >&2
1241 elif [ ${1:0:1} = '-' ]; then
1242 for ((i
=1; i
<${#1}; i
++)); do
1243 if [[ "$short_options" =~
"${1:i:1}" ]]; then
1244 if [[ "$short_options" =~
"${1:i:1}:" ]]; then
1245 if [ -n "${1:$i+1}" ]; then
1246 printf ' -%s' "${1:i:1}"
1247 printf " '%s'" "${1:$i+1}"
1249 if [ -n "$2" ]; then
1250 printf ' -%s' "${1:i:1}"
1252 printf " '%s'" "${1}"
1254 echo "makepkg: option $(gettext "requires an argument
") -- '${1:i:1}'" >&2
1260 printf ' -%s' "${1:i:1}"
1263 echo "makepkg: $(gettext "invalid option
") -- '${1:i:1}'" >&2
1268 unused_options
="${unused_options} '$1'"
1274 if [ -n "$unused_options" ]; then
1275 for i
in ${unused_options[@]}; do
1279 if [ -n "$1" ]; then
1280 while [ -n "$1" ]; do
1281 printf " '%s'" "${1}"
1291 printf "makepkg (pacman) %s\n" "$myver"
1293 printf "$(gettext "Usage
: %s
[options
]")\n" "$0"
1295 echo "$(gettext "Options
:")"
1296 printf "$(gettext " -A, --ignorearch Ignore incomplete arch field
in %s
")\n" "$BUILDSCRIPT"
1297 echo "$(gettext " -c, --clean Clean up work files after build
")"
1298 echo "$(gettext " -C, --cleancache Clean up
source files from the cache
")"
1299 printf "$(gettext " --config <config
> Use an alternate config
file (instead of
'%s')")\n" "$confdir/makepkg.conf"
1300 echo "$(gettext " -d, --nodeps Skip all dependency checks
")"
1301 echo "$(gettext " -e, --noextract Do not extract
source files
(use existing src
/ dir
)")"
1302 echo "$(gettext " -f, --force Overwrite existing package
")"
1303 echo "$(gettext " -g, --geninteg Generate integrity checks
for source files
")"
1304 echo "$(gettext " -h, --help This
help")"
1305 echo "$(gettext " -i, --install Install package after successful build
")"
1306 echo "$(gettext " -L, --log Log package build process
")"
1307 echo "$(gettext " -m, --nocolor Disable colorized output messages
")"
1308 echo "$(gettext " -o, --nobuild Download and extract files only
")"
1309 printf "$(gettext " -p <buildscript
> Use an alternate build
script (instead of
'%s')")\n" "$BUILDSCRIPT"
1310 echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build
")"
1311 # fix flyspray feature request #2978
1312 echo "$(gettext " -R, --repackage Repackage contents of pkg
/ without building
")"
1313 echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman
")"
1314 echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources
")"
1315 echo "$(gettext " --asroot Allow makepkg to run as root user
")"
1316 echo "$(gettext " --holdver Prevent automatic version bumping
for development PKGBUILDs
")"
1317 echo "$(gettext " --source Generate a source-only tarball without downloaded sources
")"
1319 echo "$(gettext "These options can be passed to pacman
:")"
1321 echo "$(gettext " --noconfirm Do not ask
for confirmation when resolving dependencies
")"
1322 echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files
")"
1324 printf "$(gettext "If
-p is not specified
, makepkg will
look for '%s'")\n" "$BUILDSCRIPT"
1329 printf "makepkg (pacman) %s\n" "$myver"
1330 printf "$(gettext "\
1331 Copyright
(C
) 2002-2007 Judd Vinet
<jvinet@zeroflux.org
>.
\n\n\
1332 This is free software
; see the
source for copying conditions.
\n\
1333 There is NO WARRANTY
, to the extent permitted by law.
\n")"
1338 # determine whether we have gettext; make it a no-op if we do not
1339 if [ ! $
(type -t gettext) ]; then
1347 # Parse Command Line Options.
1348 OPT_SHORT
="AbcCdefFghiLmop:rRsV"
1349 OPT_LONG
="allsource,asroot,ignorearch,builddeps,clean,cleancache,nodeps"
1350 OPT_LONG
="$OPT_LONG,noextract,force,forcever:,geninteg,help,holdver"
1351 OPT_LONG
="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source"
1352 OPT_LONG
="$OPT_LONG,syncdeps,version,config:"
1354 OPT_LONG
="$OPT_LONG,noconfirm,noprogressbar"
1355 OPT_TEMP
="$(parse_options $OPT_SHORT $OPT_LONG "$@
" || echo 'PARSE_OPTIONS FAILED')"
1356 if echo "$OPT_TEMP" |
grep -q 'PARSE_OPTIONS FAILED'; then
1357 # This is a small hack to stop the script bailing with 'set -e'
1358 echo; usage
; exit 1 # E_INVALID_OPTION;
1360 eval set -- "$OPT_TEMP"
1361 unset OPT_SHORT OPT_LONG OPT_TEMP
1366 --noconfirm) PACMAN_OPTS
="$PACMAN_OPTS --noconfirm" ;;
1367 --noprogressbar) PACMAN_OPTS
="$PACMAN_OPTS --noprogressbar" ;;
1370 --allsource) SOURCEONLY
=2 ;;
1371 --asroot) ASROOT
=1 ;;
1372 -A|
--ignorearch) IGNOREARCH
=1 ;;
1373 -c|
--clean) CLEANUP
=1 ;;
1374 -C|
--cleancache) CLEANCACHE
=1 ;;
1375 --config) shift; MAKEPKG_CONF
=$1 ;;
1376 -d|
--nodeps) NODEPS
=1 ;;
1377 -e|
--noextract) NOEXTRACT
=1 ;;
1378 -f|
--force) FORCE
=1 ;;
1379 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1380 --forcever) shift; FORCE_VER
=$1;;
1382 -g|
--geninteg) GENINTEG
=1 ;;
1383 --holdver) HOLDVER
=1 ;;
1384 -i|
--install) INSTALL
=1 ;;
1385 -L|
--log) LOGGING
=1 ;;
1386 -m|
--nocolor) USE_COLOR
='n' ;;
1387 -o|
--nobuild) NOBUILD
=1 ;;
1388 -p) shift; BUILDSCRIPT
=$1 ;;
1389 -r|
--rmdeps) RMDEPS
=1 ;;
1390 -R|
--repackage) REPKG
=1 ;;
1391 --source) SOURCEONLY
=1 ;;
1392 -s|
--syncdeps) DEP_BIN
=1 ;;
1394 -h|
--help) usage
; exit 0 ;; # E_OK
1395 -V|
--version) version
; exit 0 ;; # E_OK
1397 --) OPT_IND
=0; shift; break;;
1398 *) usage
; exit 1 ;; # E_INVALID_OPTION
1403 #preserve environment variables
1407 # default config is makepkg.conf
1408 MAKEPKG_CONF
=${MAKEPKG_CONF:-$confdir/makepkg.conf}
1410 # Source the config file; fail if it is not found
1411 if [ -r "$MAKEPKG_CONF" ]; then
1412 source "$MAKEPKG_CONF"
1414 error
"$(gettext "%s not found.
")" "$MAKEPKG_CONF"
1415 plain
"$(gettext "Aborting...
")"
1416 exit 1 # $E_CONFIG_ERROR
1419 # Source user-specific makepkg.conf overrides
1420 if [ -r ~
/.makepkg.conf
]; then
1421 source ~
/.makepkg.conf
1424 # override settings with an environment variable for batch processing
1425 PKGDEST
=${_PKGDEST:-$PKGDEST}
1426 PKGDEST
=${PKGDEST:-$startdir} #default to $startdir if undefined
1427 SRCDEST
=${_SRCDEST:-$SRCDEST}
1428 SRCDEST
=${SRCDEST:-$startdir} #default to $startdir if undefined
1431 if [ "$HOLDVER" = "1" -a "$FORCE_VER" != "" ]; then
1432 # The '\\0' is here to prevent gettext from thinking --holdver is an option
1433 error
"$(gettext "\\0--holdver and
--forcever cannot both be specified
" )"
1437 if [ "$CLEANCACHE" = "1" ]; then
1438 #fix flyspray feature request #5223
1439 if [ -n "$SRCDEST" -a "$SRCDEST" != "$startdir" ]; then
1440 msg
"$(gettext "Cleaning up ALL files from
%s.
")" "$SRCDEST"
1441 echo -n "$(gettext " Are you sure you wish to
do this?
")"
1442 echo -n "$(gettext "[Y
/n
]")"
1444 answer
=$
(echo $answer |
tr '[:lower:]' '[:upper:]')
1445 if [ "$answer" = "$(gettext "YES
")" -o "$answer" = "$(gettext "Y
")" ]; then
1447 if [ $?
-ne 0 ]; then
1448 error
"$(gettext "Problem removing files
; you may not have correct permissions
in %s
")" "$SRCDEST"
1452 msg
"$(gettext "Source cache cleaned.
")"
1457 msg
"$(gettext "No files have been removed.
")"
1461 # $SRCDEST is $startdir, two possibilities
1462 error
"$(gettext "Source destination must be defined
in %s.
")" "$MAKEPKG_CONF"
1463 plain
"$(gettext "In addition
, please run makepkg
-C outside of your cache directory.
")"
1468 if [ -z "$BUILDSCRIPT" ]; then
1469 error
"$(gettext "BUILDSCRIPT is undefined
! Ensure you have updated
%s.
")" "$MAKEPKG_CONF"
1473 if [ "$INFAKEROOT" = "0" ]; then
1474 if [ $EUID -eq 0 -a "$ASROOT" = "0" ]; then
1475 # Warn those who like to live dangerously.
1476 error
"$(gettext "Running makepkg as root is a BAD idea and can cause
")"
1477 plain
"$(gettext "permanent
, catastrophic damage to your system. If you
")"
1478 plain
"$(gettext "wish to run as root
, please use the
--asroot option.
")"
1479 exit 1 # $E_USER_ABORT
1480 elif [ $EUID -gt 0 -a "$ASROOT" = "1" ]; then
1481 # Warn those who try to use the --asroot option when they are not root
1482 error
"$(gettext "The
--asroot option is meant
for the root user only.
")"
1483 plain
"$(gettext "Please rerun makepkg without the
--asroot flag.
")"
1484 exit 1 # $E_USER_ABORT
1485 elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then
1486 if [ ! $
(type -p fakeroot
) ]; then
1487 error
"$(gettext "Fakeroot must be installed
if using the
'fakeroot' option
")"
1488 plain
"$(gettext "in the BUILDENV array
in %s.
")" "$MAKEPKG_CONF"
1491 elif [ $EUID -gt 0 ]; then
1492 warning
"$(gettext "Running makepkg as an unprivileged user will result
in non-root
")"
1493 plain
"$(gettext "ownership of the packaged files. Try using the fakeroot environment by
")"
1494 plain
"$(gettext "placing
'fakeroot' in the BUILDENV array
in %s.
")" "$MAKEPKG_CONF"
1498 if [ "$FAKEROOTKEY" = "" ]; then
1499 error
"$(gettext "Do not use the
'-F' option. This option is only
for use by makepkg.
")"
1500 exit 1 # TODO: error code
1504 # check for sudo if we will need it during makepkg execution
1505 if [ "$ASROOT" = "0" -a \
( "$DEP_BIN" = "1" \
1506 -o "$RMDEPS" = "1" -o "$INSTALL" = "1" \
) ]; then
1507 if [ ! "$(type -p sudo)" ]; then
1508 error
"$(gettext "Cannot
find the sudo binary
! Is sudo installed?
")"
1509 plain
"$(gettext "Missing dependencies cannot be installed or removed as a normal user
")"
1510 plain
"$(gettext "without sudo
; install and configure sudo to auto-resolve dependencies.
")"
1515 unset pkgname pkgver pkgrel pkgdesc url license groups provides md5sums
1516 unset replaces depends conflicts backup
source install build makedepends
1517 unset optdepends options noextract
1519 if [ ! -f "$BUILDSCRIPT" ]; then
1521 error
"$(gettext "%s does not exist.
")" "$BUILDSCRIPT"
1524 # PKGBUILD passed through a pipe
1525 BUILDSCRIPT
=/dev
/stdin
1528 crlftest
=$
(file $BUILDSCRIPT |
grep -F 'CRLF' || true
)
1529 if [ "$crlftest" != "" ]; then
1530 error
"$(gettext "%s contains CRLF characters and cannot be sourced.
")" "$BUILDSCRIPT"
1535 source "$BUILDSCRIPT"
1537 if [ "$GENINTEG" = "1" ]; then
1545 # check for no-no's in the build script
1546 if [ -z "$pkgname" ]; then
1547 error
"$(gettext "%s is not allowed to be empty.
")" "pkgname"
1550 if [ -z "$pkgver" ]; then
1551 error
"$(gettext "%s is not allowed to be empty.
")" "pkgver"
1554 if [ -z "$pkgrel" ]; then
1555 error
"$(gettext "%s is not allowed to be empty.
")" "pkgrel"
1558 if [ "$pkgver" != "${pkgver//-/}" ]; then
1559 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgver"
1562 if [ "$pkgrel" != "${pkgrel//-/}" ]; then
1563 error
"$(gettext "%s is not allowed to contain hyphens.
")" "pkgrel"
1567 if [ "$arch" = 'any' ]; then
1571 if ! in_array
$CARCH ${arch[@]}; then
1572 if [ "$IGNOREARCH" = "0" ]; then
1573 error
"$(gettext "%s is not available
for the
'%s' architecture.
")" "$pkgname" "$CARCH"
1574 plain
"$(gettext "Note that many packages may need a line added to their
%s
")" "$BUILDSCRIPT"
1575 plain
"$(gettext "such as arch
=('%s').
")" "$CARCH"
1580 for provide
in ${provides[@]}; do
1581 if [ $provide != ${provide//</} -o $provide != ${provide//>/} ]; then
1582 error
"$(gettext "Provides array cannot contain comparison
(< or
>) operators.
")"
1588 if [ "$install" -a ! -f "$install" ]; then
1589 error
"$(gettext "Install scriptlet
(%s
) does not exist.
")" "$install"
1594 for opt
in ${options[@]}; do
1596 # check if option matches a known option or its inverse
1597 for kopt
in ${packaging_options[@]} ${other_options[@]}; do
1598 if [ "${opt}" = "${kopt}" -o "${opt}" = "!${kopt}" ]; then
1602 if [ $known -eq 0 ]; then
1603 error
"$(gettext "options array contains unknown option
'%s'")" "$opt"
1607 if [ $valid_options -eq 0 ]; then
1610 unset valid_options opt known kopt
1612 # We need to run devel_update regardless of whether we are in the fakeroot
1613 # build process so that if the user runs makepkg --forcever manually, we
1614 # 1) output the correct pkgver, and 2) use the correct filename when
1615 # checking if the package file already exists - fixes FS #9194
1619 if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \
1620 -a "$FORCE" = "0" -a "$SOURCEONLY" = "0" -a "$NOBUILD" = "0" ]; then
1621 if [ "$INSTALL" = "1" ]; then
1622 warning
"$(gettext "A package has already been built
, installing existing package...
")"
1626 error
"$(gettext "A package has already been built.
(use
-f to overwrite
)")"
1631 # Run the bare minimum in fakeroot
1632 if [ "$INFAKEROOT" = "1" ]; then
1633 if [ "$REPKG" = "0" ]; then
1634 if [ "$(type -t package)" != "function" ]; then
1644 msg
"$(gettext "Leaving fakeroot environment.
")"
1648 msg
"$(gettext "Making package
: %s
")" "$pkgname $pkgver-$pkgrel $CARCH ($(date))"
1650 # if we are creating a source-only package, go no further
1651 if [ "$SOURCEONLY" != "0" ]; then
1652 if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}${SRCEXT}" \
1653 -a "$FORCE" = "0" ]; then
1654 error
"$(gettext "A package has already been built.
(use
-f to overwrite
)")"
1658 msg
"$(gettext "Source package created
: %s
")" "$pkgname ($(date))"
1662 # fix flyspray bug #5973
1663 if [ "$NODEPS" = "1" -o "$NOBUILD" = "1" -o "$REPKG" = "1" ]; then
1664 # no warning message needed for nobuild, repkg
1665 if [ "$NODEPS" = "1" ]; then
1666 warning
"$(gettext "Skipping dependency checks.
")"
1668 elif [ $
(type -p pacman
) ]; then
1669 unset pkgdeps
# Set by resolve_deps() and used by remove_deps()
1672 msg
"$(gettext "Checking Runtime Dependencies...
")"
1673 resolve_deps
${depends[@]} || deperr
=1
1675 msg
"$(gettext "Checking Buildtime Dependencies...
")"
1676 resolve_deps
${makedepends[@]} || deperr
=1
1678 if [ $deperr -eq 1 ]; then
1679 error
"$(gettext "Could not resolve all dependencies.
")"
1683 warning
"$(gettext "pacman was not found
in PATH
; skipping dependency checks.
")"
1686 # ensure we have a sane umask set
1689 # get back to our src directory so we can begin with sources
1693 if [ "$NOEXTRACT" = "1" ]; then
1694 warning
"$(gettext "Skipping
source retrieval
-- using existing src
/ tree
")"
1695 warning
"$(gettext "Skipping
source integrity checks
-- using existing src
/ tree
")"
1696 warning
"$(gettext "Skipping
source extraction
-- using existing src
/ tree
")"
1698 if [ "$NOEXTRACT" = "1" -a "$(ls "$srcdir" 2>/dev/null)" = "" ]; then
1699 error
"$(gettext "The
source directory is empty
, there is nothing to build
!")"
1700 plain
"$(gettext "Aborting...
")"
1703 elif [ "$REPKG" = "1" -a \
( ! -d "$pkgdir" -o "$(ls "$pkgdir" 2>/dev/null)" = "" \
) ]; then
1704 error
"$(gettext "The package directory is empty
, there is nothing to repackage
!")"
1705 plain
"$(gettext "Aborting...
")"
1713 if [ "$NOBUILD" = "1" ]; then
1714 msg
"$(gettext "Sources are ready.
")"
1717 # check for existing pkg directory; don't remove if we are repackaging
1718 if [ -d "$pkgdir" -a "$REPKG" = "0" ]; then
1719 msg
"$(gettext "Removing existing pkg
/ directory...
")"
1725 # if we are root or if fakeroot is not enabled, then we don't use it
1726 if [ "$(check_buildenv fakeroot)" != "y" -o $EUID -eq 0 ]; then
1727 if [ "$REPKG" = "0" ]; then
1730 if [ "$(type -t package)" == "function" ]; then
1738 if [ "$(type -t package)" == "function" ]; then
1744 msg
"$(gettext "Entering fakeroot environment...
")"
1746 if [ "$newpkgver" != "" ]; then
1747 fakeroot
-- $0 --forcever $newpkgver -F $ARGLIST ||
exit $?
1749 fakeroot
-- $0 -F $ARGLIST ||
exit $?
1753 create_xdelta
"$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
1756 msg
"$(gettext "Finished making
: %s
")" "$pkgname $pkgver-$pkgrel $CARCH ($(date))"
1762 # vim: set ts=2 sw=2 noet: