WHY2/build.sh

179 lines
3.4 KiB
Bash
Raw Normal View History

2022-04-22 18:36:35 +02:00
#!/bin/bash
2022-03-20 18:12:25 +01:00
2022-04-27 18:37:15 +02:00
####################
# Remove previous output
2022-04-27 18:37:15 +02:00
rm -rf out/*
2022-04-27 18:37:15 +02:00
# Variables
2022-05-04 18:17:33 +02:00
testFile="src/lib/test/main.c"
sourceFiles="src/lib/*.c"
2022-05-01 16:20:58 +02:00
includeFiles="include/*.h"
2022-03-20 18:12:25 +01:00
2022-05-04 18:28:15 +02:00
appFile="src/app/main.c"
2022-04-27 18:37:15 +02:00
compiler="cc"
2022-05-04 18:28:15 +02:00
2022-05-04 18:17:33 +02:00
testOutput="out/why2-test"
2022-05-04 18:28:15 +02:00
appOutput="out/why2-app"
2022-05-01 16:20:58 +02:00
installOutput="libwhy2.so"
includeDirectory="/usr/include/why2"
2022-04-27 18:37:15 +02:00
2022-05-18 19:02:41 +02:00
defaultFlags="-Wall"
bufferFlags="$defaultFlags"
2022-05-04 18:28:15 +02:00
2022-05-12 18:00:53 +02:00
runTest()
{
2022-05-01 16:20:58 +02:00
###
echo "Using '$compiler' as default compiler."
###
2022-04-27 18:37:15 +02:00
2022-05-01 16:20:58 +02:00
# Check for debug flag
2022-05-12 18:00:53 +02:00
if [[ "$1" == "debug" ]]; then ########## TEST & DEBUG ##########
2022-05-18 19:02:41 +02:00
bufferFlags="$defaultFlags -g"
2022-05-01 16:20:58 +02:00
echo "Using debug flag"
fi
2022-04-27 18:37:15 +02:00
2022-05-18 19:02:41 +02:00
bufferFlags="-lwhy2 $bufferFlags"
2022-05-01 16:35:48 +02:00
2022-05-01 16:20:58 +02:00
###
2022-05-18 19:02:41 +02:00
echo "Compiling... (flags: $bufferFlags)"
2022-05-01 16:20:58 +02:00
###
2022-04-27 18:37:15 +02:00
2022-05-01 16:20:58 +02:00
# Compile
2022-05-18 19:02:41 +02:00
$compiler $testFile $bufferFlags -o $testOutput
2022-05-01 16:20:58 +02:00
# Compilation failed
if [[ $? -ne 0 ]]; then
echo -e "\nCompilation failed. Did you run 'configure.sh' and 'build.sh install' first?"
exit 1
fi
###
2022-05-04 18:17:33 +02:00
echo "Output generated as '$testOutput'"
2022-05-01 16:20:58 +02:00
###
}
2022-05-12 18:00:53 +02:00
runInstall()
{
2022-05-06 17:55:11 +02:00
###
echo "Installing header files..."
###
2022-05-06 17:55:11 +02:00
# Create why2 directory
if [[ ! -d $includeDirectory ]]; then
mkdir $includeDirectory
fi
2022-05-01 16:35:48 +02:00
2022-05-06 17:55:11 +02:00
cp $includeFiles $includeDirectory
ln -sf $includeDirectory/why2.h /usr/include/why2.h
2022-05-05 19:04:22 +02:00
2022-05-12 18:00:53 +02:00
if [[ "$1" == "include" ]]; then
2022-05-05 19:04:22 +02:00
exit
2022-05-02 19:19:43 +02:00
fi
2022-05-01 16:20:58 +02:00
###
echo "Using '$compiler' as default compiler."
###
2022-05-18 19:02:41 +02:00
bufferFlags="-fPIC -c $defaultFlags"
2022-05-01 16:20:58 +02:00
###
2022-05-18 19:02:41 +02:00
echo "Compiling... (flags: $bufferFlags)"
2022-05-01 16:20:58 +02:00
###
2022-05-18 19:02:41 +02:00
$compiler $bufferFlags $sourceFiles
2022-05-01 16:20:58 +02:00
bufferFlags="$defaultFlags -shared -ljson-c -lcurl"
2022-05-01 16:20:58 +02:00
###
2022-05-18 19:02:41 +02:00
echo "Compiling library... (flags: $bufferFlags)"
2022-05-01 16:20:58 +02:00
###
2022-04-27 18:37:15 +02:00
$compiler -o $installOutput *.o $bufferFlags
2022-04-27 18:37:15 +02:00
2022-05-05 19:04:22 +02:00
###
echo "Installing library..."
###
2022-05-01 16:20:58 +02:00
2022-05-05 19:04:22 +02:00
mv $installOutput /usr/lib/
2022-05-01 16:20:58 +02:00
2022-05-05 19:04:22 +02:00
# Compilation failed
if [[ $? -ne 0 ]]; then
echo -e "\nCompilation failed. Did you run 'configure.sh' first and 'build.sh' with sudo?"
exit 1
2022-05-01 16:20:58 +02:00
fi
###
echo "Finished! Cleaning up..."
###
rm -rf *.o
}
2022-05-12 18:00:53 +02:00
runApp()
{
2022-05-13 18:46:30 +02:00
###
echo "Compiling why2-app..."
###
2022-05-04 18:28:15 +02:00
###
echo "Using '$compiler' as default compiler."
###
# Check for debug flag
2022-05-12 18:00:53 +02:00
if [[ "$1" == "debug" ]]; then ########## TEST & DEBUG ##########
2022-05-18 19:02:41 +02:00
bufferFlags="$defaultFlags -g"
2022-05-04 18:28:15 +02:00
echo "Using debug flag"
fi
2022-05-19 17:56:16 +02:00
bufferFlags="-lwhy2 $bufferFlags"
2022-05-04 18:52:19 +02:00
2022-05-04 18:28:15 +02:00
###
2022-05-18 19:02:41 +02:00
echo "Compiling... (flags: $bufferFlags)"
2022-05-04 18:28:15 +02:00
###
# Compile
2022-05-18 19:02:41 +02:00
$compiler $appFile $bufferFlags -o $appOutput
2022-05-04 18:28:15 +02:00
# Compilation failed
if [[ $? -ne 0 ]]; then
echo -e "\nCompilation failed."
exit 1
fi
###
echo "Output generated as '$appOutput'"
###
2022-05-13 18:46:30 +02:00
###
echo "Installing why2-app..."
###
mv $appOutput /usr/bin/why2
###
echo "Finished!"
###
}
if [[ "$1" == "test" ]]; then ########## TEST ##########
2022-05-12 18:00:53 +02:00
runTest "$2"
elif [[ "$1" == "install" ]]; then ########## INSTALL ##########
2022-05-12 18:00:53 +02:00
runInstall "$2"
elif [[ "$1" == "app" ]]; then ########## BUILD APP ##########
2022-05-12 18:00:53 +02:00
runApp "$2"
else ########## ELSE ##########
if [[ "$1" == "installTest" ]]; then ########## INSTALL & TEST ##########
2022-05-13 18:46:30 +02:00
exit 69
runInstall
runTest
else ########## ERR ##########
###
2022-05-04 18:28:15 +02:00
echo "You have to enter 'install', 'test' or 'app' as arguments. (Or 'installTest' for install & test)"
###
2022-05-01 16:20:58 +02:00
exit 1
fi
2022-05-01 16:20:58 +02:00
fi