File: Makefile

package info (click to toggle)
cpputest 4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 6,632 kB
  • sloc: cpp: 31,212; sh: 4,978; ansic: 1,360; makefile: 777; ruby: 676; xml: 8; sed: 1
file content (321 lines) | stat: -rw-r--r-- 8,929 bytes parent folder | download | duplicates (4)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
.SILENT:

#We don't need to clean up when we're making these targets
NODEPS  = clean

# CPU architecture. Passing to armcc.exe. For list: armcc --cpu list
ifndef CPU
	CPU = ARM7TDMI
endif

# ARM/THUMB mode. Passing to armcc.exe. May be 'thumb' or 'arm'
ifndef CPU_MODE
	CPU_MODE = thumb
endif

TARGET_PLATFORM =armcc_$(CPU)_$(CPU_MODE)

# Need to use only relative path! Path with logical letters does not working.
CPPUTEST_HOME = ../../..

COMPONENT_NAME = app

CPPUTEST_OBJS_DIR = objs

# directory for appication library
CPPUTEST_LIB_DIR = lib

CPPUTEST_USE_MEM_LEAK_DETECTION = N
CPPUTEST_USE_STD_CPP_LIB = Y
CPPUTEST_USE_VPATH = Y
CPPUTEST_USE_STD_C_LIB = Y
CPPUTEST_ENABLE_DEBUG = Y
CPPUTEST_USE_EXTENSIONS = N

SRC_DIRS = \

SRC_FILES = $(CPPUTEST_HOME)/examples/ApplicationLib/CircularBuffer.cpp \
  $(CPPUTEST_HOME)/examples/ApplicationLib/Printer.cpp

TEST_SRC_DIRS = \
	tests \

TEST_FILES = $(CPPUTEST_HOME)/examples/AllTests/CircularBufferTest.cpp


# directory with CppUTest and startup libraries
CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib/$(TARGET_PLATFORM)

INCLUDE_DIRS = \
  $(CPPUTEST_HOME)/include \
  $(SRC_DIRS) \
  $(CPPUTEST_HOME)/examples/ApplicationLib \

# name of extension of output file. Default Keil MDK-ARM extension is .axf which is elf format
# .axf will be .elf for eclipse debug
OUTFILE_EXT = elf

# output filename, mapfile (.map), hexfile (.mot)
OUTNAME = $(COMPONENT_NAME)
OUTFILE = $(OUTNAME).$(OUTFILE_EXT)
HEXFILE = $(OUTNAME).mot
MAPFILE = $(OUTNAME).map

# CYGWIN path
CYGWIN =C:/CYGWIN/bin
MKDIR  =$(CYGWIN)/mkdir
RM     =$(CYGWIN)/rm
TOUCH  =$(CYGWIN)/touch
ECHO   =$(CYGWIN)/echo

KEIL_DIR=D:/Keil/ARM/ARMCC
CC=$(KEIL_DIR)/bin/armcc.exe
AS=$(KEIL_DIR)/bin/armasm.exe
AR=$(KEIL_DIR)/bin/armar.exe
LD=$(KEIL_DIR)/bin/armlink.exe
FROMELF=$(KEIL_DIR)/bin/fromelf.exe
# armcc system include path
SYS_INCLUDE_DIRS =$(KEIL_DIR)/include 

JFLASH ="C:/Program Files (x86)/SEGGER/JLink_V490b/JFlash.exe"
JFLASHPRJ =AT91SAM7A3.jflash
LDSCRIPT = ROM.sct

CPUFLAGS =--cpu=$(CPU)
ifeq ($(CPU_MODE), thumb)
  CPUFLAGS +=--apcs=/interwork
endif
DEPFLAGS =-M \
 $(INCLUDES) \
 --depend_format=unix_escaped \
 --depend_single_line \
 --no_depend_system_headers

OPTFLAGS =-O3

CPPUTEST_CPPFLAGS =$(CPUFLAGS) \
 $(OPTFLAGS) \
 -c \
 -g \
 $(INCLUDES) \
 --$(CPU_MODE) \
 --exceptions \
 -D__CLK_TCK=1000 \

CPPUTEST_LDFLAGS =$(CPUFLAGS) \
 --strict \
 --entry=Reset_Handler \
 --summary_stderr \
 --map \
 --callgraph \
 --info=summarysizes \
 --info=sizes \
 --info=totals \
 --info=veneers\
 --load_addr_map_info \
 --library_type=standardlib \
 --remove \
 --debug \

ARFLAGS = --debug_symbols


# new and delete for memory leak detection on by default
ifndef CPPUTEST_USE_MEM_LEAK_DETECTION
	CPPUTEST_USE_MEM_LEAK_DETECTION = Y
