WHY2/build.sh

110 lines
2.2 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-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
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-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: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-01 16:20:58 +02:00
###
echo "Installing library..."
2022-05-01 16:20:58 +02:00
###
mv $installOutput /usr/lib/
# Compilation failed
if [[ $? -ne 0 ]]; then
2022-05-01 16:37:51 +02:00
echo -e "\nCompilation failed. Did you run 'configure.sh' first and 'build.sh' with sudo?"
2022-05-01 16:20:58 +02:00
exit 1
fi
###
echo "Finished! Cleaning up..."
###
rm -rf *.o
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
exit 1
fi
2022-05-01 16:20:58 +02:00
fi