ast-grep: update to 0.30.0.
[void-pkg.git] / xbps-src
blob00e955fe8168b71f5f6e3459b162c76dff42d3b5
1 #!/bin/bash
2 # vim: set ts=4 sw=4 et:
4 print_cross_targets() {
5 local f
6 for f in "${XBPS_DISTDIR}"/common/cross-profiles/*.sh; do
7 f=${f%.sh}; f=${f##*/}; printf "\t$f\n"
8 done
11 usage() {
12 # copied from main logic because this is run before XBPS_DISTDIR is set normally
13 local _distdir="$(readlink -f "${0%/*}")"
14 if [ "${_distdir}" = "." ]; then
15 readonly XBPS_DISTDIR="$(pwd -P)"
16 else
17 readonly XBPS_DISTDIR="${_distdir}"
19 cat << _EOF
20 $PROGNAME: [options] <target> [arguments]
22 Targets: (only one may be specified)
24 binary-bootstrap
25 Install bootstrap packages from host repositories into <masterdir>.
26 If the optional '-A <arch>' flag is set, it will install bootstrap packages
27 from this architecture, and its required xbps utilities. The <masterdir> will
28 be initialized for chroot operations.
30 bootstrap
31 Build and install from source the bootstrap packages into <masterdir>.
32 If the optional '-A <arch>' flag is set, it will build and install bootstrap
33 packages from this architecture, and its required xbps utilities. The <masterdir>
34 will be initialized for chroot operations.
36 bootstrap-update
37 Updates bootstrap packages with latest versions available from registered
38 repositories in the XBPS configuration file.
40 consistency-check
41 Runs a consistency check on all packages
43 chroot
44 Enter to the chroot in <masterdir>.
46 clean-repocache
47 Removes obsolete packages from <hostdir>/repocache.
49 fetch <pkgname>
50 Download package source distribution file(s).
52 extract <pkgname>
53 Extract package source distribution file(s) into the build directory.
54 By default set to <masterdir>/builddir.
56 patch <pkgname>
57 Patch the package sources and perform other operations required to
58 prepare a package for configuring and building
60 configure <pkgname>
61 Configure a package (fetch + extract + patch + configure).
63 build <pkgname>
64 Build package source (fetch + extract + patch + configure + build).
66 check <pkgname>
67 Run the package check(s) after building the package source.
69 install <pkgname>
70 Install target package into <destdir> but not building the binary package
71 and not removing build directory for inspection purposes.
73 pkg <pkgname>
74 Build binary package for <pkgname> and all required dependencies.
76 clean [pkgname]
77 Removes auto dependencies, cleans up <masterdir>/builddir and <masterdir>/destdir.
78 If <pkgname> argument is specified, package files from <masterdir>/destdir and its
79 build directory in <masterdir>/buiddir are removed.
81 list
82 Lists installed packages in <masterdir>.
84 remove <pkgname>
85 Remove target package from <destdir>. If <pkgname>-<version> is not matched
86 from build template nothing is removed.
88 remove-autodeps
89 Removes all package dependencies that were installed automatically.
91 purge-distfiles
92 Removes all obsolete distfiles in <hostdir>/sources.
94 show <pkgname>
95 Show information for the specified package.
97 show-avail <pkgname>
98 Returns 0 if package can be built for the given architecture,
99 any other error otherwise.
101 show-build-deps <pkgname>
102 Show required build dependencies for <pkgname>.
104 show-check-deps <pkgname>
105 Show required check dependencies for <pkgname>.
107 show-deps <pkgname>
108 Show required run-time dependencies for <pkgname>. Package must be
109 installed into destdir.
111 show-files <pkgname>
112 Show files installed by <pkgname>. Package must be installed into destdir.
114 show-hostmakedepends <pkgname>
115 Show required host build dependencies for <pkgname>.
117 show-makedepends <pkgname>
118 Show required target build dependencies for <pkgname>.
120 show-options <pkgname>
121 Show available build options by <pkgname>.
123 show-shlib-provides <pkgname>
124 Show list of provided shlibs for <pkgname>. Package must be installed into destdir.
126 show-shlib-requires <pkgname>
127 Show list of required shlibs for <pkgname>. Package must be installed into destdir.
129 show-var <var>
130 Prints the value of <var> if it's defined in xbps-src.
132 show-repo-updates
133 Prints the list of outdated packages in XBPS repositories.
135 show-sys-updates
136 Prints the list of outdated packages in your system.
138 show-local-updates
139 Prints the list of outdated packages in your local repositories.
141 sort-dependencies <pkg> <pkgN+1> ...
142 Given a list of packages specified as additional arguments, a sorted dependency
143 list will be returned to stdout.
145 update-bulk
146 Rebuilds all packages in the system repositories that are outdated.
148 update-sys
149 Rebuilds all packages in your system that are outdated and updates them.
151 update-local
152 Rebuilds all packages in your local repositories that are outdated.
154 update-check <pkgname>
155 Check upstream site of <pkgname> for new releases.
157 update-hash-cache
158 Update the hash cache with existing source distfiles.
161 Removes a masterdir but preserving ccache, distcc and host directories.
163 Options:
165 -1 If dependencies of target package are missing, fail instead of building them.
167 -A <host>
168 Use this host machine. Automatically creates masterdir-<host> if it doesn't
169 already exist. Some host machines may require qemu-user and
170 binfmt-support if not natively supported by the processor. Supported hosts:
172 $(print_cross_targets)
174 -a <target>
175 Cross compile packages for this target machine. Supported targets:
177 $(print_cross_targets)
179 -b Build packages even if marked as broken, nocross, or excluded with archs.
181 -c <configuration>
182 If specified, etc/conf.<configuration> will be used as the primary config
183 file name; etc/conf will only be attempted if that does not exist.
185 -C Do not remove build directory, automatic dependencies and
186 package destdir after successful install.
188 -E If a binary package exists in a repository for the target package,
189 do not try to build it, exit immediately.
191 -f Force running the specified stage (configure/build/install/pkg)
192 even if it ran successfully.
194 -G Enable XBPS_USE_GIT_REVS (see etc/defaults.conf for more information).
196 -g Enable building -dbg packages with debugging symbols.
198 -H <hostdir>
199 Absolute path to a directory to be bind mounted at <masterdir>/host.
200 The host directory stores binary packages, sources and package dependencies
201 downloaded from remote repositories.
202 If unset defaults to void-packages/hostdir.
204 -h Usage output.
206 -I Ignore required dependencies, useful for extracting/fetching sources.
208 -i Make xbps-src internal errors non-fatal.
210 -j Number of parallel build jobs to use when building packages.
212 -L Disable ASCII colors.
214 -m <masterdir>
215 Absolute path to a directory to be used as masterdir.
216 The masterdir is the main directory to build/store/compile packages.
217 If unset defaults to void-packages/masterdir-<host>.
219 -N Disable use of remote repositories to resolve dependencies.
221 -o <opt,~opt2,...>
222 Enable or disable (prefixed with ~) package build options. If 'etc/conf'
223 already specifies some, it is merged. Keep in mind that these options
224 apply to all packages within the build, as in if a dependency needs to
225 be built, it will inherit these options.
227 Supported options can be shown with the 'show-options' target.
229 -p <variable,variable2,...>
230 For show target, show specified variables in addition to default ones.
231 Variable is split and each word is printed in separate line by default.
232 In order to print the whole value in one line, append asterisk to variable name.
234 -Q Enable running the check stage.
236 -K Enable running the check stage with longer tests.
238 -q Suppress informational output of xbps-src (build output is still printed).
240 -r <repo>
241 Use an alternative local repository to store generated binary packages.
242 If unset defaults to <hostdir>/binpkgs. If set the binpkgs will
243 be stored into <hostdir>/binpkgs/<repo>.
244 This alternative repository will also be used to resolve dependencies
245 with highest priority order than others.
247 -s Make vsed warnings errors.
249 -t Create a temporary masterdir to not pollute the current one. Note that
250 the existing masterdir must be fully populated with binary-bootstrap first.
251 Once the target has finished, this temporary masterdir will be removed.
252 This flag requires xbps-uchroot(1), and won't work on filesystems that don't
253 support overlayfs.
255 -v Show verbose messages (only affects update-check).
257 -V Print version of xbps, then exit.
259 _EOF
262 check_reqhost_utils() {
263 local broken
265 [ "$IN_CHROOT" ] && return 0
267 for f in ${REQHOST_UTILS}; do
268 if ! command -v ${f} &>/dev/null; then
269 echo "${f} is missing in your system, can't continue!" 1>&2
270 broken=1
272 done
273 [ "$broken" ] && exit 1
274 [ -z "$1" ] && return 0
276 for f in ${REQHOST_UTILS_BOOTSTRAP}; do
277 if ! command -v ${f} &>/dev/null; then
278 echo "${f} is missing in your system, can't continue!" 1>&2
279 broken=1
281 done
282 [ "$broken" ] && exit 1
285 check_build_requirements() {
286 local found
288 case "$XBPS_TARGET" in
289 *bootstrap*) found=1;;
290 *) ;;
291 esac
292 if [ -z "$found" ]; then
293 xbps-uhelper cmpver "$XBPS_VERSION" "$XBPS_VERSION_REQ"
294 if [ $? -eq 255 ]; then
295 echo "ERROR: requires xbps>=${XBPS_VERSION_REQ}" 1>&2
296 echo "Bootstrap packages must be updated with 'xbps-src bootstrap-update'" 1>&2
297 exit 1
302 chroot_check() {
303 if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
304 export CHROOT_READY=1
308 check_native_arch() {
309 if [ "$CHROOT_READY" ]; then
310 if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
311 export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
312 else
313 export XBPS_ARCH=$(xbps-uhelper arch)
315 else
316 export XBPS_ARCH="$XBPS_MACHINE"
320 masterdir_zap() {
321 rm -rf "$XBPS_MASTERDIR"
322 mkdir -p "$XBPS_MASTERDIR"
323 msg_normal "xbps-src: $XBPS_MASTERDIR masterdir cleaned up.\n"
326 exit_func() {
327 wait
328 if [ "$sourcepkg" ]; then
329 remove_pkg $XBPS_CROSS_BUILD
331 if [ -z "$IN_CHROOT" ]; then
332 msg_red "xbps-src: a failure has occurred! exiting...\n"
334 exit 2
337 read_pkg() {
338 if [ -z "${XBPS_TARGET_PKG}" ]; then
339 [ ! -r ./template ] && msg_error "xbps-src: missing build template in $(pwd).\n"
340 XBPS_TARGET_PKG=${PWD##*/}
342 setup_pkg "$XBPS_TARGET_PKG" "$XBPS_CROSS_BUILD" "$1"
345 setup_distfiles_mirror() {
346 local mirror scheme path
348 # Scheme file:// mirror locations only work with uchroot
349 for mirror in $XBPS_DISTFILES_MIRROR; do
350 scheme="file"
351 if [[ "$mirror" == *://* ]]; then
352 scheme="${mirror%%://*}"
353 path="${mirror#${scheme}://}"
354 else
355 path="$mirror"
357 [ "$scheme" != "file" ] && continue
358 if [ "$XBPS_CHROOT_CMD" == "uchroot" ]; then
359 if [ ! -d "$path" ]; then
360 msg_warn "xbps-src: Invalid path in XBPS_DISTFILES_MIRROR ($mirror)\n"
361 continue
363 mkdir -p "$XBPS_MASTERDIR/$path"
364 XBPS_CHROOT_CMD_ARGS+=" -b $path:$path"
365 else
366 case "$XBPS_TARGET" in
367 fetch|extract|patch|configure|build|check|install|pkg|bootstrap|bootstrap-update|update-sys)
368 msg_warn "xbps-src: File URLs ($mirror) don't work with '$XBPS_CHROOT_CMD'\n"
369 esac
371 done
375 # main()
377 readonly PROGNAME="${0##*/}"
378 readonly XBPS_VERSION_REQ="0.55"
379 XBPS_VERSION=$(xbps-uhelper -V)
380 XBPS_VERSION=${XBPS_VERSION%%API*}
381 XBPS_VERSION=${XBPS_VERSION##*:}
382 readonly XBPS_SRC_VERSION="113"
383 export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
385 XBPS_OPTIONS=
386 XBPS_OPTSTRING="1A:a:bc:CEfgGhH:iIj:Lm:No:p:qsQKr:tvV"
388 # Preprocess arguments in order to allow options before and after XBPS_TARGET.
389 eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
391 # Options are saved as XBPS_ARG_FOO instead of XBPS_FOO for now; this is
392 # because configuration files may override those and we want arguments to
393 # take precedence over configuration files
394 while getopts "$XBPS_OPTSTRING" opt; do
395 case $opt in
396 1) XBPS_ARG_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
397 A) XBPS_ARG_MACHINE="$OPTARG"; XBPS_OPTIONS+=" -A $OPTARG";;
398 a) XBPS_ARG_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
399 b) XBPS_ARG_IGNORE_BROKENNESS=yes; XBPS_OPTIONS+=" -b";;
400 c) XBPS_ARG_CONFIG="$OPTARG"; XBPS_OPTIONS+=" -c $OPTARG";;
401 C) XBPS_ARG_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
402 E) XBPS_ARG_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
403 f) XBPS_ARG_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
404 G) XBPS_ARG_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
405 g) XBPS_ARG_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
406 H) XBPS_ARG_HOSTDIR="$OPTARG"; XBPS_OPTIONS+=" -H $OPTARG";;
407 h) usage && exit 0;;
408 i) XBPS_ARG_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
409 I) XBPS_ARG_SKIP_DEPS=1; XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -I -N";;
410 j) XBPS_ARG_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
411 L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
412 m) XBPS_ARG_MASTERDIR="$OPTARG"; XBPS_OPTIONS+=" -m $OPTARG";;
413 N) XBPS_ARG_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
414 o) XBPS_ARG_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
415 p) XBPS_ARG_PRINT_VARIABLES="$OPTARG"; XBPS_OPTIONS+=" -p $OPTARG";;
416 q) XBPS_ARG_QUIET=1; XBPS_OPTIONS+=" -q";;
417 Q) XBPS_ARG_CHECK_PKGS=yes; XBPS_OPTIONS+=" -Q";;
418 K) XBPS_ARG_CHECK_PKGS=full; XBPS_OPTIONS+=" -K";;
419 r) XBPS_ARG_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
420 s) XBPS_ARG_STRICT=yes; XBPS_OPTIONS+=" -s";;
421 t) XBPS_ARG_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
422 v) XBPS_ARG_VERBOSE=1; XBPS_OPTIONS+=" -v";;
423 V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
424 --) shift; break;;
425 esac
426 done
427 shift $(($OPTIND - 1))
429 [ $# -eq 0 ] && usage && exit 1
431 # Check if stdout is a tty; if false disable colors.
432 test -t 1 || export NOCOLORS=1
433 # http://no-color.org
434 if [ "${NO_COLOR+x}" ]; then
435 export NOCOLORS=1
438 # sane umask
439 umask 022
442 # Check for required utilities in host system.
444 # Required utilities in host system for the bootstrap target.
445 readonly REQHOST_UTILS_BOOTSTRAP="file objdump find make gawk bash sed gcc g++ gnat \
446 perl bsdtar gzip patch flock pkg-config"
448 # Required utilities in host.
449 readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
450 xbps-reconfigure xbps-remove xbps-create xbps-uchroot xbps-uunshare"
452 check_reqhost_utils
455 # Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
456 # and XBPS_HOSTDIR.
458 if [ "$IN_CHROOT" ]; then
459 readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
460 readonly XBPS_DISTDIR=/void-packages
461 readonly XBPS_MASTERDIR=/
462 readonly XBPS_HOSTDIR=/host
463 else
464 _distdir="$(readlink -f ${0%/*})"
465 if [ "${_distdir}" = "." ]; then
466 readonly XBPS_DISTDIR="$(pwd -P)"
467 else
468 readonly XBPS_DISTDIR="${_distdir}"
470 # Read defaults and then the local configuration file
471 if [ -f $XBPS_DISTDIR/etc/defaults.conf ]; then
472 . $XBPS_DISTDIR/etc/defaults.conf
474 if [ -n "$XBPS_ARG_CONFIG" -a -s $XBPS_DISTDIR/etc/conf.$XBPS_ARG_CONFIG ]; then
475 # If specified, read custom user configuration...
476 readonly XBPS_CONFIG_FILE=$XBPS_DISTDIR/etc/conf.$XBPS_ARG_CONFIG
477 elif [ -s $XBPS_DISTDIR/etc/conf ]; then
478 # ... otherwise read generic user configuration...
479 readonly XBPS_CONFIG_FILE=$XBPS_DISTDIR/etc/conf
480 elif [ -s ${XDG_CONFIG_HOME:-$HOME/.config}/xbps-src.conf ]; then
481 readonly XBPS_CONFIG_FILE=${XDG_CONFIG_HOME:-$HOME/.config}/xbps-src.conf
482 elif [ -s $HOME/.xbps-src.conf ]; then
483 # ... fallback to ~/.xbps-src.conf otherwise.
484 readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
487 # Read settings from config file
488 [ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
490 # show colors unconditionally in CI
491 [ "$XBPS_BUILD_ENVIRONMENT" = void-packages-ci ] && export NOCOLORS=
493 # Set options passed on command line, after configuration files have been read
494 [ -n "$XBPS_ARG_BUILD_ONLY_ONE_PKG" ] && XBPS_BUILD_ONLY_ONE_PKG=yes
495 [ -n "$XBPS_ARG_IGNORE_BROKENNESS" ] && XBPS_IGNORE_BROKENNESS=1
496 [ -n "$XBPS_ARG_SKIP_REMOTEREPOS" ] && XBPS_SKIP_REMOTEREPOS=1
497 [ -n "$XBPS_ARG_BUILD_FORCEMODE" ] && XBPS_BUILD_FORCEMODE=1
498 [ -n "$XBPS_ARG_INFORMATIVE_RUN" ] && XBPS_INFORMATIVE_RUN=1
499 [ -n "$XBPS_ARG_TEMP_MASTERDIR" ] && XBPS_TEMP_MASTERDIR=1
500 [ -n "$XBPS_ARG_BINPKG_EXISTS" ] && XBPS_BINPKG_EXISTS=1
501 [ -n "$XBPS_ARG_USE_GIT_REVS" ] && XBPS_USE_GIT_REVS=1
502 [ -n "$XBPS_ARG_DEBUG_PKGS" ] && XBPS_DEBUG_PKGS=1
503 [ -n "$XBPS_ARG_SKIP_DEPS" ] && XBPS_SKIP_DEPS=1
504 [ -n "$XBPS_ARG_KEEP_ALL" ] && XBPS_KEEP_ALL=1
505 [ -n "$XBPS_ARG_QUIET" ] && XBPS_QUIET=1
506 [ -n "$XBPS_ARG_PRINT_VARIABLES" ] && XBPS_PRINT_VARIABLES="$XBPS_ARG_PRINT_VARIABLES"
507 [ -n "$XBPS_ARG_ALT_REPOSITORY" ] && XBPS_ALT_REPOSITORY="$XBPS_ARG_ALT_REPOSITORY"
508 [ -n "$XBPS_ARG_STRICT" ] && XBPS_STRICT="$XBPS_ARG_STRICT"
509 [ -n "$XBPS_ARG_MACHINE" ] && XBPS_MACHINE="$XBPS_ARG_MACHINE"
510 [ -n "$XBPS_ARG_CROSS_BUILD" ] && XBPS_CROSS_BUILD="$XBPS_ARG_CROSS_BUILD"
511 [ -n "$XBPS_ARG_CHECK_PKGS" ] && XBPS_CHECK_PKGS="$XBPS_ARG_CHECK_PKGS"
512 [ -n "$XBPS_ARG_MAKEJOBS" ] && XBPS_MAKEJOBS="$XBPS_ARG_MAKEJOBS"
513 [ -n "$XBPS_ARG_VERBOSE" ] && XBPS_VERBOSE="$XBPS_ARG_VERBOSE"
515 # Default to nproc for XBPS_MAKEJOBS if not set and nproc is available
516 if command -v nproc >/dev/null ; then
517 : ${XBPS_MAKEJOBS:=$(nproc)}
518 else
519 : ${XBPS_MAKEJOBS:=1}
522 export XBPS_BUILD_ONLY_ONE_PKG XBPS_SKIP_REMOTEREPOS XBPS_BUILD_FORCEMODE \
523 XBPS_INFORMATIVE_RUN XBPS_TEMP_MASTERDIR XBPS_BINPKG_EXISTS \
524 XBPS_USE_GIT_REVS XBPS_CHECK_PKGS XBPS_DEBUG_PKGS XBPS_SKIP_DEPS \
525 XBPS_KEEP_ALL XBPS_QUIET XBPS_ALT_REPOSITORY XBPS_STRICT XBPS_CROSS_BUILD \
526 XBPS_MAKEJOBS XBPS_PRINT_VARIABLES XBPS_IGNORE_BROKENNESS
528 # The masterdir/hostdir variables are forced and readonly in chroot
529 if [ -z "$IN_CHROOT" ]; then
530 [ -n "$XBPS_ARG_MASTERDIR" ] && XBPS_MASTERDIR="$XBPS_ARG_MASTERDIR"
531 [ -n "$XBPS_ARG_HOSTDIR" ] && XBPS_HOSTDIR="$XBPS_ARG_HOSTDIR"
533 # Sanitize masterdir/hostdir once set for real (resolve links)
534 export XBPS_MASTERDIR="$(readlink -f $XBPS_MASTERDIR 2>/dev/null)"
535 export XBPS_HOSTDIR="$(readlink -f $XBPS_HOSTDIR 2>/dev/null)"
538 # Forbid root unless XBPS_ALLOW_CHROOT_BREAKOUT is set
539 # (for CI).
540 if [ -z "$IN_CHROOT" -a "$UID" -eq 0 -a -z "$XBPS_ALLOW_CHROOT_BREAKOUT" ]; then
541 echo "ERROR: xbps-src cannot be used as root." 1>&2
542 exit 1
545 # if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir-<host machine>
546 # unless in a container for simplicity of container/CI usage
547 if [ "$XBPS_CHROOT_CMD" = ethereal ]; then
548 : "${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}"
549 elif [ -n "$XBPS_ARG_MASTERDIR" ]; then
550 : # Don't mess with masterdir in argv
551 else
552 : "${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir-$XBPS_MACHINE}"
553 # but use $XBPS_DISTDIR/masterdir if it exists and the new style doesn't
554 if [ ! -d "${XBPS_MASTERDIR}" ] && [ -r "${XBPS_DISTDIR}/masterdir/.xbps_chroot_init" ] \
555 && [ "$(cat "${XBPS_DISTDIR}/masterdir/.xbps_chroot_init")" = "$XBPS_MACHINE" ]; then
556 XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
559 [ ! -d "$XBPS_MASTERDIR" ] && mkdir -p "$XBPS_MASTERDIR"
561 # if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
562 : ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
563 [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
565 if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
566 echo "ERROR: can't write to masterdir $XBPS_MASTERDIR." 1>&2
567 exit 1
570 # Try using chroot-git then git from the host system
571 XBPS_GIT_CMD="$(PATH="/usr/libexec/chroot-git:$PATH:$XBPS_MASTERDIR/usr/libexec/chroot-git" command -v git 2>/dev/null)"
572 if [ -n "$XBPS_GIT_CMD" ]; then
573 export XBPS_GIT_CMD
574 elif [ -z "$XBPS_USE_BUILD_MTIME" ] || [ "$XBPS_USE_GIT_REVS" ]; then
575 echo "neither chroot-git or git are available in your system!" 1>&2
576 exit 1
577 else
578 unset XBPS_GIT_CMD
581 if [ -n "$XBPS_HOSTDIR" ]; then
582 export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
583 readonly XBPS_SRCDISTDIR=$XBPS_HOSTDIR/sources
584 else
585 export XBPS_REPOSITORY=$XBPS_MASTERDIR/host/binpkgs
586 readonly XBPS_SRCDISTDIR=$XBPS_MASTERDIR/host/sources
589 # Set XBPS_REPOSITORY to our current branch.
590 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
591 pushd "$PWD" &>/dev/null
592 cd $XBPS_DISTDIR
593 _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
594 if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
595 export XBPS_ALT_REPOSITORY="${_gitbranch}"
596 export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
598 popd &>/dev/null
599 else
600 export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
603 readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
604 readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
605 readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
606 readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
607 readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
608 readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
609 readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
610 readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
612 readonly XBPS_TARGET="$1"
613 if [ "$2" ]; then
614 XBPS_TARGET_PKG="${2##*/}"
617 # Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
618 chroot_check
619 check_native_arch
621 # test if to use linux32 for 32-bit masterdirs in 64-bit environments
622 # x86_64, ppc64 (BE) and aarch64 are capable of this, others are not
623 linux32_check() {
624 local hostarch="$1"
625 local tgtarch="$2"
626 case "$hostarch" in
627 x86_64*) if [[ "$tgtarch" == i686* ]]; then return 0; fi ;;
628 ppc64le*) if [[ "$tgtarch" == ppcle* ]]; then return 0; fi ;;
629 ppc64*)
630 case "$tgtarch" in
631 ppc64*) return 1 ;;
632 ppc*) return 0 ;;
633 esac
635 aarch64*) if [[ "$tgtarch" == armv* ]]; then return 0; fi ;;
636 esac
637 return 1
640 # Reconfigure pkgs for 32bit on 64-bit systems and reexec itself.
641 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
642 export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
643 if linux32_check "$XBPS_MACHINE" "$XBPS_ARCH"; then
644 # reconfigure pkgs via linux32
645 linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
646 # reexec itself via linux32
647 export XBPS_REINIT=1
648 exec linux32 $0 ${XBPS_OPTIONS} "$@"
651 if [ -n "$XBPS_ARCH" ]; then
652 export XBPS_MACHINE=$XBPS_ARCH
654 # At this point if XBPS_TARGET_MACHINE isn't defined we assume
655 # it's a native build.
656 if [ -z "$XBPS_TARGET_MACHINE" ]; then
657 export XBPS_TARGET_MACHINE=$XBPS_MACHINE
660 if [ "$IN_CHROOT" ]; then
661 readonly XBPS_UHELPER_CMD="xbps-uhelper"
662 readonly XBPS_INSTALL_CMD="xbps-install -c /host/repocache-$XBPS_MACHINE"
663 readonly XBPS_QUERY_CMD="xbps-query -c /host/repocache-$XBPS_MACHINE"
664 readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
665 readonly XBPS_REMOVE_CMD="xbps-remove"
666 readonly XBPS_CHECKVERS_CMD="xbps-checkvers"
667 readonly XBPS_DESTDIR=/destdir
668 readonly XBPS_BUILDDIR=/builddir
669 else
670 readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
671 readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache-$XBPS_MACHINE -r $XBPS_MASTERDIR -C etc/xbps.d"
672 readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache-$XBPS_MACHINE -r $XBPS_MASTERDIR -C etc/xbps.d"
673 readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
674 readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
675 readonly XBPS_CHECKVERS_CMD="xbps-checkvers -r $XBPS_MASTERDIR"
676 readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
677 readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
679 readonly XBPS_RINDEX_CMD="xbps-rindex"
680 readonly XBPS_FETCH_CMD="xbps-fetch"
681 readonly XBPS_DIGEST_CMD="xbps-digest"
682 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
684 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
685 XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
686 XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_STRICT XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
687 XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
688 XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
689 XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
690 XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
691 XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
692 XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
693 XBPS_SKIP_REMOTEREPOS XBPS_CROSS_BUILD XBPS_ARG_PKG_OPTIONS XBPS_CONFIG_FILE \
694 XBPS_KEEP_ALL XBPS_HOSTDIR XBPS_MASTERDIR XBPS_SRC_VERSION \
695 XBPS_DESTDIR XBPS_MACHINE XBPS_TEMP_MASTERDIR XBPS_BINPKG_EXISTS \
696 XBPS_LIBEXECDIR XBPS_DISTDIR XBPS_DISTFILES_MIRROR XBPS_ALLOW_RESTRICTED \
697 XBPS_USE_GIT_COMMIT_DATE XBPS_PKG_COMPTYPE XBPS_REPO_COMPTYPE \
698 XBPS_BUILDHELPERDIR XBPS_USE_BUILD_MTIME XBPS_BUILD_ENVIRONMENT \
699 XBPS_PRESERVE_PKGS XBPS_IGNORE_BROKENNESS
701 for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
702 eval val="\$XBPS_$i"
703 if [ ! -d "$val" ]; then
704 mkdir -p $val
706 unset val
707 done
709 # A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
710 # on tmpfs (available with xbps-0.45).
711 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
712 export XBPS_CHROOT_CMD="uchroot"
713 export XBPS_CHROOT_CMD_ARGS+=" -O"
716 # Sanitize PATH.
718 if [ -z "$IN_CHROOT" ]; then
719 # In non chroot case always prefer host tools.
720 export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
724 # Set up ccache
726 if [ "$XBPS_CCACHE" ]; then
727 export CCACHEPATH="/usr/lib/ccache/bin"
728 export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
729 # Avoid not using cached files just due to compiler mtime
730 # changes when e.g. bootstrapping
731 export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
732 export PATH="$CCACHEPATH:$PATH"
733 mkdir -p $CCACHE_DIR
737 # Set up distcc
739 if [ "$XBPS_DISTCC" ]; then
740 if [ "$XBPS_CCACHE" ]; then
741 export CCACHE_PREFIX="/usr/bin/distcc"
742 else
743 DISTCCPATH="/usr/lib/distcc/bin"
744 export PATH="$DISTCCPATH:$PATH"
746 export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
747 export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
748 mkdir -p $DISTCC_DIR
751 check_build_requirements
754 # Read funcs from helpers
756 for f in ${XBPS_SHUTILSDIR}/*.sh; do
757 [ -r "$f" ] && . $f
758 done
760 if [ -z "$IN_CHROOT" ]; then
761 trap 'exit_func' INT TERM
762 if [ -n "$XBPS_DISTFILES_MIRROR" ]; then
763 setup_distfiles_mirror
767 reconfigure_base_chroot
770 # Main switch.
772 case "$XBPS_TARGET" in
773 binary-bootstrap)
774 if [ -n "$XBPS_TARGET_PKG" ]; then
775 msg_error "xbps-src: binary-bootstrap <arch> is no longer supported, use '-A <arch>' instead\n"
776 exit 1
778 install_base_chroot "$XBPS_MACHINE"
780 bootstrap)
781 if [ -n "$XBPS_CHECK_PKGS" ]; then
782 msg_error "xbps-src: disable tests for bootstrap\n"
783 exit 1
785 if [ -n "$XBPS_TARGET_PKG" ]; then
786 msg_error "xbps-src: bootstrap <arch> is no longer supported, use '-A <arch>' instead\n"
787 exit 1
789 # base-chroot building on host
790 # check for required host utils
791 check_reqhost_utils bootstrap
793 export XBPS_ARCH=$XBPS_MACHINE
794 export XBPS_SKIP_REMOTEREPOS=1
795 chroot_sync_repodata
796 $XBPS_LIBEXECDIR/build.sh \
797 base-chroot base-chroot $XBPS_TARGET || exit 1
798 ) || exit 1
799 [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
800 install_base_chroot "$XBPS_MACHINE"
802 bootstrap-update)
803 if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
804 chroot_handler bootstrap-update
805 else
806 chroot_sync_repodata
807 update_base_chroot
810 chroot)
811 chroot_sync_repodata
812 chroot_handler chroot dummy
814 clean)
815 if [ -z "$XBPS_TARGET_PKG" ]; then
816 if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
817 chroot_handler remove-autodeps
818 else
819 remove_pkg_autodeps
821 msg_normal "xbps-src: cleaning up masterdir...\n"
822 # Needed to remove Go Modules
823 [ -d "$XBPS_BUILDDIR" ] && chmod -R +wX $XBPS_BUILDDIR
824 rm -rf \
825 $XBPS_BUILDDIR \
826 $XBPS_DESTDIR
827 rm -rf $XBPS_MASTERDIR/tmp
828 mkdir -p $XBPS_MASTERDIR/tmp
829 else
830 read_pkg
831 if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
832 chroot_handler $XBPS_TARGET $XBPS_TARGET_PKG || exit $?
833 else
834 if declare -f do_clean >/dev/null; then
835 run_func do_clean
837 remove_pkg_wrksrc
838 remove_pkg_statedir
840 remove_pkg $XBPS_CROSS_BUILD
843 clean-repocache)
844 export XBPS_TARGET_ARCH="${XBPS_CROSS_BUILD:-$XBPS_TARGET_MACHINE}"
845 $XBPS_REMOVE_CMD -C /dev/null -c $XBPS_HOSTDIR/repocache-${XBPS_TARGET_ARCH} -O
847 consistency-check)
848 consistency_check
850 remove-autodeps)
851 if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
852 chroot_handler remove-autodeps
853 else
854 remove_pkg_autodeps
857 fetch|extract|patch|configure|build|check|install|pkg)
858 if [ "$XBPS_TARGET" = "check" ] && [ -z "$XBPS_CHECK_PKGS" ]; then
859 export XBPS_CHECK_PKGS=full
861 read_pkg
862 if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
863 chroot_handler $XBPS_TARGET $XBPS_TARGET_PKG
864 else
865 check_existing_pkg
866 chroot_sync_repodata
867 # prevent update_base_chroot from removing the builddir/destdir
868 update_base_chroot keep-all-force
869 $XBPS_LIBEXECDIR/build.sh $XBPS_TARGET_PKG $XBPS_TARGET_PKG \
870 $XBPS_TARGET $XBPS_CROSS_BUILD || exit $?
873 remove|remove-destdir)
874 read_pkg
875 remove_pkg $XBPS_CROSS_BUILD
877 list)
878 $XBPS_QUERY_CMD -l
880 purge-distfiles)
881 purge_distfiles
883 show)
884 read_pkg ignore-problems
885 show_pkg $XBPS_PRINT_VARIABLES
887 show-avail)
888 read_pkg &>/dev/null
889 show_avail
891 show-files)
892 read_pkg ignore-problems
893 show_pkg_files
895 show-deps)
896 read_pkg ignore-problems
897 show_pkg_deps
899 show-build-deps)
900 read_pkg ignore-problems
901 show_pkg_build_deps
903 show-hostmakedepends)
904 read_pkg ignore-problems
905 show_pkg_hostmakedepends
907 show-makedepends)
908 read_pkg ignore-problems
909 show_pkg_makedepends
911 show-checkdepends)
912 read_pkg ignore-problems
913 show_pkg_checkdepends
915 show-pkg-var-dump)
916 read_pkg ignore-problems
917 for sub_name in $subpackages; do
918 if [ $sub_name = $XBPS_TARGET_PKG ]; then
919 . ${XBPS_COMMONDIR}/environment/setup-subpkg/subpkg.sh
920 ${sub_name}_package
922 done
923 printf "archs: %s\n\n" "$archs"
924 printf "bootstrap: %s\n\n" "$bootstrap"
925 printf "broken: %s\n\n" "$broken"
926 printf "depends: %s\n\n" "$depends"
927 printf "hostmakedepends: %s\n\n" "$hostmakedepends"
928 printf "makedepends: %s\n\n" "$makedepends"
929 printf "nocross: %s\n\n" "$nocross"
930 printf "pkgname: %s\n\n" "$pkgname"
931 printf "restricted: %s\n\n" "$restricted"
932 printf "revision: %s\n\n" "$revision"
933 printf "subpackages: %s\n\n" "$subpackages"
934 printf "version: %s\n\n" "$version"
935 printf "provides: %s\n\n" "$provides"
936 printf "lib32disabled: %s\n\n" "$lib32disabled"
937 printf "nodebug: %s\n\n" "$nodebug"
939 show-pkg-var)
940 read_pkg ignore-problems
941 for sub_name in $subpackages; do
942 if [ $sub_name = $XBPS_TARGET_PKG ]; then
943 . ${XBPS_COMMONDIR}/environment/setup-subpkg/subpkg.sh
944 ${sub_name}_package
946 done
947 while IFS= read -r pkg_var; do
948 print_var=
949 case "${pkg_var}" in
950 archs) print_var="$archs ";;
951 bootstrap) print_var="$bootstrap ";;
952 broken) print_var="$broken ";;
953 depends) print_var="$depends ";;
954 hostmakedepends) print_var="$hostmakedepends ";;
955 makedepends) print_var="$makedepends ";;
956 nocross) print_var="$nocross ";;
957 pkgname) print_var="$pkgname ";;
958 restricted) print_var="$restricted ";;
959 revision) print_var="$revision ";;
960 subpackages) print_var="$subpackages ";;
961 version) print_var="$version ";;
962 provides) print_var="$provides ";;
963 lib32disabled) print_var="$lib32disabled ";;
964 nodebug) print_var="$nodebug ";;
965 esac # the space at the end of each is essential for unset vars
966 if [ -n "$print_var" ]; then
967 printf "%s\n" "$(printf "${print_var% }" | tr -t '\n\r' ' ')"
968 fi # The trailing space gets stripped before printing anyway
969 done
971 dbulk-dump)
972 read_pkg
973 check_pkg_arch "$XBPS_CROSS_BUILD"
974 for x in pkgname version revision; do
975 printf '%s: %s\n' "$x" "${!x}"
976 done
977 for x in bootstrap; do
978 [[ ${!x} ]] && printf '%s: %s\n' "$x" "${!x}"
979 done
980 for x in hostmakedepends makedepends; do
981 arr=(${!x})
982 if [[ ${#arr} -gt 0 ]]; then
983 printf '%s:\n' "$x"
984 printf ' %s\n' "${arr[@]}"
986 done
987 _cleandeps=$(setup_pkg_depends "" 1 1 | { grep -vF "$(printf "%s\n" $pkgname $subpackages)" || :; } | sort -u) || exit 1
988 if [[ $_cleandeps ]]; then
989 printf 'depends:\n'
990 printf ' %s\n' $_cleandeps
992 if [[ $subpackages ]]; then
993 printf 'subpackages:\n'
994 printf ' %s\n' $subpackages
997 show-options)
998 read_pkg ignore-problems
999 show_pkg_build_options
1001 show-shlib-provides)
1002 read_pkg ignore-problems
1003 show_pkg_shlib_provides
1005 show-shlib-requires)
1006 read_pkg ignore-problems
1007 show_pkg_shlib_requires
1009 show-var)
1010 for f in ${XBPS_COMMONDIR}/environment/setup/*.sh; do
1011 source $f
1012 done
1013 if [ "$XBPS_CROSS_BUILD" ]; then
1014 source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
1015 else
1016 source ${XBPS_COMMONDIR}/build-profiles/${XBPS_MACHINE}.sh
1018 eval value="\${$XBPS_TARGET_PKG}"
1019 echo $value
1021 show-repo-updates)
1022 bulk_build
1024 show-sys-updates)
1025 bulk_build installed
1027 show-local-updates)
1028 bulk_build local
1030 sort-dependencies)
1031 bulk_sortdeps ${@/$XBPS_TARGET/}
1033 update-bulk)
1034 bulk_update
1036 update-sys)
1037 bulk_update installed
1039 update-local)
1040 bulk_update local
1042 update-check)
1043 read_pkg ignore-problems
1044 update_check
1046 update-hash-cache)
1047 update_hash_cache
1049 zap)
1050 masterdir_zap
1053 msg_red "xbps-src: invalid target $XBPS_TARGET.\n"
1054 usage && exit 1
1056 esac
1058 exit_and_cleanup $?