@@ -0,0 +1,72 @@ |
| 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_arithmetic_m.f90 \ |
| 23 | + $(SRCDIR)/fortbite_io_m.f90 \ |
| 24 | + $(SRCDIR)/fortbite.f90 |
| 25 | + |
| 26 | +# Object files |
| 27 | +OBJECTS = $(SOURCES:$(SRCDIR)/%.f90=$(BUILDDIR)/%.o) |
| 28 | + |
| 29 | +# Default target |
| 30 | +all: directories $(TARGET) |
| 31 | + |
| 32 | +# Create necessary directories |
| 33 | +directories: |
| 34 | + @mkdir -p $(BUILDDIR) $(MODDIR) $(BINDIR) |
| 35 | + |
| 36 | +# Link the executable |
| 37 | +$(TARGET): $(OBJECTS) |
| 38 | + $(FC) $(LDFLAGS) -J$(MODDIR) -o $@ $^ $(LIBS) |
| 39 | + @echo "Built FORTBITE successfully!" |
| 40 | + |
| 41 | +# Compile Fortran source files |
| 42 | +$(BUILDDIR)/%.o: $(SRCDIR)/%.f90 |
| 43 | + $(FC) $(FFLAGS) -J$(MODDIR) -c $< -o $@ |
| 44 | + |
| 45 | +# Dependencies (manually specified for now) |
| 46 | +$(BUILDDIR)/fortbite_types_m.o: $(BUILDDIR)/fortbite_precision_m.o |
| 47 | +$(BUILDDIR)/fortbite_arithmetic_m.o: $(BUILDDIR)/fortbite_precision_m.o $(BUILDDIR)/fortbite_types_m.o |
| 48 | +$(BUILDDIR)/fortbite_io_m.o: $(BUILDDIR)/fortbite_precision_m.o $(BUILDDIR)/fortbite_types_m.o |
| 49 | +$(BUILDDIR)/fortbite.o: $(BUILDDIR)/fortbite_precision_m.o $(BUILDDIR)/fortbite_types_m.o $(BUILDDIR)/fortbite_io_m.o |
| 50 | + |
| 51 | +# Clean up |
| 52 | +clean: |
| 53 | + rm -rf $(BUILDDIR) |
| 54 | + |
| 55 | +# Run the program |
| 56 | +run: $(TARGET) |
| 57 | + ./$(TARGET) |
| 58 | + |
| 59 | +# Install (optional) |
| 60 | +install: $(TARGET) |
| 61 | + cp $(TARGET) /usr/local/bin/fortbite |
| 62 | + |
| 63 | +# Help |
| 64 | +help: |
| 65 | + @echo "FORTBITE Makefile targets:" |
| 66 | + @echo " all - Build the executable (default)" |
| 67 | + @echo " clean - Remove build files" |
| 68 | + @echo " run - Build and run FORTBITE" |
| 69 | + @echo " install - Install to /usr/local/bin" |
| 70 | + @echo " help - Show this help message" |
| 71 | + |
| 72 | +.PHONY: all clean run install help directories |