Makefile · 10061 bytes Raw Blame History
1 # Makefile for facsimile
2 # Detect operating system
3 UNAME_S := $(shell uname -s)
4 UNAME_M := $(shell uname -m)
5
6 # Default compilers
7 FC = gfortran
8 CC = gcc
9
10 # Platform-specific settings
11 ifeq ($(UNAME_S),Darwin)
12 # macOS
13 ifeq ($(UNAME_M),arm64)
14 # Apple Silicon - use gfortran-15 for syntax highlighting support
15 BREW_PREFIX = /opt/homebrew
16 ifneq ($(wildcard $(BREW_PREFIX)/bin/gfortran-15),)
17 FC = $(BREW_PREFIX)/bin/gfortran-15
18 FFLAGS = -O2 -Wall -ffree-line-length-none
19 FFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wunused-variable -Wuninitialized \
20 -Wimplicit-interface -fcheck=all -fbacktrace -ffree-line-length-none
21 FFLAGS_DEBUG = -O0 -g -fcheck=all -fbacktrace -ffree-line-length-none
22 else ifneq ($(wildcard $(BREW_PREFIX)/bin/flang-new),)
23 # Fallback to flang-new if gfortran-15 not available
24 FC = $(BREW_PREFIX)/bin/flang-new
25 # flang-new flags
26 FFLAGS = -O2
27 # Development flags (flang-new has very limited warning support)
28 # For comprehensive warnings, use gfortran instead
29 FFLAGS_DEV = -O0 -g -pedantic
30 # Debug flags with debug symbols
31 FFLAGS_DEBUG = -O0 -g
32 else
33 # Fallback to any available gfortran
34 ifneq ($(wildcard $(BREW_PREFIX)/bin/gfortran-*),)
35 FC = $(shell ls $(BREW_PREFIX)/bin/gfortran-* | head -n1)
36 endif
37 FFLAGS = -O2 -Wall -ffree-line-length-none
38 FFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wunused-variable -Wuninitialized \
39 -Wimplicit-interface -fcheck=all -fbacktrace -ffree-line-length-none
40 FFLAGS_DEBUG = -O0 -g -fcheck=all -fbacktrace -ffree-line-length-none
41 endif
42 CFLAGS = -O2 -Wall
43 CFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wconversion
44 else
45 # Intel Mac
46 BREW_PREFIX = /usr/local
47 FFLAGS = -O2 -Wall -ffree-line-length-none
48 FFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wunused-variable -Wuninitialized \
49 -fcheck=all -fbacktrace -ffree-line-length-none
50 FFLAGS_DEBUG = -O0 -g -fcheck=all -fbacktrace -ffree-line-length-none
51 CFLAGS = -O2 -Wall
52 CFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wconversion
53 endif
54 else
55 # Linux
56 FFLAGS = -O2 -Wall
57 FFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wunused-variable -Wuninitialized \
58 -fcheck=all -fbacktrace
59 FFLAGS_DEBUG = -O0 -g -fcheck=all -fbacktrace
60 CFLAGS = -O2 -Wall
61 CFLAGS_DEV = -O0 -g -Wall -Wextra -pedantic -Wconversion
62 endif
63
64 TARGET = fac
65 VERSION := $(shell cat VERSION 2>/dev/null || echo "unknown")
66
67 # Source files (order matters for dependencies)
68 SOURCES = src/version_module.f90 \
69 src/utils/utf8_module.f90 \
70 src/utils/regex_module.f90 \
71 src/buffer/text_buffer_module.f90 \
72 src/clipboard/yank_stack_module.f90 \
73 src/clipboard/clipboard_module.f90 \
74 src/terminal/raw_mode_module.f90 \
75 src/terminal/terminal_io_module.f90 \
76 src/terminal/input_handler_module.f90 \
77 src/utils/bracket_matching_module.f90 \
78 src/navigation/jump_stack_module.f90 \
79 src/lsp/json_module.f90 \
80 src/lsp/lsp_protocol_module.f90 \
81 src/lsp/lsp_server_manager_module.f90 \
82 src/lsp/lsp_client_module.f90 \
83 src/lsp/document_sync_module.f90 \
84 src/lsp/diagnostics_module.f90 \
85 src/ui/completion_popup_module.f90 \
86 src/ui/hover_tooltip_module.f90 \
87 src/ui/diagnostics_panel_module.f90 \
88 src/ui/references_panel_module.f90 \
89 src/ui/code_actions_menu_module.f90 \
90 src/ui/symbols_panel_module.f90 \
91 src/ui/signature_tooltip_module.f90 \
92 src/ui/command_palette_module.f90 \
93 src/ui/workspace_symbols_panel_module.f90 \
94 src/editor_state_module.f90 \
95 src/undo/undo_stack_module.f90 \
96 src/workspace/file_tree_module.f90 \
97 src/workspace/git_ops_module.f90 \
98 src/workspace/file_tree_renderer_module.f90 \
99 src/workspace/config_module.f90 \
100 src/workspace/favorites_module.f90 \
101 src/workspace/recents_module.f90 \
102 src/workspace/workspace_module.f90 \
103 src/workspace/backup_module.f90 \
104 src/syntax/syntax_highlighter_module.f90 \
105 src/ui/help_display_module.f90 \
106 src/ui/text_prompt_module.f90 \
107 src/ui/rename_prompt_module.f90 \
108 src/ui/search_prompt_module.f90 \
109 src/ui/unified_search_module.f90 \
110 src/terminal/renderer_module.f90 \
111 src/ui/replace_prompt_module.f90 \
112 src/ui/goto_prompt_module.f90 \
113 src/ui/save_prompt_module.f90 \
114 src/ui/binary_prompt_module.f90 \
115 src/fortress/filesystem/fortress_fs_module.f90 \
116 src/fortress/ui/fortress_display_module.f90 \
117 src/fortress/ui/welcome_menu_module.f90 \
118 src/fortress/fortress_navigator_module.f90 \
119 src/commands/command_handler_module.f90 \
120 app/main.f90
121
122 OBJECTS = $(SOURCES:.f90=.o)
123 C_SOURCES = src/terminal/termios_wrapper.c \
124 src/utils/regex_wrapper.c \
125 src/lsp/lsp_process_wrapper.c
126 C_OBJECTS = $(C_SOURCES:.c=.o)
127
128 all: $(TARGET)
129
130 # Generate version module before building
131 src/version_module.f90: VERSION
132 @echo "Generating version module..."
133 @echo "module version_module" > $@
134 @echo " implicit none" >> $@
135 @echo " character(len=*), parameter :: VERSION = '$(VERSION)'" >> $@
136 @echo "end module version_module" >> $@
137
138 $(TARGET): src/version_module.f90 $(OBJECTS) $(C_OBJECTS)
139 $(FC) $(FFLAGS) -o $(TARGET) $(OBJECTS) $(C_OBJECTS)
140
141 # Disable parallel builds to ensure correct module compilation order
142 .NOTPARALLEL:
143
144 %.o: %.f90
145 $(FC) $(FFLAGS) -c $< -o $@
146
147 %.o: %.c
148 $(CC) $(CFLAGS) -c $< -o $@
149
150 clean:
151 rm -f $(OBJECTS) $(C_OBJECTS) $(TARGET) *.mod src/*/*.mod src/workspace/*.o src/utils/*.o
152
153 # Development build with comprehensive warnings
154 dev: clean
155 @echo "Building with development flags (warnings + checks)..."
156 @echo "Fortran flags: $(FFLAGS_DEV)"
157 @echo "C flags: $(CFLAGS_DEV)"
158 @echo ""
159 @$(MAKE) all FFLAGS="$(FFLAGS_DEV)" CFLAGS="$(CFLAGS_DEV)"
160
161 # Debug build with runtime checks and symbols
162 debug: clean
163 @echo "Building with debug flags (runtime checks + symbols)..."
164 @echo "Fortran flags: $(FFLAGS_DEBUG)"
165 @echo ""
166 @$(MAKE) all FFLAGS="$(FFLAGS_DEBUG)"
167
168 # Show current compiler and flags
169 info:
170 @echo "Compiler: $(FC)"
171 @echo "Default FFLAGS: $(FFLAGS)"
172 @echo "Dev FFLAGS: $(FFLAGS_DEV)"
173 @echo "Debug FFLAGS: $(FFLAGS_DEBUG)"
174 @echo ""
175 @echo "C Compiler: $(CC)"
176 @echo "Default CFLAGS: $(CFLAGS)"
177 @echo "Dev CFLAGS: $(CFLAGS_DEV)"
178
179 # Version management targets
180 bump-patch:
181 @echo "Current version: $(VERSION)"
182 @NEW_VERSION=$$(echo $(VERSION) | awk -F. '{print $$1"."$$2"."$$3+1}'); \
183 echo "Bumping to: $$NEW_VERSION"; \
184 echo $$NEW_VERSION > VERSION; \
185 echo "Updated VERSION file to $$NEW_VERSION"; \
186 $(MAKE) src/version_module.f90; \
187 echo "Updated src/version_module.f90"
188 @echo "Now run: make clean && make"
189
190 bump-minor:
191 @echo "Current version: $(VERSION)"
192 @NEW_VERSION=$$(echo $(VERSION) | awk -F. '{print $$1"."$$2+1".0"}'); \
193 echo "Bumping to: $$NEW_VERSION"; \
194 echo $$NEW_VERSION > VERSION; \
195 echo "Updated VERSION file to $$NEW_VERSION"; \
196 $(MAKE) src/version_module.f90; \
197 echo "Updated src/version_module.f90"
198 @echo "Now run: make clean && make"
199
200 bump-major:
201 @echo "Current version: $(VERSION)"
202 @NEW_VERSION=$$(echo $(VERSION) | awk -F. '{print $$1+1".0.0"}'); \
203 echo "Bumping to: $$NEW_VERSION"; \
204 echo $$NEW_VERSION > VERSION; \
205 echo "Updated VERSION file to $$NEW_VERSION"; \
206 $(MAKE) src/version_module.f90; \
207 echo "Updated src/version_module.f90"
208 @echo "Now run: make clean && make"
209
210 # Show current version
211 version:
212 @echo "$(VERSION)"
213
214 # Release checklist
215 release: clean all
216 @echo ""
217 @echo "========================================"
218 @echo "Release Build Complete: v$(VERSION)"
219 @echo "========================================"
220 @echo ""
221 @./$(TARGET) --version
222 @echo ""
223 @echo "Next steps:"
224 @echo "1. Test the binary: ./$(TARGET)"
225 @echo "2. Commit changes: git add VERSION src/version_module.f90"
226 @echo "3. Commit: git commit -m 'Release v$(VERSION)'"
227 @echo "4. Tag: git tag v$(VERSION)"
228 @echo "5. Push: git push && git push --tags"
229 @echo ""
230
231 # LSP development targets
232 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
233 @echo "LSP modules built successfully"
234
235 test-lsp: lsp-modules
236 @echo "Testing LSP JSON parser..."
237 @$(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
238 @echo ""
239 @echo "Testing LSP initialization..."
240 @$(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
241
242 test-lsp-editor: all
243 @echo "Testing LSP in editor with sample C file..."
244 @echo "Opening tests/lsp/sample.c - check for LSP server initialization"
245 @timeout 2 ./fac tests/lsp/sample.c < /dev/null 2>&1 | grep -q "LSP server initialized" && \
246 echo "✓ LSP server initialized for C file" || \
247 echo "✗ LSP server did not initialize (check if clangd is installed)"
248
249 clean-lsp:
250 rm -f src/lsp/*.o src/lsp/*.mod /tmp/test_json /tmp/test_lsp_init /tmp/test_lsp_raw
251
252 # Build LSP modules with debug flags for development
253 lsp-dev: clean-lsp
254 @echo "Building LSP modules with debug flags..."
255 @$(MAKE) lsp-modules FFLAGS="$(FFLAGS_DEBUG)" CFLAGS="$(CFLAGS_DEV)"
256
257 .PHONY: all clean dev debug info bump-patch bump-minor bump-major version release lsp-modules test-lsp test-lsp-editor clean-lsp lsp-dev