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
|
|
|
####################
|
|
|
|
|
2022-04-29 17:16:32 +02:00
|
|
|
# Remove previous output
|
2022-04-27 18:37:15 +02:00
|
|
|
rm -rf out/*
|
2022-04-22 18:35:27 +02:00
|
|
|
|
2022-04-27 18:37:15 +02:00
|
|
|
# Variables
|
2022-05-01 16:20:58 +02:00
|
|
|
testFile="src/test/main.c"
|
|
|
|
sourceFiles="src/*.c"
|
|
|
|
includeFiles="include/*.h"
|
2022-03-20 18:12:25 +01:00
|
|
|
|
2022-04-27 18:37:15 +02:00
|
|
|
compiler="cc"
|
|
|
|
output="out/why2"
|
2022-05-01 16:20:58 +02:00
|
|
|
installOutput="libwhy2.so"
|
2022-04-30 16:51:49 +02:00
|
|
|
flags="-Wall -ljson-c -lcurl"
|
2022-05-01 16:20:58 +02:00
|
|
|
includeDirectory="/usr/include/why2"
|
2022-04-27 18:37:15 +02:00
|
|
|
|
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
|
|
|
|
2022-05-03 17:10:22 +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-01 16:35:48 +02:00
|
|
|
$compiler $testFile $flags -o $output
|
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
|
|
|
|
|
|
|
|
###
|
|
|
|
echo "Output generated as '$output'"
|
|
|
|
###
|
|
|
|
elif [[ "$1" == "install" ]]; then ########## INSTALL ##########
|
2022-05-02 19:19:43 +02:00
|
|
|
if [[ "$2" != "lib" ]]; then
|
|
|
|
###
|
|
|
|
echo "Installing header files..."
|
|
|
|
###
|
2022-05-01 16:29:53 +02:00
|
|
|
|
2022-05-02 19:19:43 +02:00
|
|
|
# Create why2 directory
|
|
|
|
if [[ ! -d $includeDirectory ]]; then
|
|
|
|
mkdir $includeDirectory
|
|
|
|
fi
|
2022-05-01 16:35:48 +02:00
|
|
|
|
2022-05-02 19:19:43 +02:00
|
|
|
cp $includeFiles $includeDirectory
|
|
|
|
fi
|
2022-05-01 16:29:53 +02:00
|
|
|
|
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-04-27 18:47:33 +02:00
|
|
|
|
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-03 17:19:19 +02:00
|
|
|
if [[ "$2" != "lib" ]]; then
|
|
|
|
###
|
|
|
|
echo "Installing library..."
|
|
|
|
###
|
2022-05-01 16:20:58 +02:00
|
|
|
|
2022-05-03 17:19:19 +02:00
|
|
|
mv $installOutput /usr/lib/
|
2022-05-01 16:20:58 +02:00
|
|
|
|
2022-05-03 17:19:19 +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
|
|
|
|
fi
|
2022-05-01 16:20:58 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
###
|
|
|
|
echo "Finished! Cleaning up..."
|
|
|
|
###
|
|
|
|
|
|
|
|
rm -rf *.o
|
2022-05-02 18:05:12 +02:00
|
|
|
else ########## ELSE ##########
|
|
|
|
if [[ "$1" == "installTest" ]]; then ########## INSTALL & TEST ##########
|
|
|
|
./build.sh install
|
|
|
|
./build.sh test
|
|
|
|
else ########## ERR ##########
|
|
|
|
###
|
|
|
|
echo "You have to enter 'test' or 'install' as arguments."
|
|
|
|
###
|
2022-05-01 16:20:58 +02:00
|
|
|
|
2022-05-02 18:05:12 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2022-05-01 16:20:58 +02:00
|
|
|
fi
|