-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·153 lines (125 loc) · 4.52 KB
/
setup.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# ANSI color codes for error and warning
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
SUCCEED="${GREEN}[Succeed]${NC} "
WARNING="${YELLOW}[Warning]${NC} "
ERROR="${RED}[ Error ]${NC} "
INFO="${BLUE}[ Info. ]${NC} "
INQUIRE="${MAGENTA}[Inquire]${NC} "
PROGRES="${CYAN}[Progres]${NC} "
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo -e "${INFO} To set specific compiler and/or Eigen dependency:"
echo -e "${INFO} ./setup.sh [COMPILER] [/PATH/TO/EIGEN]"
exit 0
fi
echo -e "${INFO} Setting up build directory, C++ compiler, and Eigen path."
make_build=$(mkdir build 2>&1)
if [[ $? -eq 0 ]]; then
echo -e "${SUCCEED} 'build' directioy has been created"
else
echo -e "${WARNING} Something wrong: --> ${YELLOW}${make_build}${NC}"
# echo -e "--"
# read -p "Press enter to continue."
fi
# Generate config.mk
echo "# Configuration file for compiler and Eigen." > config.mk
# Check if the user has provided a compiler as an argument
if [ ! -z "$1" ]; then
CC="$1"
else
# Check for available compilers
if command_exists g++; then
CC="g++"
elif command_exists clang++; then
CC="clang++"
else
echo -e "${ERROR} Neither g++ nor clang++ found! Please install a C++ compiler or specify one."
exit 1
fi
fi
# Check if the selected compiler (CC) is linked to clang
if $CC --version 2>/dev/null | grep -q "clang"; then
echo -e "${WARNING} Only clang++ is found or g++ is linked to clang++."
echo -e "${INFO} Program compiled via clang++ is marginally slower than the on via g++."
echo -e "${INQUIRE} Do you want to manually specify a different compiler? [y/N]: "
read -r USER_INPUT
if [[ "$USER_INPUT" =~ ^[Yy]$ ]]; then
echo -e "${INQUIRE} Please enter the compiler command you want to use (e.g., g++-14, g++-12, cc): "
read -r USER_CC
CC="$USER_CC"
fi
fi
echo -e "${SUCCEED} Selected compiler: $CC"
echo "# compiler" >> config.mk
echo "CC := $CC" >> config.mk
# Define Eigen path
# Check user definitation
if [ ! -z "$2" ]; then
EIGEN_DIR="$2"
else
# No user defined Eigen path
if [ $(uname -s) == "Darwin" ]; then
if [ -d "/usr/include/eigen3/" ]; then
EIGEN_DIR="/usr/include/eigen3/"
else
# No Eigen at default path Trying to ask homebrew
EIGEN_DIR=$(brew --prefix eigen 2>&1)/include/eigen3
if [[ $? -eq 0 ]]; then
echo -e "${SUCCEED} Found Eigen: $EIGEN_DIR"
else
echo -e "${WARNING} homebrew$EIGEN_DIR"
fi
fi
else
EIGEN_DIR="/usr/include/eigen3/"
fi
fi
if [ -d "$EIGEN_DIR" ]; then
# Found Eigen
echo -e "${SUCCEED} Eigen: $EIGEN_DIR"
echo "# Eigen" >> config.mk
echo "EIGEN_FOUND = 1" >> config.mk
echo "EIGEN_DIR = $EIGEN_DIR" >> config.mk
else
echo -e "${WARNING} No Eigen library found, Eigen implementation will be disabled, carrying on."
echo -e "${INFO} You can manually specify a Eigen path by run ./setup.h compiler /path/to/Eigen/"
echo -e " e.g. ./setup.h g++-14 /usr/include/eigen3"
echo "# Eigen" >> config.mk
echo "EIGEN_FOUND = 0" >> config.mk
echo "EIGEN_DIR = $EIGEN_DIR" >> config.mk # Should not be used
fi
if [ -d "./MATLAB/PopIn" ]; then
# Found Eigen
echo -e "${SUCCEED} You have PopIn in the ./MATLAB folder"
else
echo -e "${INQUIRE} No PopIn in the ./MATLAB folder, do you want to download now? [y/N]: "
read -r USER_INPUT
if [[ "$USER_INPUT" =~ ^[Yy]$ ]]; then
echo -e "${INFO} Downloading and unzipping........."
if command_exists curl; then
curl -sS -L -o PopIn.zip https://github.com/DavidMercier/PopIn/archive/refs/heads/master.zip
elif command_exists clang++; then
wget -q -O PopIn.zip https://github.com/DavidMercier/PopIn/archive/refs/heads/master.zip
else
echo -e "${ERROR} curl nor wget command is found. Cannot download PopIn. Carrying on."
fi
if [ -f "PopIn.zip" ]; then
unzip -qq PopIn.zip -d ./MATLAB/
mv ./MATLAB/PopIn-master ./MATLAB/PopIn
rm PopIn.zip
echo -e "${SUCCEED} PopIn downloaded to the ./MATLAB folder"
fi
fi
fi
echo -e "${SUCCEED} Setup complete! You can now run 'make all' to build the project."
echo -e "${INFO} Then use './runtest.sh' to run test."