clojure-lsp: update to 2024.08.05.
[void-pkg.git] / common / xbps-src / libexec / build.sh
blob72432316e6ead41d1cf76d3c61f1e7a63aacaa1a
1 #!/bin/bash
3 # vim: set ts=4 sw=4 et:
5 # Passed arguments:
6 # $1 - current pkgname to build [REQUIRED]
7 # $2 - target pkgname (origin) to build [REQUIRED]
8 # $3 - xbps target [REQUIRED]
9 # $4 - cross target [OPTIONAL]
10 # $5 - internal [OPTIONAL]
12 if [ $# -lt 3 -o $# -gt 5 ]; then
13 echo "${0##*/}: invalid number of arguments: pkgname targetpkg target [cross-target]"
14 exit 1
17 readonly PKGNAME="$1"
18 readonly XBPS_TARGET_PKG="$2"
19 readonly XBPS_TARGET="$3"
20 readonly XBPS_CROSS_BUILD="$4"
21 readonly XBPS_CROSS_PREPARE="$5"
23 export XBPS_TARGET
25 for f in $XBPS_SHUTILSDIR/*.sh; do
26 . $f
27 done
29 last="${XBPS_DEPENDS_CHAIN##*,}"
30 case "$XBPS_DEPENDS_CHAIN" in
31 *,$last,*)
32 msg_error "Build-time cyclic dependency$last,${XBPS_DEPENDS_CHAIN##*,$last,} detected.\n"
33 esac
35 setup_pkg "$PKGNAME" $XBPS_CROSS_BUILD
36 readonly SOURCEPKG="$sourcepkg"
38 check_existing_pkg
40 show_pkg_build_options
41 check_pkg_arch $XBPS_CROSS_BUILD
43 if [ -z "$XBPS_CROSS_PREPARE" ]; then
44 prepare_cross_sysroot $XBPS_CROSS_BUILD || exit $?
46 # Install dependencies from binary packages
47 if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
48 install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
51 if [ "$XBPS_CROSS_BUILD" ]; then
52 install_cross_pkg $XBPS_CROSS_BUILD || exit $?
55 # Fetch distfiles after installing required dependencies,
56 # because some of them might be required for do_fetch().
57 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
58 [ "$XBPS_TARGET" = "fetch" ] && exit 0
60 # Fetch, extract, build and install into the destination directory.
61 $XBPS_LIBEXECDIR/xbps-src-doextract.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
62 [ "$XBPS_TARGET" = "extract" ] && exit 0
64 # Run patch phrase
65 $XBPS_LIBEXECDIR/xbps-src-dopatch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
66 [ "$XBPS_TARGET" = "patch" ] && exit 0
68 # Run configure phase
69 $XBPS_LIBEXECDIR/xbps-src-doconfigure.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
70 [ "$XBPS_TARGET" = "configure" ] && exit 0
72 # Run build phase
73 $XBPS_LIBEXECDIR/xbps-src-dobuild.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
74 [ "$XBPS_TARGET" = "build" ] && exit 0
76 # Run check phase
77 $XBPS_LIBEXECDIR/xbps-src-docheck.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
78 [ "$XBPS_TARGET" = "check" ] && exit 0
80 # Install pkgs into destdir.
81 $XBPS_LIBEXECDIR/xbps-src-doinstall.sh $SOURCEPKG no $XBPS_CROSS_BUILD || exit 1
83 for subpkg in ${subpackages} ${sourcepkg}; do
84 $XBPS_LIBEXECDIR/xbps-src-doinstall.sh $subpkg yes $XBPS_CROSS_BUILD || exit 1
85 done
86 for subpkg in ${subpackages} ${sourcepkg}; do
87 $XBPS_LIBEXECDIR/xbps-src-prepkg.sh $subpkg $XBPS_CROSS_BUILD || exit 1
88 done
90 for subpkg in ${subpackages} ${sourcepkg}; do
91 if [ "$PKGNAME" = "${subpkg}" -a "$XBPS_TARGET" = "install" ]; then
92 exit 0
94 done
96 # Clean list of preregistered packages
97 printf "" > ${XBPS_STATEDIR}/.${sourcepkg}_register_pkg
98 # If install went ok generate the binpkgs.
99 for subpkg in ${subpackages} ${sourcepkg}; do
100 $XBPS_LIBEXECDIR/xbps-src-dopkg.sh $subpkg "$XBPS_REPOSITORY" "$XBPS_CROSS_BUILD" || exit 1
101 done
103 # Registering packages at once per repository. This makes sure that staging is
104 # triggered for all new packages if any of them introduces inconsistencies.
105 cut -d: -f 1,2 ${XBPS_STATEDIR}/.${sourcepkg}_register_pkg | sort -u | \
106 while IFS=: read -r arch repo; do
107 paths=$(grep "^$arch:$repo:" "${XBPS_STATEDIR}/.${sourcepkg}_register_pkg" | \
108 cut -d : -f 2,3 | tr ':' '/')
109 if [ -z "$XBPS_PRESERVE_PKGS" ] || [ "$XBPS_BUILD_FORCEMODE" ]; then
110 force=-f
112 if [ -n "${arch}" ]; then
113 msg_normal "Registering new packages to $repo ($arch)\n"
114 XBPS_TARGET_ARCH=${arch} $XBPS_RINDEX_CMD \
115 ${XBPS_REPO_COMPTYPE:+--compression $XBPS_REPO_COMPTYPE} ${force} -a ${paths}
116 else
117 msg_normal "Registering new packages to $repo\n"
118 if [ -n "$XBPS_CROSS_BUILD" ]; then
119 $XBPS_RINDEX_XCMD ${XBPS_REPO_COMPTYPE:+--compression $XBPS_REPO_COMPTYPE} \
120 ${force} -a ${paths}
121 else
122 $XBPS_RINDEX_CMD ${XBPS_REPO_COMPTYPE:+--compression $XBPS_REPO_COMPTYPE} \
123 ${force} -a ${paths}
126 done
128 # pkg cleanup
129 if declare -f do_clean >/dev/null; then
130 run_func do_clean
133 if [ -n "$XBPS_DEPENDENCY" -o -z "$XBPS_KEEP_ALL" ]; then
134 remove_pkg_autodeps
135 remove_pkg_wrksrc
136 remove_pkg $XBPS_CROSS_BUILD
137 remove_pkg_statedir
140 exit 0