-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
187 lines (170 loc) · 5.99 KB
/
Makefile
File metadata and controls
187 lines (170 loc) · 5.99 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
177
178
179
180
181
182
183
184
185
186
.PHONY: build run clean test help install uninstall build-frontend build-prod build-dev
# Binary name
BINARY_NAME=claude-with-openai-api
# Installation directory (can be overridden)
INSTALL_DIR?=~/.local/bin
# System installation directory (requires sudo)
SYSTEM_INSTALL_DIR=/usr/local/bin
# Default target
all: build-prod
# Build frontend (React app)
build-frontend:
@echo "Building frontend..."
@cd frontend && npm run build
@echo "Frontend build complete!"
# Build for production (with embedded frontend)
build-prod: build-frontend
@echo "Building claude-with-openai-api (production with embedded frontend)..."
@go build -o $(BINARY_NAME) .
@echo "Production build complete! Frontend files are embedded in the binary."
# Build for development (without embedded frontend)
build-dev:
@echo "Building claude-with-openai-api (development mode)..."
@go build -tags dev -o $(BINARY_NAME) .
@echo "Development build complete! Will use filesystem frontend files."
# Build the application (production by default)
build: build-prod
# Run the application
run: build
@echo "Starting server..."
@./claude-with-openai-api
# Run without building (use existing binary)
start:
@echo "Starting server..."
@./claude-with-openai-api
# Clean build artifacts
clean:
@echo "Cleaning..."
@rm -f claude-with-openai-api
@echo "Clean complete!"
# Download dependencies
deps:
@echo "Downloading dependencies..."
@go mod download
@go mod tidy
@echo "Dependencies downloaded!"
# Format code
fmt:
@echo "Formatting code..."
@go fmt ./...
@echo "Format complete!"
# Run tests
test:
@echo "Running tests..."
@go test -v ./...
# Install the binary to PATH
install: build
@echo "Installing $(BINARY_NAME)..."
@if [ ! -f ./$(BINARY_NAME) ]; then \
echo "❌ Error: Binary $(BINARY_NAME) not found. Please run 'make build' first."; \
exit 1; \
fi
@# Expand tilde in INSTALL_DIR
@INSTALL_PATH=$$(echo $(INSTALL_DIR) | sed "s|^~|$$HOME|"); \
PARENT_DIR=$$(dirname "$$INSTALL_PATH"); \
\
echo "📦 Target directory: $$INSTALL_PATH"; \
\
# Try to create and use user directory \
if mkdir -p "$$INSTALL_PATH" 2>/dev/null && [ -w "$$INSTALL_PATH" ] 2>/dev/null; then \
cp ./$(BINARY_NAME) "$$INSTALL_PATH/$(BINARY_NAME)"; \
chmod +x "$$INSTALL_PATH/$(BINARY_NAME)"; \
echo "✅ Installed $(BINARY_NAME) to $$INSTALL_PATH/$(BINARY_NAME)"; \
echo ""; \
\
# Check if directory is in PATH \
if echo "$$PATH" | grep -qE "(^|:)$$INSTALL_PATH(:|$$)"; then \
echo "✅ $$INSTALL_PATH is already in your PATH."; \
echo " You can now run '$(BINARY_NAME)' from anywhere."; \
else \
echo "⚠️ Warning: $$INSTALL_PATH is not in your PATH."; \
echo ""; \
echo " To add it to your PATH, run:"; \
if [ -f "$$HOME/.zshrc" ]; then \
echo " echo 'export PATH=\"$$INSTALL_PATH:\$$PATH\"' >> ~/.zshrc"; \
echo " source ~/.zshrc"; \
elif [ -f "$$HOME/.bashrc" ]; then \
echo " echo 'export PATH=\"$$INSTALL_PATH:\$$PATH\"' >> ~/.bashrc"; \
echo " source ~/.bashrc"; \
else \
echo " export PATH=\"$$INSTALL_PATH:\$$PATH\""; \
echo " (Add this to your shell profile file)"; \
fi; \
fi; \
else \
echo "⚠️ Cannot write to $$INSTALL_PATH (permission denied)"; \
echo ""; \
echo " Options:"; \
echo " 1. Install to system directory (requires sudo):"; \
echo " make install-system"; \
echo ""; \
echo " 2. Install to a custom directory:"; \
echo " make install INSTALL_DIR=/path/to/your/bin"; \
echo ""; \
echo " 3. Manually copy the binary:"; \
echo " sudo cp ./$(BINARY_NAME) $(SYSTEM_INSTALL_DIR)/$(BINARY_NAME)"; \
echo " sudo chmod +x $(SYSTEM_INSTALL_DIR)/$(BINARY_NAME)"; \
exit 1; \
fi
# Install to system directory (requires sudo)
install-system: build
@echo "Installing $(BINARY_NAME) to system directory..."
@if [ ! -f ./$(BINARY_NAME) ]; then \
echo "❌ Error: Binary $(BINARY_NAME) not found. Please run 'make build' first."; \
exit 1; \
fi
@sudo cp ./$(BINARY_NAME) $(SYSTEM_INSTALL_DIR)/$(BINARY_NAME)
@sudo chmod +x $(SYSTEM_INSTALL_DIR)/$(BINARY_NAME)
@echo "✅ Installed $(BINARY_NAME) to $(SYSTEM_INSTALL_DIR)/$(BINARY_NAME)"
@echo " You can now run '$(BINARY_NAME)' from anywhere."
# Uninstall the binary from PATH
uninstall:
@echo "Uninstalling $(BINARY_NAME)..."
@INSTALL_PATH=$$(echo $(INSTALL_DIR) | sed "s|^~|$$HOME|"); \
USER_INSTALL="$$INSTALL_PATH/$(BINARY_NAME)"; \
SYS_INSTALL="$(SYSTEM_INSTALL_DIR)/$(BINARY_NAME)"; \
FOUND=0; \
\
if [ -f "$$USER_INSTALL" ]; then \
rm -f "$$USER_INSTALL"; \
echo "✅ Removed $$USER_INSTALL"; \
FOUND=1; \
fi; \
\
if [ -f "$$SYS_INSTALL" ]; then \
sudo rm -f "$$SYS_INSTALL"; \
echo "✅ Removed $$SYS_INSTALL"; \
FOUND=1; \
fi; \
\
if [ $$FOUND -eq 0 ]; then \
echo "⚠️ $(BINARY_NAME) not found in common installation directories."; \
echo ""; \
echo " Searched:"; \
echo " - $$USER_INSTALL"; \
echo " - $$SYS_INSTALL"; \
echo ""; \
echo " To remove from a custom location:"; \
echo " make uninstall INSTALL_DIR=/path/to/your/bin"; \
echo ""; \
echo " Or manually remove:"; \
echo " which $(BINARY_NAME)"; \
echo " rm \$$(which $(BINARY_NAME))"; \
fi
# Display help
help:
@echo "Available targets:"
@echo " build - Build for production (with embedded frontend)"
@echo " build-prod - Build for production (with embedded frontend)"
@echo " build-dev - Build for development (use filesystem frontend)"
@echo " build-frontend - Build frontend only"
@echo " run - Build and run the application"
@echo " start - Run existing binary"
@echo " clean - Remove build artifacts"
@echo " deps - Download and tidy dependencies"
@echo " fmt - Format code"
@echo " test - Run tests"
@echo " install - Install binary to ~/.local/bin (or system directory if needed)"
@echo " install-system - Install binary to /usr/local/bin (requires sudo)"
@echo " uninstall - Remove binary from PATH"
@echo " help - Show this help message"