Merge pull request #11024 from ctzsnooze/update-Rx.md-note-about-ADC-filter
[betaflight.git] / src / test / Makefile
blob1546ca1dceea2d4f4f83e1667afe6856e5a8aea1
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.
6 # SYNOPSIS:
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.
14 USER_DIR = ../main
15 TEST_DIR = unit
16 ROOT = ../..
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:
27 # <test_name>_SRC
28 # <test_name>_DEFINES
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 := \
48 USE_GPS_RESCUE=
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 := \
58 USE_BARO_BMP085=
60 baro_bmp280_unittest_SRC := \
61 $(USER_DIR)/drivers/barometer/barometer_bmp280.c
63 baro_bmp280_unittest_DEFINES := \
64 USE_BARO_BMP280= \
65 USE_BARO_SPI_BMP280=
67 baro_bmp388_unittest_SRC := \
68 $(USER_DIR)/common/maths.c \
69 $(USER_DIR)/drivers/barometer/barometer_bmp388.c
71 baro_bmp388_unittest_DEFINES := \
72 USE_EXTI= \
73 USE_BARO_BMP388= \
74 USE_BARO_SPI_BMP388=
76 baro_ms5611_unittest_SRC := \
77 $(USER_DIR)/drivers/barometer/barometer_ms5611.c
79 baro_ms5611_unittest_DEFINES := \
80 USE_BARO_MS5611= \
81 USE_BARO_SPI_MS5611=
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 := \
115 USE_OSD= \
116 USE_CLI= \
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 := \
142 USE_GPS_RESCUE=
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 := \
175 USE_LED_STRIP=
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 := \
198 USE_OSD= \
199 USE_GPS= \
200 USE_RTC_TIME= \
201 USE_ADC_INTERNAL=
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 \
221 $(USER_DIR)/pg/rx.c
223 link_quality_unittest_DEFINES := \
224 USE_OSD= \
225 USE_CRSF_LINK_STATISTICS= \
226 USE_RX_LINK_QUALITY_INFO=
228 pg_unittest_SRC := \
229 $(USER_DIR)/pg/pg.c
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 \
260 $(USER_DIR)/pg/rx.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 \
269 $(USER_DIR)/pg/rx.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 := \
306 FLASH_SIZE=128 \
307 STM32F10X_MD= \
308 __TARGET__="TEST" \
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 = \
348 TARGET=$1 \
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 := \
367 USE_HUFFMAN=
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 \
385 $(USER_DIR)/pg/pg.c
387 pid_unittest_DEFINES := \
388 USE_ITERM_RELAX= \
389 USE_RC_SMOOTHING_FILTER= \
390 USE_ABSOLUTE_CONTROL= \
391 USE_LAUNCH_CONTROL= \
392 USE_FEEDFORWARD=
394 rcdevice_unittest_DEFINES := \
395 USE_RCDEVICE=
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 := \
410 USE_VTX_COMMON= \
411 USE_VTX_CONTROL= \
412 USE_VTX_SMARTAUDIO=
414 rx_spi_spektrum_unittest_SRC := \
415 $(USER_DIR)/rx/cyrf6936_spektrum.c
417 rx_spi_spektrum_unittest_DEFINES := \
418 USE_RX_SPI \
419 USE_RX_SPEKTRUM
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
431 CC := clang-10
432 CXX := clang++-10
433 ifeq ($(shell which $(CC) 2>/dev/null),)
434 $(info Falling back to 'clang'.)
435 CC := clang
436 CXX := clang++
437 endif
439 #CC := gcc
440 #CXX := g++
442 # These flags are needed for clang 10 (linux / MacOS) to make test work:
443 # -Wno-c99-extensions
444 # -Wno-reorder
446 COMMON_FLAGS = \
447 -g \
448 -Wall \
449 -Wextra \
450 -Werror \
451 -Wno-error=unused-command-line-argument \
452 -ggdb3 \
453 -O0 \
454 -DUNIT_TEST \
455 -isystem $(GTEST_DIR)/inc \
456 -MMD -MP \
457 -Wno-c99-extensions \
458 -Wno-reorder
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)
473 COMMON_FLAGS += \
474 -fcommon \
475 -Wno-void-pointer-to-int-cast
476 endif
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).)
480 endif
482 COMMON_FLAGS += -fblocks
483 ifndef CYGWIN
484 ifneq ($(OSFAMILY), macosx)
485 LDFLAGS += -lBlocksRuntime
486 endif
487 endif
488 endif
490 $(info CC version: $(shell $(CC) --version))
491 $(info CXX version: $(shell $(CXX) --version))
493 USE_PTHREAD = YES
494 USE_COVERAGE = YES
495 ifeq ($(OSFAMILY), macosx)
496 USE_PTHREAD =
497 endif
498 ifdef CYGWIN
499 USE_PTHREAD =
500 USE_COVERAGE =
501 endif
503 ifdef USE_PTHREAD
504 COMMON_FLAGS += -pthread
505 endif
507 # Flags passed to the C compiler.
508 C_FLAGS = $(COMMON_FLAGS) \
509 -std=gnu99
511 # Flags passed to the C++ compiler.
512 CXX_FLAGS = $(COMMON_FLAGS) \
513 -std=gnu++11
515 # Compiler flags for coverage instrumentation
516 ifdef USE_COVERAGE
517 COVERAGE_FLAGS := --coverage
518 endif
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
528 else
529 LDFLAGS += -Wl,-T,$(TEST_DIR)/pg.ld -Wl,-Map,$(OBJECT_DIR)/$@.map
530 endif
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
545 # definition.
546 GTEST_HEADERS = $(GTEST_DIR)/inc/gtest/*.h
548 ## V : Set verbosity level based on the V= parameter
549 ## V=0 Low
550 ## V=1 High
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
574 @echo ""
575 @echo "Makefile for Unit Tests"
576 @echo ""
577 @echo "Usage:"
578 @echo " make [goal] "
579 @echo ""
580 @echo "Valid goals are:"
581 @echo ""
582 @sed -n 's/^## //p' $<
583 @echo ""
584 @echo "Any of the Unit Test programs can be used as goals to build:"
585 @$(foreach test, $(TESTS), echo " $(OBJECT_DIR)/$(test)/$(test)";)
586 @echo ""
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)";)
590 versions:
591 @echo "C compiler: $(CC): $(CC_VERSION)"
592 @echo "C++ compiler: $(CXX): $(CXX_VERSION)"
594 ## clean : Cleanup the UnitTest binaries.
595 clean :
596 rm -rf $(OBJECT_DIR)
599 # Builds gtest.a and gtest_main.a.
601 # Usually you shouldn't tweak such internal variables, indicated by a
602 # trailing _.
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)"
611 @mkdir -p $(dir $@)
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)"
617 @mkdir -p $(dir $@)
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)))
662 else
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))
671 endif
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)) \
687 -c $$< -o $$@
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)) \
694 -c $$< -o $$@
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)) \
703 -c $$< -o $$@
704 endif
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)) \
711 -c $$< -o $$@
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"
724 endef
727 ifeq ($(MAKECMDGOALS),test-all)
728 $(eval $(foreach test,$(TESTS_ALL),$(call test-specific-stuff,$(test))))
729 else
730 ifeq ($(MAKECMDGOALS),test-representative)
731 $(eval $(foreach test,$(TESTS_REPRESENTATIVE),$(call test-specific-stuff,$(test))))
732 else
733 $(eval $(foreach test,$(TESTS),$(call test-specific-stuff,$(test))))
734 endif
735 endif
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)))
743 target_list:
744 @echo ========== BASE TARGETS ==========
745 @echo $(BASE_TARGETS)
746 @echo ========== ALT TARGETS ==========
747 @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)))