-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·55 lines (44 loc) · 1.66 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
#!/bin/bash
# Logging function
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}
# Error handling function
handle_error() {
log "ERROR: $1"
log "Build failed. Exiting."
exit 1
}
# Check if Go is installed
if ! command -v go &> /dev/null; then
handle_error "Go command not found. Please install Go and try again."
fi
# Create build directory
BUILD_DIR="./build"
log "Starting Pancake build..."
# Check if build directory exists and delete it
if [ -d "$BUILD_DIR" ]; then
log "Build directory exists. Deleting $BUILD_DIR..."
rm -rf "$BUILD_DIR" || handle_error "Failed to delete existing build directory."
fi
log "Creating build directory: $BUILD_DIR"
mkdir -p "$BUILD_DIR" || handle_error "Failed to create build directory."
# Build for Linux
log "Building for Linux (amd64)..."
GOOS=linux GOARCH=amd64 go build -o "$BUILD_DIR/pancake-linux-amd64" || handle_error "Failed to build for Linux."
# Build for macOS
log "Building for macOS (amd64)..."
GOOS=darwin GOARCH=amd64 go build -o "$BUILD_DIR/pancake-darwin-amd64" || handle_error "Failed to build for macOS."
# Build for Windows
log "Building for Windows (amd64)..."
GOOS=windows GOARCH=amd64 go build -o "$BUILD_DIR/pancake-windows-amd64.exe" || handle_error "Failed to build for Windows."
# Copy readme.txt to build directory
README_FILE="./readme.txt"
log "Copying $README_FILE to $BUILD_DIR..."
if [ -f "$README_FILE" ]; then
cp "$README_FILE" "$BUILD_DIR/" || handle_error "Failed to copy $README_FILE."
else
handle_error "$README_FILE not found. Please ensure it exists in the adjacent folder."
fi
# Log success
log "Build completed successfully. Binaries and readme.txt are in $BUILD_DIR."