-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
161 lines (125 loc) · 5.27 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
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
156
157
158
159
160
161
##=============================================================================#
# makefile
#
# author: Tom Verloop
# last change: 16/6/2016
#
# Makefile c/c++ projects
#=============================================================================#
#=============================================================================#
# include configuration
#=============================================================================#
include makefile.cfg
#=============================================================================#
# set the VPATH according to SRCS_DIRS
#=============================================================================#
VPATH = $(SRCS_DIRS)
#=============================================================================#
# when using output folder, append trailing slash to its name
#=============================================================================#
ifeq ($(strip $(OUT_DIR)), )
OUT_DIR_F =
else
OUT_DIR_F = $(strip $(OUT_DIR))/
endif
#=============================================================================#
# various compilation flags
#=============================================================================#
# core flags
CORE_FLAGS =
# flags for C++ compiler
CXX_FLAGS = -std=$(CXX_STD) -g3 -Wall
# flags for C compiler
C_FLAGS = -std=$(C_STD) -g3 -Wall
# flags for assembler
AS_FLAGS =
# flags for linker
LD_FLAGS =
#=============================================================================#
# do some formatting
#=============================================================================#
CXX_OBJS = $(addprefix $(OUT_DIR_F), $(notdir $(CXX_SRCS:.$(CXX_EXT)=.o)))
C_OBJS = $(addprefix $(OUT_DIR_F), $(notdir $(C_SRCS:.$(C_EXT)=.o)))
AS_OBJS = $(addprefix $(OUT_DIR_F), $(notdir $(AS_SRCS:.$(AS_EXT)=.o)))
OBJS = $(AS_OBJS) $(C_OBJS) $(CXX_OBJS) $(USER_OBJS)
DEPS = $(OBJS:.o=.d)
INC_DIRS_F = -I. $(patsubst %, -I%, $(INC_DIRS))
LIB_DIRS_F = $(patsubst %, -L%, $(LIB_DIRS))
ifeq ($(OS),Windows_NT)
EXECUTABLE = $(OUT_DIR_F)$(PROJECT).exe
else
EXECUTABLE = $(OUT_DIR_F)$(PROJECT)
endif
# format final flags for tools, request dependancies for C++, C and asm
CXX_FLAGS_F = $(CORE_FLAGS) $(OPTIMIZATION) $(CXX_WARNINGS) $(CXX_FLAGS) $(CXX_DEFS) -MD -MP -MF $(OUT_DIR_F)$(@F:.o=.d) $(INC_DIRS_F)
C_FLAGS_F = $(CORE_FLAGS) $(OPTIMIZATION) $(C_WARNINGS) $(C_FLAGS) $(C_DEFS) -MD -MP -MF $(OUT_DIR_F)$(@F:.o=.d) $(INC_DIRS_F)
AS_FLAGS_F = $(CORE_FLAGS) $(AS_FLAGS) $(AS_DEFS) -MD -MP -MF $(OUT_DIR_F)$(@F:.o=.d) $(INC_DIRS_F)
LD_FLAGS_F = $(CORE_FLAGS) $(LD_FLAGS) $(LIB_DIRS_F)
#contents of output directory
GENERATED = $(wildcard $(patsubst %, $(OUT_DIR_F)*.%, bin d dmp elf hex lss lst map o su stk cgraph asm))
#=============================================================================#
# make all
#=============================================================================#
all : make_output_dir $(EXECUTABLE)
# make object files dependent on Makefile
$(OBJS) : makefile makefile.cfg
#-----------------------------------------------------------------------------#
# linking - objects -> Executable
#-----------------------------------------------------------------------------#
$(EXECUTABLE) : $(OBJS)
@echo 'Linking target: $(PROJECT)'
$(CXX) $(LD_FLAGS_F) $(OBJS) $(LIBS) -o $@
@echo ' '
#-----------------------------------------------------------------------------#
# compiling - C++ source -> objects
#-----------------------------------------------------------------------------#
$(OUT_DIR_F)%.o : %.$(CXX_EXT)
@echo 'Compiling file: $<'
$(CXX) -c $(CXX_FLAGS_F) $< -o $@
@echo ' '
#-----------------------------------------------------------------------------#
# compiling - C source -> objects
#-----------------------------------------------------------------------------#
$(OUT_DIR_F)%.o : %.$(C_EXT)
@echo 'Compiling file: $<'
$(CC) -c $(C_FLAGS_F) $< -o $@
@echo ' '
#-----------------------------------------------------------------------------#
# assembling - ASM source -> objects
#-----------------------------------------------------------------------------#
$(OUT_DIR_F)%.o : %.$(AS_EXT)
@echo 'Assembling file: $<'
$(AS) -c $(AS_FLAGS_F) $< -o $@
@echo ' '
#-----------------------------------------------------------------------------#
# create the desired output directory
#-----------------------------------------------------------------------------#
make_output_dir :
$(shell mkdir $(OUT_DIR_F) 2>/dev/null)
#=============================================================================#
# make clean
#=============================================================================#
clean:
ifeq ($(strip $(OUT_DIR_F)), )
@echo 'Removing all generated output files'
else
@echo 'Removing all generated output files from output directory: $(OUT_DIR_F)'
endif
ifneq ($(strip $(GENERATED)), )
$(RM) $(GENERATED)
else
@echo 'Nothing to remove...'
endif
#=============================================================================#
# make doxygen
#=============================================================================#
doxygen :
@echo 'generating doxygen documentation'
doxygen
#=============================================================================#
# global exports
#=============================================================================#
.PHONY: all clean dependents
.SECONDARY:
# include dependancy files
-include $(DEPS)