I am trying to set up a simple script to compile my project that takes the name of the module(s) to compile, or if no arguments, compile them all.
None of the other answers on StackOverflow have worked for me.
When I try the below script I get this error:
$ ./build.sh updater
Creating the build path: build/0.1.4-master
./build.sh: line 21: updater: command not found
I don't like the ambiguity of the language, it could be a function or a command. But it is what it is. How can I make it execute the function and not try to run a command called updater
?
#! /bin/sh -e
# release="0.0.0-$(git rev-parse --abbrev-ref HEAD)"
release="$(git describe --tags --abbrev=0)-$(git rev-parse --abbrev-ref HEAD)"
echo "Creating the build path: build/$release"
mkdir -p "build/$release"
while [ "$#" -gt 0 ]; do
param="$1"
case $param in
s|setup)
setup
shift
;;
l|launcher)
launcher
shift
;;
u|updater)
updater
shift
;;
d|deflector)
deflector
shift
;;
# *)
# setup
# launcher
# updater
# deflector
# shift
# ;;
esac
done
function setup {
echo "Compiling executable: build/$release/setup.exe"
ldc2 "source/setup.d" "source/common.d" -of="build/$release/setup.exe" \
-O3 -ffast-math -release -g
echo "Adding icon to executable: build/$release/setup.exe"
[ -e "build/$release/setup.exe" ] && \
rcedit "build/$release/setup.exe" --set-icon "icons/icon.ico"
}
function launcher {
echo "Compiling executable: build/$release/launcher.exe"
ldc2 "source/launcher.d" "source/common.d" -of="build/$release/launcher.exe" \
-O3 -ffast-math -release -g
echo "Adding icon to executable: build/$release/launcher.exe"
[ -e "build/$release/launcher.exe" ] && \
rcedit "build/$release/launcher.exe" --set-icon "icons/icon.ico"
}
function updater {
echo "Compiling executable: build/$release/updater.exe"
ldc2 "source/updater.d" "source/common.d" -of="build/$release/updater.exe" \
-O3 -ffast-math -release -g
}
function deflector {
echo "Compiling executable: build/$release/deflector.exe"
ldc2 "source/deflector.d" "source/common.d" -of="build/$release/deflector.exe" \
-O3 -ffast-math -release -g
}
echo "Removing residual object files."
find "build/$release" -name "*.obj" -delete
echo "Copying engines file: build/$release/engines.txt"
cp "engines.txt" "build/$release"
echo "Copying libcurl library: build/$release/libcurl.dll"
cp $(which libcurl.dll) "build/$release"
I would also like help making a default case for when there are no arguments passed to the script. My attempt can be seen in the commented block in the switch case.
Appreciate any help.