mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2025-01-12 14:58:06 +03:00
compile.sh - Rewritten and added small features
Ability to compile single or multiple files and checking compiler version. For more information and examples See https://forums.alliedmods.net/showthread.php?t=325181
This commit is contained in:
parent
ed1ab00faf
commit
8fb9543fd6
@ -7,18 +7,125 @@
|
|||||||
#
|
#
|
||||||
# This file is part of AMX Mod X.
|
# This file is part of AMX Mod X.
|
||||||
|
|
||||||
# new code contributed by \malex\
|
#####################
|
||||||
|
# GENERAL FUNCTIONS #
|
||||||
|
#####################
|
||||||
|
|
||||||
test -e compiled || mkdir compiled
|
# Quit script
|
||||||
rm -f temp.txt
|
quit_script () {
|
||||||
|
if (( $# != 0 )); then
|
||||||
|
echo "$@"; fi
|
||||||
|
|
||||||
|
echo "Exiting..."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
for sourcefile in *.sma
|
# Checks if folder exists
|
||||||
do
|
exists () {
|
||||||
amxxfile="`echo $sourcefile | sed -e 's/\.sma$/.amxx/'`"
|
test -e $1
|
||||||
echo -n "Compiling $sourcefile ..."
|
}
|
||||||
./amxxpc $sourcefile -ocompiled/$amxxfile >> temp.txt
|
|
||||||
echo "done"
|
|
||||||
done
|
|
||||||
|
|
||||||
less temp.txt
|
#####################
|
||||||
rm temp.txt
|
# ARGUMENT CHECKING #
|
||||||
|
#####################
|
||||||
|
|
||||||
|
# Checks if exists any argument
|
||||||
|
check_for_arguments () {
|
||||||
|
if [ $# != 0 ]; then
|
||||||
|
return 0; # Argument exist
|
||||||
|
else return 1; fi # Argument doesn't exist
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if argument is a command
|
||||||
|
check_for_commands () {
|
||||||
|
if [[ $1 == -* && $1 != *.* ]]; then
|
||||||
|
return 0; # Argument is command
|
||||||
|
else return 1; fi # Argument is file
|
||||||
|
}
|
||||||
|
|
||||||
|
#####################
|
||||||
|
# COMMAND FUNCTIONS #
|
||||||
|
#####################
|
||||||
|
|
||||||
|
# HELP
|
||||||
|
__help () {
|
||||||
|
echo " Usage:"
|
||||||
|
echo "--help (-h) : This menu"
|
||||||
|
echo -e "--version (-v) : AMX MOD X Compiler version\n"
|
||||||
|
echo "To compile all source files in the directory"
|
||||||
|
echo " execute the script without any parameters"
|
||||||
|
echo "To compile specific or multiple source files"
|
||||||
|
echo " execute the script with parameters set as source files' name"
|
||||||
|
echo " e.g ./compile.sh admin.sma admincmd.sma adminchat.sma"
|
||||||
|
}
|
||||||
|
|
||||||
|
# VERSION
|
||||||
|
__version () {
|
||||||
|
if exists amxxpc; then
|
||||||
|
./amxxpc -q | head -n 3
|
||||||
|
else quit_script "amxxpc does not exists"; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Execute command
|
||||||
|
execute_command () {
|
||||||
|
case "$1" in
|
||||||
|
"--help" | "-h" ) __help ;;
|
||||||
|
"--version" | "-v" ) __version ;;
|
||||||
|
*)
|
||||||
|
echo " $1 is not a valid command"
|
||||||
|
echo " Type \"$0 --help\" to see more information"
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
#####################
|
||||||
|
# COMPILE SOURCE #
|
||||||
|
#####################
|
||||||
|
|
||||||
|
# Compile source file
|
||||||
|
compile_source_file () {
|
||||||
|
amxxfile="`echo $1 | sed -e 's/\.sma$/.amxx/'`"
|
||||||
|
echo -n "Compiling $1 ..."
|
||||||
|
./amxxpc $1 -ocompiled/$amxxfile >> temp.txt
|
||||||
|
echo "done"
|
||||||
|
}
|
||||||
|
|
||||||
|
#####################
|
||||||
|
# MAIN FUNCTION #
|
||||||
|
#####################
|
||||||
|
|
||||||
|
# Main function
|
||||||
|
main () {
|
||||||
|
if check_for_arguments "$@"; then
|
||||||
|
for arg in "$@"; do
|
||||||
|
if check_for_commands $arg; then
|
||||||
|
execute_command $arg
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
test -e amxxpc || quit_script "amxxpc does not exists"
|
||||||
|
if [[ $arg == *.sma ]]; then
|
||||||
|
test -e temp.txt && rm -f temp.txt
|
||||||
|
test -e compiled || mkdir compiled
|
||||||
|
compile_source_file $arg
|
||||||
|
less temp.txt && rm temp.txt
|
||||||
|
else
|
||||||
|
echo " $arg not a valid file"
|
||||||
|
echo " Type \"$0 --help\" to see more information"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
test -e compiled || mkdir compiled
|
||||||
|
test -e amxxpc || quit_script "amxxpc does not exists"
|
||||||
|
test -e temp.txt && rm -f temp.txt
|
||||||
|
for sourcefile in *.sma; do
|
||||||
|
compile_source_file $sourcefile
|
||||||
|
done
|
||||||
|
less temp.txt && rm temp.txt
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#####################
|
||||||
|
# EXECUTE MAIN FUNC #
|
||||||
|
#####################
|
||||||
|
main "$@"
|
||||||
|
#####################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user