| 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/variables.o \ |
| 26 | $(BUILDDIR)/scripting/config.o \ |
| 27 | $(BUILDDIR)/scripting/aliases.o \ |
| 28 | $(BUILDDIR)/io/readline.o \ |
| 29 | $(BUILDDIR)/execution/builtins.o \ |
| 30 | $(BUILDDIR)/execution/executor.o \ |
| 31 | $(BUILDDIR)/fortsh.o |
| 32 | |
| 33 | # Target executable |
| 34 | TARGET = $(BINDIR)/fortsh |
| 35 | |
| 36 | # Default target |
| 37 | all: $(TARGET) |
| 38 | |
| 39 | # Create directories |
| 40 | $(BUILDDIR) $(BINDIR): |
| 41 | mkdir -p $@ |
| 42 | |
| 43 | $(BUILDDIR)/common $(BUILDDIR)/system $(BUILDDIR)/parsing $(BUILDDIR)/execution $(BUILDDIR)/scripting $(BUILDDIR)/io: | $(BUILDDIR) |
| 44 | mkdir -p $@ |
| 45 | |
| 46 | # Build target |
| 47 | $(TARGET): $(OBJECTS) | $(BINDIR) |
| 48 | $(FC) $(OBJECTS) -o $@ $(LDFLAGS) |
| 49 | @echo "Fortsh built successfully!" |
| 50 | |
| 51 | # Individual compilation rules with proper dependencies |
| 52 | $(BUILDDIR)/common/types.o: src/common/types.f90 | $(BUILDDIR)/common |
| 53 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 54 | |
| 55 | $(BUILDDIR)/common/error_handling.o: src/common/error_handling.f90 | $(BUILDDIR)/common |
| 56 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 57 | |
| 58 | $(BUILDDIR)/common/performance.o: src/common/performance.f90 | $(BUILDDIR)/common |
| 59 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 60 | |
| 61 | $(BUILDDIR)/system/interface.o: src/system/interface.f90 $(BUILDDIR)/common/types.o | $(BUILDDIR)/system |
| 62 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 63 | |
| 64 | $(BUILDDIR)/system/signals.o: src/system/signals.f90 $(BUILDDIR)/system/interface.o | $(BUILDDIR)/system |
| 65 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 66 | |
| 67 | $(BUILDDIR)/parsing/glob.o: src/parsing/glob.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/common/performance.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/parsing |
| 68 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 69 | |
| 70 | $(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)/parsing/glob.o | $(BUILDDIR)/parsing |
| 71 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 72 | |
| 73 | $(BUILDDIR)/execution/jobs.o: src/execution/jobs.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/execution |
| 74 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 75 | |
| 76 | $(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 |
| 77 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 78 | |
| 79 | $(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)/parsing/parser.o | $(BUILDDIR)/execution |
| 80 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 81 | |
| 82 | $(BUILDDIR)/scripting/control_flow.o: src/scripting/control_flow.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/scripting |
| 83 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 84 | |
| 85 | $(BUILDDIR)/scripting/test_builtin.o: src/scripting/test_builtin.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/scripting |
| 86 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 87 | |
| 88 | $(BUILDDIR)/scripting/variables.o: src/scripting/variables.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/scripting |
| 89 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 90 | |
| 91 | $(BUILDDIR)/scripting/config.o: src/scripting/config.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o $(BUILDDIR)/scripting/variables.o | $(BUILDDIR)/scripting |
| 92 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 93 | |
| 94 | $(BUILDDIR)/scripting/aliases.o: src/scripting/aliases.f90 $(BUILDDIR)/common/types.o | $(BUILDDIR)/scripting |
| 95 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 96 | |
| 97 | $(BUILDDIR)/io/readline.o: src/io/readline.f90 $(BUILDDIR)/common/types.o $(BUILDDIR)/system/interface.o | $(BUILDDIR)/io |
| 98 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 99 | |
| 100 | $(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) |
| 101 | $(FC) $(FCFLAGS) -J$(BUILDDIR) -c $< -o $@ |
| 102 | |
| 103 | # Clean targets |
| 104 | clean: |
| 105 | rm -rf $(BUILDDIR) $(BINDIR) |
| 106 | @echo "Clean completed!" |
| 107 | |
| 108 | distclean: clean |
| 109 | rm -f *.mod |
| 110 | |
| 111 | # Install target (optional) |
| 112 | install: $(TARGET) |
| 113 | cp $(TARGET) /usr/local/bin/ |
| 114 | @echo "Fortsh installed to /usr/local/bin/" |
| 115 | |
| 116 | # Development targets |
| 117 | test: $(TARGET) |
| 118 | @echo "Running basic functionality test..." |
| 119 | @echo "echo 'Hello from Fortsh!'" | $(TARGET) |
| 120 | |
| 121 | debug: FCFLAGS += -g -fbacktrace -fcheck=bounds |
| 122 | debug: $(TARGET) |
| 123 | |
| 124 | # Help target |
| 125 | help: |
| 126 | @echo "Fortran Shell (Fortsh) Build System" |
| 127 | @echo "===================================" |
| 128 | @echo "" |
| 129 | @echo "Available targets:" |
| 130 | @echo " all - Build fortsh (default)" |
| 131 | @echo " clean - Remove build artifacts" |
| 132 | @echo " distclean - Remove all generated files" |
| 133 | @echo " install - Install fortsh to /usr/local/bin" |
| 134 | @echo " test - Run basic functionality test" |
| 135 | @echo " debug - Build with debug flags" |
| 136 | @echo " help - Show this help" |
| 137 | @echo " dist - Create distribution package" |
| 138 | @echo " rpm - Build RPM package" |
| 139 | @echo " check - Run comprehensive checks" |
| 140 | @echo " smoke-test- Run basic functionality tests" |
| 141 | |
| 142 | # Package information |
| 143 | PACKAGE = fortsh |
| 144 | VERSION = 1.0.0 |
| 145 | |
| 146 | # Distribution and packaging targets |
| 147 | dist: clean |
| 148 | @echo "Creating distribution package..." |
| 149 | tar czf $(PACKAGE)-$(VERSION).tar.gz \ |
| 150 | --exclude='.git*' \ |
| 151 | --exclude='*.o' \ |
| 152 | --exclude='*.mod' \ |
| 153 | --exclude='build' \ |
| 154 | --exclude='bin' \ |
| 155 | --transform 's,^,$(PACKAGE)-$(VERSION)/,' \ |
| 156 | src/ tests/ Makefile README.md fortsh.spec |
| 157 | |
| 158 | rpm: dist |
| 159 | @echo "Building RPM package..." |
| 160 | @command -v rpmbuild >/dev/null 2>&1 || (echo "rpmbuild not available - install rpm-build package" && exit 1) |
| 161 | mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} |
| 162 | cp $(PACKAGE)-$(VERSION).tar.gz ~/rpmbuild/SOURCES/ |
| 163 | cp $(PACKAGE).spec ~/rpmbuild/SPECS/ |
| 164 | rpmbuild -ba ~/rpmbuild/SPECS/$(PACKAGE).spec |
| 165 | @echo "RPM packages created in ~/rpmbuild/RPMS/" |
| 166 | |
| 167 | dev-install: $(TARGET) |
| 168 | @echo "Installing fortsh for development..." |
| 169 | mkdir -p ~/.local/bin |
| 170 | cp $(TARGET) ~/.local/bin/ |
| 171 | @echo "fortsh installed to ~/.local/bin/fortsh" |
| 172 | @echo "Make sure ~/.local/bin is in your PATH" |
| 173 | |
| 174 | uninstall: |
| 175 | @echo "Uninstalling fortsh..." |
| 176 | @rm -f ~/.local/bin/fortsh 2>/dev/null || true |
| 177 | @rm -f /usr/local/bin/fortsh 2>/dev/null || sudo rm -f /usr/local/bin/fortsh 2>/dev/null || true |
| 178 | @echo "Uninstall complete!" |
| 179 | |
| 180 | check: $(TARGET) |
| 181 | @echo "Running comprehensive checks..." |
| 182 | @echo "✓ Build system works" |
| 183 | ./tests/integration_test.sh |
| 184 | @echo "✓ Integration tests completed" |
| 185 | |
| 186 | smoke-test: $(TARGET) |
| 187 | @echo "Running smoke tests..." |
| 188 | @echo "echo 'Hello from Fortsh!'" | $(TARGET) && echo "✓ Basic execution works" |
| 189 | @echo -e "help\nexit" | $(TARGET) >/dev/null && echo "✓ Help command works" |
| 190 | @echo -e "echo *.txt\nexit" | $(TARGET) >/dev/null && echo "✓ Glob expansion works" |
| 191 | @echo "perf on\necho 'test'\nperf\nexit" | $(TARGET) >/dev/null && echo "✓ Performance monitoring works" |
| 192 | @echo "All smoke tests passed!" |
| 193 | |
| 194 | .PHONY: all clean distclean install test debug help dist rpm dev-install uninstall check smoke-test |