-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
176 lines (150 loc) · 3.87 KB
/
build.sh
File metadata and controls
176 lines (150 loc) · 3.87 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/bash
#
# Build script for SecReg-Linux
#
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Print functions
print_status() {
echo -e "${GREEN}[*]${NC} $1"
}
print_success() {
echo -e "${GREEN}[+]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[!]${NC} $1"
}
print_error() {
echo -e "${RED}[-]${NC} $1"
}
# Configuration
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="${PROJECT_DIR}/build"
INSTALL_PREFIX="/usr/local"
# Parse arguments
CLEAN=0
BUILD_TYPE="RelWithDebInfo"
VERBOSE=0
TESTS=1
PACKAGE=0
while [[ $# -gt 0 ]]; do
case $1 in
-c|--clean)
CLEAN=1
shift
;;
-d|--debug)
BUILD_TYPE="Debug"
shift
;;
-r|--release)
BUILD_TYPE="Release"
shift
;;
-v|--verbose)
VERBOSE=1
shift
;;
-t|--no-tests)
TESTS=0
shift
;;
-p|--package)
PACKAGE=1
shift
;;
-i|--install-prefix)
INSTALL_PREFIX="$2"
shift 2
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -c, --clean Clean build directory"
echo " -d, --debug Build in debug mode"
echo " -r, --release Build in release mode"
echo " -v, --verbose Verbose output"
echo " -t, --no-tests Skip building tests"
echo " -p, --package Create installation package"
echo " -i, --install-prefix Installation prefix (default: /usr/local)"
echo " -h, --help Show this help"
exit 0
;;
*)
print_error "Unknown option: $1"
exit 1
;;
esac
done
# Check dependencies
print_status "Checking dependencies..."
for cmd in cmake g++ make; do
if ! command -v $cmd &> /dev/null; then
print_error "$cmd is required but not installed"
exit 1
fi
done
# Check for required libraries
if ! pkg-config --exists openssl; then
print_warning "OpenSSL development files not found"
print_warning "Install with: apt-get install libssl-dev"
fi
if ! pkg-config --exists sqlite3; then
print_warning "SQLite3 development files not found"
print_warning "Install with: apt-get install libsqlite3-dev"
fi
if ! pkg-config --exists pam; then
print_warning "PAM development files not found"
print_warning "Install with: apt-get install libpam0g-dev"
fi
# Clean if requested
if [[ $CLEAN -eq 1 ]]; then
print_status "Cleaning build directory..."
rm -rf "${BUILD_DIR}"
fi
# Create build directory
mkdir -p "${BUILD_DIR}"
# Configure with CMake
print_status "Configuring with CMake..."
cd "${BUILD_DIR}"
CMAKE_ARGS=(
"-DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
"-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}"
"-DCMAKE_CXX_COMPILER=g++"
)
if [[ $TESTS -eq 0 ]]; then
CMAKE_ARGS+=("-DSECREG_BUILD_TESTS=OFF")
fi
if [[ $VERBOSE -eq 1 ]]; then
CMAKE_ARGS+=("-DCMAKE_VERBOSE_MAKEFILE=ON")
fi
cmake "${PROJECT_DIR}" "${CMAKE_ARGS[@]}"
# Build
print_status "Building..."
if [[ $VERBOSE -eq 1 ]]; then
make -j$(nproc)
else
make -j$(nproc) VERBOSE=0
fi
# Run tests
if [[ $TESTS -eq 1 ]]; then
print_status "Running tests..."
ctest --output-on-failure || print_warning "Some tests failed"
fi
# Create package
if [[ $PACKAGE -eq 1 ]]; then
print_status "Creating package..."
make package
print_success "Package created: ${BUILD_DIR}/secreg-*.tar.gz"
fi
print_success "Build complete!"
print_status "Build directory: ${BUILD_DIR}"
# Installation instructions
print_status "To install, run:"
echo " cd ${BUILD_DIR}"
echo " sudo make install"