abinfo "Building os-prober ..."
make \
    CFLAGS="${CPPFLAGS} ${CFLAGS}"
    LDFLAGS="${LDFLAGS}"

# Note: Follow debian/os-prober.install
abinfo "Installing os-prober executables ..."
install -Dvm755 "$SRCDIR"/linux-boot-prober \
    "$PKGDIR"/usr/bin/linux-boot-prober
install -Dvm755 "$SRCDIR"/os-prober \
    "$PKGDIR"/usr/bin/os-prober
install -Dvm755 "$SRCDIR"/newns \
    "$PKGDIR"/usr/lib/os-prober/newns
install -Dvm755 "$SRCDIR"/common.sh \
    "$PKGDIR"/usr/share/os-prober/common.sh

# Note: We name our architectures differently from os-prober as shown below.
if ab_match_arch loongarch64 || \
   ab_match_arch loongarch64_nosimd; then
    export PROBES_ARCH="loong64"
elif ab_match_arch amd64 || \
     ab_match_arch i486; then
    export PROBES_ARCH="x86"
elif ab_match_arch powerpc || \
     ab_match_arch ppc64 || \
     ab_match_arch ppc64el; then
    export PROBES_ARCH="powerpc"
else
    export PROBES_ARCH="$ARCH"
fi

# Note: Follow override_dh_install in debian/rules (except the udeb components
# as we don't use debian-installer.
abinfo "Installing probe scripts ..."
for probes in os-probes os-probes/mounted os-probes/init \
              linux-boot-probes linux-boot-probes/mounted; do
    mkdir -pv "$PKGDIR"/usr/lib/${probes}
    cp -av "$SRCDIR"/${probes}/common/* \
        -t "$PKGDIR"/usr/lib/${probes}/
    # Install architecture-specific probes ..."
    if [ -d "$SRCDIR"/${probes}/${PROBES_ARCH} ]; then
        abinfo "Installing architecture-specific probe scripts for $ARCH ..."
        cp -av "$SRCDIR"/${probes}/${PROBES_ARCH}/* \
            "$PKGDIR"/usr/lib/${probes}/
    fi
done
# Note: Install macOS (Mac OS X) probes which were erroneously marked as
# powerpc-specific.
if ab_match_arch amd64 || \
   ab_match_arch i486; then
    abinfo "Installing macOS (Mac OS X) probes for $ARCH ..."
    cp -av "$SRCDIR"/os-probes/mounted/powerpc/20macosx \
        "$PKGDIR"/usr/lib/os-probes/mounted/20macosx
fi
