1 # A sample Makefile for building Google Test and using it in user
2 # A sample Makefile for building Google Test and using it in user
3 # tests. Please tweak it to suit your environment and project. You
4 # may want to move it to your project's root directory.
8 # make [all] - makes everything.
9 # make TARGET - makes the given target.
10 # make clean - removes all files generated by make.
13 # Where to find user code.
17 OBJECT_DIR
= ..
/..
/obj
/test
18 TARGET_DIR
= $(USER_DIR
)/target
20 include $(ROOT
)/make
/system-id.mk
21 include $(ROOT
)/make
/targets_list.mk
23 VPATH
:= $(VPATH
):$(USER_DIR
):$(TEST_DIR
)
25 # specify which files that are included in the test in addition to the unittest file.
26 # variables available:
29 # <test_name>_INCLUDE_DIRS
30 # <test_name>_EXPAND (run for each target, call the above with target as $1)
31 # <test_name>_BLACKLIST (targets to exclude from an expanded test's run)
33 alignsensor_unittest_SRC
:= \
34 $(USER_DIR
)/sensors
/boardalignment.c \
35 $(USER_DIR
)/common
/sensor_alignment.c \
36 $(USER_DIR
)/common
/maths.c
38 arming_prevention_unittest_SRC
:= \
39 $(USER_DIR
)/fc/core.c \
40 $(USER_DIR
)/fc/dispatch.c \
41 $(USER_DIR
)/fc/rc_controls.c \
42 $(USER_DIR
)/fc/rc_modes.c \
43 $(USER_DIR
)/fc/runtime_config.c \
44 $(USER_DIR
)/flight
/gps_rescue.c \
45 $(USER_DIR
)/common
/bitarray.c
47 arming_prevention_unittest_DEFINES
:= \
50 atomic_unittest_SRC
:= \
51 $(USER_DIR
)/build
/atomic.c \
52 $(TEST_DIR
)/atomic_unittest_c.c
54 baro_bmp085_unittest_SRC
:= \
55 $(USER_DIR
)/drivers
/barometer
/barometer_bmp085.c
57 baro_bmp085_unittest_DEFINES
:= \
60 baro_bmp280_unittest_SRC
:= \
61 $(USER_DIR
)/drivers
/barometer
/barometer_bmp280.c
63 baro_bmp280_unittest_DEFINES
:= \
67 baro_bmp388_unittest_SRC
:= \
68 $(USER_DIR
)/common
/maths.c \
69 $(USER_DIR
)/drivers
/barometer
/barometer_bmp388.c
71 baro_bmp388_unittest_DEFINES
:= \
76 baro_ms5611_unittest_SRC
:= \
77 $(USER_DIR
)/drivers
/barometer
/barometer_ms5611.c
79 baro_ms5611_unittest_DEFINES
:= \
83 # This test is disabled due to build errors.
84 # Its source code is archived in unit/battery_unittest.cc.txt
86 #battery_unittest_SRC := \
87 # $(USER_DIR)/sensors/battery.c \
88 # $(USER_DIR)/common/maths.c
91 blackbox_unittest_SRC
:= \
92 $(USER_DIR
)/blackbox
/blackbox.c \
93 $(USER_DIR
)/blackbox
/blackbox_encoding.c \
94 $(USER_DIR
)/blackbox
/blackbox_io.c \
95 $(USER_DIR
)/common
/encoding.c \
96 $(USER_DIR
)/common
/printf.c \
97 $(USER_DIR
)/common
/maths.c \
98 $(USER_DIR
)/common
/typeconversion.c \
99 $(USER_DIR
)/drivers
/accgyro
/gyro_sync.c
101 blackbox_encoding_unittest_SRC
:= \
102 $(USER_DIR
)/blackbox
/blackbox_encoding.c \
103 $(USER_DIR
)/common
/encoding.c \
104 $(USER_DIR
)/common
/printf.c \
105 $(USER_DIR
)/common
/typeconversion.c
107 cli_unittest_SRC
:= \
108 $(USER_DIR
)/cli
/cli.c \
109 $(USER_DIR
)/common
/printf.c \
110 $(USER_DIR
)/config
/feature.c \
111 $(USER_DIR
)/pg
/pg.c \
112 $(USER_DIR
)/common
/typeconversion.c
114 cli_unittest_DEFINES
:= \
117 SystemCoreClock
=1000000
119 cms_unittest_SRC
:= \
120 $(USER_DIR
)/cms
/cms.c \
121 $(USER_DIR
)/cms
/cms_menu_saveexit.c \
122 $(USER_DIR
)/common
/typeconversion.c \
123 $(USER_DIR
)/drivers
/display.c
126 common_filter_unittest_SRC
:= \
127 $(USER_DIR
)/common
/filter.c \
128 $(USER_DIR
)/common
/maths.c
131 encoding_unittest_SRC
:= \
132 $(USER_DIR
)/common
/encoding.c
135 flight_failsafe_unittest_SRC
:= \
136 $(USER_DIR
)/common
/bitarray.c \
137 $(USER_DIR
)/fc/rc_modes.c \
138 $(USER_DIR
)/fc/runtime_config.c \
139 $(USER_DIR
)/flight
/failsafe.c
141 flight_failsafe_unittest_DEFINES
:= \
145 flight_imu_unittest_SRC
:= \
146 $(USER_DIR
)/common
/bitarray.c \
147 $(USER_DIR
)/common
/maths.c \
148 $(USER_DIR
)/config
/feature.c \
149 $(USER_DIR
)/fc/rc_modes.c \
150 $(USER_DIR
)/flight
/position.c \
151 $(USER_DIR
)/flight
/imu.c
154 flight_mixer_unittest
:= \
155 $(USER_DIR
)/flight
/mixer.c \
156 $(USER_DIR
)/flight
/servos.c \
157 $(USER_DIR
)/common
/maths.c
160 gps_conversion_unittest_SRC
:= \
161 $(USER_DIR
)/common
/gps_conversion.c
164 io_serial_unittest_SRC
:= \
165 $(USER_DIR
)/io
/serial.c \
166 $(USER_DIR
)/drivers
/serial_pinconfig.c
169 ledstrip_unittest_SRC
:= \
170 $(USER_DIR
)/common
/bitarray.c \
171 $(USER_DIR
)/fc/rc_modes.c \
172 $(USER_DIR
)/io
/ledstrip.c
174 ledstrip_unittest_DEFINES
:= \
178 maths_unittest_SRC
:= \
179 $(USER_DIR
)/common
/maths.c
182 motor_output_unittest_SRC
:= \
183 $(USER_DIR
)/drivers
/dshot.c
186 osd_unittest_SRC
:= \
187 $(USER_DIR
)/osd
/osd.c \
188 $(USER_DIR
)/osd
/osd_elements.c \
189 $(USER_DIR
)/osd
/osd_warnings.c \
190 $(USER_DIR
)/common
/typeconversion.c \
191 $(USER_DIR
)/drivers
/display.c \
192 $(USER_DIR
)/common
/maths.c \
193 $(USER_DIR
)/common
/printf.c \
194 $(USER_DIR
)/common
/time.c \
195 $(USER_DIR
)/fc/runtime_config.c
197 osd_unittest_DEFINES
:= \
203 link_quality_unittest_SRC
:= \
204 $(USER_DIR
)/osd
/osd.c \
205 $(USER_DIR
)/osd
/osd_elements.c \
206 $(USER_DIR
)/osd
/osd_warnings.c \
207 $(USER_DIR
)/common
/typeconversion.c \
208 $(USER_DIR
)/drivers
/display.c \
209 $(USER_DIR
)/drivers
/serial.c \
210 $(USER_DIR
)/common
/crc.c \
211 $(USER_DIR
)/common
/maths.c \
212 $(USER_DIR
)/common
/printf.c \
213 $(USER_DIR
)/common
/streambuf.c \
214 $(USER_DIR
)/common
/time.c \
215 $(USER_DIR
)/fc/runtime_config.c \
216 $(USER_DIR
)/common
/bitarray.c \
217 $(USER_DIR
)/fc/rc_modes.c \
218 $(USER_DIR
)/rx
/rx.c \
219 $(USER_DIR
)/pg
/pg.c \
220 $(USER_DIR
)/rx
/crsf.c \
223 link_quality_unittest_DEFINES
:= \
225 USE_CRSF_LINK_STATISTICS
= \
226 USE_RX_LINK_QUALITY_INFO
=
232 rc_controls_unittest_SRC
:= \
233 $(USER_DIR
)/fc/rc_controls.c \
234 $(USER_DIR
)/pg
/pg.c \
235 $(USER_DIR
)/common
/bitarray.c \
236 $(USER_DIR
)/common
/maths.c \
237 $(USER_DIR
)/fc/rc_adjustments.c \
238 $(USER_DIR
)/fc/rc_modes.c
241 rx_crsf_unittest_SRC
:= \
242 $(USER_DIR
)/rx
/crsf.c \
243 $(USER_DIR
)/common
/crc.c \
244 $(USER_DIR
)/common
/printf.c \
245 $(USER_DIR
)/common
/typeconversion.c \
246 $(USER_DIR
)/common
/streambuf.c \
247 $(USER_DIR
)/drivers
/serial.c
250 rx_ibus_unittest_SRC
:= \
251 $(USER_DIR
)/rx
/ibus.c
254 rx_ranges_unittest_SRC
:= \
255 $(USER_DIR
)/common
/bitarray.c \
256 $(USER_DIR
)/common
/maths.c \
257 $(USER_DIR
)/fc/rc_modes.c \
258 $(USER_DIR
)/rx
/rx.c \
259 $(USER_DIR
)/pg
/pg.c \
263 rx_rx_unittest_SRC
:= \
264 $(USER_DIR
)/rx
/rx.c \
265 $(USER_DIR
)/fc/rc_modes.c \
266 $(USER_DIR
)/common
/bitarray.c \
267 $(USER_DIR
)/common
/maths.c \
268 $(USER_DIR
)/config
/feature.c \
271 rx_sumd_unittest_SRC
:= \
272 $(USER_DIR
)/common
/crc.c \
273 $(USER_DIR
)/common
/streambuf.c \
274 $(USER_DIR
)/rx
/sumd.c
276 scheduler_unittest_SRC
:= \
277 $(USER_DIR
)/scheduler
/scheduler.c \
278 $(USER_DIR
)/common
/crc.c \
279 $(USER_DIR
)/common
/streambuf.c
282 sensor_gyro_unittest_SRC
:= \
283 $(USER_DIR
)/sensors
/gyro.c \
284 $(USER_DIR
)/sensors
/gyro_init.c \
285 $(USER_DIR
)/sensors
/boardalignment.c \
286 $(USER_DIR
)/common
/filter.c \
287 $(USER_DIR
)/common
/maths.c \
288 $(USER_DIR
)/common
/sensor_alignment.c \
289 $(USER_DIR
)/drivers
/accgyro
/accgyro_fake.c \
290 $(USER_DIR
)/drivers
/accgyro
/gyro_sync.c \
291 $(USER_DIR
)/pg
/pg.c \
292 $(USER_DIR
)/pg
/gyrodev.c
294 telemetry_crsf_unittest_SRC
:= \
295 $(USER_DIR
)/rx
/crsf.c \
296 $(USER_DIR
)/telemetry
/crsf.c \
297 $(USER_DIR
)/common
/crc.c \
298 $(USER_DIR
)/common
/maths.c \
299 $(USER_DIR
)/common
/streambuf.c \
300 $(USER_DIR
)/common
/gps_conversion.c \
301 $(USER_DIR
)/common
/printf.c \
302 $(USER_DIR
)/common
/typeconversion.c \
303 $(USER_DIR
)/fc/runtime_config.c
305 telemetry_crsf_unittest_DEFINES
:= \
309 __REVISION__
="revision"
312 telemetry_crsf_msp_unittest_SRC
:= \
313 $(USER_DIR
)/rx
/crsf.c \
314 $(USER_DIR
)/build
/atomic.c \
315 $(USER_DIR
)/common
/crc.c \
316 $(USER_DIR
)/common
/streambuf.c \
317 $(USER_DIR
)/common
/printf.c \
318 $(USER_DIR
)/common
/streambuf.c \
319 $(USER_DIR
)/drivers
/serial.c \
320 $(USER_DIR
)/common
/typeconversion.c \
321 $(USER_DIR
)/telemetry
/crsf.c \
322 $(USER_DIR
)/common
/gps_conversion.c \
323 $(USER_DIR
)/telemetry
/msp_shared.c \
324 $(USER_DIR
)/fc/runtime_config.c
326 telemetry_crsf_msp_unittest_DEFINES
:= \
327 USE_MSP_OVER_TELEMETRY
=
330 telemetry_hott_unittest_SRC
:= \
331 $(USER_DIR
)/telemetry
/hott.c \
332 $(USER_DIR
)/common
/gps_conversion.c
335 telemetry_ibus_unittest_SRC
:= \
336 $(USER_DIR
)/telemetry
/ibus_shared.c \
337 $(USER_DIR
)/telemetry
/ibus.c
339 timer_definition_unittest_EXPAND
:= yes
341 # SITL is a simulator with empty timerHardware and many hearders in target.c.
342 timer_definition_unittest_BLACKLIST
:= SITL
344 timer_definition_unittest_SRC
= \
345 $(TARGET_DIR
)/$(call get_base_target
,$1)/target.c
347 timer_definition_unittest_DEFINES
= \
349 BASE_TARGET
=$(call get_base_target
,$1)
351 timer_definition_unittest_INCLUDE_DIRS
= \
352 $(TEST_DIR
)/timer_definition_unittest.
include \
353 $(TARGET_DIR
)/$(call get_base_target
,$1)
355 transponder_ir_unittest_SRC
:= \
356 $(USER_DIR
)/drivers
/transponder_ir_ilap.c \
357 $(USER_DIR
)/drivers
/transponder_ir_arcitimer.c
359 ws2811_unittest_SRC
:= \
360 $(USER_DIR
)/drivers
/light_ws2811strip.c
362 huffman_unittest_SRC
:= \
363 $(USER_DIR
)/common
/huffman.c \
364 $(USER_DIR
)/common
/huffman_table.c
366 huffman_unittest_DEFINES
:= \
369 rcdevice_unittest_SRC
:= \
370 $(USER_DIR
)/common
/crc.c \
371 $(USER_DIR
)/common
/bitarray.c \
372 $(USER_DIR
)/fc/rc_modes.c \
373 $(USER_DIR
)/io
/rcdevice.c \
374 $(USER_DIR
)/io
/rcdevice_cam.c \
375 $(USER_DIR
)/pg
/pg.c \
377 pid_unittest_SRC
:= \
378 $(USER_DIR
)/common
/filter.c \
379 $(USER_DIR
)/common
/maths.c \
380 $(USER_DIR
)/drivers
/accgyro
/gyro_sync.c \
381 $(USER_DIR
)/fc/controlrate_profile.c \
382 $(USER_DIR
)/fc/runtime_config.c \
383 $(USER_DIR
)/flight
/pid.c \
384 $(USER_DIR
)/flight
/pid_init.c \
387 pid_unittest_DEFINES
:= \
389 USE_RC_SMOOTHING_FILTER
= \
390 USE_ABSOLUTE_CONTROL
= \
391 USE_LAUNCH_CONTROL
= \
394 rcdevice_unittest_DEFINES
:= \
397 vtx_unittest_SRC
:= \
398 $(USER_DIR
)/fc/core.c \
399 $(USER_DIR
)/fc/dispatch.c \
400 $(USER_DIR
)/fc/rc_controls.c \
401 $(USER_DIR
)/fc/rc_modes.c \
402 $(USER_DIR
)/fc/runtime_config.c \
403 $(USER_DIR
)/drivers
/vtx_common.c \
404 $(USER_DIR
)/drivers
/vtx_table.c \
405 $(USER_DIR
)/io
/vtx_control.c \
406 $(USER_DIR
)/io
/vtx.c \
407 $(USER_DIR
)/common
/bitarray.c
409 vtx_unittest_DEFINES
:= \
414 rx_spi_spektrum_unittest_SRC
:= \
415 $(USER_DIR
)/rx
/cyrf6936_spektrum.c
417 rx_spi_spektrum_unittest_DEFINES
:= \
421 # Please tweak the following variable definitions as needed by your
422 # project, except GTEST_HEADERS, which you can use in your own targets
423 # but shouldn't modify.
425 # Points to the root of Google Test, relative to where this file is.
426 # Remember to tweak this if you move this file.
427 GTEST_DIR
= ..
/..
/lib
/test/gtest
429 # Use clang/clang++ by default
433 ifeq ($(shell which
$(CC
) 2>/dev
/null
),)
434 $(info Falling back to
'clang'.
)
442 # These flags are needed for clang 10 (linux / MacOS) to make test work:
443 # -Wno-c99-extensions
451 -Wno-error
=unused-command-line-argument \
455 -isystem
$(GTEST_DIR
)/inc \
457 -Wno-c99-extensions \
460 CC_VERSION
= $(shell $(CC
) -dumpversion
)
461 CXX_VERSION
= $(shell $(CXX
) -dumpversion
)
463 ifeq ($(shell $(CC
) -v
2>&1 | grep
-q
"clang version" && echo
"clang"),clang
)
465 # Please revisit versions when new clang version arrive. Supported versions: { Linux / OSX: 7 - 13 }
466 # Travis reports CC_VERSION of 4.2.1
467 CC_VERSION_MAJOR
:= $(firstword $(subst .
, ,$(CC_VERSION
)))
468 CC_VERSION_CHECK_MIN
:= 7
469 CC_VERSION_CHECK_MAX
:= 13
471 # Added flags for clang 11 - 13 are not backwards compatible
472 ifeq ($(shell expr
$(CC_VERSION_MAJOR
) \
> 10 \
& $(CC_VERSION_MAJOR
) \
< 14), 1)
475 -Wno-void-pointer-to-int-cast
478 ifeq ($(shell expr
$(CC_VERSION_MAJOR
) \
< $(CC_VERSION_CHECK_MIN
) \|
$(CC_VERSION_MAJOR
) \
> $(CC_VERSION_CHECK_MAX
)),1)
479 $(error
$(CC
) $(CC_VERSION
) is not supported. The officially supported version of clang is
'clang-10'. If this is not found
, 'clang' is used
as a fallback. The version of the compiler must be between
$(CC_VERSION_CHECK_MIN
) and
$(CC_VERSION_CHECK_MAX
).
)
482 COMMON_FLAGS
+= -fblocks
484 ifneq ($(OSFAMILY
), macosx
)
485 LDFLAGS
+= -lBlocksRuntime
490 $(info CC version
: $(shell $(CC
) --version
))
491 $(info CXX version
: $(shell $(CXX
) --version
))
495 ifeq ($(OSFAMILY
), macosx
)
504 COMMON_FLAGS
+= -pthread
507 # Flags passed to the C compiler.
508 C_FLAGS
= $(COMMON_FLAGS
) \
511 # Flags passed to the C++ compiler.
512 CXX_FLAGS
= $(COMMON_FLAGS
) \
515 # Compiler flags for coverage instrumentation
517 COVERAGE_FLAGS
:= --coverage
520 C_FLAGS
+= $(COVERAGE_FLAGS
)
521 CXX_FLAGS
+= $(COVERAGE_FLAGS
)
523 C_FLAGS
+= -D_GNU_SOURCE
525 # Set up the parameter group linker flags according to OS
526 ifeq ($(OSFAMILY
), macosx
)
527 LDFLAGS
+= -Wl
,-map
,$(OBJECT_DIR
)/$@.map
529 LDFLAGS
+= -Wl
,-T
,$(TEST_DIR
)/pg.
ld -Wl
,-Map
,$(OBJECT_DIR
)/$@.map
532 # Gather up all of the tests.
533 TEST_SRCS
= $(sort $(wildcard $(TEST_DIR
)/*.
cc))
534 TEST_BASENAMES
= $(TEST_SRCS
:$(TEST_DIR
)/%.
cc=%)
535 TESTS_TARGET_SPECIFIC
= $(foreach test,$(TEST_BASENAMES
),$(if
$($(test)_EXPAND
),$(test)))
536 TESTS_TARGET_SPECIFIC_EXPANDED
= $(foreach test,$(TESTS_TARGET_SPECIFIC
),$(foreach \
537 target
,$(filter-out $($(test)_BLACKLIST
),$(VALID_TARGETS
)),$(test).
$(target
)))
539 TESTS
= $(foreach test,$(TEST_BASENAMES
),$(if
$($(test)_EXPAND
),,$(test)))
540 TESTS_ALL
= $(TESTS
) $(TESTS_TARGET_SPECIFIC_EXPANDED
)
541 TESTS_REPRESENTATIVE
= $(TESTS
) $(foreach test,$(TESTS_TARGET_SPECIFIC
), \
542 $(test).
$(word 1,$(filter-out $($(test)_BLACKLIST
),$(VALID_TARGETS
))))
544 # All Google Test headers. Usually you shouldn't change this
546 GTEST_HEADERS
= $(GTEST_DIR
)/inc
/gtest
/*.h
548 ## V : Set verbosity level based on the V= parameter
551 include ..
/..
/make
/build_verbosity.mk
553 # House-keeping build targets.
555 ## test : Build and run the non target specific Unit Tests (default goal)
556 test: $(TESTS
:%=test_
%)
558 ## test-all : Build and run all Unit Tests
559 test-all
: $(TESTS_ALL
:%=test_
%)
561 ## test-representative : Build and run a representative subset of the Unit Tests (i.e. run every expanded test only for the first target)
562 test-representative
: $(TESTS_REPRESENTATIVE
:%=test_
%)
564 ## junittest : Build and run the Unit Tests, producing Junit XML result files."
565 junittest
: EXEC_OPTS
= "--gtest_output=xml:$<_results.xml"
566 junittest
: $(TESTS
:%=test_
%)
570 ## help : print this help message and exit
571 ## what : print this help message and exit
572 ## usage : print this help message and exit
573 help what usage
: Makefile
575 @echo
"Makefile for Unit Tests"
578 @echo
" make [goal] "
580 @echo
"Valid goals are:"
582 @sed
-n
's/^## //p' $<
584 @echo
"Any of the Unit Test programs can be used as goals to build:"
585 @
$(foreach test, $(TESTS
), echo
" $(OBJECT_DIR)/$(test)/$(test)";)
587 @echo
"Any of the Unit Test programs (except for target specific unit tests) can be used as goals to build and run:"
588 @
$(foreach test, $(TESTS
), echo
" test_$(test)";)
591 @echo
"C compiler: $(CC): $(CC_VERSION)"
592 @echo
"C++ compiler: $(CXX): $(CXX_VERSION)"
594 ## clean : Cleanup the UnitTest binaries.
599 # Builds gtest.a and gtest_main.a.
601 # Usually you shouldn't tweak such internal variables, indicated by a
603 GTEST_SRCS_
= $(GTEST_DIR
)/src
/*.
cc $(GTEST_DIR
)/inc
/gtest
/*.h
$(GTEST_HEADERS
)
605 # For simplicity and to avoid depending on Google Test's
606 # implementation details, the dependencies specified below are
607 # conservative and not optimized. This is fine as Google Test
608 # compiles fast and for ordinary users its source rarely changes.
609 $(OBJECT_DIR
)/gtest-all.o
: $(GTEST_SRCS_
)
610 @echo
"compiling $@" "$(STDOUT)"
612 $(V1
) $(CXX
) $(CXX_FLAGS
) -I
$(GTEST_DIR
) -Wno-missing-field-initializers
-Wno-unused-const-variable
-c \
613 $(GTEST_DIR
)/src
/gtest-all.
cc -o
$@
615 $(OBJECT_DIR
)/gtest_main.o
: $(GTEST_SRCS_
)
616 @echo
"compiling $@" "$(STDOUT)"
618 $(V1
) $(CXX
) $(CXX_FLAGS
) -I
$(GTEST_DIR
) -c \
619 $(GTEST_DIR
)/src
/gtest_main.
cc -o
$@
621 $(OBJECT_DIR
)/gtest.a
: $(OBJECT_DIR
)/gtest-all.o
622 @echo
"linking $@" "$(STDOUT)"
623 $(V1
) $(AR
) $(ARFLAGS
) $@
$^
625 $(OBJECT_DIR
)/gtest_main.a
: $(OBJECT_DIR
)/gtest-all.o
$(OBJECT_DIR
)/gtest_main.o
626 @echo
"linking $@" "$(STDOUT)"
627 $(V1
) $(AR
) $(ARFLAGS
) $@
$^
629 -include $(OBJECT_DIR
)/gtest-all.d \
630 $(OBJECT_DIR
)/gtest_main.d
633 # includes in test dir must override includes in user dir, unless the user
634 # specifies a list of endorsed directories in ${target}_INCLUDE_DIRS.
635 test_include_dirs
= $1 $(TEST_DIR
) $(USER_DIR
)
636 test_cflags
= $(addprefix -I
,$(call test_include_dirs
,$1))
639 # target name extractor
640 # param $1 = expanded test name in the form of test.target
641 target
= $(1:$(basename $1).
%=%)
643 # canned recipe for all test builds
645 # variable expansion rules of thumb (number of $'s):
646 # * parameters: one $, e.g. $1
647 # * statically accessed variables set elsewhere: one $, e.g. $(C_FLAGS)
648 # * dynamically accessed variables set elsewhere: one $, e.g. $($1_SRC)
649 # * make functions accessing only the above: one $, e.g. $(basename $1)
650 # * dynamically set and accessed variables: two $, e.g. $$($1_OBJS)
651 # * make functions accessing dynamically set variables: two $,
652 # e.g. $$(call test_cflags,$$($1_INCLUDE_DIRS))
654 # param $1 = plain test name for global tests, test.target for per-target tests
655 define test-specific-stuff
657 ifeq ($1,$(basename $1))
658 # standard global test
659 $1_OBJS = $(patsubst \
660 $(TEST_DIR
)/%,$(OBJECT_DIR
)/$1/%,$(patsubst \
661 $(USER_DIR
)/%,$(OBJECT_DIR
)/$1/%,$($1_SRC:=.o
)))
663 # test executed for each target, $1 has the form of test.target
664 $1_SRC = $(addsuffix .o
,$(call
$(basename $1)_SRC
,$(call target
,$1)))
665 $1_OBJS = $$(patsubst \
666 $(TEST_DIR
)/%,$(OBJECT_DIR
)/$1/%,$$(patsubst \
667 $(USER_DIR
)/%,$(OBJECT_DIR
)/$1/%,$$(patsubst \
668 $(TARGET_DIR
)/$(call get_base_target
,$(call target
,$1))/%,$(OBJECT_DIR
)/$1/%,$$($1_SRC))))
669 $1_DEFINES = $(call
$(basename $1)_DEFINES
,$(call target
,$1))
670 $1_INCLUDE_DIRS = $(call
$(basename $1)_INCLUDE_DIRS
,$(call target
,$1))
673 # $$(info $1 -v-v-------)
674 # $$(info $1_SRC: $$($1_SRC))
675 # $$(info $1_OBJS: $$($1_OBJS))
676 # $$(info $1 -^-^-------)
678 # include generated dependencies
679 -include $$($1_OBJS:.o
=.d
)
680 -include $(OBJECT_DIR
)/$1/$(basename $1).d
682 $(OBJECT_DIR
)/$1/%.c.o
: $(USER_DIR
)/%.c
683 @echo
"compiling $$<" "$(STDOUT)"
684 $(V1
) mkdir
-p
$$(dir $$@
)
685 $(V1
) $(CC
) $(C_FLAGS
) $$(call test_cflags
,$$($1_INCLUDE_DIRS)) \
686 $$(foreach def
,$$($1_DEFINES),-D
$$(def
)) \
689 $(OBJECT_DIR
)/$1/%.c.o
: $(TEST_DIR
)/%.c
690 @echo
"compiling test c file: $$<" "$(STDOUT)"
691 $(V1
) mkdir
-p
$$(dir $$@
)
692 $(V1
) $(CC
) $(C_FLAGS
) $$(call test_cflags
,$$($1_INCLUDE_DIRS)) \
693 $$(foreach def
,$$($1_DEFINES),-D
$$(def
)) \
696 ifneq ($1,$(basename $1))
697 # per-target tests may compile files from the target directory
698 $(OBJECT_DIR
)/$1/%.c.o
: $(TARGET_DIR
)/$(call get_base_target
,$(call target
,$1))/%.c
699 @echo
"compiling target c file: $$<" "$(STDOUT)"
700 $(V1
) mkdir
-p
$$(dir $$@
)
701 $(V1
) $(CC
) $(C_FLAGS
) $$(call test_cflags
,$$($1_INCLUDE_DIRS)) \
702 $$(foreach def
,$$($1_DEFINES),-D
$$(def
)) \
706 $(OBJECT_DIR
)/$1/$(basename $1).o
: $(TEST_DIR
)/$(basename $1).
cc
707 @echo
"compiling $$<" "$(STDOUT)"
708 $(V1
) mkdir
-p
$$(dir $$@
)
709 $(V1
) $(CXX
) $(CXX_FLAGS
) $$(call test_cflags
,$$($1_INCLUDE_DIRS)) \
710 $$(foreach def
,$$($1_DEFINES),-D
$$(def
)) \
713 $(OBJECT_DIR
)/$1/$(basename $1): $$($1_OBJS) \
714 $(OBJECT_DIR
)/$1/$(basename $1).o \
715 $(OBJECT_DIR
)/gtest_main.a
717 @echo
"linking $$@" "$(STDOUT)"
718 $(V1
) mkdir
-p
$(dir $$@
)
719 $(V1
) $(CXX
) $(CXX_FLAGS
) $(LDFLAGS
) $$^
-o
$$@
721 test_
$1: $(OBJECT_DIR
)/$1/$(basename $1)
722 $(V1
) $$< $$(EXEC_OPTS
) "$(STDOUT)" && echo
"running $$@: PASS"
727 ifeq ($(MAKECMDGOALS
),test-all
)
728 $(eval
$(foreach test,$(TESTS_ALL
),$(call test-specific-stuff
,$(test))))
730 ifeq ($(MAKECMDGOALS
),test-representative
)
731 $(eval
$(foreach test,$(TESTS_REPRESENTATIVE
),$(call test-specific-stuff
,$(test))))
733 $(eval
$(foreach test,$(TESTS
),$(call test-specific-stuff
,$(test))))
737 $(foreach test,$(TESTS_ALL
),$(if
$($(basename $(test))_SRC
),,$(error \
738 Test
'unit/$(basename $(test)).cc' has no
'$(basename $(test))_SRC' variable defined
)))
739 $(foreach var
,$(filter-out TARGET_SRC
,$(filter %_SRC
,$(.VARIABLES
))),$(if
$(filter $(var
:_SRC
=)%,$(TESTS_ALL
)),,$(error \
740 Variable
'$(var)' has no
'unit/$(var:_SRC=).cc' test)))
744 @echo
========== BASE TARGETS
==========
745 @echo
$(BASE_TARGETS
)
746 @echo
========== ALT TARGETS
==========
748 @echo
========== VALID_TARGETS
==========
749 @echo
$(VALID_TARGETS
)
750 @echo
========== BASE
/ALT PAIRS
==========
751 @echo
$(BASE_ALT_PAIRS
)
752 @echo
========== ALT
/BASE MAPPING
==========
753 @echo
$(foreach target
,$(ALT_TARGETS
),$(target
)\
>$(call get_base_target
,$(target
)))
754 @echo
========== ALT
/BASE FULL MAPPING
==========
755 @echo
$(foreach target
,$(VALID_TARGETS
),$(target
)\
>$(call get_base_target
,$(target
)))