mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-06-27 18:36:35 +02:00
[cmake] Update CPMUtil (#4123)
Notable changes - Single cpmfile - version/min_version/git_version have been fixed and replaced with version and min_version - Docs rewrite - Legacy options are gone - Fixed update/version commands - Added patch creation functionality Signed-off-by: crueter <crueter@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4123 Reviewed-by: Lizzie <lizzie@eden-emu.dev> Reviewed-by: MaranBr <maranbr@eden-emu.dev>
This commit is contained in:
parent
6bdb03d8ac
commit
c993bc01a4
35 changed files with 1500 additions and 1294 deletions
|
|
@ -3,35 +3,43 @@
|
|||
# SPDX-FileCopyrightText: Copyright 2026 crueter
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
##################################
|
||||
# CHANGE THESE FOR YOUR PROJECT! #
|
||||
##################################
|
||||
: "${CPM_SOURCE_CACHE:=$PWD/.cache/cpm}"
|
||||
: "${CPMUTIL_PATCH_DIR:=$PWD/.patch}"
|
||||
|
||||
# TODO: cache cpmfile defs
|
||||
# TODO: cache cpmfile defs?
|
||||
|
||||
cmd_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
must_install() {
|
||||
for cmd in "$@"; do
|
||||
command -v "$cmd" >/dev/null 2>&1 || { echo "-- $cmd must be installed" && exit 1; }
|
||||
cmd_exists "$cmd" || { echo "-- $cmd must be installed" && exit 1; }
|
||||
done
|
||||
}
|
||||
|
||||
must_install jq find mktemp tar 7z unzip sha512sum git patch curl xargs
|
||||
# Random integer between 100000 and 999999
|
||||
_randint() {
|
||||
awk 'BEGIN { srand(); print int(100000 + rand() * 900000) }'
|
||||
}
|
||||
|
||||
# How many levels to go (3 is 2 subdirs max)
|
||||
MAXDEPTH=3
|
||||
# Use mktemp if available, use a local temp dir otherwise
|
||||
make_temp_dir() {
|
||||
if cmd_exists mktemp; then
|
||||
mktemp -d
|
||||
else
|
||||
TMP="$PWD/.cpm/tmp-$(_randint)"
|
||||
mkdir -p "$TMP"
|
||||
echo "$TMP"
|
||||
fi
|
||||
}
|
||||
|
||||
# For your project you'll want to change this to define what dirs you have cpmfiles in
|
||||
# Remember to account for the MAXDEPTH variable!
|
||||
# Adding ./ before each will help to remove duplicates
|
||||
CPMFILES=$(find . -maxdepth "$MAXDEPTH" -name cpmfile.json | sort | uniq)
|
||||
# must_install jq find mktemp tar 7z unzip sha512sum git patch curl
|
||||
|
||||
# shellcheck disable=SC2016
|
||||
PACKAGES=$(echo "$CPMFILES" | xargs jq -s 'reduce .[] as $item ({}; . * $item)')
|
||||
|
||||
LIBS=$(echo "$PACKAGES" | jq -j 'keys_unsorted | join(" ")')
|
||||
|
||||
export PACKAGES
|
||||
export CPMFILES
|
||||
export LIBS
|
||||
export DIRS
|
||||
export MAXDEPTH
|
||||
if [ ! -s cpmfile.json ]; then
|
||||
# TODO: actually make it a no-op
|
||||
echo "-- Warning: cpmfile.json does not exist or is empty, most commands will be no-ops"
|
||||
else
|
||||
LIBS=$(jq -j 'keys_unsorted | join(" ")' cpmfile.json)
|
||||
export LIBS
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue