63 lines
2.4 KiB
Bash
63 lines
2.4 KiB
Bash
#!/bin/sh
|
|
|
|
# shmake_link.sh - Linked library configuration for shmake
|
|
# Author: Emilia Marigold
|
|
|
|
add_linked_library()
|
|
{
|
|
check_project_root
|
|
|
|
if [ $# -lt 1 ]; then
|
|
printf "Usage: %s link [library_names]\n" "$SCRIPT_NAME"
|
|
printf "Example: %s link X11 pthread m\n" "$SCRIPT_NAME"
|
|
exit 1
|
|
fi
|
|
|
|
LIB_NAMES="$*"
|
|
|
|
LIB_FLAGS=""
|
|
for lib in $LIB_NAMES; do
|
|
if [ -z "$LIB_FLAGS" ]; then
|
|
LIB_FLAGS="-l$lib"
|
|
else
|
|
LIB_FLAGS="$LIB_FLAGS -l$lib"
|
|
fi
|
|
done
|
|
|
|
printf "Adding linked libraries: %s\n" "$LIB_FLAGS"
|
|
|
|
mkdir -p "shmake_config"
|
|
|
|
if [ -f "shmake_config/linked.conf" ]; then
|
|
printf "Note: 'linked.conf' already exists.\n"
|
|
printf "Current linked libraries:\n"
|
|
cat "shmake_config/linked.conf"
|
|
printf "\nAppend? [y/N]: "
|
|
read -r append_choice
|
|
case "$append_choice" in
|
|
y|Y)
|
|
old_libs=$(grep '^LINKED_LIBS' "shmake_config/linked.conf" | sed 's/^LINKED_LIBS = //')
|
|
new_libs="$old_libs $LIB_FLAGS"
|
|
sed -i '/^LINKED_LIBS/d' "shmake_config/linked.conf"
|
|
printf "LINKED_LIBS = %s\n" "$new_libs" >> "shmake_config/linked.conf"
|
|
printf "Linked libraries appended successfully!\n"
|
|
;;
|
|
*)
|
|
sed -i '/^LINKED_LIBS/d' "shmake_config/linked.conf"
|
|
printf "LINKED_LIBS = %s\n" "$LIB_FLAGS" >> "shmake_config/linked.conf"
|
|
printf "Linked libraries overwritten successfully!\n"
|
|
;;
|
|
esac
|
|
else
|
|
cat > "shmake_config/linked.conf" << EOF
|
|
# --- shmake Linked Libraries Configuration ---
|
|
# Format: library names (automatically converted to -l flags)
|
|
# Example: LINKED_LIBS = -lX11 -lpthread -lm
|
|
LINKED_LIBS = $LIB_FLAGS
|
|
EOF
|
|
printf "Linked libraries configured successfully!\n"
|
|
fi
|
|
|
|
printf "\nRun 'shmake sync' to update Makefile with these libraries.\n"
|
|
}
|