Skip to content

Commit 0ca4176

Browse files
committed
Update makefile to compile multiple source files
1 parent ba4c390 commit 0ca4176

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
bin/
1+
bin/
2+
obj/

Makefile

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
# Generate an executable with this name
21
TARGET = tourexec
32

4-
# Define the compiler and flags to pass to that compiler
53
CC = gfortran
64
CFLAGS = -fno-automatic
75

8-
# Define the directories for source code and output binary executable
6+
LINKER = gfortran
7+
98
SRC_DIR = src
109
BIN_DIR = bin
10+
OBJ_DIR = obj
11+
12+
SOURCES := $(wildcard $(SRC_DIR)/*.f)
13+
OBJECTS := $(SOURCES:$(SRC_DIR)/%.f=$(OBJ_DIR)/%.o)
14+
rm = rm -rf
15+
16+
$(BIN_DIR)/$(TARGET): $(OBJECTS)
17+
@mkdir -p $(@D)
18+
@$(LINKER) $(OBJECTS) -o $@
19+
@echo "Linking complete"
1120

12-
$(BIN_DIR)/$(TARGET): $(SRC_DIR)/*.f
21+
$(OBJECTS): $(OBJ_DIR)/%.o : $(SRC_DIR)/%.f
1322
@mkdir -p $(@D)
14-
$(CC) $(CFLAGS) -o $@ $<
23+
@$(CC) $(CFLAGS) -c $< -o $@
24+
@echo "Compiled "$<" successfully"
25+
26+
.PHONY: clean
27+
clean:
28+
@$(rm) $(OBJ_DIR)
29+
@echo "Cleanup complete"
30+
31+
.PHONY: remove
32+
remove: clean
33+
@$(rm) $(BIN_DIR)
34+
@echo "Executable removed"

0 commit comments

Comments
 (0)