summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 464bb914e96afe1ad80631ca4ca6f7e8f60f4ec0 (plain) (blame)
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
# Khimera Portable - Makefile
# Builds portable executables for Windows, Linux, and Android

# Configuration
VERSION := 0.9
BUILD_DATE := $(shell date +%Y%m%d)
OUTPUT_DIR := khimera-portable-v$(VERSION)
LDFLAGS := -s -w -X main.Version=$(VERSION) -X main.BuildDate=$(BUILD_DATE)

# Colors for output
GREEN := \033[0;32m
YELLOW := \033[1;33m
BLUE := \033[0;34m
RED := \033[0;31m
NC := \033[0m

.PHONY: all clean windows linux android portable appimage help test install-deps

# Default target
all: portable

# Help
help:
	@echo "Khimera Portable Build System v$(VERSION)"
	@echo ""
	@echo "Usage:"
	@echo "  make portable     - Build all portable executables (local dev)"
	@echo "  make linux        - Build Linux executable only (local dev)"
	@echo "  make windows      - Build Windows executable only"
	@echo "  make appimage     - Build portable AppImage via Docker (release)"
	@echo "  make android      - Build Android APK only"
	@echo "  make clean        - Clean build artifacts"
	@echo "  make test         - Run tests"
	@echo "  make install-deps - Install build dependencies"
	@echo ""

# Install dependencies
install-deps:
	@echo "$(BLUE)[Setup]$(NC) Installing dependencies..."
	go get fyne.io/fyne/v2
	go get golang.org/x/crypto/scrypt
	go get golang.org/x/crypto/nacl/secretbox
	go get golang.org/x/net/proxy
	go get github.com/flynn/noise
	go mod tidy
	@echo "$(GREEN)✓$(NC) Dependencies installed"

# Build Windows portable
windows: install-deps
	@echo "$(BLUE)[Windows]$(NC) Building Windows portable executable..."
	@mkdir -p $(OUTPUT_DIR)/Windows
	CGO_ENABLED=1 \
	GOOS=windows \
	GOARCH=amd64 \
	CC=x86_64-w64-mingw32-gcc \
	go build \
	    -ldflags="$(LDFLAGS) -H windowsgui" \
	    -tags static \
	    -o $(OUTPUT_DIR)/Windows/khimera.exe \
	    ./khimera-main.go
	@if [ $$? -eq 0 ]; then \
		echo "$(GREEN)✓$(NC) Windows build complete"; \
	else \
		echo "$(RED)✗$(NC) Windows build failed"; \
	fi

# Build Linux portable
linux: install-deps
	@echo "$(BLUE)[Linux]$(NC) Building Linux portable executable..."
	@mkdir -p $(OUTPUT_DIR)/Linux
	CGO_ENABLED=1 \
	GOOS=linux \
	GOARCH=amd64 \
	go build \
	    -ldflags="$(LDFLAGS)" \
	    -o $(OUTPUT_DIR)/Linux/khimera-linux \
	    ./khimera-main.go
	@chmod +x $(OUTPUT_DIR)/Linux/khimera-linux
	@if [ $$? -eq 0 ]; then \
		echo "$(GREEN)✓$(NC) Linux build complete"; \
	else \
		echo "$(RED)✗$(NC) Linux build failed"; \
	fi

# Build AppImage (portable Linux release via Docker)
appimage:
	@echo "$(BLUE)╔════════════════════════════════════════╗$(NC)"
	@echo "$(BLUE)║  KHIMERA APPIMAGE BUILD v$(VERSION)         ║$(NC)"
	@echo "$(BLUE)╚════════════════════════════════════════╝$(NC)"
	@echo ""
	@echo "$(BLUE)[AppImage]$(NC) Building Docker image..."
	docker build --network=host -t khimera-builder -f docker/Dockerfile.appimage .
	@echo "$(BLUE)[AppImage]$(NC) Compiling and packaging..."
	@mkdir -p $(OUTPUT_DIR)/Linux
	docker run --rm --privileged --network=host \
	    -v $(shell pwd):/src:ro \
	    -v $(shell pwd)/$(OUTPUT_DIR)/Linux:/out \
	    khimera-builder \
	    bash -c " \
	        cp -r /src /work && cd /work && \
	        go mod tidy && \
	        CGO_ENABLED=1 go build \
	            -ldflags='$(LDFLAGS)' \
	            -o /work/khimera-bin \
	            ./khimera-main.go && \
	        mkdir -p /work/AppDir/usr/bin \
	                 /work/AppDir/usr/share/applications \
	                 /work/AppDir/usr/share/icons/hicolor/256x256/apps && \
	        cp /work/khimera-bin /work/AppDir/usr/bin/khimera && \
	        cp /work/appimage/khimera.desktop /work/AppDir/usr/share/applications/khimera.desktop && \
	        cp /work/appimage/khimera.png /work/AppDir/usr/share/icons/hicolor/256x256/apps/khimera.png && \
	        cd /work && \
	        linuxdeploy --appdir AppDir \
	            --library /usr/lib/x86_64-linux-gnu/libGL.so.1 \
	            --library /usr/lib/x86_64-linux-gnu/libX11.so.6 \
	            --desktop-file AppDir/usr/share/applications/khimera.desktop \
	            --icon-file AppDir/usr/share/icons/hicolor/256x256/apps/khimera.png \
	            --output appimage && \
	        cp /work/*.AppImage /out/Khimera-v$(VERSION)-x86_64.AppImage \
	    "
	@echo "$(GREEN)✓ AppImage build complete!$(NC)"
	@echo "Output: $(OUTPUT_DIR)/Linux/Khimera-v$(VERSION)-x86_64.AppImage"

# Build Android APK (placeholder - requires Android SDK)
android:
	@echo "$(YELLOW)[Android]$(NC) Android build not yet implemented"
	@echo "  Use build.sh for Android builds"

# Build all portable executables
portable:
	@echo "$(BLUE)╔════════════════════════════════════════╗$(NC)"
	@echo "$(BLUE)║  KHIMERA PORTABLE BUILD v$(VERSION)         ║$(NC)"
	@echo "$(BLUE)╚════════════════════════════════════════╝$(NC)"
	@echo ""
	@$(MAKE) -s linux
	@echo ""
	@echo "$(GREEN)✓ Build complete!$(NC)"
	@echo "Output: $(OUTPUT_DIR)/"

# Run tests
test:
	@echo "$(BLUE)[Test]$(NC) Running tests..."
	go test -v ./identity/...
	go test -v ./addressbook/...
	go test -v ./session/...
	go test -v ./transport/...
	@echo "$(GREEN)✓$(NC) Tests complete"

# Clean build artifacts
clean:
	@echo "$(YELLOW)[Clean]$(NC) Removing build artifacts..."
	rm -rf $(OUTPUT_DIR)
	rm -rf khimera-portable-v*.zip
	rm -rf khimera-portable-v*.tar.gz
	rm -rf AppDir
	rm -f *.AppImage
	@echo "$(GREEN)✓$(NC) Clean complete"

# Package distribution
package: portable
	@echo "$(YELLOW)[Package]$(NC) Creating distribution archives..."
	@if command -v zip > /dev/null; then \
		zip -r $(OUTPUT_DIR).zip $(OUTPUT_DIR); \
		echo "$(GREEN)✓$(NC) Created $(OUTPUT_DIR).zip"; \
	fi
	@if command -v tar > /dev/null; then \
		tar -czf $(OUTPUT_DIR).tar.gz $(OUTPUT_DIR); \
		echo "$(GREEN)✓$(NC) Created $(OUTPUT_DIR).tar.gz"; \
	fi