endif

# Use the standard C library
ifndef CPPUTEST_USE_STD_C_LIB
	CPPUTEST_USE_STD_C_LIB = Y
endif

# Use the standard C++ library
ifndef CPPUTEST_USE_STD_CPP_LIB
	CPPUTEST_USE_STD_CPP_LIB = Y
endif

# No extentions is default
ifndef CPPUTEST_USE_EXTENSIONS
	CPPUTEST_USE_EXTENSIONS = N
endif

# No VPATH is default
ifndef CPPUTEST_USE_VPATH
	CPPUTEST_USE_VPATH = N
endif
# Make empty, instead of 'N', for usage in $(if ) conditionals
ifneq ($(CPPUTEST_USE_VPATH), Y)
	CPPUTEST_USE_VPATH =
endif

# Without the C library, we'll need to disable the C++ library and ... 
ifeq ($(CPPUTEST_USE_STD_C_LIB), N)
	CPPUTEST_USE_STD_CPP_LIB = N
	CPPUTEST_USE_MEM_LEAK_DETECTION = N
	CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_C_LIB_DISABLED
	CPPUTEST_LDFLAGS +=--no_scanlib
else
	INCLUDE_DIRS +=$(SYS_INCLUDE_DIRS)
endif


ifeq ($(CPPUTEST_USE_MEM_LEAK_DETECTION), N)
	CPPUTEST_CPPFLAGS += -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED
else
    ifndef CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE
	    	CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h
    endif
    ifndef CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE
	    CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorMallocMacros.h
	endif	
endif


ifeq ($(CPPUTEST_USE_STD_CPP_LIB), N)
	CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_CPP_LIB_DISABLED
endif

# Link with CppUTest lib
CPPUTEST_LIB = $(CPPUTEST_LIB_LINK_DIR)/libCppUTest.a

# Link with startup lib
CPPUTEST_LIB += $(CPPUTEST_LIB_LINK_DIR)/libStartup_AT91SAM7A3.a

# Link with CppUTestExt lib
ifeq ($(CPPUTEST_USE_EXTENSIONS), Y)
CPPUTEST_LIB += $(CPPUTEST_LIB_LINK_DIR)/libCppUTestExt.a
endif

TARGET_LIB = \
    $(CPPUTEST_LIB_DIR)/lib$(COMPONENT_NAME).a

ifndef TEST_TARGET
	ifndef TARGET_PLATFORM
		TEST_TARGET = $(COMPONENT_NAME)_tests
	else
		TEST_TARGET = $(COMPONENT_NAME)_$(TARGET_PLATFORM)_tests
	endif
endif

