-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·147 lines (125 loc) · 3.21 KB
/
build.sh
File metadata and controls
executable file
·147 lines (125 loc) · 3.21 KB
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
#!/bin/bash
# ColorSmith Build Script
# This script provides an easy way to build the application
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Default values
BUILD_TYPE="Release"
BUILD_DIR="build"
INSTALL_PREFIX="/usr/local"
CLEAN_BUILD=false
RUN_AFTER_BUILD=false
# Print usage
print_usage() {
cat << EOF
ColorSmith Build Script
Usage: $0 [options]
Options:
-h, --help Show this help message
-d, --debug Build in Debug mode (default: Release)
-c, --clean Clean build directory before building
-r, --run Run the application after building
-p, --prefix PATH Installation prefix (default: /usr/local)
-b, --build-dir DIR Build directory (default: build)
-i, --install Install after building
-t, --test Build and run tests
Examples:
$0 # Build in Release mode
$0 -d -r # Build in Debug mode and run
$0 -c -i # Clean build and install
$0 --prefix=/usr # Build with /usr prefix
EOF
}
# Parse arguments
INSTALL=false
RUN_TESTS=false
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
print_usage
exit 0
;;
-d|--debug)
BUILD_TYPE="Debug"
shift
;;
-c|--clean)
CLEAN_BUILD=true
shift
;;
-r|--run)
RUN_AFTER_BUILD=true
shift
;;
-p|--prefix)
INSTALL_PREFIX="$2"
shift 2
;;
-b|--build-dir)
BUILD_DIR="$2"
shift 2
;;
-i|--install)
INSTALL=true
shift
;;
-t|--test)
RUN_TESTS=true
shift
;;
*)
echo -e "${RED}Error: Unknown option $1${NC}"
print_usage
exit 1
;;
esac
done
# Print configuration
echo -e "${GREEN}=== ColorSmith Build Configuration ===${NC}"
echo "Build Type: $BUILD_TYPE"
echo "Build Directory: $BUILD_DIR"
echo "Install Prefix: $INSTALL_PREFIX"
echo "Clean Build: $CLEAN_BUILD"
echo "Run Tests: $RUN_TESTS"
echo ""
# Clean if requested
if [ "$CLEAN_BUILD" = true ]; then
echo -e "${YELLOW}Cleaning build directory...${NC}"
rm -rf "$BUILD_DIR"
fi
# Create build directory
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
# Configure
echo -e "${GREEN}Configuring with CMake...${NC}"
CMAKE_ARGS=(
-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
-DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX"4
)
if [ "$RUN_TESTS" = true ]; then
CMAKE_ARGS+=(-DBUILD_TESTING=ON)
fi
cmake "${CMAKE_ARGS[@]}" ..
# Build
echo -e "${GREEN}Building...${NC}"
make -j$(nproc)
# Run tests if requested
if [ "$RUN_TESTS" = true ]; then
echo -e "${GREEN}Running tests...${NC}"
ctest --output-on-failure
fi
# Install if requested
if [ "$INSTALL" = true ]; then
echo -e "${GREEN}Installing...${NC}"
sudo make install
fi
echo -e "${GREEN}Build completed successfully!${NC}"
# Run if requested
if [ "$RUN_AFTER_BUILD" = true ]; then
echo -e "${GREEN}Running ColorSmith...${NC}"
./colorsmith
fi