Makefile · 5299 bytes Raw Blame History
1 # Makefile for FORTBITE - Modern Fortran Calculator
2 # Author: espadonne (mfw)
3
4 # Compiler and flags
5 FC = gfortran
6 FFLAGS = -Wall -Wextra -fcheck=all -g -O2 -std=f2008
7 LDFLAGS =
8 LIBS =
9
10 # Directories
11 SRCDIR = src
12 BUILDDIR = build
13 MODDIR = $(BUILDDIR)/mod
14 BINDIR = $(BUILDDIR)/bin
15
16 # Target executable
17 TARGET = $(BINDIR)/fortbite
18
19 # Source files (order matters for dependencies)
20 SOURCES = $(SRCDIR)/fortbite_precision_m.f90 \
21 $(SRCDIR)/fortbite_types_m.f90 \
22 $(SRCDIR)/fortbite_matrix_m.f90 \
23 $(SRCDIR)/fortbite_functions_m.f90 \
24 $(SRCDIR)/fortbite_arithmetic_m.f90 \
25 $(SRCDIR)/fortbite_ast_m.f90 \
26 $(SRCDIR)/fortbite_lexer_m.f90 \
27 $(SRCDIR)/fortbite_parser_m.f90 \
28 $(SRCDIR)/fortbite_evaluator_m.f90 \
29 $(SRCDIR)/fortbite_io_m.f90 \
30 $(SRCDIR)/fortbite.f90
31
32 # Object files
33 OBJECTS = $(SOURCES:$(SRCDIR)/%.f90=$(BUILDDIR)/%.o)
34
35 # Default target
36 all: directories $(TARGET)
37
38 # Create necessary directories
39 directories:
40 @mkdir -p $(BUILDDIR) $(MODDIR) $(BINDIR)
41
42 # Link the executable
43 $(TARGET): $(OBJECTS)
44 $(FC) $(LDFLAGS) -J$(MODDIR) -o $@ $^ $(LIBS)
45 @echo "Built FORTBITE successfully!"
46
47 # Compile Fortran source files
48 $(BUILDDIR)/%.o: $(SRCDIR)/%.f90
49 $(FC) $(FFLAGS) -J$(MODDIR) -c $< -o $@
50
51 # Dependencies (manually specified for now)
52 $(BUILDDIR)/fortbite_types_m.o: $(BUILDDIR)/fortbite_precision_m.o
53 $(BUILDDIR)/fortbite_matrix_m.o: $(BUILDDIR)/fortbite_types_m.o
54 $(BUILDDIR)/fortbite_functions_m.o: $(BUILDDIR)/fortbite_types_m.o
55 $(BUILDDIR)/fortbite_arithmetic_m.o: $(BUILDDIR)/fortbite_precision_m.o $(BUILDDIR)/fortbite_types_m.o $(BUILDDIR)/fortbite_matrix_m.o
56 $(BUILDDIR)/fortbite_ast_m.o: $(BUILDDIR)/fortbite_types_m.o
57 $(BUILDDIR)/fortbite_lexer_m.o: $(BUILDDIR)/fortbite_types_m.o
58 $(BUILDDIR)/fortbite_parser_m.o: $(BUILDDIR)/fortbite_types_m.o $(BUILDDIR)/fortbite_ast_m.o
59 $(BUILDDIR)/fortbite_evaluator_m.o: $(BUILDDIR)/fortbite_types_m.o $(BUILDDIR)/fortbite_ast_m.o $(BUILDDIR)/fortbite_arithmetic_m.o $(BUILDDIR)/fortbite_functions_m.o $(BUILDDIR)/fortbite_matrix_m.o
60 $(BUILDDIR)/fortbite_io_m.o: $(BUILDDIR)/fortbite_precision_m.o $(BUILDDIR)/fortbite_types_m.o $(BUILDDIR)/fortbite_lexer_m.o $(BUILDDIR)/fortbite_parser_m.o $(BUILDDIR)/fortbite_evaluator_m.o $(BUILDDIR)/fortbite_ast_m.o
61 $(BUILDDIR)/fortbite.o: $(BUILDDIR)/fortbite_precision_m.o $(BUILDDIR)/fortbite_types_m.o $(BUILDDIR)/fortbite_io_m.o
62
63 # Clean up
64 clean:
65 rm -rf $(BUILDDIR)
66
67 # Run the program
68 run: $(TARGET)
69 ./$(TARGET)
70
71 # Install (optional)
72 install: $(TARGET)
73 cp $(TARGET) /usr/local/bin/fortbite
74
75 # Test compilation
76 TEST_FRAMEWORK = tests/test_framework.f90
77 TEST_SOURCES = tests/unit/test_arithmetic.f90 \
78 tests/unit/test_functions.f90 \
79 tests/integration/test_expressions.f90
80
81 TEST_OBJECTS = $(TEST_SOURCES:tests/%.f90=$(BUILDDIR)/tests/%.o) \
82 $(BUILDDIR)/tests/test_framework.o
83
84 TEST_EXECUTABLES = $(TEST_SOURCES:tests/%.f90=$(BUILDDIR)/tests/%)
85
86 # Build test framework
87 $(BUILDDIR)/tests/test_framework.o: $(TEST_FRAMEWORK) directories
88 @mkdir -p $(BUILDDIR)/tests/unit $(BUILDDIR)/tests/integration
89 $(FC) $(FFLAGS) -J$(MODDIR) -c $< -o $@
90
91 # Library objects (all except main program)
92 LIB_OBJECTS = $(filter-out $(BUILDDIR)/fortbite.o, $(OBJECTS))
93
94 # Build test executables
95 $(BUILDDIR)/tests/unit/%.o: tests/unit/%.f90 $(BUILDDIR)/tests/test_framework.o $(LIB_OBJECTS)
96 $(FC) $(FFLAGS) -J$(MODDIR) -I$(MODDIR) -c $< -o $@
97
98 $(BUILDDIR)/tests/integration/%.o: tests/integration/%.f90 $(BUILDDIR)/tests/test_framework.o $(LIB_OBJECTS)
99 $(FC) $(FFLAGS) -J$(MODDIR) -I$(MODDIR) -c $< -o $@
100
101 $(BUILDDIR)/tests/unit/%: $(BUILDDIR)/tests/unit/%.o $(BUILDDIR)/tests/test_framework.o $(LIB_OBJECTS)
102 $(FC) $(LDFLAGS) -J$(MODDIR) -o $@ $^
103
104 $(BUILDDIR)/tests/integration/%: $(BUILDDIR)/tests/integration/%.o $(BUILDDIR)/tests/test_framework.o $(LIB_OBJECTS)
105 $(FC) $(LDFLAGS) -J$(MODDIR) -o $@ $^
106
107 # Test targets
108 test-build: directories $(TARGET) $(TEST_EXECUTABLES)
109 @echo "Test build complete!"
110
111 test: test-build
112 @./tests/run_tests.sh --no-build
113
114 test-unit: test-build
115 @echo "Running unit tests..."
116 @$(BUILDDIR)/tests/unit/test_arithmetic || true
117 @$(BUILDDIR)/tests/unit/test_functions || true
118
119 test-integration: test-build
120 @echo "Running integration tests..."
121 @$(BUILDDIR)/tests/integration/test_expressions || true
122
123 test-verbose: test-build
124 @for test in $(TEST_EXECUTABLES); do \
125 echo "=== Running $$test ==="; \
126 $$test || true; \
127 echo; \
128 done
129
130 # Clean including tests
131 clean-all: clean
132 rm -rf test_results
133
134 # Help
135 help:
136 @echo "FORTBITE Makefile targets:"
137 @echo " all - Build the executable (default)"
138 @echo " clean - Remove build files"
139 @echo " clean-all - Remove build files and test results"
140 @echo " run - Build and run FORTBITE"
141 @echo " install - Install to /usr/local/bin"
142 @echo " test - Run all tests"
143 @echo " test-unit - Run unit tests only"
144 @echo " test-integration - Run integration tests only"
145 @echo " test-verbose - Run all tests with full output"
146 @echo " test-build - Build test executables only"
147 @echo " help - Show this help message"
148
149 .PHONY: all clean clean-all run install help directories test test-unit test-integration test-verbose test-build