-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
155 lines (127 loc) · 3.69 KB
/
Makefile
File metadata and controls
155 lines (127 loc) · 3.69 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# C Project Makefile
#========= Debug mode setup ========#
# debug.h macros.
DEBUG := -DDEBUG -DVERBOSE -UTRACE
NDEBUG := -UDEBUG -DVERBOSE -UTRACE
#===== Compiler / linker setup =====#
# gcc with MinGW setup.
CC := gcc
CFLAGS := -g -O3 -Wall -Wpedantic -Wextra -std=gnu99
DFLAGS := -MP -MMD
LFLAGS := -s -lm
INCLUDE :=
LIBRARY :=
IMPORTANT := data lib
#======== Source code setup ========#
# Directory for all project files and
# the main.c file.
INCLUDE_DIR := ./src
SRC_DIR := ./src
# Source files
# CFILES excluses MAIN
CFILES := $(wildcard $(SRC_DIR)/*.c)
HFILES := $(wildcard $(INCLUDE_DIR)/*.h)
IMPORTANT += $(SRC_DIR)
# Important files
MAKEFILE := Makefile
IMPORTANT += $(MAKEFILE) README.md
#=========== Build setup ===========#
# Directory for built files.
BUILD_DIR := build
OFILES := $(CFILES:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
DFILES := $(OFILES:%.o=%.d)
# Tar file of the entire project
TAR := ./project.tar.gz
#========= Source archive ==========#
# Archive name
ARCHIVE := $(BUILD_DIR)/liball.a
# Linking
INCLUDE += -I$(INCLUDE_DIR)
LIBRARY += -L$(BUILD_DIR) -lall
#=========== OpenGL Setup ==========#
ifeq ($(shell uname),Linux)
CFLAGS += -UWINDOWS -DGLEW_STATIC
LIBRARY += -lGLEW -lglut -lGL -lGLU -UWINDOWS
else
CFLAGS += -DWINDOWS -DGLEW_STATIC
LIBRARY += -lglew32 -lglut32win -lopengl32 -lglu32
endif
#========== libshared Setup =========#
LIB_DIR := lib
LIBSHARED_DIR := $(LIB_DIR)/libshared
INCLUDE += -I$(LIBSHARED_DIR)/include
LIBRARY += -L$(LIBSHARED_DIR)/bin -lshared
#============ Main files ===========#
# Standalone text executable sources
# to link with the rest of the code.
MAIN_DIR := main
MCFILES := $(wildcard $(MAIN_DIR)/*.c)
MOFILES := $(MCFILES:$(MAIN_DIR)/%.c=$(BUILD_DIR)/$(MAIN_DIR)/%.o)
MDFILES := $(MOFILES:%.o=%.d)
IMPORTANT += $(MCFILES)
ALL_EXECUTABLES := $(MCFILES:$(MAIN_DIR)/%.c=%.exe)
TESTS := $(filter test_%.exe,$(ALL_EXECUTABLES))
EXECUTABLES := $(filter-out test_%.exe,$(ALL_EXECUTABLES))
#========== Documentation ==========#
# Doxygen documentation setup
DOC_DIR := docs
DOXYFILE := Doxyfile
DOXFILES := $(wildcard doxygen/*)
IMPORTANT += $(DOXYFILE) $(DOXFILES)
#============== Rules ==============#
# Default: just make executables
.PHONY: default
default: $(BUILD_DIR) libshared $(ARCHIVE) $(EXECUTABLES)
# Make just the tests
.PHONY: tests
tests: $(BUILD_DIR) $(ARCHIVE) $(TESTS)
# Default - make the executable
.PHONY: all
all: default tests
# Make libshared
.PHONY: libshared
libshared:
$(MAKE) -C $(LIBSHARED_DIR) default
# Put all the .o files in the build directory
$(BUILD_DIR):
-mkdir $@
-mkdir $@/$(MAIN_DIR)
# Compile the source files
.SECONDARY: $(DFILES)
.SECONDARY: $(OFILES)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(MAKEFILE)
$(CC) $(CFLAGS) $(DFLAGS) $(DEBUG) $(INCLUDE) -c $< -o $@
# Compile the main method executables
.SECONDARY: $(MDFILES)
.SECONDARY: $(MOFILES)
$(BUILD_DIR)/$(MAIN_DIR)/%.o: $(MAIN_DIR)/%.c $(MAKEFILE)
$(CC) $(CFLAGS) $(DFLAGS) $(DEBUG) $(INCLUDE) -c $< -o $@
# Automatic dependency files
-include $(DFILES)
-include $(MDFILES)
# Documentation
.PHONY: documentation
documentation: $(DOC_DIR)
$(DOC_DIR): $(DOXFILES) $(CFILES) $(HFILES) $(MCFILES)
doxygen Doxyfile
# Make archive of the code
.PHONY: archive
archive: $(ARCHIVE)
$(ARCHIVE): $(OFILES)
ar -rcs $@ $^
# Make executable for each driver
%.exe: $(BUILD_DIR)/$(MAIN_DIR)/%.o $(ARCHIVE)
$(CC) -o $@ $< $(LIBRARY) $(LFLAGS)
#============== Clean ==============#
# Clean up build files and executable
.PHONY: clean
clean:
-rm -rf $(BUILD_DIR) $(EXECUTABLES) $(TESTS) $(ARCHIVE)
$(MAKE) -C $(LIBSHARED_DIR) clean
#============= Archive =============#
# Package all the files into a tar.
.PHONY: tar
tar: $(TAR)
$(TAR): $(IMPORTANT)
tar -czvf $@ $^
#===================================#