-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·120 lines (106 loc) · 2.85 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
OS=$(awk -F'=' '/ID_LIKE/{print $2}' /etc/os-release)
RUN="TRUE"
CHECK_DEPENDENCIES="TRUE"
# Parses the arguments
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "A script for setting up and building the project"
echo "By default it builds and runs the project"
echo " "
echo "Usage: ./build.sh [options]"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-n --no-check tries to build the project without checking dependencies"
echo "-b, --build Build the project without running it"
exit 0
;;
-n|--no-check)
CHECK_DEPENDENCIES="FALSE"
shift
;;
-b|--build)
RUN="FALSE"
shift
;;
*)
break
;;
esac
done
# Downloading Dependencies
if [[ "$CHECK_DEPENDENCIES" == "TRUE" ]]; then
if [ "$OS" = "arch" ]; then
dependencies=("sdl2" "sdl2_image" "sdl2_ttf" "sdl2_mixer" "cmake")
for i in "${dependencies[@]}"; do
if pacman -Qi $i > /dev/null; then
echo "The package $i is installed"
else
echo "The package $i is not installed"
echo "Installing the package $i"
sudo pacman -S $i
fi
done
elif [ "$OS" = '"ubuntu debian"' ] || [ "$OS" = "debian" ]; then
echo "debian"
dependencies=("g++" "libsdl2-dev" "libsdl2-image-dev" "libsdl2-ttf-dev" "libsdl2-mixer-dev")
for i in "${dependencies[@]}"; do
if dpkg -l $i > /dev/null; then
echo "The package $i is installed"
else
echo "The package $i is not installed"
echo "Installing the package $i"
sudo apt-get install $i
fi
done
else
echo "Unrecognized distro"
echo "Install the following dependencies"
echo "dependencies: sdl2, sdl2_image, sdl2_ttf, sdl2_mixer, cmake"
echo "and run:"
echo "$ ./build.sh -n"
echo "Enter: $ ./build.sh --help for more info"
fi
fi
# Running for ubuntu
if [ "$OS" = '"ubuntu debian"' ] || [ "$OS" = "debian" ]; then
g++ src/* -lSDL2 -lGL -lSDL2_image -lSDL2_mixer -lSDL2_ttf -o Chess
# running is the variable is not false
if [[ "$RUN" == "FALSE" ]]; then
echo "Build complete. Executable at $(pwd)"
elif [ -f Chess ]; then
echo "Running program"
./Chess;
else
echo "Something seems to be wrong"
fi
exit 0
fi
# Running cmake
cmake -S . -B build
# if we failed to create build directory
if [ ! -d "build" ]; then
exit 1
fi
# Copying all the assets
if [ ! -d "build/assets" ]; then
cp -r assets build/assets
echo "Copying assets folder"
fi
## Changing to the directory
cd build
echo "Changed directory to: $(pwd)"
# Building
make
# running is the variable is not false
if [[ "$RUN" == "FALSE" ]]; then
echo "Build complete. Executable at $(pwd)"
elif [ -f Chess ]; then
echo "Running program"
./Chess;
else
echo "Something seems to be wrong"
fi
cd ..