]> xenbits.xensource.com Git - unikraft/libs/musl.git/commitdiff
Add script for generating Makefile.uk.musl.* entries
authorRobert Kuban <robert.kuban@opensynergy.com>
Tue, 19 Jul 2022 14:29:41 +0000 (16:29 +0200)
committerUnikraft <monkey@unikraft.io>
Wed, 23 Nov 2022 12:54:00 +0000 (12:54 +0000)
Adds a script that can find the source files for a given architecture and
sublibrary by emulating the mechanism in the original musl makefile.

Signed-off-by: Robert Kuban <robert.kuban@opensynergy.com>
Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #8

scripts/extract-lib-src.sh [new file with mode: 0644]

diff --git a/scripts/extract-lib-src.sh b/scripts/extract-lib-src.sh
new file mode 100644 (file)
index 0000000..d00db8e
--- /dev/null
@@ -0,0 +1,56 @@
+#! /bin/bash
+
+LIB=$1
+ARCH=$2
+MUSL=$3
+
+if [[ "$MUSL" == "" ]]; then
+       MUSL=$(pwd)
+fi
+
+if [[ ! "$ARCH" =~ aarch64|arm|i386|microblaze|mips|mips64|mipsn32|or1k|powerpc|powerpc64|s390x|sh|x32|x86_64|riscv64 ]]; then
+       echo "Unknown architecture: $ARCH" 1>&2
+       ARCH=""
+fi
+
+if [[ ! -d "$MUSL/src/$LIB" ]]; then
+       echo "Can not find library directory: $MUSL/$LIB" 1>&2
+       LIB=""
+fi
+
+if [[ "$LIB" == "" || "$ARCH" == "" ]]; then
+       echo "USAGE: ./extract-lib-src.sh <LIBRARY_NAME> <ARCHITECTURE> [PATH_TO_MUSL]" 1>&2
+       exit 1
+fi
+
+pushd "$MUSL" > /dev/null || exit
+BASE_SRC=$(find src/$LIB -maxdepth 1 -name '*.c' | sort)
+if [[ -d "src/$LIB/$ARCH" ]]; then
+       ARCH_SRC=$(find src/$LIB/$ARCH -maxdepth 1 -name '*.[csS]' | sort)
+else
+       ARCH_SRC=""
+fi
+popd > /dev/null || exit
+
+BASE_SUB_SRC=$(sed -r "s%/$ARCH/([^ ]*)\\.[csS]%/\\1.c%g" <(echo $ARCH_SRC))
+
+echo "# reset sources proviously added"
+echo "LIBMUSL_${LIB^^}_SRCS-y ="
+echo "# base sources (skips the ones replaced by $ARCH)"
+for src in $BASE_SRC; do
+       if [[ "$BASE_SUB_SRC" =~ $src ]] ; then
+               echo "#LIBMUSL_${LIB^^}_SRCS-y += \$(LIBMUSL)/$src"
+       else
+               echo "LIBMUSL_${LIB^^}_SRCS-y += \$(LIBMUSL)/$src"
+       fi
+done
+
+if [[ "$ARCH_SRC" != "" ]]; then
+       echo "# $ARCH specific sources"
+       for src in $ARCH_SRC; do
+               echo "LIBMUSL_${LIB^^}_SRCS-y += \$(LIBMUSL)/$src|$ARCH"
+       done
+else
+       echo "# no $ARCH specific sources"
+fi
+