-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
68 lines (52 loc) · 2.08 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
EXECUTABLE = tourexec
LIBRARY = libstrategies.so
COMPILER = gfortran
CFLAGS = -fno-automatic -fPIC
LINKER = gfortran
SRC_DIR = src
STRATEGY_SRC_DIR = $(SRC_DIR)/strategies
TOURNAMENT_SRC_DIR = $(SRC_DIR)/tournament
OBJ_DIR = obj
STRATEGY_OBJ_DIR = $(OBJ_DIR)/strategies
TOURNAMENT_OBJ_DIR = $(OBJ_DIR)/tournament
BIN_DIR = bin
# Use make's wildcard function to generate lists of source code files
STRATEGY_SOURCES := $(wildcard $(STRATEGY_SRC_DIR)/*.f)
TOURNAMENT_SOURCES := $(wildcard $(TOURNAMENT_SRC_DIR)/*.f)
# Use make's substitution references to define corresponding lists of object files
STRATEGY_OBJECTS := $(STRATEGY_SOURCES:$(STRATEGY_SRC_DIR)/%.f=$(STRATEGY_OBJ_DIR)/%.o)
TOURNAMENT_OBJECTS := $(TOURNAMENT_SOURCES:$(TOURNAMENT_SRC_DIR)/%.f=$(TOURNAMENT_OBJ_DIR)/%.o)
rm = rm -rf
.PHONY: all install uninstall clean remove
all: $(BIN_DIR)/$(EXECUTABLE)
install: $(BIN_DIR)/$(EXECUTABLE)
install -m 0755 $(BIN_DIR)/$(LIBRARY) /usr/local/lib
install -m 0755 $(BIN_DIR)/$(EXECUTABLE) /usr/local/bin
uninstall:
rm /usr/local/lib/$(LIBRARY)
rm /usr/local/bin/$(EXECUTABLE)
# Link the tournament object files and the strategies shared object file to create the executable
$(BIN_DIR)/$(EXECUTABLE): $(TOURNAMENT_OBJECTS) $(BIN_DIR)/$(LIBRARY)
@$(LINKER) -L $(BIN_DIR) $(TOURNAMENT_OBJECTS) -l strategies -o $@
@echo "Created executable file "$@
# Link the strategy object files to a create a single shared object file
$(BIN_DIR)/$(LIBRARY): $(STRATEGY_OBJECTS)
@mkdir -p $(@D)
@$(LINKER) -shared $(STRATEGY_OBJECTS) -o $@
@echo "Built shared object file "$@
# Compile all strategy source files to object files
$(STRATEGY_OBJECTS): $(STRATEGY_OBJ_DIR)/%.o : $(STRATEGY_SRC_DIR)/%.f
@mkdir -p $(@D)
@$(COMPILER) $(CFLAGS) -c $< -o $@
@echo "Compiled "$<" to "$@
# Compile all tournament source files to object files
$(TOURNAMENT_OBJECTS): $(TOURNAMENT_OBJ_DIR)/%.o : $(TOURNAMENT_SRC_DIR)/%.f
@mkdir -p $(@D)
@$(COMPILER) $(CFLAGS) -c $< -o $@
@echo "Compiled "$<" to "$@
clean:
@$(rm) $(OBJ_DIR)
@echo "Removed obj directory"
remove: clean
@$(rm) $(BIN_DIR)
@echo "Removed bin directory"