#Helper Functions
get_src_from_dir  = $(wildcard $1/*.cpp) $(wildcard $1/*.cc) $(wildcard $1/*.c) $(wildcard $1/*.asm)
get_src_from_dir_list = $(foreach dir, $1, $(call get_src_from_dir,$(dir)))
__src_to = $(subst .c,$1, $(subst .cc,$1, $(subst .cpp,$1, $(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2))))
src_to = $(addprefix $3/,$(call __src_to,$1,$2))
src_to_o = $(call src_to,.o,$1,$2)
src_to_d = $(call src_to,.d,$1,$2)
time = $(shell date +%s)
delta_t = $(eval minus, $1, $2)
debug_print_list = $(foreach word,$1,echo "  $(word)";) echo

# исходники программных модулей
SRC = $(call get_src_from_dir_list, $(SRC_DIRS)) $(SRC_FILES)
OBJ = $(call src_to_o,$(SRC),$(CPPUTEST_OBJS_DIR))
# исходники тестов
TEST_SRC = $(call get_src_from_dir_list, $(TEST_SRC_DIRS)) $(TEST_FILES)
TEST_OBJ = $(call src_to_o,$(TEST_SRC),$(CPPUTEST_OBJS_DIR))

# If we're using VPATH
ALL_SRC = $(SRC) $(TEST_SRC)
ifeq ($(CPPUTEST_USE_VPATH), Y)
# gather all the source directories and add them
	VPATH += $(sort $(dir $(ALL_SRC)))
# Add the component name to the objs dir path, to differentiate between same-name objects
	CPPUTEST_OBJS_DIR := $(addsuffix /$(COMPONENT_NAME),$(CPPUTEST_OBJS_DIR))
endif

# for building application library
INCLUDES += $(foreach dir, $(INCLUDE_DIRS), -I$(dir))
DEP_FILES = $(call src_to_d, $(SRC), $(CPPUTEST_OBJS_DIR))
DEP_TEST_FILES = $(call src_to_d, $(TEST_SRC), $(CPPUTEST_OBJS_DIR))
STUFF_TO_CLEAN = $(OBJ) $(TEST_OBJ) $(DEP_FILES) $(DEP_TEST_FILES) $(TARGET_LIB)

#Don't create CRT dependencies when we're cleaning, for instance
ifeq (0, $(words $(findstring $(MAKECMDGOALS), $(NODEPS))))
    -include $(DEP_FILES)
endif

STUFF_TO_CLEAN += $(OUTFILE) $(MAPFILE)


all: $(CPPUTEST_OBJS_DIR)/$(OUTFILE)
	echo Done!

$(TARGET_LIB): $(OBJ) | $(CPPUTEST_LIB_DIR)
	echo Building application library $@
	$(AR) $(ARFLAGS) --create $@ $^

$(CPPUTEST_OBJS_DIR)/$(OUTFILE): $(TEST_OBJ) $(CPPUTEST_LIB) $(TARGET_LIB) | ROM.sct Makefile
	echo Linking!
	$(LD) $(CPPUTEST_LDFLAGS) $^ --scatter $(LDSCRIPT) --list $(MAPFILE) -o $@


.PHONY: prog
prog:	$(CPPUTEST_OBJS_DIR)/$(HEXFILE)
	$(JFLASH) -openprj$(JFLASHPRJ) -open$< -auto -exit 

$(CPPUTEST_OBJS_DIR)/$(HEXFILE): $(CPPUTEST_OBJS_DIR)/$(OUTFILE)
	echo Converting to Motorola S19
	$(FROMELF) --m32 --output=$@ $<

debug:
	echo
	echo "Target Source files:"
	$(call debug_print_list,$(SRC))
	echo "Target Object files:"
	$(call debug_print_list,$(OBJ))
	echo "All Input Dependency files:"
	$(call debug_print_list,$(DEP_FILES))
	echo Stuff to clean:
	$(call debug_print_list,$(STUFF_TO_CLEAN))
	echo Includes:
	$(call debug_print_list,$(INCLUDES))
	echo Directories to create:
	$(call debug_print_list,$(OBJS_DIRS))
	echo Directories of CppUTest object files:
	$(call debug_print_list,$(OBJS_DIR))

#Don't create dependencies when we're cleaning, for instance
ifeq (0, $(words $(findstring $(MAKECMDGOALS), $(NODEPS))))
    -include $(DEP_FILES)
endif

OBJS_DIRS =$(sort $(dir $(STUFF_TO_CLEAN)))

$(LIB_DIR) $(OBJS_DIRS):
	echo Updating directory $@
	$(MKDIR) -p $@

#This is the rule for creating the dependency files
$(CPPUTEST_OBJS_DIR)/%.d: %.c Makefile | $(OBJS_DIRS)
	echo Compiling C file $< for dependency. Out file $@.
	$(CC) $(DEPFLAGS) $< --depend=$@ --depend_target='$(patsubst %.d,%.o,$@)'

$(CPPUTEST_OBJS_DIR)/%.d: %.cpp Makefile | $(OBJS_DIRS)
	echo Compiling C++ file $< for dependency. Out file $@.
	$(CC) $(DEPFLAGS) $< --depend=$@ --depend_target='$(patsubst %.d,%.o,$@)'

$(CPPUTEST_OBJS_DIR)/%.d: %.cc Makefile | $(OBJS_DIRS)
	echo Compiling CC++ file $< for dependency. Out file $@.
	$(CC) $(DEPFLAGS) $< --depend=$@ --depend_target='$(patsubst %.d,%.o,$@)'

#This rule does the compilation C++ files
$(CPPUTEST_OBJS_DIR)/%.o: %.cpp $(CPPUTEST_OBJS_DIR)/%.d
	echo Compiling C++ file $<. Out file $@
	$(CC) $(CPPUTEST_CPPFLAGS) $< -o $@

#This rule does the compilation CC++ files
$(CPPUTEST_OBJS_DIR)/%.o: %.cc $(CPPUTEST_OBJS_DIR)/%.d
	echo Compiling CC++ file $<. Out file $@
	$(CC) $(CPPUTEST_CPPFLAGS) $< -o $@

#This rule does the compilation C files
$(CPPUTEST_OBJS_DIR)/%.o: %.c $(CPPUTEST_OBJS_DIR)/%.d
	echo Compiling C file $<. Out file $@
	$(CC) $(CPPUTEST_CPPFLAGS) $< -o $@

clean:
	$(RM) -f $(STUFF_TO_CLEAN)