From 4f73e4a740041635eecd30abccc2fdafabb21582 Mon Sep 17 00:00:00 2001 From: Rory Fewell Date: Fri, 31 Jan 2025 23:37:17 +0000 Subject: [PATCH] Enhancement: Fixes #355, Add an option for buildall to build on deb- even if it detects other systems. --- packaging/build.sh | 40 ++++++-- packaging/buildall.sh | 46 ++++++--- packaging/chkdeps.sh | 46 +++++++-- packaging/distid.sh | 227 ++++++++++++++++++++++++++++++------------ packaging/package.sh | 40 ++++++-- packaging/zzz_inc.sh | 30 ++++++ 6 files changed, 330 insertions(+), 99 deletions(-) create mode 100755 packaging/zzz_inc.sh diff --git a/packaging/build.sh b/packaging/build.sh index f58b3be..270957c 100755 --- a/packaging/build.sh +++ b/packaging/build.sh @@ -18,6 +18,7 @@ SCRIPTDIR=`dirname "$0"` REPO_ROOT=`realpath "${SCRIPTDIR}/.."` SH_DISTID="${SCRIPTDIR}/distid.sh" +SH_ZZZINC="${SCRIPTDIR}/zzz_inc.sh" @@ -26,10 +27,11 @@ SH_DISTID="${SCRIPTDIR}/distid.sh" # OPT_BUILD_ROOT="${CURDIR}/build" OPT_BUILD_TYPE="Release" +OPT_DIST_TARGET="" OPT_SKU="xpclient-pro" OPT_USE_LOCAL_LIBS=0 -while getopts "b:dhls:" opt; +while getopts "b:dhls:t:" opt; do case "${opt}" in b) @@ -41,13 +43,14 @@ do ;; h) - echo "Usage: build.sh [-bhls] " + echo "Usage: build.sh [-bdhlst] " echo "" echo " -b : specify the directory to build relative to" echo " -d : produce checked build" echo " -h : display this help screen" echo " -l : use wintc libraries compiled here, not system" - echo " -s : specify SKU to build (default xpclient-pro)" + echo " -s : specify SKU to build (default 'xpclient-pro')" + echo " -t : specify the distro target (don't autodetect)" echo "" exit 0 @@ -60,6 +63,10 @@ do s) OPT_SKU="${OPTARG}" ;; + + t) + OPT_DIST_TARGET="${OPTARG}" + ;; esac done @@ -85,6 +92,12 @@ then exit 1 fi +if [[ ! -f "${SH_ZZZINC}" ]] +then + echo "zzz_inc.sh not found - this should never happen!!" + exit 1 +fi + # Check component exists # if [[ ! -d "${full_component_dir}" ]] @@ -93,6 +106,20 @@ then exit 1 fi +# Pull includes +# +. "${SH_ZZZINC}" + +if [[ ! -z "${OPT_DIST_TARGET}" ]] +then + zzz_dist_target_to_vars "${OPT_DIST_TARGET}" + + if [[ $? -gt 0 ]] + then + exit 1 + fi +fi + # Identify distro build # dist_prefix="/usr" @@ -101,7 +128,6 @@ dist_prefix="/usr" if [[ $? -gt 0 ]] then - "Failed to identify distribution." exit 1 fi @@ -119,7 +145,7 @@ mkdir -p "${full_build_dir}" if [[ $? -gt 0 ]] then - echo "Unable to ensure the build directory exists, aborting." + echo "build: Unable to ensure the build directory exists, aborting." >&2 exit 1 fi @@ -149,8 +175,8 @@ cd "${CURDIR}" if [[ $build_result -gt 0 ]] then - echo "Failed build for ${rel_component_dir}" + echo "build: Failed build for ${rel_component_dir}" >&2 exit 1 fi -echo "Built ${rel_component_dir}" +echo "build: Built ${rel_component_dir}" diff --git a/packaging/buildall.sh b/packaging/buildall.sh index 27ad6b6..51ededd 100755 --- a/packaging/buildall.sh +++ b/packaging/buildall.sh @@ -24,6 +24,7 @@ SH_CHKDEPS="${SCRIPTDIR}/chkdeps.sh" SH_DISTID="${SCRIPTDIR}/distid.sh" SH_GENTAG="${BLDUTILS_ROOT}/gentag/gentag.sh" SH_PACKAGE="${SCRIPTDIR}/package.sh" +SH_ZZZINC="${SCRIPTDIR}/zzz_inc.sh" @@ -32,11 +33,12 @@ SH_PACKAGE="${SCRIPTDIR}/package.sh" # OPT_BUILDLIST="${TARGETS_PATH}" OPT_CHECKED=0 +OPT_DIST_TARGET= OPT_OUTPUT_DIR="" OPT_SKU="xpclient-pro" OPT_SKIP_PACKAGING=0 -while getopts "c:dho:s:z" opt; +while getopts "c:dho:s:t:z" opt; do case "${opt}" in c) @@ -48,12 +50,14 @@ do ;; h) - echo "Usage: buildall.sh [-chosz]" + echo "Usage: buildall.sh [-cdhostz]" + echo "" echo " -c : provide a list of components (default 'targets')" echo " -d : produce checked build" echo " -h : display this help screen" echo " -o : specify output directory for packages" - echo " -s : specify SKU to build (default xpclient-pro)" + echo " -s : specify SKU to build (default 'xpclient-pro')" + echo " -t : specify the distro target (don't autodetect)" echo " -z : skip packaging steps, compile only" echo "" @@ -68,6 +72,10 @@ do OPT_SKU="${OPTARG}" ;; + t) + OPT_DIST_TARGET="${OPTARG}" + ;; + z) OPT_SKIP_PACKAGING=1 ;; @@ -137,7 +145,7 @@ build_component() if [[ $? -gt 0 ]] then - echo "buildall: Compile failure, bailing." + echo "buildall: Compile failure, bailing." >&2 exit 1 fi @@ -178,7 +186,7 @@ check_present() if [[ ! -f "${check_path}" ]] then - echo "${check_path} not found - this should never happen!!" + echo "buildall: ${check_path} not found - this should never happen!!" >&2 exit 1 fi } @@ -192,20 +200,34 @@ check_present "${SH_CHKDEPS}" check_present "${SH_DISTID}" check_present "${SH_GENTAG}" check_present "${SH_PACKAGE}" +check_present "${SH_ZZZINC}" if [[ ! -f "${OPT_BUILDLIST}" ]] then - echo "Build list not found or readable: ${OPT_BUILDLIST}" + echo "buildall: Build list not found or readable: ${OPT_BUILDLIST}" >&2 exit 1 fi +# Pull includes +# +. "${SH_ZZZINC}" + +if [[ ! -z "${OPT_DIST_TARGET}" ]] +then + zzz_dist_target_to_vars "${OPT_DIST_TARGET}" + + if [[ $? -gt 0 ]] + then + exit 1 + fi +fi + # Identify our distro # . "${SH_DISTID}" if [[ $? -gt 0 ]] then - echo "Failed to identify distribution." exit 1 fi @@ -222,7 +244,7 @@ then build_type="checked" fi -echo "Doing full system build for ${tag} (${cur_arch}, ${DIST_ID}-${DIST_ID_EXT}) (${build_type})" +echo "buildall: Doing full system build for ${tag} (${cur_arch}, ${DIST_ID}-${DIST_ID_EXT}) (${build_type})" # Handle output dir for packaging # @@ -237,11 +259,11 @@ then if [[ ! -d "${OPT_OUTPUT_DIR}" ]] then - echo "Cannot ensure output directory "${OPT_OUTPUT_DIR}" exists." + echo "buildall: Cannot ensure output directory "${OPT_OUTPUT_DIR}" exists." >&2 exit 1 fi else - echo "Packaging will be skipped for this session." + echo "buildall: Packaging will be skipped for this session." fi # Check system deps @@ -250,7 +272,7 @@ fi if [[ $? -gt 0 ]] then - echo "Dependencies check unsatisfied or failed." + echo "buildall: Dependencies check unsatisfied or failed." >&2 exit 1 fi @@ -261,4 +283,4 @@ do build_component "${rel_target_dir}" done {targets_fd}<"${OPT_BUILDLIST}" -echo "Build complete for ${tag} (${build_type})" +echo "buildall: Build complete for ${tag} (${build_type})" diff --git a/packaging/chkdeps.sh b/packaging/chkdeps.sh index 6305867..cbf4262 100755 --- a/packaging/chkdeps.sh +++ b/packaging/chkdeps.sh @@ -18,6 +18,7 @@ SCRIPTDIR=`dirname "$0"` REPO_ROOT=`realpath "${SCRIPTDIR}/.."` SH_DISTID="${SCRIPTDIR}/distid.sh" +SH_ZZZINC="${SCRIPTDIR}/zzz_inc.sh" DEPMAP_PY="${REPO_ROOT}/tools/bldutils/depmap/depmap.py" @@ -26,9 +27,10 @@ DEPMAP_PY="${REPO_ROOT}/tools/bldutils/depmap/depmap.py" # ARGUMENTS # OPT_BUILDLIST="${SCRIPTDIR}/targets" +OPT_DIST_TARGET="" OPT_USE_LOCAL_LIBS=0 -while getopts "c:hl" opt; +while getopts "c:hlt:" opt; do case "${opt}" in c) @@ -36,11 +38,12 @@ do ;; h) - echo "Usage: chkdeps.sh [-chl]" + echo "Usage: chkdeps.sh [-chlt]" echo "" echo " -c : provide a list of components (default 'targets')" echo " -h : display this help screen" echo " -l : use wintc libraries compiled here, not system" + echo " -t : specify the distro target (don't autodetect)" echo "" exit 0 @@ -49,6 +52,10 @@ do l) OPT_USE_LOCAL_LIBS=1 ;; + + t) + OPT_DIST_TARGET="${OPTARG}" + ;; esac done @@ -77,7 +84,7 @@ check_deps() if [[ $? -gt 0 ]] then - echo "Failed to map dependencies." + echo "chkdeps: Failed to map dependencies." >&2 exit 1 fi @@ -141,7 +148,7 @@ check_deps() if [[ $found_pkg -eq 0 ]] then - echo "${pkg_name} is unavailable for your distro." + echo "chkdeps: ${pkg_name} is unavailable for your distro." >&2 exit 1 fi fi @@ -180,7 +187,7 @@ check_deps() xbps-query --show "${pkg_name}" >/dev/null 2>&1 ;; *) - echo "Package format not implemented!" + echo "chkdeps: Package format not implemented!" >&2 exit 1 ;; esac @@ -199,29 +206,48 @@ check_deps() # if [[ ! -f "${SH_DISTID}" ]] then - echo "distid.sh not found - this should never happen!!" + echo "chkdeps: distid.sh not found - this should never happen!!" >&2 + exit 1 +fi + +if [[ ! -f "${SH_ZZZINC}" ]] +then + echo "chkdeps: zzz_inc.sh not found - this should never happen!!" >&2 exit 1 fi if [[ ! -f "${DEPMAP_PY}" ]] then - echo "depmap tool not found - this should never happen!!" + echo "chkdeps: depmap tool not found - this should never happen!!" >&2 exit 1 fi if [[ ! -f "${OPT_BUILDLIST}" ]] then - echo "Build list not found or readable: ${OPT_BUILDLIST}" + echo "chkdeps: Build list not found or readable: ${OPT_BUILDLIST}" >&2 exit 1 fi +# Pull includes +# +. "${SH_ZZZINC}" + +if [[ ! -z "${OPT_DIST_TARGET}" ]] +then + zzz_dist_target_to_vars "${OPT_DIST_TARGET}" + + if [[ $? -gt 0 ]] + then + exit 1 + fi +fi + # Identify our distro # . "${SH_DISTID}" if [[ $? -gt 0 ]] then - echo "Failed to identify distribution." exit 1 fi @@ -236,7 +262,7 @@ done {buildlist_fd}<"${OPT_BUILDLIST}" # if [[ "${#g_needed_pkgs[@]}" -eq 0 ]] then - echo "All dependencies verified." + echo "chkdeps: All dependencies OK!" >&2 exit 0 fi diff --git a/packaging/distid.sh b/packaging/distid.sh index e3781f6..79759fd 100755 --- a/packaging/distid.sh +++ b/packaging/distid.sh @@ -9,19 +9,90 @@ # Author(s): Rory Fewell # +# +# FUNCTIONS +# +g_ambiguous=0 +g_compare_against_env=0 +g_compare_successful=0 +g_detected_pkgmgr="" +g_detected_pkgmgr_ext="" + +set_pkgmgr() +{ + if [[ \ + ${g_compare_against_env} -eq 1 && \ + "${1}" == "${DIST_ID}" && \ + "${2}" == "${DIST_ID_EXT}" \ + ]] + then + g_compare_successful=1 + fi + + if [[ ${g_detected_pkgmgr} != "" ]] + then + g_ambiguous=1 + fi + + g_detected_pkgmgr=${1} + g_detected_pkgmgr_ext=${2} +} + + + # # MAIN SCRIPT # +# If DIST_ID is already defined, validate it +# +if [[ ! -z "${DIST_ID}" ]] +then + l_target_valid=0 + + case "${DIST_ID}" in + # For all these distros, only -std is valid + # + apk | archpkg | bsdpkg | deb | rpm) + if [[ -z "${DIST_ID_EXT}" ]] + then + DIST_ID_EXT="std" + fi + + if [[ "${DIST_ID_EXT}" == "std" ]] + then + l_target_valid=1 + fi + + ;; + + # xbps must be either musl or glibc + # + xbps) + case "${DIST_ID_EXT}" in + glibc | musl) + l_target_valid=1 + ;; + esac + + ;; + esac + + if [[ $l_target_valid -eq 1 ]] + then + # Proceed on with the check as normal, to ensure the desired package + # manager is installed + # + g_compare_against_env=1 + else + echo "distid: The distro target is not valid." >&2 + return 1 + fi +fi + # Probe for package managers to try and determine what distro we're # on # -# NOTE: Since #253, Debian/dpkg is checked last, because potentially users of -# other distros might have dpkg installed which throws off detection -# -# I think it's unlikely the other package managers will be installed on -# different distros... mainly just dpkg -# # Check Arch Linux # @@ -29,9 +100,7 @@ which pacman >/dev/null 2>&1 if [[ $? -eq 0 ]] then - export DIST_ID="archpkg" - export DIST_ID_EXT="std" - return 0 + set_pkgmgr "archpkg" "std" fi # Check Alpine Linux @@ -40,55 +109,7 @@ which apk >/dev/null 2>&1 if [[ $? -eq 0 ]] then - export DIST_ID="apk" - export DIST_ID_EXT="std" - return 0 -fi - -# Check FreeBSD -# -which pkg >/dev/null 2>&1 - -if [[ $? -eq 0 ]] -then - export DIST_ID="bsdpkg" - export DIST_ID_EXT="std" - return 0 -fi - -# Check Red Hat -# -which rpm >/dev/null 2>&1 - -if [[ $? -eq 0 ]] -then - export DIST_ID="rpm" - export DIST_ID_EXT="std" - return 0 -fi - -# Check Void Linux -# -which xbps-create >/dev/null 2>&1 - -if [[ $? -eq 0 ]] -then - export DIST_ID="xbps" - - # This might be a rubbish way to determine glibc vs. musl, if it does suck - # then someone needs to whinge and then I'll have to come up with something - # better - # - find /usr/lib -iname "*ld-musl*" | read - - if [[ $? -eq 0 ]] - then - export DIST_ID_EXT="musl" - else - export DIST_ID_EXT="glibc" - fi - - return 0 + set_pkgmgr "apk" "std" fi # Check Debian @@ -97,12 +118,92 @@ which dpkg >/dev/null 2>&1 if [[ $? -eq 0 ]] then - export DIST_ID="deb" - export DIST_ID_EXT="std" + set_pkgmgr "deb" "std" +fi + +# Check FreeBSD +# +which pkg >/dev/null 2>&1 + +if [[ $? -eq 0 ]] +then + set_pkgmgr "bsdpkg" "std" +fi + +# Check Red Hat +# +which rpm >/dev/null 2>&1 + +if [[ $? -eq 0 ]] +then + set_pkgmgr "rpm" "std" +fi + +# Check Void Linux +# +which xbps-create >/dev/null 2>&1 + +if [[ $? -eq 0 ]] +then + # This might be a rubbish way to determine glibc vs. musl, if it does suck + # then someone needs to whinge and then I'll have to come up with something + # better + # + find /usr/lib -iname "*ld-musl*" | read + + if [[ $? -eq 0 ]] + then + set_pkgmgr "xbps" "musl" + else + set_pkgmgr "xbps" "glibc" + fi + return 0 fi -# Nothing else to probe, it's over! +# If we were just double-checking the already-set DIST_ID to make sure we have +# the package manager installed, then deal with that first # -echo "Unsupported distribution." -return 1 +if [[ ${g_compare_against_env} -eq 1 ]] +then + if [[ ${g_compare_successful} -eq 1 ]] + then + export DIST_ID="${DIST_ID}" + export DIST_ID_EXT="${DIST_ID_EXT}" + return 0 + else + echo "distid: The format ${DIST_ID}-${DIST_ID_EXT} was specified." >&2 + echo "distid: Couldn't find the package manager for this format." >&2 + echo "distid:" >&2 + echo "distid: Please double check what distro you're using, and" >&2 + echo "distid: that you definitely have the package manager for" >&2 + echo "distid: the format installed." >&2 + return 1 + fi +fi + +# Okay so it was down to auto-detection, make sure we found a supported package +# manager - if we found more than 1 then the user must explicitly state what +# one to use via -t +# +if [[ ${g_ambiguous} -gt 0 ]] +then + echo "distid: Ambiguity because multiple package managers present." >&2 + echo "distid: Use the -t switch to specify the target format." >&2 + echo "distid: eg. -t deb" >&2 + echo "distid: eg. -t xbps-musl" >&2 + return 1 +fi + +if [[ ${g_detected_pkgmgr} == "" ]] +then + echo "distid: No known package manager could be found." >&2 + echo "distid: Please check your distribution is supported." >&2 + return 1 +fi + +# We passed the checks, happy days! +# +export DIST_ID="${g_detected_pkgmgr}" +export DIST_ID_EXT="${g_detected_pkgmgr_ext}" +return 0 diff --git a/packaging/package.sh b/packaging/package.sh index 5aebcba..de6e70c 100755 --- a/packaging/package.sh +++ b/packaging/package.sh @@ -18,6 +18,7 @@ SCRIPTDIR=`dirname "$0"` REPO_ROOT=`realpath "${SCRIPTDIR}/../.."` SH_DISTID="${SCRIPTDIR}/distid.sh" +SH_ZZZINC="${SCRIPTDIR}/zzz_inc.sh" @@ -25,17 +26,19 @@ SH_DISTID="${SCRIPTDIR}/distid.sh" # ARGUMENTS # OPT_BUILD_DIR="${CURDIR}/build" +OPT_DIST_TARGET="" OPT_OUTPUT_DIR="${CURDIR}/local-out" -while getopts "hi:o:" opt; +while getopts "hi:o:t:" opt; do case "${opt}" in h) - echo "Usage: package.sh [-hio] " + echo "Usage: package.sh [-hiot] " echo "" echo " -h : display this help screen" echo " -i : specify root build directory" echo " -o : specify output directory" + echo " -t : specify the distro target (don't autodetect)" echo "" exit 0 @@ -48,6 +51,10 @@ do o) OPT_OUTPUT_DIR="${OPTARG}" ;; + + t) + OPT_DIST_TARGET="${OPTARG}" + ;; esac done @@ -55,7 +62,7 @@ shift $((OPTIND-1)) if [[ $# -ne 1 ]] then - echo "Should specify single component to package." + echo "package: Should specify single component to package." >&2 exit 1 fi @@ -70,6 +77,26 @@ then exit 1 fi +if [[ ! -f "${SH_ZZZINC}" ]] +then + echo "zzz_inc.sh not found - this should never happen!!" + exit 1 +fi + +# Pull includes +# +. "${SH_ZZZINC}" + +if [[ ! -z "${OPT_DIST_TARGET}" ]] +then + zzz_dist_target_to_vars "${OPT_DIST_TARGET}" + + if [[ $? -gt 0 ]] + then + exit 1 + fi +fi + # Ensure the output containing dir exists # if [[ ! -d "${OPT_OUTPUT_DIR}" ]] @@ -78,7 +105,7 @@ then if [[ $? -gt 0 ]] then - echo "Unable to ensure output directory exists, aborting." + echo "package: Unable to ensure output directory exists, aborting." >&2 exit 1 fi fi @@ -89,7 +116,6 @@ fi if [[ $? -gt 0 ]] then - echo "Failed to identify distribution." exit 1 fi @@ -99,7 +125,7 @@ sh_pkg_impl="${SCRIPTDIR}/${DIST_ID}/pkgimpl.sh" if [[ ! -f "${sh_pkg_impl}" ]] then - echo "Packaging implementation for ${DIST_ID} not found!" + echo "package: Packaging implementation for ${DIST_ID} not found!" >&2 exit 1 fi @@ -110,7 +136,7 @@ full_component_dir="${OPT_BUILD_DIR}/${rel_component_dir}" if [[ ! -d "${full_component_dir}" ]] then - echo "Component doesn't seem to be built at ${full_component_dir}" + echo "package: Component doesn't seem to be built at ${full_component_dir}" >&2 exit 1 fi diff --git a/packaging/zzz_inc.sh b/packaging/zzz_inc.sh new file mode 100755 index 0000000..addcdee --- /dev/null +++ b/packaging/zzz_inc.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# +# zzz_inc.sh - Build Script Includes +# +# This source-code is part of Windows XP stuff for XFCE: +# <> +# +# Author(s): Rory Fewell +# + +# +# FUNCTIONS +# +zzz_dist_target_to_vars() +{ + if [[ "${1}" =~ ^([a-z]+)(-([a-z]+))?$ ]] + then + export DIST_ID="${BASH_REMATCH[1]}" + export DIST_ID_EXT="${BASH_REMATCH[3]}" + return 0 + fi + + echo "zzz_inc: Target passed in via -t was not understood." >&2 + echo "zzz_inc: Should look like" >&2 + echo "zzz_inc: -t deb" >&2 + echo "zzz_inc: -t xbps-glibc" >&2 + + return 1 +}