Makefile · 11272 bytes Raw Blame History
1 # Fortran Shell (Fortsh) Makefile
2 # ====================================
3
4 # Compiler settings
5 FC = gfortran
6 FCFLAGS = -Wall -Wextra -std=f2018 -fPIC -g -O2
7 LDFLAGS =
8
9 # Directory structure
10 SRCDIR = src
11 BUILDDIR = build
12 BINDIR = bin
13
14 # Object files in dependency order
15 OBJECTS = $(BUILDDIR)/common/types.o \
16 $(BUILDDIR)/common/error_handling.o \
17 $(BUILDDIR)/common/performance.o \
18 $(BUILDDIR)/system/interface.o \
19 $(BUILDDIR)/system/signals.o \
20 $(BUILDDIR)/parsing/glob.o \
21 $(BUILDDIR)/parsing/parser.o \
22 $(BUILDDIR)/execution/jobs.o \
23 $(BUILDDIR)/scripting/control_flow.o \
24 $(BUILDDIR)/scripting/test_builtin.o \
25 $(BUILDDIR)/scripting/advanced_test.o \
26 $(BUILDDIR)/scripting/printf_builtin.o \
27 $(BUILDDIR)/scripting/read_builtin.o \
28 $(BUILDDIR)/scripting/getopts_builtin.o \
29 $(BUILDDIR)/scripting/directory_builtin.o \
30 $(BUILDDIR)/scripting/command_builtin.o \
31 $(BUILDDIR)/scripting/variables.o \
32 $(BUILDDIR)/scripting/expansion.o \
33 $(BUILDDIR)/scripting/substitution.o \
34 $(BUILDDIR)/scripting/config.o \
35 $(BUILDDIR)/scripting/aliases.o \
36 $(BUILDDIR)/scripting/shell_options.o \
37 $(BUILDDIR)/execution/coprocess.o \
38 $(BUILDDIR)/io/readline.o \
39 $(BUILDDIR)/io/heredoc.o \
40 $(BUILDDIR)/io/fd_redirection.o \
41 $(BUILDDIR)/execution/builtins.o \
42 $(BUILDDIR)/execution/executor.o \
43 $(BUILDDIR)/fortsh.o
44
45 # Target executable
46 TARGET = $(BINDIR)/fortsh
47
48 # Default target
49 all: $(TARGET)
50
51 # Create directories
52 $(BUILDDIR) $(BINDIR):
53 mkdir -p $@
54
55 $(BUILDDIR)/common $(BUILDDIR)/system $(BUILDDIR)/parsing $(BUILDDIR)/execution $(BUILDDIR)/scripting $(BUILDDIR)/io: | $(BUILDDIR)
56 mkdir -p $@
57
58 # Build target
59 $(TARGET): $(OBJECTS) | $(BINDIR)
60 $(FC) $(OBJECTS) -o $@ $(LDFLAGS)
61 @echo "Fortsh built successfully!"
62
63 # Individual compilation rules with proper dependencies
64 $(BUILDDIR)/common/types.o: src/common/types.f90 | $(BUILDDIR)/common
65 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
66
67 $(BUILDDIR)/common/error_handling.o: src/common/error_handling.f90 | $(BUILDDIR)/common
68 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
69
70 $(BUILDDIR)/common/performance.o: src/common/performance.f90 | $(BUILDDIR)/common
71 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
72
73 $(BUILDDIR)/system/interface.o: src/system/interface.f90 $(BUILDDIR)/common/types.o | $(BUILDDIR)/system
74 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
75
76 $(BUILDDIR)/system/signals.o: src/system/signals.f90 $(BUILDDIR)/system/interface.o | $(BUILDDIR)/system
77 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
78
79 $(BUILDDIR)/parsing/glob.o: src/parsing/glob.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/common/performance.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/parsing
80 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
81
82 $(BUILDDIR)/parsing/parser.o: src/parsing/parser.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/common/error_handling.o $(BUILDDIR)/common/performance.o $(BUILDDIR)/system/interface.o $(BUILDDIR)/scripting/variables.o $(BUILDDIR)/scripting/expansion.o $(BUILDDIR)/parsing/glob.o | $(BUILDDIR)/parsing
83 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
84
85 $(BUILDDIR)/execution/jobs.o: src/execution/jobs.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/execution
86 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
87
88 $(BUILDDIR)/execution/executor.o: src/execution/executor.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/common/error_handling.o $(BUILDDIR)/common/performance.o $(BUILDDIR)/system/interface.o $(BUILDDIR)/parsing/parser.o $(BUILDDIR)/execution/jobs.o $(BUILDDIR)/scripting/variables.o $(BUILDDIR)/scripting/control_flow.o $(BUILDDIR)/execution/builtins.o | $(BUILDDIR)/execution
89 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
90
91 $(BUILDDIR)/execution/builtins.o: src/execution/builtins.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/common/performance.o $(BUILDDIR)/system/interface.o $(BUILDDIR)/execution/jobs.o $(BUILDDIR)/scripting/test_builtin.o $(BUILDDIR)/io/readline.o $(BUILDDIR)/scripting/config.o $(BUILDDIR)/scripting/aliases.o $(BUILDDIR)/scripting/shell_options.o $(BUILDDIR)/parsing/parser.o $(BUILDDIR)/execution/coprocess.o $(BUILDDIR)/scripting/substitution.o | $(BUILDDIR)/execution
92 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
93
94 $(BUILDDIR)/scripting/control_flow.o: src/scripting/control_flow.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/scripting
95 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
96
97 $(BUILDDIR)/scripting/test_builtin.o: src/scripting/test_builtin.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/scripting
98 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
99
100 $(BUILDDIR)/scripting/advanced_test.o: src/scripting/advanced_test.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/scripting/variables.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/scripting
101 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
102
103 $(BUILDDIR)/scripting/printf_builtin.o: src/scripting/printf_builtin.f90 $(BUILDDIR)/common/types.o | $(BUILDDIR)/scripting
104 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
105
106 $(BUILDDIR)/scripting/read_builtin.o: src/scripting/read_builtin.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/scripting/variables.o | $(BUILDDIR)/scripting
107 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
108
109 $(BUILDDIR)/scripting/getopts_builtin.o: src/scripting/getopts_builtin.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/scripting/variables.o | $(BUILDDIR)/scripting
110 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
111
112 $(BUILDDIR)/scripting/directory_builtin.o: src/scripting/directory_builtin.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/scripting/variables.o | $(BUILDDIR)/scripting
113 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
114
115 $(BUILDDIR)/scripting/command_builtin.o: src/scripting/command_builtin.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/scripting/variables.o | $(BUILDDIR)/scripting
116 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
117
118 $(BUILDDIR)/scripting/variables.o: src/scripting/variables.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/scripting
119 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
120
121 $(BUILDDIR)/scripting/expansion.o: src/scripting/expansion.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/scripting/variables.o | $(BUILDDIR)/scripting
122 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
123
124 $(BUILDDIR)/scripting/substitution.o: src/scripting/substitution.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/scripting
125 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
126
127 $(BUILDDIR)/execution/coprocess.o: src/execution/coprocess.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/execution
128 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
129
130 $(BUILDDIR)/scripting/config.o: src/scripting/config.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o $(BUILDDIR)/scripting/variables.o | $(BUILDDIR)/scripting
131 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
132
133 $(BUILDDIR)/scripting/aliases.o: src/scripting/aliases.f90 $(BUILDDIR)/common/types.o | $(BUILDDIR)/scripting
134 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
135
136 $(BUILDDIR)/scripting/shell_options.o: src/scripting/shell_options.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/scripting
137 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
138
139 $(BUILDDIR)/io/readline.o: src/io/readline.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/io
140 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
141
142 $(BUILDDIR)/io/heredoc.o: src/io/heredoc.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/scripting/variables.o | $(BUILDDIR)/io
143 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
144
145 $(BUILDDIR)/io/fd_redirection.o: src/io/fd_redirection.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/io
146 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
147
148 $(BUILDDIR)/fortsh.o: src/fortsh.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o $(BUILDDIR)/system/signals.o $(BUILDDIR)/parsing/parser.o $(BUILDDIR)/execution/executor.o $(BUILDDIR)/execution/jobs.o $(BUILDDIR)/io/readline.o $(BUILDDIR)/scripting/config.o $(BUILDDIR)/scripting/aliases.o $(BUILDDIR)/scripting/shell_options.o | $(BUILDDIR)
149 $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@
150
151 # Clean targets
152 clean:
153 rm -rf $(BUILDDIR) $(BINDIR)
154 @echo "Clean completed!"
155
156 distclean: clean
157 rm -f *.mod
158
159 # Install target (optional)
160 install: $(TARGET)
161 cp $(TARGET) /usr/local/bin/
162 @echo "Fortsh installed to /usr/local/bin/"
163
164 # Development targets
165 test: $(TARGET)
166 @echo "Running basic functionality test..."
167 @echo "echo 'Hello from Fortsh!'" | $(TARGET)
168
169 debug: FCFLAGS += -g -fbacktrace -fcheck=bounds
170 debug: $(TARGET)
171
172 # Help target
173 help:
174 @echo "Fortran Shell (Fortsh) Build System"
175 @echo "==================================="
176 @echo ""
177 @echo "Available targets:"
178 @echo " all - Build fortsh (default)"
179 @echo " clean - Remove build artifacts"
180 @echo " distclean - Remove all generated files"
181 @echo " install - Install fortsh to /usr/local/bin"
182 @echo " test - Run basic functionality test"
183 @echo " debug - Build with debug flags"
184 @echo " help - Show this help"
185 @echo " dist - Create distribution package"
186 @echo " rpm - Build RPM package"
187 @echo " check - Run comprehensive checks"
188 @echo " smoke-test- Run basic functionality tests"
189
190 # Package information
191 PACKAGE = fortsh
192 VERSION = 2.0.0
193
194 # Distribution and packaging targets
195 dist: clean
196 @echo "Creating distribution package..."
197 tar czf $(PACKAGE)-$(VERSION).tar.gz \
198 --exclude='.git*' \
199 --exclude='*.o' \
200 --exclude='*.mod' \
201 --exclude='build' \
202 --exclude='bin' \
203 --transform 's,^,$(PACKAGE)-$(VERSION)/,' \
204 src/ tests/ Makefile README.md fortsh.spec
205
206 rpm: dist
207 @echo "Building RPM package..."
208 @command -v rpmbuild >/dev/null 2>&1 || (echo "rpmbuild not available - install rpm-build package" && exit 1)
209 mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
210 cp $(PACKAGE)-$(VERSION).tar.gz ~/rpmbuild/SOURCES/
211 cp $(PACKAGE).spec ~/rpmbuild/SPECS/
212 rpmbuild -ba ~/rpmbuild/SPECS/$(PACKAGE).spec
213 @echo "RPM packages created in ~/rpmbuild/RPMS/"
214
215 dev-install: $(TARGET)
216 @echo "Installing fortsh for development..."
217 mkdir -p ~/.local/bin
218 cp $(TARGET) ~/.local/bin/
219 @echo "fortsh installed to ~/.local/bin/fortsh"
220 @echo "Make sure ~/.local/bin is in your PATH"
221
222 uninstall:
223 @echo "Uninstalling fortsh..."
224 @rm -f ~/.local/bin/fortsh 2>/dev/null || true
225 @rm -f /usr/local/bin/fortsh 2>/dev/null || sudo rm -f /usr/local/bin/fortsh 2>/dev/null || true
226 @echo "Uninstall complete!"
227
228 check: $(TARGET)
229 @echo "Running comprehensive checks..."
230 @echo "✓ Build system works"
231 ./tests/integration_test.sh
232 @echo "✓ Integration tests completed"
233
234 smoke-test: $(TARGET)
235 @echo "Running smoke tests..."
236 @echo "echo 'Hello from Fortsh!'" | $(TARGET) && echo "✓ Basic execution works"
237 @echo -e "help\nexit" | $(TARGET) >/dev/null && echo "✓ Help command works"
238 @echo -e "echo *.txt\nexit" | $(TARGET) >/dev/null && echo "✓ Glob expansion works"
239 @echo "perf on\necho 'test'\nperf\nexit" | $(TARGET) >/dev/null && echo "✓ Performance monitoring works"
240 @echo "All smoke tests passed!"
241
242 .PHONY: all clean distclean install test debug help dist rpm dev-install uninstall check smoke-test