makepkg: add functions for backup and restore of package fields
[pacman-ng.git] / scripts / makepkg.sh.in
blob4d33a9c06997c4fecf6c944f6024c3b89e942a03
1 #!/bin/bash -e
3 # makepkg - make packages compatable for use with pacman
4 # @configure_input@
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@'
42 startdir="$PWD"
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
52 # Options
53 ASROOT=0
54 CLEANUP=0
55 CLEANCACHE=0
56 DEP_BIN=0
57 FORCE=0
58 INFAKEROOT=0
59 GENINTEG=0
60 INSTALL=0
61 NOBUILD=0
62 NODEPS=0
63 NOEXTRACT=0
64 RMDEPS=0
65 REPKG=0
66 LOGGING=0
67 SOURCEONLY=0
68 IGNOREARCH=0
69 HOLDVER=0
71 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
72 # when dealing with svn/cvs/etc PKGBUILDs.
73 FORCE_VER=""
75 PACMAN_OPTS=
77 ### SUBROUTINES ###
79 plain() {
80 local mesg=$1; shift
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
83 else
84 printf " ${mesg}\n" "$@" >&2
88 msg() {
89 local mesg=$1; shift
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
92 else
93 printf "==> ${mesg}\n" "$@" >&2
97 msg2() {
98 local mesg=$1; shift
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
101 else
102 printf " -> ${mesg}\n" "$@" >&2
106 warning() {
107 local mesg=$1; shift
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
110 else
111 printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
115 error() {
116 local mesg=$1; shift
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
119 else
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.
129 trap_exit() {
130 if [ "$INFAKEROOT" = "0" ]; then
131 echo
132 error "$@"
134 exit 1
139 # Clean up function. Called automatically when the script exits.
141 clean_up() {
142 local EXIT_CODE=$?
144 if [ "$INFAKEROOT" = "1" ]; then
145 # Don't clean up when leaving fakeroot, we're not done yet.
146 return
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*"
159 remove_deps
164 # Signal Traps
166 trap 'clean_up' 0
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
176 get_filename() {
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
184 get_url() {
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
195 # n - disabled
196 # ? - not found
198 check_option() {
199 local ret=$(in_opt_array "$1" ${options[@]})
200 if [ "$ret" != '?' ]; then
201 echo $ret
202 return
205 # fall back to makepkg.conf options
206 ret=$(in_opt_array "$1" ${OPTIONS[@]})
207 if [ "$ret" != '?' ]; then
208 echo $ret
209 return
212 echo '?' # Not Found
217 # Check if option is present in BUILDENV
219 # usage : check_buildenv( $option )
220 # return : y - enabled
221 # n - disabled
222 # ? - not found
224 check_buildenv() {
225 echo $(in_opt_array "$1" ${BUILDENV[@]})
230 # usage : in_opt_array( $needle, $haystack )
231 # return : y - enabled
232 # n - disabled
233 # ? - not found
235 in_opt_array() {
236 local needle=$(echo $1 | tr '[:upper:]' '[:lower:]'); shift
238 local opt
239 for opt in "$@"; do
240 opt=$(echo $opt | tr '[:upper:]' '[:lower:]')
241 if [ "$opt" = "$needle" ]; then
242 echo 'y' # Enabled
243 return
244 elif [ "$opt" = "!$needle" ]; then
245 echo 'n' # Disabled
246 return
248 done
250 echo '?' # Not Found
255 # usage : in_array( $needle, $haystack )
256 # return : 0 - found
257 # 1 - not found
259 in_array() {
260 local needle=$1; shift
261 [ -z "$1" ] && return 1 # Not Found
262 local item
263 for item in "$@"; do
264 [ "$item" = "$needle" ] && return 0 # Found
265 done
266 return 1 # Not Found
269 get_downloadclient() {
270 # $1 = url with valid protocol prefix
271 local url=$1
272 local proto=$(echo "$url" | sed 's|://.*||')
274 # loop through DOWNLOAD_AGENTS variable looking for protocol
275 local i
276 for i in "${DLAGENTS[@]}"; do
277 local handler=$(echo $i | sed 's|::.*||')
278 if [ "$proto" == "$handler" ]; then
279 agent=$(echo $i | sed 's|^.*::||')
280 break
282 done
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
300 echo "$agent"
303 download_file() {
304 # download command
305 local dlcmd=$1
306 # url of the file
307 local url=$2
308 # destination file
309 local file=$3
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}
316 dlfile="$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}
321 else
322 dlcmd="$dlcmd $url"
325 $dlcmd || return $?
327 # rename the temporary download file to the final destination
328 if [ "$dlfile" != "$file" ]; then
329 mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
333 check_deps() {
334 [ $# -gt 0 ] || return
336 pmout=$(pacman $PACMAN_OPTS -T "$@")
337 ret=$?
338 if [ $ret -eq 127 ]; then #unresolved deps
339 echo "$pmout"
340 elif [ $ret -ne 0 ]; then
341 error "$(gettext "Pacman returned a fatal error (%i): %s")" "$ret" "$pmout"
342 exit 1
346 handledeps() {
347 local R_DEPS_SATISFIED=0
348 local R_DEPS_MISSING=1
350 [ $# -eq 0 ] && return $R_DEPS_SATISFIED
352 local deplist="$*"
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...")"
361 local ret=0
363 if [ "$ASROOT" = 0 ]; then
364 sudo pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$?
365 else
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
377 set +e
378 source /etc/profile &>/dev/null
379 set -e
381 return $R_DEPS_SATISFIED
384 resolve_deps() {
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:")"
404 local dep
405 for dep in $deplist; do
406 msg2 "$dep"
407 done
409 return $R_DEPS_MISSING
412 # fix flyspray bug #5923
413 remove_deps() {
414 # $pkgdeps is a GLOBAL variable, set by resolve_deps()
415 [ "$RMDEPS" = "0" ] && return
416 [ "$pkgdeps" = "" ] && return
418 local dep depstrip deplist
419 deplist=""
420 for dep in $pkgdeps; do
421 depstrip=$(echo $dep | sed -e 's|=.*$||' -e 's|>.*$||' -e 's|<.*$||')
422 deplist="$deplist $depstrip"
423 done
425 msg "Removing installed dependencies..."
426 local ret=0
427 if [ "$ASROOT" = "0" ]; then
428 sudo pacman $PACMAN_OPTS -Rns $deplist || ret=$?
429 else
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.")"
436 return 0
440 download_sources() {
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...")"
446 exit 1
449 pushd "$SRCDEST" &>/dev/null
451 local netfile
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/"
459 continue
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/"
464 continue
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
478 local ret=0
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...")"
483 exit 1
485 rm -f "$srcdir/$file"
486 ln -s "$SRCDEST/$file" "$srcdir/"
487 done
489 popd &>/dev/null
492 generate_checksums() {
493 msg "$(gettext "Generating checksums for source files...")"
494 plain ""
496 if [ ! $(type -p openssl) ]; then
497 error "$(gettext "Cannot find openssl.")"
498 exit 1 # $E_MISSING_PROGRAM
501 local integ
502 for integ in ${INTEGRITY_CHECK[@]}; do
503 integ="$(echo $integ | tr '[:upper:]' '[:lower:]')"
504 case "$integ" in
505 md5|sha1|sha256|sha384|sha512) : ;;
507 error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
508 exit 1;; # $E_CONFIG_ERROR
509 esac
511 local ct=0
512 local numsrc=${#source[@]}
513 echo -n "${integ}sums=("
515 local i=0;
516 local indent=''
517 while [ $i -lt $((${#integ}+6)) ]; do
518 indent="$indent "
519 i=$(($i+1))
520 done
522 local netfile
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...")"
530 exit 1
531 else
532 file="$SRCDEST/$file"
536 local sum="$(openssl dgst -${integ} "$file" | awk '{print $NF}')"
537 [ $ct -gt 0 ] && echo -n "$indent"
538 echo -n "'$sum'"
539 ct=$(($ct+1))
540 [ $ct -lt $numsrc ] && echo
541 done
543 echo ")"
544 done
547 check_checksums() {
548 if [ ! $(type -p openssl) ]; then
549 error "$(gettext "Cannot find openssl.")"
550 exit 1 # $E_MISSING_PROGRAM
553 local correlation=0
554 local integ required
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"
559 correlation=1
560 local errors=0
561 local idx=0
562 local file
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
570 errors=1
571 continue
572 else
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
581 else
582 echo "$(gettext "FAILED")" >&2
583 errors=1
586 idx=$((idx + 1))
587 done
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
597 done
599 if [ $correlation -eq 0 ]; then
600 error "$(gettext "Integrity checks are missing.")"
601 exit 1 # TODO: error code
605 extract_sources() {
606 msg "$(gettext "Extracting Sources...")"
607 local netfile
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
613 continue
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...")"
620 exit 1
621 else
622 file="$SRCDEST/$file"
626 # fix flyspray #6246
627 local file_type=$(file -bizL "$file")
628 local cmd=''
629 case "$file_type" in
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
639 continue;;
640 esac
642 local ret=0
643 msg2 "$cmd"
644 $cmd || ret=$?
645 if [ $ret -ne 0 ]; then
646 error "$(gettext "Failed to extract %s")" "$file"
647 plain "$(gettext "Aborting...")"
648 exit 1
650 done
652 if [ $EUID -eq 0 ]; then
653 # change perms of all source files to root user & root group
654 chown -R 0:0 "$srcdir"
658 run_build() {
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"
662 export DISTCC_HOSTS
663 elif [ "$(check_option distcc)" = "n" ]; then
664 # if it is not wanted, clear the makeflags too
665 MAKEFLAGS=""
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
675 MAKEFLAGS=""
678 msg "$(gettext "Starting build()...")"
679 cd "$srcdir"
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)
686 local ret=0
687 if [ "$LOGGING" = "1" ]; then
688 BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-build.log"
689 if [ -f "$BUILDLOG" ]; then
690 local i=1
691 while true; do
692 if [ -f "$BUILDLOG.$i" ]; then
693 i=$(($i +1))
694 else
695 break
697 done
698 mv "$BUILDLOG" "$BUILDLOG.$i"
701 build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]}
702 else
703 build 2>&1 || ret=$?
705 # reset our shell options
706 eval "$shellopts"
708 if [ $ret -gt 0 ]; then
709 error "$(gettext "Build Failed.")"
710 plain "$(gettext "Aborting...")"
711 remove_deps
712 exit 2 # $E_BUILD_FAILED
716 run_package() {
717 # clear user-specified makeflags if requested
718 if [ "$(check_option makeflags)" = "n" ]; then
719 MAKEFLAGS=""
722 msg "$(gettext "Starting package()...")"
723 cd "$srcdir"
725 # ensure all necessary build variables are exported
726 export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
728 local ret=0
729 if [ "$LOGGING" = "1" ]; then
730 BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-package.log"
731 if [ -f "$BUILDLOG" ]; then
732 local i=1
733 while true; do
734 if [ -f "$BUILDLOG.$i" ]; then
735 i=$(($i +1))
736 else
737 break
739 done
740 mv "$BUILDLOG" "$BUILDLOG.$i"
743 package 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]}
744 else
745 package 2>&1 || ret=$?
748 if [ $ret -gt 0 ]; then
749 error "$(gettext "Packaging Failed.")"
750 plain "$(gettext "Aborting...")"
751 remove_deps
752 exit 2 # $E_BUILD_FAILED
756 tidy_install() {
757 cd "$pkgdir"
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...")"
767 local pt
768 for pt in "${PURGE_TARGETS[@]}"; do
769 if [ "${pt}" == "${pt//\/}" ]; then
770 find . -type f -name "${pt}" -exec rm -f -- '{}' \;
771 else
772 rm -f ${pt}
774 done
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
784 ext="${manpage##*.}"
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 |
789 while read link ; do
790 rm -f "$link"
791 ln -sf "${file}.gz" "${link}.gz"
792 done
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
798 rm -f "${hl}";
799 done
800 # compress the original
801 gzip -9 "$manpage"
802 # recreate hard links removed earlier
803 for hl in ${hardlinks}; do
804 ln "${manpage}.gz" "${hl}.gz"
805 chmod 644 ${hl}.gz
806 done
809 done
812 if [ "$(check_option strip)" = "y" -a -n "${STRIP_DIRS[*]}" ]; then
813 msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")"
814 local binary
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";;
823 esac
824 done
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
838 create_package() {
839 if [ ! -d "$pkgdir" ]; then
840 error "$(gettext "Missing pkg/ directory.")"
841 plain "$(gettext "Aborting...")"
842 exit 1 # $E_MISSING_PKGDIR
845 cd "$pkgdir"
846 msg "$(gettext "Creating package...")"
848 local builddate=$(date -u "+%s")
849 if [ "$PACKAGER" != "" ]; then
850 local packager="$PACKAGER"
851 else
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
877 local it
878 for it in "${license[@]}"; do
879 echo "license = $it" >>.PKGINFO
880 done
881 for it in "${replaces[@]}"; do
882 echo "replaces = $it" >>.PKGINFO
883 done
884 for it in "${groups[@]}"; do
885 echo "group = $it" >>.PKGINFO
886 done
887 for it in "${depends[@]}"; do
888 echo "depend = $it" >>.PKGINFO
889 done
890 for it in "${optdepends[@]}"; do
891 echo "optdepend = $it" >>.PKGINFO
892 done
893 for it in "${conflicts[@]}"; do
894 echo "conflict = $it" >>.PKGINFO
895 done
896 for it in "${provides[@]}"; do
897 echo "provides = $it" >>.PKGINFO
898 done
899 for it in "${backup[@]}"; do
900 echo "backup = $it" >>.PKGINFO
901 done
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
907 else
908 echo "makepkgopt = !$it" >>.PKGINFO
911 done
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"
936 # tar it up
937 msg2 "$(gettext "Compressing package...")"
939 local TAR_OPT
940 case "$PKGEXT" in
941 *tar.gz) TAR_OPT="z" ;;
942 *tar.bz2) TAR_OPT="j" ;;
943 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
944 "$PKGEXT" ;;
945 esac
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
951 shopt -s nullglob
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
957 shopt -u nullglob
960 create_xdelta() {
961 if [ "$(check_buildenv xdelta)" != "y" ]; then
962 return
963 elif [ ! "$(type -p xdelta)" ]; then
964 error "$(gettext "Cannot find the xdelta binary! Is xdelta installed?")"
965 return
968 local pkg_file=$1
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
989 done
991 rm -f "$pkginfo"
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"
996 local ret=0
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
1007 # errors.
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")"
1010 ret=0
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.")"
1014 exit 1
1016 else
1017 warning "$(gettext "Delta was not able to be created.")"
1019 else
1020 warning "$(gettext "No previous version found, skipping xdelta.")"
1024 create_srcpackage() {
1025 cd "$startdir"
1026 if [ "$SOURCEONLY" = "2" ]; then
1027 # get back to our src directory so we can begin with sources
1028 mkdir -p "$srcdir"
1029 cd "$srcdir"
1030 download_sources
1031 # we can only check checksums if we have all files
1032 check_checksums
1033 cd "$startdir"
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}/"
1046 else
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}"
1056 local netfile
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}/"
1066 done
1068 local TAR_OPT
1069 case "$SRCEXT" in
1070 *tar.gz) TAR_OPT="z" ;;
1071 *tar.bz2) TAR_OPT="j" ;;
1072 *) warning "$(gettext "'%s' is not a valid archive extension.")" \
1073 "$SRCEXT" ;;
1074 esac
1076 local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}${SRCEXT}"
1078 # tar it up
1079 msg2 "$(gettext "Compressing source package...")"
1080 cd "${srclinks}"
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
1085 cd "${startdir}"
1086 rm -rf "${srclinks}"
1089 install_package() {
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 $?
1094 else
1095 pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} || exit $?
1099 devel_check() {
1100 newpkgver=""
1101 # Only update pkgver if --holdver is not set
1102 if [ "$HOLDVER" = "1" ]; then
1103 return
1105 # Cannot update pkgver/pkgrel if reading PKGBUILD from pipe
1106 if [ ! -f "./$BUILDSCRIPT" ]; then
1107 return
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.
1115 oldpkgver=$pkgver
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
1140 cd ./src/$_hgrepo
1141 hg pull
1142 hg update
1143 else
1144 [[ ! -d ./src/ ]] && mkdir ./src/
1145 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1146 cd ./src/$_hgrepo
1148 newpkgver=$(hg tip --template "{rev}")
1149 cd ../../
1152 if [ "$newpkgver" != "" ]; then
1153 msg2 "$(gettext "Version found: %s")" "$newpkgver"
1154 pkgver=$newpkgver
1155 pkgrel=1
1158 else
1159 # Version number retrieved from fakeroot->makepkg argument
1160 newpkgver=$FORCE_VER
1164 devel_update() {
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.:
1170 # pkgver=23
1171 # ...
1172 # _foo=pkgver
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}\""
1189 done
1192 restore_package_variables() {
1193 for var in ${splitpkg_overrides[@]}; do
1194 indirect="${var}_backup"
1195 if [ -n "${!indirect}" ]; then
1196 eval "${var}=\"${!indirect}\""
1197 else
1198 unset ${var}
1200 done
1203 # getopt like parser
1204 parse_options() {
1205 local short_options=$1; shift;
1206 local long_options=$1; shift;
1207 local ret=0;
1208 local unused_options=""
1210 while [ -n "$1" ]; do
1211 if [ ${1:0:2} = '--' ]; then
1212 if [ -n "${1:2}" ]; then
1213 local match=""
1214 for i in ${long_options//,/ }; do
1215 if [ ${1:2} = ${i//:} ]; then
1216 match=$i
1217 break
1219 done
1220 if [ -n "$match" ]; then
1221 if [ ${1:2} = $match ]; then
1222 printf ' %s' "$1"
1223 else
1224 if [ -n "$2" ]; then
1225 printf ' %s' "$1"
1226 shift
1227 printf " '%s'" "$1"
1228 else
1229 echo "makepkg: option '$1' $(gettext "requires an argument")" >&2
1230 ret=1
1233 else
1234 echo "makepkg: $(gettext "unrecognized option") '$1'" >&2
1235 ret=1
1237 else
1238 shift
1239 break
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}"
1248 else
1249 if [ -n "$2" ]; then
1250 printf ' -%s' "${1:i:1}"
1251 shift
1252 printf " '%s'" "${1}"
1253 else
1254 echo "makepkg: option $(gettext "requires an argument") -- '${1:i:1}'" >&2
1255 ret=1
1258 break
1259 else
1260 printf ' -%s' "${1:i:1}"
1262 else
1263 echo "makepkg: $(gettext "invalid option") -- '${1:i:1}'" >&2
1264 ret=1
1266 done
1267 else
1268 unused_options="${unused_options} '$1'"
1270 shift
1271 done
1273 printf " --"
1274 if [ -n "$unused_options" ]; then
1275 for i in ${unused_options[@]}; do
1276 printf ' %s' "$i"
1277 done
1279 if [ -n "$1" ]; then
1280 while [ -n "$1" ]; do
1281 printf " '%s'" "${1}"
1282 shift
1283 done
1285 printf "\n"
1287 return $ret
1290 usage() {
1291 printf "makepkg (pacman) %s\n" "$myver"
1292 echo
1293 printf "$(gettext "Usage: %s [options]")\n" "$0"
1294 echo
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")"
1318 echo
1319 echo "$(gettext "These options can be passed to pacman:")"
1320 echo
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")"
1323 echo
1324 printf "$(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1325 echo
1328 version() {
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")"
1336 # PROGRAM START
1338 # determine whether we have gettext; make it a no-op if we do not
1339 if [ ! $(type -t gettext) ]; then
1340 gettext() {
1341 echo "$@"
1345 ARGLIST=$@
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:"
1353 # Pacman Options
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
1363 while true; do
1364 case "$1" in
1365 # Pacman Options
1366 --noconfirm) PACMAN_OPTS="$PACMAN_OPTS --noconfirm" ;;
1367 --noprogressbar) PACMAN_OPTS="$PACMAN_OPTS --noprogressbar" ;;
1369 # Makepkg Options
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;;
1381 -F) INFAKEROOT=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
1399 esac
1400 shift
1401 done
1403 #preserve environment variables
1404 _PKGDEST=${PKGDEST}
1405 _SRCDEST=${SRCDEST}
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"
1413 else
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" )"
1434 exit 1
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]")"
1443 read answer
1444 answer=$(echo $answer | tr '[:lower:]' '[:upper:]')
1445 if [ "$answer" = "$(gettext "YES")" -o "$answer" = "$(gettext "Y")" ]; then
1446 rm "$SRCDEST"/*
1447 if [ $? -ne 0 ]; then
1448 error "$(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1449 exit 1
1450 else
1451 # removal worked
1452 msg "$(gettext "Source cache cleaned.")"
1453 exit 0
1455 else
1456 # answer = no
1457 msg "$(gettext "No files have been removed.")"
1458 exit 0
1460 else
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.")"
1464 exit 1
1468 if [ -z "$BUILDSCRIPT" ]; then
1469 error "$(gettext "BUILDSCRIPT is undefined! Ensure you have updated %s.")" "$MAKEPKG_CONF"
1470 exit 1
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"
1489 exit 1
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"
1495 sleep 1
1497 else
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.")"
1511 exit 1
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
1520 if [ -t 0 ]; then
1521 error "$(gettext "%s does not exist.")" "$BUILDSCRIPT"
1522 exit 1
1523 else
1524 # PKGBUILD passed through a pipe
1525 BUILDSCRIPT=/dev/stdin
1527 else
1528 crlftest=$(file $BUILDSCRIPT | grep -F 'CRLF' || true)
1529 if [ "$crlftest" != "" ]; then
1530 error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDSCRIPT"
1531 exit 1
1535 source "$BUILDSCRIPT"
1537 if [ "$GENINTEG" = "1" ]; then
1538 mkdir -p "$srcdir"
1539 cd "$srcdir"
1540 download_sources
1541 generate_checksums
1542 exit 0 # $E_OK
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"
1548 exit 1
1550 if [ -z "$pkgver" ]; then
1551 error "$(gettext "%s is not allowed to be empty.")" "pkgver"
1552 exit 1
1554 if [ -z "$pkgrel" ]; then
1555 error "$(gettext "%s is not allowed to be empty.")" "pkgrel"
1556 exit 1
1558 if [ "$pkgver" != "${pkgver//-/}" ]; then
1559 error "$(gettext "%s is not allowed to contain hyphens.")" "pkgver"
1560 exit 1
1562 if [ "$pkgrel" != "${pkgrel//-/}" ]; then
1563 error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
1564 exit 1
1567 if [ "$arch" = 'any' ]; then
1568 CARCH='any'
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"
1576 exit 1
1580 for provide in ${provides[@]}; do
1581 if [ $provide != ${provide//</} -o $provide != ${provide//>/} ]; then
1582 error "$(gettext "Provides array cannot contain comparison (< or >) operators.")"
1583 exit 1
1585 done
1586 unset provide
1588 if [ "$install" -a ! -f "$install" ]; then
1589 error "$(gettext "Install scriptlet (%s) does not exist.")" "$install"
1590 exit 1
1593 valid_options=1
1594 for opt in ${options[@]}; do
1595 known=0
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
1599 known=1
1601 done
1602 if [ $known -eq 0 ]; then
1603 error "$(gettext "options array contains unknown option '%s'")" "$opt"
1604 valid_options=0
1606 done
1607 if [ $valid_options -eq 0 ]; then
1608 exit 1
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
1616 devel_check
1617 devel_update
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...")"
1623 install_package
1624 exit $?
1625 else
1626 error "$(gettext "A package has already been built. (use -f to overwrite)")"
1627 exit 1
1631 # Run the bare minimum in fakeroot
1632 if [ "$INFAKEROOT" = "1" ]; then
1633 if [ "$REPKG" = "0" ]; then
1634 if [ "$(type -t package)" != "function" ]; then
1635 run_build
1636 else
1637 run_package
1639 tidy_install
1642 create_package
1644 msg "$(gettext "Leaving fakeroot environment.")"
1645 exit 0 # $E_OK
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)")"
1655 exit 1
1657 create_srcpackage
1658 msg "$(gettext "Source package created: %s")" "$pkgname ($(date))"
1659 exit 0
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()
1670 deperr=0
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.")"
1680 exit 1
1682 else
1683 warning "$(gettext "pacman was not found in PATH; skipping dependency checks.")"
1686 # ensure we have a sane umask set
1687 umask 0022
1689 # get back to our src directory so we can begin with sources
1690 mkdir -p "$srcdir"
1691 cd "$srcdir"
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...")"
1701 exit 1
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...")"
1706 exit 1
1707 else
1708 download_sources
1709 check_checksums
1710 extract_sources
1713 if [ "$NOBUILD" = "1" ]; then
1714 msg "$(gettext "Sources are ready.")"
1715 exit 0 #E_OK
1716 else
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...")"
1720 rm -rf "$pkgdir"
1722 mkdir -p "$pkgdir"
1723 cd "$startdir"
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
1728 devel_update
1729 run_build
1730 if [ "$(type -t package)" == "function" ]; then
1731 run_package
1733 tidy_install
1736 create_package
1737 else
1738 if [ "$(type -t package)" == "function" ]; then
1739 devel_update
1740 run_build
1741 cd "$startdir"
1744 msg "$(gettext "Entering fakeroot environment...")"
1746 if [ "$newpkgver" != "" ]; then
1747 fakeroot -- $0 --forcever $newpkgver -F $ARGLIST || exit $?
1748 else
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))"
1758 install_package
1760 exit 0 #E_OK
1762 # vim: set ts=2 sw=2 noet: