WHY2/build.sh

159 lines
3.1 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-04 18:28:15 +02:00
flags="-Wall -ljson-c -lcurl"
2022-05-01 16:20:58 +02:00
if [[ "$1" == "test" ]]; then ########## TEST ##########
###
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
if [[ "$2" == "debug" ]]; then ########## TEST & DEBUG ##########
flags="$flags -g"
echo "Using debug flag"
fi
2022-04-27 18:37:15 +02:00
flags="-lwhy2 $flags"
2022-05-01 16:35:48 +02:00
2022-05-01 16:20:58 +02:00
###
echo "Compiling... (Flags: $flags)"
###
2022-04-27 18:37:15 +02:00
2022-05-01 16:20:58 +02:00
# Compile
2022-05-04 18:17:33 +02:00
$compiler $testFile $flags -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
###
elif [[ "$1" == "install" ]]; then ########## INSTALL ##########
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
2022-05-05 19:04:22 +02:00
2022-05-06 17:55:11 +02:00
if [[ "$2" == "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-02 19:31:38 +02:00
flags="-Wall -fPIC -c"
2022-05-01 16:20:58 +02:00
###
echo "Compiling... (Flags: $flags)"
###
$compiler $flags $sourceFiles
2022-05-02 19:31:38 +02:00
flags="-Wall -shared"
2022-05-01 16:20:58 +02:00
###
echo "Compiling library... (Flags: $flags)"
###
2022-04-27 18:37:15 +02:00
2022-05-01 16:20:58 +02:00
$compiler $flags -o $installOutput *.o
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
2022-05-04 19:04:25 +02:00
###
echo "Compiling why2-app..."
###
./build.sh app
###
echo "Installing why2-app..."
###
mv $appOutput /usr/bin/why2
2022-05-04 19:04:25 +02:00
2022-05-01 16:20:58 +02:00
###
echo "Finished! Cleaning up..."
###
rm -rf *.o
2022-05-04 18:28:15 +02:00
elif [[ "$1" == "app" ]]; then ########## BUILD APP ##########
###
echo "Using '$compiler' as default compiler."
###
# Check for debug flag
if [[ "$2" == "debug" ]]; then ########## TEST & DEBUG ##########
flags="$flags -g"
echo "Using debug flag"
fi
2022-05-04 18:52:19 +02:00
flags="-lwhy2 $flags"
2022-05-04 18:28:15 +02:00
###
echo "Compiling... (Flags: $flags)"
###
# Compile
$compiler $appFile $flags -o $appOutput
# Compilation failed
if [[ $? -ne 0 ]]; then
echo -e "\nCompilation failed."
exit 1
fi
###
echo "Output generated as '$appOutput'"
###
else ########## ELSE ##########
if [[ "$1" == "installTest" ]]; then ########## INSTALL & TEST ##########
./build.sh install
./build.sh test
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