Skip to content

Commit 56888ab

Browse files
committed
Modify makefile to create and use shared object file
1 parent 9f59547 commit 56888ab

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

Makefile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,60 @@
1+
EXECUTABLE = tourexec
2+
LIBRARY = libstrategies.so
13

4+
COMPILER = gfortran
5+
CFLAGS = -fno-automatic
6+
7+
LINKER = gfortran
8+
9+
SRC_DIR = src
10+
STRATEGY_SRC_DIR = $(SRC_DIR)/strategies
11+
TOURNAMENT_SRC_DIR = $(SRC_DIR)/tournament
12+
13+
OBJ_DIR = obj
14+
STRATEGY_OBJ_DIR = $(OBJ_DIR)/strategies
15+
TOURNAMENT_OBJ_DIR = $(OBJ_DIR)/tournament
16+
17+
BIN_DIR = bin
18+
19+
# Use make's wildcard function to generate lists of source code files
20+
STRATEGY_SOURCES := $(wildcard $(STRATEGY_SRC_DIR)/*.f)
21+
TOURNAMENT_SOURCES := $(wildcard $(TOURNAMENT_SRC_DIR)/*.f)
22+
# Use make's substitution references to define corresponding lists of object files
23+
STRATEGY_OBJECTS := $(STRATEGY_SOURCES:$(STRATEGY_SRC_DIR)/%.f=$(STRATEGY_OBJ_DIR)/%.o)
24+
TOURNAMENT_OBJECTS := $(TOURNAMENT_SOURCES:$(TOURNAMENT_SRC_DIR)/%.f=$(TOURNAMENT_OBJ_DIR)/%.o)
25+
26+
rm = rm -rf
27+
28+
.PHONY: all clean remove
29+
all: $(BIN_DIR)/$(EXECUTABLE)
30+
31+
# Link the tournament object files and the strategies shared object file to create the executable
32+
$(BIN_DIR)/$(EXECUTABLE): $(TOURNAMENT_OBJECTS) $(BIN_DIR)/$(LIBRARY)
33+
@$(LINKER) -L $(BIN_DIR) $(TOURNAMENT_OBJECTS) -l strategies -o $@
34+
@echo "Created executable file "$@
35+
36+
# Link the strategy object files to a create a single shared object file
37+
$(BIN_DIR)/$(LIBRARY): $(STRATEGY_OBJECTS)
38+
@mkdir -p $(@D)
39+
@$(LINKER) -shared $(STRATEGY_OBJECTS) -o $@
40+
@echo "Built shared object file "$@
41+
42+
# Compile all strategy source files to object files
43+
$(STRATEGY_OBJECTS): $(STRATEGY_OBJ_DIR)/%.o : $(STRATEGY_SRC_DIR)/%.f
44+
@mkdir -p $(@D)
45+
@$(COMPILER) $(CFLAGS) -c $< -o $@
46+
@echo "Compiled "$<" to "$@
47+
48+
# Compile all tournament source files to object files
49+
$(TOURNAMENT_OBJECTS): $(TOURNAMENT_OBJ_DIR)/%.o : $(TOURNAMENT_SRC_DIR)/%.f
50+
@mkdir -p $(@D)
51+
@$(COMPILER) $(CFLAGS) -c $< -o $@
52+
@echo "Compiled "$<" to "$@
53+
54+
clean:
55+
@$(rm) $(OBJ_DIR)
56+
@echo "Removed obj directory"
57+
58+
remove: clean
59+
@$(rm) $(BIN_DIR)
60+
@echo "Removed bin directory"

0 commit comments

Comments
 (0)