-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·162 lines (139 loc) · 4.59 KB
/
build
File metadata and controls
executable file
·162 lines (139 loc) · 4.59 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
#!/bin/bash
# Olc Build Script
# usage: ./build.sh [option]
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
ZYL_HOME="$HOME/.olc"
LOCAL_BIN="$HOME/.local/bin"
EXECUTABLE_NAME="olc" # Assumes 'dub' produces a binary named 'olc'
log_info() { echo -e "${YELLOW}[INFO] $1${NC}"; }
log_success() { echo -e "${GREEN}[SUCCESS] $1${NC}"; }
log_error() { echo -e "${RED}[ERROR] $1${NC}"; }
# Function to check and install dependencies
check_dependencies() {
log_info "Checking dependencies..."
local MISSING_DEPS=0
# Check for LDC2
if ! command -v ldc2 &> /dev/null; then
log_info "LDC2 not found."
MISSING_DEPS=1
fi
# Check for DUB
if ! command -v dub &> /dev/null; then
log_info "DUB not found."
MISSING_DEPS=1
fi
if [ $MISSING_DEPS -eq 1 ]; then
log_info "Attempting to install missing dependencies (ldc, dub, llvm-devel)..."
if [ -f /etc/os-release ]; then
. /etc/os-release
case $ID in
ubuntu|debian|pop|mint)
log_info "Detected Debian-based system."
sudo apt-get update
# Note: Package names might vary slightly by version, but these are standard
sudo apt-get install -y ldc dub llvm-dev libxml2-dev clang
;;
fedora|rhel|centos)
log_info "Detected Fedora-based system."
sudo dnf install -y ldc dub llvm-devel libxml2-devel clang
;;
arch|manjaro)
log_info "Detected Arch-based system."
sudo pacman -S --noconfirm ldc dub llvm clang
;;
*)
log_error "Unsupported distribution for auto-install ($ID)."
log_error "Please install 'ldc', 'dub', and 'llvm-devel' manually."
exit 1
;;
esac
else
log_error "Cannot detect OS. Please install dependencies manually."
exit 1
fi
else
log_info "Dependencies found (ldc2, dub)."
fi
}
# Function to setup ~/.olc and copy stdlib
setup_environment() {
log_info "Setting up Olc environment at $ZYL_HOME..."
if [ ! -d "./std" ]; then
log_error "Standard library folder './std' not found in current directory!"
exit 1
fi
# Create directory
mkdir -p "$ZYL_HOME"
# Copy stdlib (remove old one to ensure clean update)
rm -rf "$ZYL_HOME/std"
cp -r "./std" "$ZYL_HOME/std"
log_success "Environment setup complete. Stdlib copied to $ZYL_HOME/std"
}
# Function to build the compiler
build_compiler() {
log_info "Building Olc compiler using LDC2..."
# Run dub build
if dub build --compiler=ldc2; then
log_success "Build successful!"
else
log_error "Build failed."
exit 1
fi
}
# Function to install the binary to ~/.local/bin
install_binary() {
log_info "Installing binary to $LOCAL_BIN..."
mkdir -p "$LOCAL_BIN"
if [ -f "./$EXECUTABLE_NAME" ]; then
cp "./$EXECUTABLE_NAME" "$LOCAL_BIN/"
chmod +x "$LOCAL_BIN/$EXECUTABLE_NAME"
log_success "Binary installed to $LOCAL_BIN/$EXECUTABLE_NAME"
# Check PATH
if [[ ":$PATH:" != *":$LOCAL_BIN:"* ]]; then
echo ""
log_info "WARNING: $LOCAL_BIN is not in your PATH."
echo "Please add the following line to your shell configuration (.bashrc, .zshrc, etc.):"
echo -e "${GREEN}export PATH=\"\$PATH:$LOCAL_BIN\"${NC}"
echo ""
fi
else
log_error "Executable './$EXECUTABLE_NAME' not found. Did the build pass?"
exit 1
fi
}
show_help() {
echo "Usage: ./build.sh [OPTION]"
echo "Options:"
echo " (no arguments) Full process: Check deps, setup env, build, and install."
echo " --build-only Only compile the project."
echo " --stdlib-only Only copy ./std to ~/.olc/std."
echo " --validate Only check and install dependencies."
echo " --help Show this message."
}
# Main Execution Logic
case "$1" in
--build-only)
build_compiler
;;
--stdlib-only)
setup_environment
;;
--validate)
check_dependencies
;;
--help)
show_help
;;
*)
# Default behavior: Full install
check_dependencies
setup_environment
build_compiler
install_binary
log_success "Olc is ready! Run 'olc --help' to test."
;;
esac