| 1 |
# ------------------------------------------------------------------------------ |
| 2 |
# |
| 3 |
# Generic Makefile |
| 4 |
# |
| 5 |
# Copyright Marco Paland 2007 - 2017 |
| 6 |
# Distributed under the MIT License |
| 7 |
# |
| 8 |
# ------------------------------------------------------------------------------ |
| 9 |
|
| 10 |
# ------------------------------------------------------------------------------ |
| 11 |
# Paths |
| 12 |
# ------------------------------------------------------------------------------ |
| 13 |
PATH_TOOLS_CC = /usr/bin/ |
| 14 |
PATH_TOOLS_CC_LIB = /usr/lib/ |
| 15 |
PATH_TOOLS_UTIL = |
| 16 |
|
| 17 |
PATH_BIN = bin |
| 18 |
PATH_TMP = tmp |
| 19 |
PATH_NUL = /dev/null |
| 20 |
PATH_OBJ = $(PATH_TMP)/obj |
| 21 |
PATH_LST = $(PATH_TMP)/lst |
| 22 |
PATH_ERR = $(PATH_TMP)/err |
| 23 |
PATH_PRE = $(PATH_TMP)/pre |
| 24 |
PATH_COV = $(PATH_TMP)/cov |
| 25 |
|
| 26 |
|
| 27 |
# ------------------------------------------------------------------------------ |
| 28 |
# Application to build |
| 29 |
# ------------------------------------------------------------------------------ |
| 30 |
|
| 31 |
APP = test_suite |
| 32 |
|
| 33 |
|
| 34 |
# ----------------------------------------------------------------------------- |
| 35 |
# Project file list |
| 36 |
# Format is: |
| 37 |
# FILES_PRJ = file1 \ |
| 38 |
# foo/file2 \ |
| 39 |
# bar/file3 |
| 40 |
# ----------------------------------------------------------------------------- |
| 41 |
|
| 42 |
FILES_PRJ = test/test_suite |
| 43 |
|
| 44 |
|
| 45 |
# ------------------------------------------------------------------------------ |
| 46 |
# Additional include files and compiler defines |
| 47 |
# Format is: |
| 48 |
# C_INCLUDES = -Iinclude_path1 \ |
| 49 |
# -Iinclude_path2 \ |
| 50 |
# -Iinclude_path3 \ |
| 51 |
# ------------------------------------------------------------------------------ |
| 52 |
|
| 53 |
C_INCLUDES = |
| 54 |
|
| 55 |
C_DEFINES = |
| 56 |
|
| 57 |
|
| 58 |
# ------------------------------------------------------------------------------ |
| 59 |
# The target name and location |
| 60 |
# ------------------------------------------------------------------------------ |
| 61 |
TRG = $(PATH_BIN)/$(APP) |
| 62 |
|
| 63 |
|
| 64 |
# ------------------------------------------------------------------------------ |
| 65 |
# object files |
| 66 |
# ------------------------------------------------------------------------------ |
| 67 |
FILES_TMP = $(FILES_PRJ) |
| 68 |
FILES_O = $(addsuffix .o, $(FILES_TMP)) |
| 69 |
|
| 70 |
|
| 71 |
# ------------------------------------------------------------------------------ |
| 72 |
# VPATH definition |
| 73 |
# |
| 74 |
# VPATH is required for the maker to find the C-/ASM-Source files. |
| 75 |
# Extract the directory/module names from the file list with the dir |
| 76 |
# command and remove the duplicated directory names with the sort command. |
| 77 |
# FILES_PRJ is listed first to make sure that the source files in the project |
| 78 |
# directory are searched first. |
| 79 |
# ------------------------------------------------------------------------------ |
| 80 |
VPATH := $(sort $(dir $(FILES_TMP))) |
| 81 |
|
| 82 |
|
| 83 |
# ------------------------------------------------------------------------------ |
| 84 |
# Development tools |
| 85 |
# ------------------------------------------------------------------------------ |
| 86 |
AR = $(PATH_TOOLS_CC)ar |
| 87 |
AS = $(PATH_TOOLS_CC)g++ |
| 88 |
CC = $(PATH_TOOLS_CC)g++ |
| 89 |
CL = $(PATH_TOOLS_CC)g++ |
| 90 |
NM = $(PATH_TOOLS_CC)nm |
| 91 |
GCOV = $(PATH_TOOLS_CC)gcov |
| 92 |
OBJDUMP = $(PATH_TOOLS_CC)objdump |
| 93 |
OBJCOPY = $(PATH_TOOLS_CC)objcopy |
| 94 |
READELF = $(PATH_TOOLS_CC)readelf |
| 95 |
SIZE = $(PATH_TOOLS_CC)size |
| 96 |
|
| 97 |
ECHO = $(PATH_TOOLS_UTIL)echo |
| 98 |
MAKE = $(PATH_TOOLS_UTIL)make |
| 99 |
MKDIR = $(PATH_TOOLS_UTIL)mkdir |
| 100 |
RM = $(PATH_TOOLS_UTIL)rm |
| 101 |
SED = $(PATH_TOOLS_UTIL)sed |
| 102 |
|
| 103 |
|
| 104 |
# ------------------------------------------------------------------------------ |
| 105 |
# Compiler flags for the target architecture |
| 106 |
# ------------------------------------------------------------------------------ |
| 107 |
|
| 108 |
GCCFLAGS = $(C_INCLUDES) \ |
| 109 |
$(C_DEFINES) \ |
| 110 |
-std=c++11 \ |
| 111 |
-g \ |
| 112 |
-Wall \ |
| 113 |
-pedantic \ |
| 114 |
-Wmain \ |
| 115 |
-Wundef \ |
| 116 |
-Wsign-conversion \ |
| 117 |
-Wuninitialized \ |
| 118 |
-Wshadow \ |
| 119 |
-Wunreachable-code \ |
| 120 |
-Wswitch-default \ |
| 121 |
-Wswitch \ |
| 122 |
-Wcast-align \ |
| 123 |
-Wmissing-include-dirs \ |
| 124 |
-Winit-self \ |
| 125 |
-Wdouble-promotion \ |
| 126 |
-gdwarf-2 \ |
| 127 |
-fno-exceptions \ |
| 128 |
-O2 \ |
| 129 |
-ffunction-sections \ |
| 130 |
-ffat-lto-objects \ |
| 131 |
-fdata-sections \ |
| 132 |
-fverbose-asm \ |
| 133 |
-Wextra \ |
| 134 |
-Wunused-parameter \ |
| 135 |
-Wfloat-equal |
| 136 |
|
| 137 |
CFLAGS = $(GCCFLAGS) \ |
| 138 |
-Wunsuffixed-float-constants \ |
| 139 |
-x c \ |
| 140 |
-std=c99 |
| 141 |
|
| 142 |
CPPFLAGS = $(GCCFLAGS) \ |
| 143 |
-x c++ \ |
| 144 |
-fno-rtti \ |
| 145 |
-fstrict-enums \ |
| 146 |
-fno-use-cxa-atexit \ |
| 147 |
-fno-use-cxa-get-exception-ptr \ |
| 148 |
-fno-nonansi-builtins \ |
| 149 |
-fno-threadsafe-statics \ |
| 150 |
-fno-enforce-eh-specs \ |
| 151 |
-ftemplate-depth-64 \ |
| 152 |
-fexceptions |
| 153 |
|
| 154 |
AFLAGS = $(GCCFLAGS) \ |
| 155 |
-x assembler |
| 156 |
|
| 157 |
LFLAGS = $(GCCFLAGS) \ |
| 158 |
-x none \ |
| 159 |
-Wl,--gc-sections |
| 160 |
|
| 161 |
# ------------------------------------------------------------------------------ |
| 162 |
# Targets |
| 163 |
# ------------------------------------------------------------------------------ |
| 164 |
|
| 165 |
# ------------------------------------------------------------------------------ |
| 166 |
# Main-Dependencies (app: all) |
| 167 |
# ------------------------------------------------------------------------------ |
| 168 |
.PHONY: all |
| 169 |
all: clean_prj $(TRG) $(TRG)_nm.txt |
| 170 |
|
| 171 |
|
| 172 |
# ------------------------------------------------------------------------------ |
| 173 |
# Main-Dependencies (app: rebuild) |
| 174 |
# ------------------------------------------------------------------------------ |
| 175 |
.PHONY: rebuild |
| 176 |
rebuild: clean $(TRG) $(TRG)_nm.txt |
| 177 |
|
| 178 |
|
| 179 |
# ------------------------------------------------------------------------------ |
| 180 |
# clean project |
| 181 |
# ------------------------------------------------------------------------------ |
| 182 |
.PHONY: clean_prj |
| 183 |
clean_prj: |
| 184 |
@-$(ECHO) +++ cleaning project |
| 185 |
@-$(RM) -rf $(PATH_BIN) 2> $(PATH_NUL) |
| 186 |
@-$(MKDIR) -p $(PATH_BIN) |
| 187 |
@-$(MKDIR) -p $(PATH_OBJ) |
| 188 |
@-$(MKDIR) -p $(PATH_ERR) |
| 189 |
@-$(MKDIR) -p $(PATH_LST) |
| 190 |
@-$(MKDIR) -p $(PATH_PRE) |
| 191 |
@-$(MKDIR) -p $(PATH_COV) |
| 192 |
|
| 193 |
|
| 194 |
# ------------------------------------------------------------------------------ |
| 195 |
# clean all |
| 196 |
# ------------------------------------------------------------------------------ |
| 197 |
.PHONY: clean |
| 198 |
clean: |
| 199 |
@-$(ECHO) +++ cleaning all |
| 200 |
@-$(RM) -rf $(PATH_BIN) 2> $(PATH_NUL) |
| 201 |
@-$(RM) -rf $(PATH_TMP) 2> $(PATH_NUL) |
| 202 |
@-$(MKDIR) -p $(PATH_BIN) |
| 203 |
@-$(MKDIR) -p $(PATH_OBJ) |
| 204 |
@-$(MKDIR) -p $(PATH_ERR) |
| 205 |
@-$(MKDIR) -p $(PATH_LST) |
| 206 |
@-$(MKDIR) -p $(PATH_COV) |
| 207 |
|
| 208 |
|
| 209 |
# ------------------------------------------------------------------------------ |
| 210 |
# print the GNUmake version and the compiler version |
| 211 |
# ------------------------------------------------------------------------------ |
| 212 |
.PHONY: version |
| 213 |
version: |
| 214 |
# Print the GNU make version and the compiler version |
| 215 |
@$(ECHO) GNUmake version: |
| 216 |
@$(MAKE) --version |
| 217 |
@$(ECHO) GCC version: |
| 218 |
@$(CL) -v |
| 219 |
|
| 220 |
|
| 221 |
# ------------------------------------------------------------------------------ |
| 222 |
# Rules |
| 223 |
# ------------------------------------------------------------------------------ |
| 224 |
|
| 225 |
# ------------------------------------------------------------------------------ |
| 226 |
# Link/locate application |
| 227 |
# ------------------------------------------------------------------------------ |
| 228 |
$(TRG) : $(FILES_O) |
| 229 |
@-$(ECHO) +++ linkink application to generate: $(TRG) |
| 230 |
@-$(CL) $(LFLAGS) -L. -lc $(PATH_OBJ)/*.o -Wl,-Map,$(TRG).map -o $(TRG) |
| 231 |
# profiling |
| 232 |
@-$(CL) $(LFLAGS) -L. -lc $(PATH_COV)/*.o --coverage -o $(PATH_COV)/$(APP) |
| 233 |
|
| 234 |
|
| 235 |
# ------------------------------------------------------------------------------ |
| 236 |
# parse the object files to obtain symbol information, and create a size summary |
| 237 |
# ------------------------------------------------------------------------------ |
| 238 |
$(TRG)_nm.txt : $(TRG) |
| 239 |
@-$(ECHO) +++ parsing symbols with nm to generate: $(TRG)_nm.txt |
| 240 |
@-$(NM) --numeric-sort --print-size $(TRG) > $(TRG)_nm.txt |
| 241 |
@-$(ECHO) +++ demangling symbols with c++filt to generate: $(TRG)_cppfilt.txt |
| 242 |
@-$(NM) --numeric-sort --print-size $(TRG) | $(CPPFILT) > $(TRG)_cppfilt.txt |
| 243 |
@-$(ECHO) +++ creating size summary table with size to generate: $(TRG)_size.txt |
| 244 |
@-$(SIZE) -A -t $(TRG) > $(TRG)_size.txt |
| 245 |
|
| 246 |
|
| 247 |
%.o : %.cpp |
| 248 |
@$(ECHO) +++ compile: $< |
| 249 |
# Compile the source file |
| 250 |
# ...and Reformat (using sed) any possible error/warning messages for the VisualStudio(R) output window |
| 251 |
# ...and Create an assembly listing using objdump |
| 252 |
# ...and Generate a dependency file (using the -MM flag) |
| 253 |
@-$(CL) $(CPPFLAGS) $< -E -o $(PATH_PRE)/$(basename $(@F)).pre |
| 254 |
@-$(CL) $(CPPFLAGS) $< -c -o $(PATH_OBJ)/$(basename $(@F)).o 2> $(PATH_ERR)/$(basename $(@F)).err |
| 255 |
@-$(SED) -e 's|.h:\([0-9]*\),|.h(\1) :|' -e 's|:\([0-9]*\):|(\1) :|' $(PATH_ERR)/$(basename $(@F)).err |
| 256 |
@-$(OBJDUMP) --disassemble --line-numbers -S $(PATH_OBJ)/$(basename $(@F)).o > $(PATH_LST)/$(basename $(@F)).lst |
| 257 |
@-$(CL) $(CPPFLAGS) $< -MM > $(PATH_OBJ)/$(basename $(@F)).d |
| 258 |
# profiling |
| 259 |
@-$(CL) $(CPPFLAGS) -O0 --coverage $< -c -o $(PATH_COV)/$(basename $(@F)).o 2> $(PATH_NUL) |
| 260 |
|
| 261 |
%.o : %.c |
| 262 |
@$(ECHO) +++ compile: $< |
| 263 |
# Compile the source file |
| 264 |
# ...and Reformat (using sed) any possible error/warning messages for the VisualStudio(R) output window |
| 265 |
# ...and Create an assembly listing using objdump |
| 266 |
# ...and Generate a dependency file (using the -MM flag) |
| 267 |
@-$(CL) $(CFLAGS) $< -E -o $(PATH_PRE)/$(basename $(@F)).pre |
| 268 |
@-$(CC) $(CFLAGS) $< -c -o $(PATH_OBJ)/$(basename $(@F)).o 2> $(PATH_ERR)/$(basename $(@F)).err |
| 269 |
@-$(SED) -e 's|.h:\([0-9]*\),|.h(\1) :|' -e 's|:\([0-9]*\):|(\1) :|' $(PATH_ERR)/$(basename $(@F)).err |
| 270 |
@-$(OBJDUMP) -S $(PATH_OBJ)/$(basename $(@F)).o > $(PATH_LST)/$(basename $(@F)).lst |
| 271 |
@-$(CC) $(CFLAGS) $< -MM > $(PATH_OBJ)/$(basename $(@F)).d |