-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
86 lines (67 loc) · 2.26 KB
/
build.sh
File metadata and controls
86 lines (67 loc) · 2.26 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
#!/bin/bash
# Syshash C Implementation Build Script
# Requires: mingw64 with gcc and nasm
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
OUTPUT_NAME="syshash"
SOURCE_FILE="main.c"
BUILD_DIR="build"
echo -e "${BLUE}=== Syshash C Implementation Build Script ===${NC}"
echo -e "${BLUE}Building for Windows x64 using mingw64...${NC}"
# Check if we have the required tools
echo -e "${YELLOW}Checking for required tools...${NC}"
if ! command -v gcc &> /dev/null; then
echo -e "${RED}ERROR: gcc not found. Please install mingw64.${NC}"
exit 1
fi
if ! command -v nasm &> /dev/null; then
echo -e "${RED}ERROR: nasm not found. Please install nasm.${NC}"
exit 1
fi
echo -e "${GREEN}✓ gcc found: $(gcc --version | head -n1)${NC}"
echo -e "${GREEN}✓ nasm found: $(nasm --version)${NC}"
# Create build directory
echo -e "${YELLOW}Creating build directory...${NC}"
mkdir -p "$BUILD_DIR"
# Check if source file exists
if [ ! -f "$SOURCE_FILE" ]; then
echo -e "${RED}ERROR: Source file '$SOURCE_FILE' not found!${NC}"
exit 1
fi
echo -e "${GREEN}✓ Source file found: $SOURCE_FILE${NC}"
# Compiler flags
CFLAGS="-std=c11 -Wall -Wextra -O2 -m64"
LDFLAGS="-lkernel32 -lntdll -ladvapi32 -static-libgcc"
# Debug build option
if [[ "$1" == "debug" ]]; then
echo -e "${YELLOW}Building DEBUG version...${NC}"
CFLAGS="$CFLAGS -g -DDEBUG -O0"
OUTPUT_NAME="${OUTPUT_NAME}_debug"
else
echo -e "${YELLOW}Building RELEASE version...${NC}"
CFLAGS="$CFLAGS -DNDEBUG -s"
LDFLAGS="$LDFLAGS -Wl,--strip-all"
fi
# Build command
BUILD_CMD="gcc $CFLAGS $SOURCE_FILE -o $BUILD_DIR/${OUTPUT_NAME}.exe $LDFLAGS"
echo -e "${YELLOW}Compiling...${NC}"
echo -e "${BLUE}Command: $BUILD_CMD${NC}"
# Execute build
if $BUILD_CMD 2>&1; then
echo -e "${GREEN}✓ Build successful!${NC}"
echo -e "${GREEN}✓ Executable created: $BUILD_DIR/${OUTPUT_NAME}.exe${NC}"
# Get file size
FILE_SIZE=$(stat -c%s "$BUILD_DIR/${OUTPUT_NAME}.exe" 2>/dev/null || echo "unknown")
echo -e "${GREEN}✓ File size: $FILE_SIZE bytes${NC}"
echo ""
echo -e "${GREEN}Build completed successfully!${NC}"
else
echo -e "${RED}✗ Build failed!${NC}"
exit 1
fi