-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathbuild_linux.sh
164 lines (144 loc) · 5.62 KB
/
build_linux.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
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# Function to display help information and usage instructions
Help()
{
# Display Help
echo
echo "Usages:"
echo
echo "Syntax: build_linux.sh --tier=[standard|free] --arch=[cpu|gpu] --test=[on|off]"
echo "options:"
echo " --help Show the usages of the parameters"
echo " --tier Build tier, choose 'standard' or 'free'. Default is 'standard'"
echo " --arch Build architecture, choose 'cpu' or 'gpu'. Default is 'cpu'"
echo " --test Enable or disable unit test, choose 'on' or 'off'. Default is 'on'"
echo
}
# Default configuration values
TIER="standard" # Build tier (standard/free)
ARCH="cpu" # Build architecture (cpu/gpu)
TEST="on" # Unit test flag (on/off)
# Parse command line arguments
# Supports --help, --tier, --arch, and --test parameters
for i in "$@"; do
case $i in
--help*)
Help
exit;;
--tier=*)
TIER="${i#*=}"
shift # past argument
;;
--arch=*)
ARCH="${i#*=}"
shift # past argument
;;
--test=*)
TEST="${i#*=}"
shift # past argument
;;
--*)
echo "Unknown option $1"
exit 1
;;
*)
;;
esac
done
# Validate the tier parameter
if [ "${TIER,,}" != "standard" ] && [ "${TIER,,}" != "free" ]; then
echo "ERROR: Invalid --tier parameters, please choose 'free' or 'standard'"
exit 1
fi
# Validate the architecture parameter
if [ "${ARCH,,}" != "cpu" ] && [ "${ARCH,,}" != "gpu" ]; then
echo "ERROR: Invalid --arch parameters, please choose 'cpu' or 'gpu'"
exit 1
fi
# Validate the test parameter
if [ "${TEST,,}" != "on" ] && [ "${TEST,,}" != "off" ]; then
echo "ERROR: Invalid --test parameters, please choose 'on' or 'off'"
exit 1
fi
# Display project banner and copyright information
echo "Automatic build script of radarsimcpp/radarsimpy for Linux"
echo ""
echo "----------"
echo "RadarSimPy - A Radar Simulator Built with Python"
echo "Copyright (C) 2018 - PRESENT radarsimx.com"
echo "E-mail: [email protected]"
echo "Website: https://radarsimx.com"
echo ""
echo "██████╗ █████╗ ██████╗ █████╗ ██████╗ ███████╗██╗███╗ ███╗██╗ ██╗"
echo "██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔════╝██║████╗ ████║╚██╗██╔╝"
echo "██████╔╝███████║██║ ██║███████║██████╔╝███████╗██║██╔████╔██║ ╚███╔╝ "
echo "██╔══██╗██╔══██║██║ ██║██╔══██║██╔══██╗╚════██║██║██║╚██╔╝██║ ██╔██╗ "
echo "██║ ██║██║ ██║██████╔╝██║ ██║██║ ██║███████║██║██║ ╚═╝ ██║██╔╝ ██╗"
echo "╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝"
# Store current working directory
workpath=$(pwd)
# Clean up previous build artifacts
echo "## Clean old build files ##"
rm -rf ./src/radarsimcpp/build
rm -rf ./radarsimpy
# Build libradarsimcpp.so
echo "## Building libradarsimcpp.so with ${ARCH^^} ##"
mkdir ./src/radarsimcpp/build
cd ./src/radarsimcpp/build
# Configure CMake based on architecture and test settings
if [ "${ARCH,,}" == "gpu" ]; then
if [ "${TEST,,}" == "on" ]; then
# GPU build with tests enabled
cmake -DCMAKE_BUILD_TYPE=Release -DGPU_BUILD=ON -DGTEST=ON ..
elif [ "${TEST,,}" == "off" ]; then
# GPU build without tests
cmake -DCMAKE_BUILD_TYPE=Release -DGPU_BUILD=ON -DGTEST=OFF ..
fi
elif [ "${ARCH,,}" == "cpu" ]; then
if [ "${TEST,,}" == "on" ]; then
# CPU build with tests enabled
cmake -DCMAKE_BUILD_TYPE=Release -DGTEST=ON ..
elif [ "${TEST,,}" == "off" ]; then
# CPU build without tests
cmake -DCMAKE_BUILD_TYPE=Release -DGTEST=OFF ..
fi
fi
# Build the project using CMake
cmake --build .
# Build Python extensions using Cython
echo "## Building radarsimpy with Cython ##"
cd $workpath
python setup.py build_ext -b ./ --tier "${TIER}" --arch "${ARCH}"
# Copy library files to radarsimpy directory
echo "## Copying lib files to ./radarsimpy ##"
cp ./src/radarsimpy/*.py ./radarsimpy
cp ./src/radarsimpy/lib/__init__.py ./radarsimpy/lib
cp ./src/radarsimcpp/build/*.so ./radarsimpy
# Clean up intermediate build files
echo "## Cleaning radarsimpy builds ##"
rm -rf build
# Remove generated C/C++ source files and HTML documentation
rm -f ./src/radarsimpy/*.c
rm -f ./src/radarsimpy/*.cpp
rm -f ./src/radarsimpy/*.html
rm -f ./src/radarsimpy/raytracing/*.c
rm -f ./src/radarsimpy/raytracing/*.cpp
rm -f ./src/radarsimpy/raytracing/*.html
rm -f ./src/radarsimpy/lib/*.cpp
rm -f ./src/radarsimpy/lib/*.html
rm -f ./src/*.cpp
rm -f ./src/*.html
echo "## Build completed ##"
return_code=0
# Run tests if enabled
if [ "${TEST,,}" == "on" ]; then
# Run C++ unit tests using Google Test
echo "## Run Google test ##"
./src/radarsimcpp/build/radarsimcpp_test
return_code=$(($return_code + $?))
# Run Python unit tests using pytest
echo "## Pytest ##"
pytest
return_code=$(($return_code + $?))
fi
exit $return_code