fr.po : fix one minor alignment problem.
[pacman-ng.git] / scripts / makepkg.sh.in
blob175edb8fc7bc3d47b6079cc99a0bb8e16bc6387c
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, sed
32 # gettext initialization
33 export TEXTDOMAIN='pacman'
34 export TEXTDOMAINDIR='@localedir@'
36 myver='@PACKAGE_VERSION@'
37 confdir='@sysconfdir@'
38 startdir="$PWD"
39 srcdir="$startdir/src"
40 pkgdir="$startdir/pkg"
42 # Options
43 ASROOT=0
44 CLEANUP=0
45 CLEANCACHE=0
46 DEP_BIN=0
47 DEP_SRC=0
48 FORCE=0
49 INFAKEROOT=0
50 GENINTEG=0
51 INSTALL=0
52 NOBUILD=0
53 NODEPS=0
54 NOEXTRACT=0
55 RMDEPS=0
56 REPKG=0
57 LOGGING=0
58 SOURCEONLY=0
59 IGNOREARCH=0
60 HOLDVER=0
62 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
63 # when dealing with svn/cvs/etc PKGBUILDs.
64 FORCE_VER=""
66 PACMAN_OPTS=
68 ### SUBROUTINES ###
70 plain() {
71 local mesg=$1; shift
72 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
73 printf "\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
74 else
75 printf " ${mesg}\n" "$@" >&2
79 msg() {
80 local mesg=$1; shift
81 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
82 printf "\033[1;32m==>\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
83 else
84 printf "==> ${mesg}\n" "$@" >&2
88 msg2() {
89 local mesg=$1; shift
90 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
91 printf "\033[1;34m ->\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
92 else
93 printf " -> ${mesg}\n" "$@" >&2
97 warning() {
98 local mesg=$1; shift
99 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
100 printf "\033[1;33m==> $(gettext "WARNING:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
101 else
102 printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
106 error() {
107 local mesg=$1; shift
108 if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
109 printf "\033[1;31m==> $(gettext "ERROR:")\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
110 else
111 printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
117 # Special exit call for traps, Don't print any error messages when inside,
118 # the fakeroot call, the error message will be printed by the main call.
120 trap_exit() {
121 if [ "$INFAKEROOT" = "0" ]; then
122 echo
123 error "$@"
125 exit 1
130 # Clean up function. Called automatically when the script exits.
132 clean_up() {
133 local EXIT_CODE=$?
135 if [ "$INFAKEROOT" = "1" ]; then
136 # Don't clean up when leaving fakeroot, we're not done yet.
137 return
140 if [ $EXIT_CODE -eq 0 -a "$CLEANUP" = "1" ]; then
141 # If it's a clean exit and -c/--clean has been passed...
142 msg "$(gettext "Cleaning up...")"
143 cd "$startdir"
144 rm -rf pkg src
145 if [ "$pkgname" != "" ]; then
146 # Can't do this unless the BUILDSCRIPT has been sourced.
147 rm -f "${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log*"
151 remove_deps
156 # Signal Traps
158 trap 'clean_up' 0
159 trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
160 trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
161 trap 'trap_exit "$(gettext "An unknown error has occured. Exiting...")"' ERR
164 strip_url() {
165 echo "$1" | sed 's|^.*://.*/||g'
170 # Checks to see if options are present in makepkg.conf or PKGBUILD;
171 # PKGBUILD options always take precedence.
173 # usage : check_option( $option )
174 # return : y - enabled
175 # n - disabled
176 # ? - not found
178 check_option() {
179 local ret=$(in_opt_array "$1" ${options[@]})
180 if [ "$ret" != '?' ]; then
181 echo $ret
182 return
185 # BEGIN DEPRECATED
186 # TODO: This code should be removed in the next release of makepkg.
187 local needle=$(echo $1 | tr [:upper:] [:lower:])
188 local opt
189 for opt in ${options[@]}; do
190 opt=$(echo $opt | tr [:upper:] [:lower:])
191 if [ "$opt" = "no$needle" ]; then
192 warning "$(gettext "Options beginning with 'no' will be deprecated in the next version of makepkg!")"
193 plain "$(gettext "Please replace 'no' with '!': %s -> %s.")" "no$needle" "!$needle"
194 echo 'n' # Disabled
195 return
196 elif [ "$opt" = "keepdocs" -a "$needle" = "docs" ]; then
197 warning "$(gettext "Option 'keepdocs' may not work as intended. Please replace with 'docs'.")"
198 echo 'y' # Enabled
199 return
201 done
202 # END DEPRECATED
204 # fall back to makepkg.conf options
205 ret=$(in_opt_array "$1" ${OPTIONS[@]})
206 if [ "$ret" != '?' ]; then
207 echo $ret
208 return
211 echo '?' # Not Found
216 # Check if option is present in BUILDENV
218 # usage : check_buildenv( $option )
219 # return : y - enabled
220 # n - disabled
221 # ? - not found
223 check_buildenv() {
224 echo $(in_opt_array "$1" ${BUILDENV[@]})
229 # usage : in_opt_array( $needle, $haystack )
230 # return : y - enabled
231 # n - disabled
232 # ? - not found
234 in_opt_array() {
235 local needle=$(echo $1 | tr [:upper:] [:lower:]); shift
237 local opt
238 for opt in "$@"; do
239 opt=$(echo $opt | tr [:upper:] [:lower:])
240 if [ "$opt" = "$needle" ]; then
241 echo 'y' # Enabled
242 return
243 elif [ "$opt" = "!$needle" ]; then
244 echo 'n' # Disabled
245 return
247 done
249 echo '?' # Not Found
254 # usage : in_array( $needle, $haystack )
255 # return : 0 - found
256 # 1 - not found
258 in_array() {
259 local needle=$1; shift
260 [ -z "$1" ] && return 1 # Not Found
261 local item
262 for item in "$@"; do
263 [ "$item" = "$needle" ] && return 0 # Found
264 done
265 return 1 # Not Found
268 get_downloadclient() {
269 # $1 = url with valid protocol prefix
270 local url=$1
271 local proto=$(echo $netfile | sed 's|://.*||')
273 # loop through DOWNLOAD_AGENTS variable looking for protocol
274 local i
275 for i in "${DLAGENTS[@]}"; do
276 local handler=$(echo $i | sed 's|::.*||')
277 if [ "$proto" == "$handler" ]; then
278 agent=$(echo $i | sed 's|^.*::||')
279 break
281 done
283 # if we didn't find an agent, return an error
284 if [ -z "$agent" ]; then
285 error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$confdir/makepkg.conf"
286 plain "$(gettext "Aborting...")"
287 exit 1 # $E_CONFIG_ERROR
290 # ensure specified program is installed
291 local program="$(echo $agent | awk '{print $1 }')"
292 if [ ! -x "$program" ]; then
293 local baseprog=$(basename $program)
294 error "$(gettext "The download program %s is not installed.")" "$baseprog"
295 plain "$(gettext "Aborting...")"
296 exit 1 # $E_MISSING_PROGRAM
299 echo "$agent"
302 check_deps() {
303 [ $# -gt 0 ] || return
305 pmout=$(pacman $PACMAN_OPTS -T "$@")
306 ret=$?
307 if [ $ret -eq 127 ]; then #unresolved deps
308 echo "$pmout"
309 elif [ $ret -ne 0 ]; then
310 error "$(gettext "Pacman returned a fatal error (%i): %s")" "$ret" "$pmout"
311 exit 1
315 handledeps() {
316 local R_DEPS_SATISFIED=0
317 local R_DEPS_MISSING=1
319 [ $# -eq 0 ] && return $R_DEPS_SATISFIED
321 local deplist="$*"
322 local dep depstrip striplist
323 for dep in $deplist; do
324 depstrip="$(echo $dep | sed -e 's|=.*$||' -e 's|>.*$||' -e 's|<.*$||')"
325 striplist="$striplist $depstrip"
326 done
328 if [ "$DEP_SRC" = "0" -a "$DEP_BIN" = "0" ]; then
329 return $R_DEPS_MISSING
332 if [ "$DEP_BIN" = "1" ]; then
333 # install missing deps from binary packages (using pacman -S)
334 msg "$(gettext "Installing missing dependencies...")"
335 local ret=0
337 if [ "$ASROOT" = 0 ]; then
338 sudo pacman $PACMAN_OPTS -S --asdeps $striplist || ret=$?
339 else
340 pacman $PACMAN_OPTS -S --asdeps $striplist || ret=$?
343 if [ $ret -ne 0 ]; then
344 error "$(gettext "Pacman failed to install missing dependencies.")"
345 exit 1 # TODO: error code
347 elif [ "$DEP_SRC" = "1" ]; then
348 msg "$(gettext "Building missing dependencies...")"
350 # install missing deps by building them from source.
351 # we look for each package name in $SRCROOT and build it.
352 if [ "$SRCROOT" = "" ]; then
353 error "$(gettext "Source root cannot be found - please make sure it is specified in %s.")" "$confdir/makepkg.conf"
354 exit 1 # TODO: error code
357 # TODO: handle version comparators (eg, glibc>=2.2.5)
358 for dep in $striplist; do
359 local candidates="$(find "$SRCROOT" -type d -name "$dep")"
360 if [ "$candidates" = "" ]; then
361 error "$(gettext "Could not find '%s' under %s")" "$dep" "$SRCROOT"
362 exit 1 # TODO: error code
365 local makepkg_opts='-i -c -b'
366 [ "$RMDEPS" = "1" ] && makepkg_opts="$makepkg_opts -r"
367 [ "$ASROOT" = "1" ] && makepkg_opts="$makepkg_opts --asroot"
368 local ret packagedir
369 for packagedir in $candidates; do
370 if [ -f "$packagedir/$BUILDSCRIPT" ]; then
371 cd "$packagedir"
372 ret=0
373 PKGDEST="$PKGDEST" makepkg $makepkg_opts $PACMAN_OPTS || ret=$?
374 [ $ret -eq 0 ] && continue 2
376 done
378 error "$(gettext "Failed to build '%s'")" "$dep"
379 exit 1 # TODO: error code
380 done
383 # rerun any additional sh scripts found in /etc/profile.d/
384 local script
385 for script in /etc/profile.d/*.sh; do
386 if [ -x $script ]; then
387 source $script &>/dev/null
389 done
391 return $R_DEPS_SATISFIED
394 resolve_deps() {
395 # $pkgdeps is a GLOBAL variable, used by remove_deps()
396 local R_DEPS_SATISFIED=0
397 local R_DEPS_MISSING=1
399 local deplist="$(check_deps $*)"
400 if [ "$deplist" = "" ]; then
401 return $R_DEPS_SATISFIED
402 else
403 pkgdeps="$pkgdeps $deplist"
406 if handledeps $deplist; then
407 # check deps again to make sure they were resolved
408 deplist="$(check_deps $*)"
409 [ "$deplist" = "" ] && return $R_DEPS_SATISFIED
410 elif [ "$DEP_BIN" = "1" -o "$DEP_SRC" = "1" ]; then
411 error "$(gettext "Failed to install all missing dependencies.")"
414 msg "$(gettext "Missing Dependencies:")"
415 local dep
416 for dep in $deplist; do
417 msg2 "$dep"
418 done
420 return $R_DEPS_MISSING
423 # fix flyspray bug #5923
424 remove_deps() {
425 # $pkgdeps is a GLOBAL variable, set by resolve_deps()
426 [ "$RMDEPS" = "0" ] && return
427 [ "$pkgdeps" = "" ] && return
429 local dep depstrip deplist
430 for dep in $pkgdeps; do
431 depstrip=$(echo $dep | sed -e 's|=.*$||' -e 's|>.*$||' -e 's|<.*$||')
432 deplist="$deplist $depstrip"
433 done
435 msg "Removing installed dependencies..."
436 if [ "$ASROOT" = "0" ]; then
437 sudo pacman $PACMAN_OPTS -Rns $deplist
438 else
439 pacman $PACMAN_OPTS -Rns $deplist
443 download_sources() {
444 msg "$(gettext "Retrieving Sources...")"
446 if [ ! -w "$SRCDEST" ] ; then
447 error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
448 plain "$(gettext "Aborting...")"
449 exit 1
452 pushd "$SRCDEST" &>/dev/null
454 local netfile
455 for netfile in ${source[@]}; do
456 local file=$(strip_url "$netfile")
457 if [ -f "$startdir/$file" ]; then
458 msg2 "$(gettext "Found %s in build dir")" "$file"
459 cp -s --remove-destination "$startdir/$file" "$srcdir/"
460 continue
461 elif [ -f "$SRCDEST/$file" ]; then
462 msg2 "$(gettext "Using cached copy of %s")" "$file"
463 cp -s --remove-destination "$SRCDEST/$file" "$srcdir/"
464 continue
467 # if we get here, check to make sure it was a URL, else fail
468 if [ "$file" = "$netfile" ]; then
469 error "$(gettext "%s was not found in the build directory and is not a URL.")" "$netfile"
470 exit 1 # $E_MISSING_FILE
473 # find the client we should use for this URL
474 local dlclient=$(get_downloadclient $netfile) || exit $?
476 msg2 "$(gettext "Downloading %s...")" "$file"
477 # fix flyspray bug #3289
478 local ret=0
479 $dlclient "$netfile" || ret=$?
480 if [ $ret -gt 0 ]; then
481 error "$(gettext "Failure while downloading %s")" "$file"
482 plain "$(gettext "Aborting...")"
483 exit 1
485 cp -s --remove-destination "$SRCDEST/$file" "$srcdir/"
486 done
488 popd &>/dev/null
491 generate_checksums() {
492 msg "$(gettext "Generating checksums for source files...")"
493 plain ""
495 local integ
496 for integ in ${INTEGRITY_CHECK[@]}; do
497 integ="$(echo $integ | tr [:upper:] [:lower:])"
498 case "$integ" in
499 md5|sha1|sha256|sha384|sha512) : ;;
501 error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
502 exit 1;; # $E_CONFIG_ERROR
503 esac
505 if [ ! $(type -p "${integ}sum") ]; then
506 error "$(gettext "Cannot find the '%s' program.")" "${integ}sum"
507 exit 1 # $E_MISSING_PROGRAM
510 local ct=0
511 local numsrc=${#source[@]}
512 echo -n "${integ}sums=("
514 local i=0;
515 local indent=''
516 while [ $i -lt $((${#integ}+6)) ]; do
517 indent="$indent "
518 i=$(($i+1))
519 done
521 local netfile
522 for netfile in ${source[@]}; do
523 local file="$(strip_url "$netfile")"
525 if [ ! -f "$file" ] ; then
526 if [ ! -f "$SRCDEST/$file" ] ; then
527 error "$(gettext "Unable to find source file %s to generate checksum.")" "$file"
528 plain "$(gettext "Aborting...")"
529 exit 1
530 else
531 file=$SRCDEST/$file
535 local sum="$(${integ}sum "$file" | cut -d ' ' -f 1)"
536 [ $ct -gt 0 ] && echo -n "$indent"
537 echo -n "'$sum'"
538 ct=$(($ct+1))
539 [ $ct -lt $numsrc ] && echo
540 done
542 echo ")"
543 done
546 check_checksums() {
547 local integ
548 for integ in ${INTEGRITY_CHECK[@]}; do
549 integ="$(echo $integ | tr [:upper:] [:lower:])"
550 case "$integ" in
551 md5|sha1|sha256|sha384|sha512) : ;;
553 error "$(gettext "Invalid integrity algorithm '%s' specified")" "$integ"
554 exit 1;; # $E_CONFIG_ERROR
555 esac
557 if [ ! $(type -p "${integ}sum") ]; then
558 error "$(gettext "Cannot find the '%s' program.")" "${integ}sum"
559 exit 1 # $E_MISSING_PROGRAM
562 local integrity_sums=($(eval echo \${${integ}sums[@]}))
563 if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then
564 msg "$(gettext "Validating source files with %s...")" "${integ}sums"
565 local errors=0
566 local idx=0
567 local file
568 for file in "${source[@]}"; do
569 file="$(strip_url "$file")"
570 echo -n " $file ... " >&2
572 if [ ! -f "$file" ] ; then
573 if [ ! -f "$file" ] ; then
574 echo "$(gettext "NOT FOUND")" >&2
575 errors=1
576 continue
577 else
578 file=$SRCDEST/$file
582 if echo "${integrity_sums[$idx]} $file" | ${integ}sum --status -c - &>/dev/null; then
583 echo "$(gettext "Passed")" >&2
584 else
585 echo "$(gettext "FAILED")" >&2
586 errors=1
589 idx=$((idx + 1))
590 done
592 if [ $errors -gt 0 ]; then
593 error "$(gettext "One or more files did not pass the validity check!")"
594 exit 1 # TODO: error code
596 else
597 warning "$(gettext "Integrity checks (%s) are missing or incomplete.")" "$integ"
599 done
602 extract_sources() {
603 msg "$(gettext "Extracting Sources...")"
604 local netfile
605 for netfile in "${source[@]}"; do
606 file=$(strip_url "$netfile")
607 if in_array "$file" ${noextract[@]}; then
608 #skip source files in the noextract=() array
609 # these are marked explicitly to NOT be extracted
610 continue
613 if [ ! -f "$file" ] ; then
614 if [ ! -f "$SRCDEST/$file" ] ; then
615 error "$(gettext "Unable to find source file %s for extraction.")" "$file"
616 plain "$(gettext "Aborting...")"
617 exit 1
618 else
619 file=$SRCDEST/$file
623 # fix flyspray #6246
624 local file_type=$(file -bizL "$file")
625 local cmd=''
626 case "$file_type" in
627 *application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*)
628 cmd="bsdtar -x -f $file" ;;
629 *application/x-gzip*)
630 cmd="gunzip -d -f $file" ;;
631 *application/x-bzip*)
632 cmd="bunzip2 -f $file" ;;
634 # Don't know what to use to extract this file,
635 # skip to the next file
636 continue;;
637 esac
639 local ret=0
640 msg2 "$cmd"
641 $cmd || ret=$?
642 if [ $ret -ne 0 ]; then
643 error "$(gettext "Failed to extract %s")" "$file"
644 plain "$(gettext "Aborting...")"
645 exit 1
647 done
649 if [ $EUID -eq 0 ]; then
650 # chown all source files to root.root
651 chown -R root.root "$srcdir"
655 run_build() {
656 # use distcc if it is requested (check buildenv and PKGBUILD opts)
657 if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then
658 [ -d /usr/lib/distcc/bin ] && export PATH="/usr/lib/distcc/bin:$PATH"
659 export DISTCC_HOSTS
660 elif [ "$(check_option distcc)" = "n" ]; then
661 # if it is not wanted, clear the makeflags too
662 MAKEFLAGS=""
665 # use ccache if it is requested (check buildenv and PKGBUILD opts)
666 if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then
667 [ -d /usr/lib/ccache/bin ] && export PATH="/usr/lib/ccache/bin:$PATH"
670 # clear user-specified makeflags if requested
671 if [ "$(check_option makeflags)" = "n" ]; then
672 MAKEFLAGS=""
675 msg "$(gettext "Starting build()...")"
676 cd "$srcdir"
678 # ensure all necessary build variables are exported
679 export CFLAGS CXXFLAGS MAKEFLAGS CHOST
681 local ret=0
682 if [ "$LOGGING" = "1" ]; then
683 BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log"
684 if [ -f "$BUILDLOG" ]; then
685 local i=1
686 while true; do
687 if [ -f "$BUILDLOG.$i" ]; then
688 i=$(($i +1))
689 else
690 break
692 done
693 mv "$BUILDLOG" "$BUILDLOG.$i"
696 build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]}
697 else
698 build 2>&1 || ret=$?
701 if [ $ret -gt 0 ]; then
702 error "$(gettext "Build Failed.")"
703 plain "$(gettext "Aborting...")"
704 remove_deps
705 exit 2 # $E_BUILD_FAILED
709 tidy_install() {
710 cd "$pkgdir"
711 msg "$(gettext "Tidying install...")"
713 if [ "$(check_option docs)" = "n" ]; then
714 msg2 "$(gettext "Removing info/doc files...")"
715 #fix flyspray bug #5021
716 rm -rf ${DOC_DIRS[@]}
719 msg2 "$(gettext "Compressing man pages...")"
720 local manpage mandirs ext file link hardlinks hl
721 mandirs="usr/man usr/share/man usr/local/man usr/local/share/man opt/*/man"
722 find ${mandirs} -type f 2>/dev/null | while read manpage ; do
723 # check file still exists (potentially compressed with hard link)
724 if [ -f ${manpage} ]; then
725 ext="${manpage##*.}"
726 file="${manpage##*/}"
727 if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then
728 # update symlinks to this manpage
729 find ${mandirs} -lname "$file" 2>/dev/null | while read link ; do
730 rm -f "$link"
731 ln -sf "${file}.gz" "${link}.gz"
732 done
733 # find hard links and remove them
734 # the '|| true' part keeps the script from bailing if find returned an
735 # error, such as when one of the man directories doesn't exist
736 hardlinks="$(find ${mandirs} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
737 for hl in ${hardlinks}; do
738 rm -f "${hl}";
739 done
740 # compress the original
741 gzip -9 "$manpage"
742 # recreate hard links removed earlier
743 for hl in ${hardlinks}; do
744 ln "${manpage}.gz" "${hl}.gz"
745 chmod 644 ${hl}.gz
746 done
749 done
752 if [ "$(check_option strip)" = "y" ]; then
753 msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")"
754 local binary bindirs
755 bindirs="bin lib sbin usr/bin usr/lib usr/sbin usr/local/bin usr/local/lib usr/local/sbin opt/*/bin opt/*/lib opt/*/sbin"
756 find ${bindirs} -type f 2>/dev/null | while read binary ; do
757 case "$(file -biz "$binary")" in
758 *application/x-sharedlib*) # Libraries
759 /usr/bin/strip --strip-debug "$binary";;
760 *application/x-executable*) # Binaries
761 /usr/bin/strip "$binary";;
762 esac
763 done
766 if [ "$(check_option libtool)" = "n" ]; then
767 msg2 "$(gettext "Removing libtool .la files...")"
768 find . -type f -name "*.la" -exec rm -f -- '{}' \;
771 if [ "$(check_option emptydirs)" = "n" ]; then
772 msg2 "$(gettext "Removing empty directories...")"
773 find . -depth -type d -empty -delete
777 create_package() {
778 if [ ! -d "$pkgdir" ]; then
779 error "$(gettext "Missing pkg/ directory.")"
780 plain "$(gettext "Aborting...")"
781 exit 1 # $E_MISSING_PKGDIR
784 cd "$pkgdir"
785 msg "$(gettext "Creating package...")"
787 local builddate=$(date -u "+%s")
788 if [ "$PACKAGER" != "" ]; then
789 local packager="$PACKAGER"
790 else
791 local packager="Unknown Packager"
793 local size=$(du -sb | awk '{print $1}')
795 # write the .PKGINFO file
796 msg2 "$(gettext "Generating .PKGINFO file...")"
797 echo "# Generated by makepkg $myver" >.PKGINFO
798 if [ "$INFAKEROOT" = "1" ]; then
799 echo "# using $(fakeroot -v)" >>.PKGINFO
801 echo "# $(LC_ALL= LANG= date -u)" >>.PKGINFO
802 echo "pkgname = $pkgname" >>.PKGINFO
803 echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO
804 echo "pkgdesc = $pkgdesc" >>.PKGINFO
805 echo "url = $url" >>.PKGINFO
806 echo "builddate = $builddate" >>.PKGINFO
807 echo "packager = $packager" >>.PKGINFO
808 echo "size = $size" >>.PKGINFO
809 if [ "$CARCH" != "" ]; then
810 echo "arch = $CARCH" >>.PKGINFO
812 if [ "$(check_option force)" = "y" ]; then
813 echo "force = true" >> .PKGINFO
816 local it
817 for it in "${license[@]}"; do
818 echo "license = $it" >>.PKGINFO
819 done
820 for it in "${replaces[@]}"; do
821 echo "replaces = $it" >>.PKGINFO
822 done
823 for it in "${groups[@]}"; do
824 echo "group = $it" >>.PKGINFO
825 done
826 for it in "${depends[@]}"; do
827 echo "depend = $it" >>.PKGINFO
828 done
829 for it in "${optdepends[@]}"; do
830 echo "optdepend = $it" >>.PKGINFO
831 done
832 for it in "${conflicts[@]}"; do
833 echo "conflict = $it" >>.PKGINFO
834 done
835 for it in "${provides[@]}"; do
836 echo "provides = $it" >>.PKGINFO
837 done
838 for it in "${backup[@]}"; do
839 echo "backup = $it" >>.PKGINFO
840 done
842 # TODO maybe remove this at some point
843 # warn if license array is not present or empty
844 if [ "$license" = "" ]; then
845 warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT"
846 plain "$(gettext "Example for GPL'ed software: license=('GPL').")"
849 local comp_files=".PKGINFO"
851 # check for an install script
852 # TODO: should we include ${pkgname}.install if it exists and $install is unset?
853 if [ "$install" != "" ]; then
854 msg2 "$(gettext "Adding install script...")"
855 cp "$startdir/$install" .INSTALL
856 comp_files="$comp_files .INSTALL"
859 # do we have a changelog?
860 if [ -f "$startdir/ChangeLog" ]; then
861 msg2 "$(gettext "Adding package changelog...")"
862 cp "$startdir/ChangeLog" .CHANGELOG
863 comp_files="$comp_files .CHANGELOG"
866 # tar it up
867 msg2 "$(gettext "Compressing package...")"
869 local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
871 if ! bsdtar -czf "$pkg_file" $comp_files $(ls); then
872 error "$(gettext "Failed to create package file.")"
873 exit 1 # TODO: error code
877 create_xdelta() {
878 if [ "$(check_buildenv xdelta)" != "y" ]; then
879 return
880 elif [ ! "$(type -p xdelta)" ]; then
881 error "$(gettext "Cannot find the xdelta binary! Is xdelta installed?")"
882 return
885 local pkg_file=$1
886 local cache_dir="/var/cache/pacman/pkg" # TODO: autoconf me
887 local pkginfo="$(mktemp "$startdir"/xdelta-pkginfo.XXXXXXXXX)"
889 local old_file old_version
890 for old_file in $(ls {"$cache_dir","$PKGDEST"}/${pkgname}-*-*{,-$CARCH}$PKGEXT 2>/dev/null); do
891 bsdtar -xOf "$old_file" .PKGINFO > "$pkginfo" || continue
892 if [ "$(cat "$pkginfo" | grep '^pkgname = ')" != "pkgname = $pkgname" ]; then
893 continue # Package name does not match.
894 elif [ "$(cat "$pkginfo" | grep '^arch = ')" != "arch = $CARCH" ] ; then
895 continue # Not same arch.
898 old_version="$(cat "$pkginfo" | grep '^pkgver = ' | sed 's/^pkgver = //')"
900 # old_version may include the target package, only use the old versions
901 local vercmp=$(vercmp "$old_version" "$latest_version")
902 if [ "$old_version" != "$pkgver-$pkgrel" -a $vercmp -gt 0 ]; then
903 local latest_version=$old_version
904 local base_file=$old_file
906 done
908 rm -f "$pkginfo"
910 if [ "$base_file" != "" ]; then
911 msg "$(gettext "Making delta from version %s...")" "$latest_version"
912 local delta_file="$PKGDEST/$pkgname-${latest_version}_to_$pkgver-$pkgrel-$CARCH.delta"
913 local ret=0
915 # xdelta will decompress base_file & pkg_file into TMP_DIR (or /tmp if
916 # TMP_DIR is unset) then perform the delta on the resulting tars
917 xdelta delta "$base_file" "$pkg_file" "$delta_file" || ret=$?
919 if [ $ret -eq 0 -o $ret -eq 1 ]; then
920 # Generate the final gz using xdelta for compression. xdelta will be our
921 # common denominator compression utility between the packager and the
922 # users. makepkg and pacman must use the same compression algorithm or
923 # the delta generated package may not match, producing md5 checksum
924 # errors.
925 msg2 "$(gettext "Recreating package tarball from delta to match md5 signatures")"
926 msg2 "$(gettext "NOTE: the delta should ONLY be distributed with this tarball")"
927 ret=0
928 xdelta patch "$delta_file" "$base_file" "$pkg_file" || ret=$?
929 if [ $ret -ne 0 ]; then
930 error "$(gettext "Could not generate the package from the delta.")"
931 exit 1
933 else
934 warning "$(gettext "Delta was not able to be created.")"
936 else
937 warning "$(gettext "No previous version found, skipping xdelta.")"
941 create_srcpackage() {
942 cd "$startdir"
943 msg "$(gettext "Creating source package...")"
944 local comp_files="$BUILDSCRIPT"
945 msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
947 if [ "$install" != "" ]; then
948 if [ -f $install ]; then
949 msg2 "$(gettext "Adding install script...")"
950 comp_files="$comp_files $install"
951 else
952 error "$(gettext "Install script %s not found.")" "$install"
956 if [ -f ChangeLog ]; then
957 msg2 "$(gettext "Adding %s...")" "ChangeLog"
958 comp_files="$comp_files ChangeLog"
961 local i
962 for i in ${source[@]}; do
963 if [ -f $i ]; then
964 msg2 "$(gettext "Adding %s...")" "$i"
965 comp_files="$comp_files $i"
967 done
969 local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}${SRCEXT}"
971 # tar it up
972 msg2 "$(gettext "Compressing source package...")"
973 if ! bsdtar -czf "$pkg_file" $comp_files; then
974 error "$(gettext "Failed to create source package file.")"
975 exit 1 # TODO: error code
979 install_package() {
980 [ "$INSTALL" = "0" ] && return
981 msg "$(gettext "Installing package ${pkgname} with pacman -U...")"
982 if [ "$ASROOT" = "0" ]; then
983 sudo pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} || exit $?
984 else
985 pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} || exit $?
989 devel_check() {
990 newpkgver=""
991 # Only update pkgver if --holdver is not set
992 if [ "$HOLDVER" = "1" ]; then
993 return
995 if [ "$FORCE_VER" = "" ]; then
996 # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
997 # This will only be used on the first call to makepkg; subsequent
998 # calls to makepkg via fakeroot will explicitly pass the version
999 # number to avoid having to determine the version number twice.
1000 # Also do a brief check to make sure we have the VCS tool available.
1001 oldpkgver=$pkgver
1002 if [ ! -z ${_darcstrunk} ] && [ ! -z ${_darcsmod} ] ; then
1003 [ $(type -p darcs) ] || return 0
1004 msg "$(gettext "Determining latest darcs revision...")"
1005 newpkgver=$(date +%Y%m%d)
1006 elif [ ! -z ${_cvsroot} ] && [ ! -z ${_cvsmod} ] ; then
1007 [ $(type -p cvs) ] || return 0
1008 msg "$(gettext "Determining latest cvs revision...")"
1009 newpkgver=$(date +%Y%m%d)
1010 elif [ ! -z ${_gitroot} ] && [ ! -z ${_gitname} ] ; then
1011 [ $(type -p git) ] || return 0
1012 msg "$(gettext "Determining latest git revision...")"
1013 newpkgver=$(date +%Y%m%d)
1014 elif [ ! -z ${_svntrunk} ] && [ ! -z ${_svnmod} ] ; then
1015 [ $(type -p svn) ] || return 0
1016 msg "$(gettext "Determining latest svn revision...")"
1017 newpkgver=$(svn log $_svntrunk --limit 1 -q | sed -n 's/^r\([0-9]*\) .*$/\1/p')
1018 elif [ ! -z ${_bzrtrunk} ] && [ ! -z ${_bzrmod} ] ; then
1019 [ $(type -p bzr) ] || return 0
1020 msg "$(gettext "Determining latest bzr revision...")"
1021 newpkgver=$(bzr revno ${_bzrtrunk})
1022 elif [ ! -z ${_hgroot} ] && [ ! -z ${_hgrepo} ] ; then
1023 [ $(type -p hg) ] || return 0
1024 msg "$(gettext "Determining latest hg revision...")"
1025 if [ -d ./src/$_hgrepo ] ; then
1026 cd ./src/$_hgrepo
1027 hg pull
1028 hg update
1029 else
1030 [[ ! -d ./src/ ]] && mkdir ./src/
1031 hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
1032 cd ./src/$_hgrepo
1034 newpkgver=$(hg tip | sed -n '1s/[^0-9]*\([^:]*\):.*$/\1/p')
1035 cd ../../
1038 if [ "$newpkgver" != "" ]; then
1039 msg2 "$(gettext "Version found: %s")" "$newpkgver"
1040 pkgver=$newpkgver
1043 else
1044 # Version number retrieved from fakeroot->makepkg argument
1045 newpkgver=$FORCE_VER
1049 devel_update() {
1050 # This is lame, but if we're wanting to use an updated pkgver for
1051 # retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
1052 # the new pkgver and then re-source it. This is the most robust
1053 # method for dealing with PKGBUILDs that use, e.g.:
1055 # pkgver=23
1056 # ...
1057 # _foo=pkgver
1059 if [ "$newpkgver" != "" ]; then
1060 if [ "newpkgver" != "$pkgver" ]; then
1061 sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" ./$BUILDSCRIPT
1062 source $BUILDSCRIPT
1067 usage() {
1068 printf "makepkg (pacman) %s\n" "$myver"
1069 echo
1070 printf "$(gettext "Usage: %s [options]")\n" "$0"
1071 echo
1072 echo "$(gettext "Options:")"
1073 printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
1074 echo "$(gettext " -b, --builddeps Build missing dependencies from source")"
1075 echo "$(gettext " -c, --clean Clean up work files after build")"
1076 echo "$(gettext " -C, --cleancache Clean up source files from the cache")"
1077 echo "$(gettext " -d, --nodeps Skip all dependency checks")"
1078 echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
1079 echo "$(gettext " -f, --force Overwrite existing package")"
1080 echo "$(gettext " -g, --geninteg Generate integrity checks for source files")"
1081 echo "$(gettext " -h, --help This help")"
1082 echo "$(gettext " -i, --install Install package after successful build")"
1083 echo "$(gettext " -L, --log Log package build process")"
1084 echo "$(gettext " -m, --nocolor Disable colorized output messages")"
1085 echo "$(gettext " -o, --nobuild Download and extract files only")"
1086 printf "$(gettext " -p <buildscript> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
1087 echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")"
1088 # fix flyspray feature request #2978
1089 echo "$(gettext " -R, --repackage Repackage contents of pkg/ without building")"
1090 echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")"
1091 echo "$(gettext " --asroot Allow makepkg to run as root user")"
1092 echo "$(gettext " --holdver Prevent automatic version bumping for development PKGBUILDs")"
1093 echo "$(gettext " --source Do not build package; generate a source-only tarball")"
1094 echo
1095 echo "$(gettext "These options can be passed to pacman:")"
1096 echo
1097 echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")"
1098 echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")"
1099 echo
1100 printf "$(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT"
1101 echo
1104 version() {
1105 printf "makepkg (pacman) %s\n" "$myver"
1106 printf "$(gettext "\
1107 Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>.\n\n\
1108 This is free software; see the source for copying conditions.\n\
1109 There is NO WARRANTY, to the extent permitted by law.\n")"
1112 # PROGRAM START
1114 # determine whether we have gettext; make it a no-op if we do not
1115 if [ ! $(type -t gettext) ]; then
1116 gettext() {
1117 echo "$@"
1121 ARGLIST=$@
1123 #preserve environment variables
1124 _PKGDEST=${PKGDEST}
1125 _SRCDEST=${SRCDEST}
1127 # Source makepkg.conf; fail if it is not found
1128 if [ -r "$confdir/makepkg.conf" ]; then
1129 source "$confdir/makepkg.conf"
1130 else
1131 error "$(gettext "%s not found.")" "$confdir/makepkg.conf"
1132 plain "$(gettext "Aborting...")"
1133 exit 1 # $E_CONFIG_ERROR
1136 # Source user-specific makepkg.conf overrides
1137 if [ -r ~/.makepkg.conf ]; then
1138 source ~/.makepkg.conf
1141 # override settings with an environment variable for batch processing
1142 PKGDEST=${_PKGDEST:-$PKGDEST}
1143 PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
1144 SRCDEST=${_SRCDEST:-$SRCDEST}
1145 SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
1147 # Parse Command Line Options.
1148 OPT_SHORT="AbcCdefFghiLmop:rRsSV"
1149 OPT_LONG="ignorearch,asroot,builddeps,clean,cleancache,nodeps,noextract,force,forcever:,geninteg,help,holdver"
1150 OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source,syncdeps,usesudo,version"
1151 # Pacman Options
1152 OPT_LONG="$OPT_LONG,noconfirm,noprogressbar"
1153 OPT_TEMP="$(getopt -o "$OPT_SHORT" -l "$OPT_LONG" -n "$(basename "$0")" -- "$@" || echo 'GETOPT GO BANG!')"
1154 if echo "$OPT_TEMP" | grep -q 'GETOPT GO BANG!'; then
1155 # This is a small hack to stop the script bailing with 'set -e'
1156 echo; usage; exit 1 # E_INVALID_OPTION;
1158 eval set -- "$OPT_TEMP"
1159 unset OPT_SHORT OPT_LONG OPT_TEMP
1161 while true; do
1162 case "$1" in
1163 # Pacman Options
1164 --noconfirm) PACMAN_OPTS="$PACMAN_OPTS --noconfirm" ;;
1165 --noprogressbar) PACMAN_OPTS="$PACMAN_OPTS --noprogressbar" ;;
1167 # Makepkg Options
1168 --asroot) ASROOT=1 ;;
1169 -A|--ignorearch) IGNOREARCH=1 ;;
1170 -b|--builddeps) DEP_SRC=1 ;;
1171 -c|--clean) CLEANUP=1 ;;
1172 -C|--cleancache) CLEANCACHE=1 ;;
1173 -d|--nodeps) NODEPS=1 ;;
1174 -e|--noextract) NOEXTRACT=1 ;;
1175 -f|--force) FORCE=1 ;;
1176 #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver
1177 --forcever) shift; FORCE_VER=$1;;
1178 -F) INFAKEROOT=1 ;;
1179 -g|--geninteg) GENINTEG=1 ;;
1180 --holdver) HOLDVER=1 ;;
1181 -i|--install) INSTALL=1 ;;
1182 -L|--log) LOGGING=1 ;;
1183 -m|--nocolor) USE_COLOR='n' ;;
1184 -o|--nobuild) NOBUILD=1 ;;
1185 -p) shift; BUILDSCRIPT=$1 ;;
1186 -r|--rmdeps) RMDEPS=1 ;;
1187 -R|--repackage) REPKG=1 ;;
1188 --source) SOURCEONLY=1 ;;
1189 -s|--syncdeps) DEP_BIN=1 ;;
1191 # BEGIN DEPRECATED
1192 -S|--usesudo)
1193 warning "$(gettext "Sudo is used by default now. The --usesudo option is deprecated!")" ;;
1194 # END DEPRECATED
1196 -h|--help) usage; exit 0 ;; # E_OK
1197 -V|--version) version; exit 0 ;; # E_OK
1199 --) OPT_IND=0; shift; break;;
1200 *) usage; exit 1 ;; # E_INVALID_OPTION
1201 esac
1202 shift
1203 done
1205 if [ "$HOLDVER" = "1" -a "$FORCE_VER" != "" ]; then
1206 # The extra '--' is here to prevent gettext from thinking --holdver is
1207 # an option
1208 error "$(gettext "\\0--holdver and --forcever cannot both be specified" )"
1209 exit 1
1212 if [ "$CLEANCACHE" = "1" ]; then
1213 #fix flyspray feature request #5223
1214 if [ -n "$SRCDEST" -a "$SRCDEST" != "$startdir" ]; then
1215 msg "$(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
1216 echo -n "$(gettext " Are you sure you wish to do this? [Y/n] ")"
1217 read answer
1218 answer=$(echo $answer | tr [:upper:] [:lower:])
1219 if [ "$answer" = "yes" -o "$answer" = "y" ]; then
1220 rm "$SRCDEST"/*
1221 if [ $? -ne 0 ]; then
1222 error "$(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST"
1223 exit 1
1224 else
1225 # removal worked
1226 msg "$(gettext "Source cache cleaned.")"
1227 exit 0
1229 else
1230 # answer = no
1231 msg "$(gettext "No files have been removed.")"
1232 exit 0
1234 else
1235 # $SRCDEST is $startdir, two possibilities
1236 error "$(gettext "Source destination must be defined in makepkg.conf.")"
1237 plain "$(gettext "In addition, please run makepkg -C outside of your cache directory.")"
1238 exit 1
1242 if [ -z $BUILDSCRIPT ]; then
1243 error "$(gettext "BUILDSCRIPT is undefined! Ensure you have updated %s.")" "$confdir/makepkg.conf"
1244 exit 1
1247 if [ "$INFAKEROOT" = "0" ]; then
1248 if [ $EUID -eq 0 -a "$ASROOT" = "0" ]; then
1249 # Warn those who like to live dangerously.
1250 error "$(gettext "Running makepkg as root is a BAD idea and can cause")"
1251 plain "$(gettext "permanent, catastrophic damage to your system. If you")"
1252 plain "$(gettext "wish to run as root, please use the --asroot option.")"
1253 exit 1 # $E_USER_ABORT
1254 elif [ $EUID -gt 0 -a "$ASROOT" = "1" ]; then
1255 # Warn those who try to use the --asroot option when they are not root
1256 error "$(gettext "The --asroot option is meant for the root user only.")"
1257 plain "$(gettext "Please rerun makepkg without the --asroot flag.")"
1258 exit 1 # $E_USER_ABORT
1259 elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then
1260 if [ ! $(type -p fakeroot) ]; then
1261 error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
1262 plain "$(gettext "in the BUILDENV array in %s.")" "$confdir/makepkg.conf"
1263 exit 1
1265 elif [ $EUID -gt 0 ]; then
1266 warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")"
1267 plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
1268 plain "$(gettext "placing 'fakeroot' in the BUILDENV array in makepkg.conf.")"
1269 sleep 1
1271 else
1272 if [ "$FAKEROOTKEY" = "" ]; then
1273 error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
1274 exit 1 # TODO: error code
1278 # check for sudo if we will need it during makepkg execution
1279 if [ "$ASROOT" = "0" -a \( "$DEP_BIN" = "1" -o "$DEP_SRC" = "1" \
1280 -o "$RMDEPS" = "1" -o "$INSTALL" = "1" \) ]; then
1281 if [ ! "$(type -p sudo)" ]; then
1282 error "$(gettext "Cannot find the sudo binary! Is sudo installed?")"
1283 plain "$(gettext "Missing dependencies cannot be installed or removed as a normal user")"
1284 plain "$(gettext "without sudo; install and configure sudo to auto-resolve dependencies.")"
1285 exit 1
1289 unset pkgname pkgver pkgrel pkgdesc url license groups provides md5sums
1290 unset replaces depends conflicts backup source install build makedepends
1291 unset optdepends options noextract
1293 if [ ! -f "$BUILDSCRIPT" ]; then
1294 error "$(gettext "%s does not exist.")" "$BUILDSCRIPT"
1295 exit 1
1296 #TODO this is an attempt at a generic way to unset all package specific
1297 #variables in a PKGBUILD
1298 #else
1299 # #this is fun.... we'll unset
1300 # for var in $(grep "=" $BUILDSCRIPT | sed "s|.*\(\<.*\>\)=.*|\1|g"); do
1301 # unset $var
1302 # done
1305 source "$BUILDSCRIPT"
1307 # check for no-no's in the build script
1308 if [ -z "$pkgname" ]; then
1309 error "$(gettext "%s is not allowed to be empty.")" "pkgname"
1310 exit 1
1312 if [ -z "$pkgver" ]; then
1313 error "$(gettext "%s is not allowed to be empty.")" "pkgver"
1314 exit 1
1316 if [ -z "$pkgrel" ]; then
1317 error "$(gettext "%s is not allowed to be empty.")" "pkgrel"
1318 exit 1
1320 if [ $(echo "$pkgver" | grep '-') ]; then
1321 error "$(gettext "%s is not allowed to contain hyphens.")" "pkgver"
1322 exit 1
1324 if [ $(echo "$pkgrel" | grep '-') ]; then
1325 error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
1326 exit 1
1329 if [ "$arch" = 'any' ]; then
1330 CARCH='any'
1333 if ! in_array $CARCH ${arch[@]}; then
1334 if [ "$IGNOREARCH" = "0" ]; then
1335 error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgname" "$CARCH"
1336 plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
1337 plain "$(gettext "such as arch=('%s').")" "$CARCH"
1338 exit 1
1339 else
1340 warning "$(gettext "%s is not available for the '%s' architecture.")" "$pkgname" "$CARCH"
1341 plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
1342 plain "$(gettext "such as arch=('%s').")" "$CARCH"
1346 if [ "$install" -a ! -f "$install" ]; then
1347 error "$(gettext "Install scriptlet (%s) does not exist.")" "$install"
1348 exit 1
1351 # We need to run devel_update regardless of whether we are in the fakeroot
1352 # build process so that if the user runs makepkg --forcever manually, we
1353 # 1) output the correct pkgver, and 2) use the correct filename when
1354 # checking if the package file already exists - fixes FS #9194
1355 devel_check
1356 devel_update
1358 if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \
1359 -a "$FORCE" = "0" -a "$GENINTEG" = "0" -a "$SOURCEONLY" = "0" -a "$NOBUILD" = "0" ]; then
1360 if [ "$INSTALL" = "1" ]; then
1361 warning "$(gettext "A package has already been built, installing existing package...")"
1362 install_package
1363 exit $?
1364 else
1365 error "$(gettext "A package has already been built. (use -f to overwrite)")"
1366 exit 1
1370 # Run the bare minimum in fakeroot
1371 # fix flyspray bug 6208 -- using makepkg with fakeroot gives an error
1372 if [ "$INFAKEROOT" = "1" ]; then
1373 if [ "$REPKG" = "1" ]; then
1374 warning "$(gettext "Skipping build.")"
1375 else
1376 run_build
1377 tidy_install
1380 create_package
1382 msg "$(gettext "Leaving fakeroot environment.")"
1383 exit 0 # $E_OK
1386 msg "$(gettext "Making package: %s")" "$pkgname $pkgver-$pkgrel ($(date))"
1388 if [ $EUID -eq 0 ]; then
1389 warning "$(gettext "Running makepkg as root...")"
1392 # if we are creating a source-only package, go no further
1393 if [ "$SOURCEONLY" = "1" ]; then
1394 if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}${SRCEXT}" \
1395 -a "$FORCE" = "0" ]; then
1396 error "$(gettext "A package has already been built. (use -f to overwrite)")"
1397 exit 1
1399 create_srcpackage
1400 msg "$(gettext "Source package created: %s")" "$pkgname ($(date))"
1401 exit 0
1404 # fix flyspray bug #5973
1405 if [ "$NODEPS" = "1" -o "$GENINTEG" = "1" -o "$NOBUILD" = "1" -o "$REPKG" = "1" ]; then
1406 if [ "$NODEPS" = "1" ]; then
1407 warning "$(gettext "Skipping dependency checks.")"
1409 # skip printing a warning message for the others: geninteg, nobuild, repkg
1410 elif [ $(type -p pacman) ]; then
1411 unset pkgdeps # Set by resolve_deps() and used by remove_deps()
1412 deperr=0
1414 msg "$(gettext "Checking Runtime Dependencies...")"
1415 resolve_deps ${depends[@]} || deperr=1
1417 msg "$(gettext "Checking Buildtime Dependencies...")"
1418 resolve_deps ${makedepends[@]} || deperr=1
1420 if [ $deperr -eq 1 ]; then
1421 error "$(gettext "Could not resolve all dependencies.")"
1422 exit 1
1424 else
1425 warning "$(gettext "pacman was not found in PATH; skipping dependency checks.")"
1428 # ensure we have a sane umask set
1429 umask 0022
1431 # get back to our src directory so we can begin with sources
1432 mkdir -p "$srcdir"
1433 cd "$srcdir"
1435 if [ "$GENINTEG" = "1" ]; then
1436 download_sources
1437 generate_checksums
1438 exit 0 # $E_OK
1441 if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
1442 warning "$(gettext "Skipping source retrieval -- using existing src/ tree")"
1443 warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")"
1444 warning "$(gettext "Skipping source extraction -- using existing src/ tree")"
1446 if [ "$NOEXTRACT" = "1" -a "$(ls "$srcdir" 2>/dev/null)" = "" ]; then
1447 error "$(gettext "The source directory is empty, there is nothing to build!")"
1448 plain "$(gettext "Aborting...")"
1449 exit 1
1450 elif [ "$REPKG" = "1" -a \( ! -d "$pkgdir" -o "$(ls "$pkgdir" 2>/dev/null)" = "" \) ]; then
1451 error "$(gettext "The package directory is empty, there is nothing to repackage!")"
1452 plain "$(gettext "Aborting...")"
1453 exit 1
1455 else
1456 download_sources
1457 check_checksums
1458 extract_sources
1461 if [ "$NOBUILD" = "1" ]; then
1462 msg "$(gettext "Sources are ready.")"
1463 exit 0 #E_OK
1464 else
1465 # check for existing pkg directory; don't remove if we are repackaging
1466 if [ -d "$pkgdir" -a "$REPKG" = "0" ]; then
1467 msg "$(gettext "Removing existing pkg/ directory...")"
1468 rm -rf "$pkgdir"
1470 mkdir -p "$pkgdir"
1471 cd "$startdir"
1473 if [ $EUID -eq 0 ]; then
1474 # if we are root, then we don't need to recall makepkg with fakeroot
1475 if [ "$REPKG" = "1" ]; then
1476 warning "$(gettext "Skipping build.")"
1477 else
1478 devel_update
1479 run_build
1480 tidy_install
1483 create_package
1484 else
1485 msg "$(gettext "Entering fakeroot environment...")"
1487 if [ "$newpkgver" != "" ]; then
1488 fakeroot -- $0 --forcever $newpkgver -F $ARGLIST || exit $?
1489 else
1490 fakeroot -- $0 -F $ARGLIST || exit $?
1494 create_xdelta "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
1497 msg "$(gettext "Finished making: %s")" "$pkgname ($(date))"
1499 install_package
1501 exit 0 #E_OK
1503 # vim: set ts=2 sw=2 noet: