-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
420 lines (384 loc) · 17 KB
/
Copy pathMakefile
File metadata and controls
420 lines (384 loc) · 17 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# Makefile for facsimile
# Detect operating system
UNAME_S := $(shell uname -s 2>/dev/null || echo Windows)
UNAME_M := $(shell uname -m 2>/dev/null || echo x86_64)
# Default compilers
FC = gfortran
CC = gcc
# Platform-specific settings
ifeq ($(UNAME_S),Darwin)
# macOS
ifeq ($(UNAME_M),arm64)
# Apple Silicon - use gfortran-15 for syntax highlighting support
BREW_PREFIX = /opt/homebrew
ifneq ($(wildcard $(BREW_PREFIX)/bin/gfortran-15),)
FC = $(BREW_PREFIX)/bin/gfortran-15
FFLAGS = -O2 -Wall -ffree-line-length-none
FFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wunused-variable -Wuninitialized \
-Wimplicit-interface -fcheck=all -fbacktrace -ffree-line-length-none
FFLAGS_DEBUG = -O0 -g -fcheck=all -fbacktrace -ffree-line-length-none
else ifneq ($(wildcard $(BREW_PREFIX)/bin/flang-new),)
# Fallback to flang-new if gfortran-15 not available
FC = $(BREW_PREFIX)/bin/flang-new
# flang-new flags
FFLAGS = -O2
# Development flags (flang-new has very limited warning support)
# For comprehensive warnings, use gfortran instead
FFLAGS_DEV = -O0 -g -pedantic
# Debug flags with debug symbols
FFLAGS_DEBUG = -O0 -g
else
# Fallback to any available gfortran
ifneq ($(wildcard $(BREW_PREFIX)/bin/gfortran-*),)
FC = $(shell ls $(BREW_PREFIX)/bin/gfortran-* | head -n1)
endif
FFLAGS = -O2 -Wall -ffree-line-length-none
FFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wunused-variable -Wuninitialized \
-Wimplicit-interface -fcheck=all -fbacktrace -ffree-line-length-none
FFLAGS_DEBUG = -O0 -g -fcheck=all -fbacktrace -ffree-line-length-none
endif
CFLAGS = -O2 -Wall
CFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wconversion
else
# Intel Mac
BREW_PREFIX = /usr/local
FFLAGS = -O2 -Wall -ffree-line-length-none
FFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wunused-variable -Wuninitialized \
-fcheck=all -fbacktrace -ffree-line-length-none
FFLAGS_DEBUG = -O0 -g -fcheck=all -fbacktrace -ffree-line-length-none
CFLAGS = -O2 -Wall
CFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wconversion
endif
TARGET = fac
else ifneq (,$(findstring MINGW,$(UNAME_S)))
# Windows (MSYS2/MinGW)
FFLAGS = -O2 -Wall -ffree-line-length-none
FFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wunused-variable -Wuninitialized \
-fcheck=all -fbacktrace -ffree-line-length-none
FFLAGS_DEBUG = -O0 -g -fcheck=all -fbacktrace -ffree-line-length-none
CFLAGS = -O2 -Wall
CFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wconversion
TARGET = fac.exe
else ifneq (,$(findstring MSYS,$(UNAME_S)))
# Windows (MSYS2)
FFLAGS = -O2 -Wall -ffree-line-length-none
FFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wunused-variable -Wuninitialized \
-fcheck=all -fbacktrace -ffree-line-length-none
FFLAGS_DEBUG = -O0 -g -fcheck=all -fbacktrace -ffree-line-length-none
CFLAGS = -O2 -Wall
CFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wconversion
TARGET = fac.exe
else ifeq ($(UNAME_S),Windows)
# Windows (native or cross-compile)
FFLAGS = -O2 -Wall -ffree-line-length-none
FFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wunused-variable -Wuninitialized \
-fcheck=all -fbacktrace -ffree-line-length-none
FFLAGS_DEBUG = -O0 -g -fcheck=all -fbacktrace -ffree-line-length-none
CFLAGS = -O2 -Wall
CFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wconversion
TARGET = fac.exe
else
# Linux
FFLAGS = -O2 -Wall
FFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wunused-variable -Wuninitialized \
-fcheck=all -fbacktrace
FFLAGS_DEBUG = -O0 -g -fcheck=all -fbacktrace
CFLAGS = -O2 -Wall
CFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wconversion
TARGET = fac
endif
VERSION := $(shell cat VERSION 2>/dev/null || echo "unknown")
# Source files (order matters for dependencies)
# Note: the fortress modules sit before renderer_module -- the editor frame
# now draws the browser window, so the renderer uses them.
SOURCES = src/version_module.f90 \
src/utils/platform_module.f90 \
src/utils/utf8_module.f90 \
src/utils/regex_module.f90 \
src/utils/dir_scan_module.f90 \
src/workspace/session_ipc_module.f90 \
src/ui/clickable_region_module.f90 \
src/ui/tab_drag_module.f90 \
src/syntax/comment_syntax_module.f90 \
src/ai/ai_http_module.f90 \
src/ai/completion_cache_module.f90 \
src/ai/ai_state_module.f90 \
src/ai/ai_json_module.f90 \
src/ai/completion_sanitize_module.f90 \
src/ai/ollama_client_module.f90 \
src/buffer/text_buffer_module.f90 \
src/ai/completion_context_module.f90 \
src/ai/completion_prompt_module.f90 \
src/clipboard/yank_stack_module.f90 \
src/clipboard/clipboard_module.f90 \
src/terminal/raw_mode_module.f90 \
src/terminal/terminal_io_module.f90 \
src/terminal/input_handler_module.f90 \
src/utils/bracket_matching_module.f90 \
src/navigation/jump_stack_module.f90 \
src/lsp/json_module.f90 \
src/lsp/lsp_protocol_module.f90 \
src/lsp/lsp_server_manager_module.f90 \
src/lsp/lsp_client_module.f90 \
src/lsp/document_sync_module.f90 \
src/lsp/diagnostics_module.f90 \
src/lsp/server_detection_module.f90 \
src/lsp/server_installer_module.f90 \
src/ui/context_menu_module.f90 \
src/ui/completion_popup_module.f90 \
src/ui/hover_tooltip_module.f90 \
src/ui/diagnostics_panel_module.f90 \
src/ui/references_panel_module.f90 \
src/ui/code_actions_panel_module.f90 \
src/ui/symbols_panel_module.f90 \
src/ui/signature_tooltip_module.f90 \
src/ui/command_palette_module.f90 \
src/ui/workspace_symbols_panel_module.f90 \
src/ui/lsp_server_installer_panel_module.f90 \
src/ui/modal_box_module.f90 \
src/ui/group_picker_module.f90 \
src/ui/terminal_panel_module.f90 \
src/ui/ghost_text_module.f90 \
src/editor_state_module.f90 \
src/undo/undo_stack_module.f90 \
src/workspace/file_tree_module.f90 \
src/workspace/git_ops_module.f90 \
src/workspace/file_tree_renderer_module.f90 \
src/workspace/config_module.f90 \
src/workspace/settings_module.f90 \
src/workspace/app_state_module.f90 \
src/workspace/favorites_module.f90 \
src/workspace/recents_module.f90 \
src/workspace/workspace_module.f90 \
src/workspace/backup_module.f90 \
src/syntax/syntax_highlighter_module.f90 \
src/ui/help_display_module.f90 \
src/ui/text_prompt_module.f90 \
src/ui/rename_prompt_module.f90 \
src/ui/search_prompt_module.f90 \
src/ui/unified_search_module.f90 \
src/fortress/filesystem/fortress_fs_module.f90 \
src/fortress/ui/fortress_display_module.f90 \
src/fortress/fortress_navigator_module.f90 \
src/terminal/renderer_module.f90 \
src/ui/replace_prompt_module.f90 \
src/ui/goto_prompt_module.f90 \
src/ui/save_prompt_module.f90 \
src/ui/binary_prompt_module.f90 \
src/fortress/ui/welcome_menu_module.f90 \
src/ai/ai_engine_module.f90 \
src/commands/comment_command_module.f90 \
src/commands/indent_policy_module.f90 \
src/commands/command_handler_module.f90 \
app/main.f90
OBJECTS = $(SOURCES:.f90=.o)
C_SOURCES = src/terminal/termios_wrapper.c \
src/terminal/pty_wrapper.c \
src/terminal/vt100_grid.c \
src/utils/regex_wrapper.c \
src/utils/platform_wrapper.c \
src/utils/dir_scan_wrapper.c \
src/lsp/lsp_process_wrapper.c \
src/ai/ai_http.c
C_OBJECTS = $(C_SOURCES:.c=.o)
all: $(TARGET)
# Generate version module before building
src/version_module.f90: VERSION
@echo "Generating version module..."
@echo "module version_module" > $@
@echo " implicit none" >> $@
@echo " character(len=*), parameter :: VERSION = '$(VERSION)'" >> $@
@echo "end module version_module" >> $@
$(TARGET): src/version_module.f90 $(OBJECTS) $(C_OBJECTS)
$(FC) $(FFLAGS) -o $(TARGET) $(OBJECTS) $(C_OBJECTS)
# version_module has no tracked .mod dependency, so a version bump would
# otherwise only recompile version_module.o and leave stale VERSION strings
# inlined in modules that `use` it (e.g. app/main.o). Force a full rebuild.
$(OBJECTS): src/version_module.f90
# Disable parallel builds to ensure correct module compilation order
.NOTPARALLEL:
%.o: %.f90
$(FC) $(FFLAGS) -c $< -o $@
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f $(OBJECTS) $(C_OBJECTS) $(TARGET) fac fac.exe *.mod src/*/*.mod src/workspace/*.o src/utils/*.o
# Development build with comprehensive warnings
dev: clean
@echo "Building with development flags (warnings + checks)..."
@echo "Fortran flags: $(FFLAGS_DEV)"
@echo "C flags: $(CFLAGS_DEV)"
@echo ""
@$(MAKE) all FFLAGS="$(FFLAGS_DEV)" CFLAGS="$(CFLAGS_DEV)"
# Debug build with runtime checks and symbols
debug: clean
@echo "Building with debug flags (runtime checks + symbols)..."
@echo "Fortran flags: $(FFLAGS_DEBUG)"
@echo ""
@$(MAKE) all FFLAGS="$(FFLAGS_DEBUG)"
# Show current compiler and flags
info:
@echo "Platform: $(UNAME_S)"
@echo "Architecture: $(UNAME_M)"
@echo "Target: $(TARGET)"
@echo ""
@echo "Fortran Compiler: $(FC)"
@echo "Default FFLAGS: $(FFLAGS)"
@echo "Dev FFLAGS: $(FFLAGS_DEV)"
@echo "Debug FFLAGS: $(FFLAGS_DEBUG)"
@echo ""
@echo "C Compiler: $(CC)"
@echo "Default CFLAGS: $(CFLAGS)"
@echo "Dev CFLAGS: $(CFLAGS_DEV)"
# Generate compile_commands.json for clangd, covering the C wrappers.
# Without it clangd falls back to fpm's build/compile_commands.json and
# interpolates gfortran flags (-ffree-form, -J) onto the C files. Uses
# dev CFLAGS so the editor surfaces the same warnings as `make dev`.
compile-commands:
@echo '[' > compile_commands.json
@first=1; for f in $(C_SOURCES); do \
[ $$first -eq 1 ] || echo ' ,' >> compile_commands.json; \
first=0; \
printf ' {"directory": "%s", "file": "%s", "arguments": ["$(CC)"' \
"$$(pwd)" "$$f" >> compile_commands.json; \
for a in $(CFLAGS_DEV); do \
printf ', "%s"' "$$a" >> compile_commands.json; \
done; \
printf ', "-c", "%s", "-o", "%s"]}\n' \
"$$f" "$${f%.c}.o" >> compile_commands.json; \
done
@echo ']' >> compile_commands.json
@echo "Wrote compile_commands.json ($(words $(C_SOURCES)) C entries)"
# Installation (supports DESTDIR and PREFIX for packaging)
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
DOCDIR ?= $(PREFIX)/share/doc/facsimile
install: $(TARGET)
@echo "Installing to $(DESTDIR)$(BINDIR)..."
install -d "$(DESTDIR)$(BINDIR)"
install -m755 "$(TARGET)" "$(DESTDIR)$(BINDIR)/fac"
ln -sf fac "$(DESTDIR)$(BINDIR)/facsimile"
install -d "$(DESTDIR)$(DOCDIR)"
install -m644 README.md "$(DESTDIR)$(DOCDIR)/README.md"
uninstall:
rm -f "$(DESTDIR)$(BINDIR)/fac" "$(DESTDIR)$(BINDIR)/facsimile"
rm -rf "$(DESTDIR)$(DOCDIR)"
# Version management targets
bump-patch:
@echo "Current version: $(VERSION)"
@NEW_VERSION=$$(echo $(VERSION) | awk -F. '{print $$1"."$$2"."$$3+1}'); \
echo "Bumping to: $$NEW_VERSION"; \
echo $$NEW_VERSION > VERSION; \
echo "Updated VERSION file to $$NEW_VERSION"; \
$(MAKE) src/version_module.f90; \
echo "Updated src/version_module.f90"
@echo "Now run: make clean && make"
bump-minor:
@echo "Current version: $(VERSION)"
@NEW_VERSION=$$(echo $(VERSION) | awk -F. '{print $$1"."$$2+1".0"}'); \
echo "Bumping to: $$NEW_VERSION"; \
echo $$NEW_VERSION > VERSION; \
echo "Updated VERSION file to $$NEW_VERSION"; \
$(MAKE) src/version_module.f90; \
echo "Updated src/version_module.f90"
@echo "Now run: make clean && make"
bump-major:
@echo "Current version: $(VERSION)"
@NEW_VERSION=$$(echo $(VERSION) | awk -F. '{print $$1+1".0.0"}'); \
echo "Bumping to: $$NEW_VERSION"; \
echo $$NEW_VERSION > VERSION; \
echo "Updated VERSION file to $$NEW_VERSION"; \
$(MAKE) src/version_module.f90; \
echo "Updated src/version_module.f90"
@echo "Now run: make clean && make"
# Show current version
version:
@echo "$(VERSION)"
# Release checklist
release: clean all
@echo ""
@echo "========================================"
@echo "Release Build Complete: v$(VERSION)"
@echo "========================================"
@echo ""
@./$(TARGET) --version
@echo ""
@echo "Next steps:"
@echo "1. Test the binary: ./$(TARGET)"
@echo "2. Commit changes: git add VERSION src/version_module.f90"
@echo "3. Commit: git commit -m 'Release v$(VERSION)'"
@echo "4. Tag: git tag v$(VERSION)"
@echo "5. Push: git push && git push --tags"
@echo ""
# LSP development targets
lsp-modules: src/lsp/json_module.o src/lsp/lsp_protocol_module.o src/lsp/lsp_server_manager_module.o src/lsp/lsp_client_module.o src/lsp/lsp_process_wrapper.o
@echo "LSP modules built successfully"
test-lsp: lsp-modules
@echo "Testing LSP JSON parser..."
@$(FC) $(FFLAGS_DEBUG) tests/lsp/test_json.f90 src/lsp/json_module.o -o tests/lsp/test_json 2>/dev/null && tests/lsp/test_json || true
@echo ""
@echo "Testing LSP initialization..."
@$(FC) $(FFLAGS_DEBUG) tests/lsp/test_lsp_init.f90 src/lsp/json_module.o src/lsp/lsp_protocol_module.o src/lsp/lsp_process_wrapper.o src/lsp/lsp_client_module.o src/lsp/lsp_server_manager_module.o -o tests/lsp/test_lsp_init 2>/dev/null && tests/lsp/test_lsp_init || true
@echo ""
@echo "Testing that a server which never reads cannot hang us..."
@$(CC) -O1 -o tests/lsp/test_write_deadlock tests/lsp/test_write_deadlock.c \
src/lsp/lsp_process_wrapper.o && timeout 60 tests/lsp/test_write_deadlock
@echo ""
@echo "Testing that a server's stderr is read, so it cannot wedge on its log..."
@$(CC) -O1 -o tests/lsp/test_stderr_drain tests/lsp/test_stderr_drain.c \
src/lsp/lsp_process_wrapper.o && timeout 90 tests/lsp/test_stderr_drain
# Syntax-check the _WIN32 branches without a Windows toolchain. See
# tests/winstub/README.md -- these branches are invisible to the normal build,
# and a mistake in one is otherwise found only after a tag has been cut.
WIN_CHECK_SRC = src/utils/platform_wrapper.c src/terminal/pty_wrapper.c src/ai/ai_http.c \
src/lsp/lsp_process_wrapper.c
# One frame, one write. Every module draws through terminal_write, which
# batches into a buffer the renderer flushes once at the end of a frame.
# A module that writes to the unit itself puts half a frame on the terminal
# ahead of the other half -- which is exactly how the fortress window came
# to flicker as it scrolled (360 write() syscalls over ten scroll steps,
# against 12 once it went through the buffer).
check-render:
@printf 'Checking that nothing draws past the frame buffer... '
@bad=`grep -rln 'write(output_unit' src/ || true`; \
if [ -n "$$bad" ]; then \
echo; \
echo " these write to the unit instead of terminal_write:"; \
for f in $$bad; do echo " $$f"; done; \
echo " (see the note above this target -- it causes visible flicker)"; \
exit 1; \
fi
@echo ok
check-windows:
@echo "Syntax-checking the Windows branches..."
@for f in $(WIN_CHECK_SRC); do \
printf ' %-40s ' "$$f"; \
$(CC) -fsyntax-only -D_WIN32 -Itests/winstub "$$f" || exit 1; \
echo ok; \
done
@echo "Checking for lsp_ helpers defined on one platform only..."
@$(CC) -c -D_WIN32 -Itests/winstub src/lsp/lsp_process_wrapper.c \
-o tests/winstub/.win.o
@undef=`nm -u tests/winstub/.win.o | awk '{print $$NF}' | grep '^lsp_' || true`; \
rm -f tests/winstub/.win.o; \
if [ -n "$$undef" ]; then \
echo " MISSING on Windows: $$undef"; \
echo " (every lsp_ helper lives in this one file; an undefined one means"; \
echo " it was written into the POSIX branch only, and Windows will not link)"; \
exit 1; \
fi
@echo " no one-sided lsp_ helpers ok"
@echo "Windows branches OK (see tests/winstub/README.md for what is not covered)"
test-lsp-editor: all
@echo "Testing LSP in editor with sample C file..."
@echo "Opening tests/lsp/sample.c - check for LSP server initialization"
@timeout 2 ./fac tests/lsp/sample.c < /dev/null 2>&1 | grep -q "LSP server initialized" && \
echo "✓ LSP server initialized for C file" || \
echo "✗ LSP server did not initialize (check if clangd is installed)"
clean-lsp:
rm -f src/lsp/*.o src/lsp/*.mod /tmp/test_json /tmp/test_lsp_init /tmp/test_lsp_raw
# Build LSP modules with debug flags for development
lsp-dev: clean-lsp
@echo "Building LSP modules with debug flags..."
@$(MAKE) lsp-modules FFLAGS="$(FFLAGS_DEBUG)" CFLAGS="$(CFLAGS_DEV)"
.PHONY: all clean dev debug info install uninstall bump-patch bump-minor bump-major version release lsp-modules test-lsp test-lsp-editor clean-lsp lsp-dev compile-commands