Merge pull request #11299 from daleckystepan/vtx-start-bit
[betaflight.git] / src / test / Makefile
blob4d770a704d6414620338aafd1d5451392d9b749b
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
281 scheduler_unittest_DEFINES := \
282 USE_OSD=
284 sensor_gyro_unittest_SRC := \
285 $(USER_DIR)/sensors/gyro.c \
286 $(USER_DIR)/sensors/gyro_init.c \
287 $(USER_DIR)/sensors/boardalignment.c \
288 $(USER_DIR)/common/filter.c \
289 $(USER_DIR)/common/maths.c \
290 $(USER_DIR)/common/sensor_alignment.c \
291 $(USER_DIR)/drivers/accgyro/accgyro_fake.c \
292 $(USER_DIR)/drivers/accgyro/gyro_sync.c \
293 $(USER_DIR)/pg/pg.c \
294 $(USER_DIR)/pg/gyrodev.c
296 telemetry_crsf_unittest_SRC := \
297 $(USER_DIR)/rx/crsf.c \
298 $(USER_DIR)/telemetry/crsf.c \
299 $(USER_DIR)/common/crc.c \
300 $(USER_DIR)/common/maths.c \
301 $(USER_DIR)/common/streambuf.c \
302 $(USER_DIR)/common/gps_conversion.c \
303 $(USER_DIR)/common/printf.c \
304 $(USER_DIR)/common/typeconversion.c \
305 $(USER_DIR)/fc/runtime_config.c
307 telemetry_crsf_unittest_DEFINES := \
308 FLASH_SIZE=128 \
309 STM32F10X_MD= \
310 __TARGET__="TEST" \
311 __REVISION__="revision"
314 telemetry_crsf_msp_unittest_SRC := \
315 $(USER_DIR)/rx/crsf.c \
316 $(USER_DIR)/build/atomic.c \
317 $(USER_DIR)/common/crc.c \
318 $(USER_DIR)/common/streambuf.c \
319 $(USER_DIR)/common/printf.c \
320 $(USER_DIR)/common/streambuf.c \
321 $(USER_DIR)/drivers/serial.c \
322 $(USER_DIR)/common/typeconversion.c \
323 $(USER_DIR)/telemetry/crsf.c \
324 $(USER_DIR)/common/gps_conversion.c \
325 $(USER_DIR)/telemetry/msp_shared.c \
326 $(USER_DIR)/fc/runtime_config.c
328 telemetry_crsf_msp_unittest_DEFINES := \
329 USE_MSP_OVER_TELEMETRY=
332 telemetry_hott_unittest_SRC := \
333 $(USER_DIR)/telemetry/hott.c \
334 $(USER_DIR)/common/gps_conversion.c
337 telemetry_ibus_unittest_SRC := \
338 $(USER_DIR)/telemetry/ibus_shared.c \
339 $(USER_DIR)/telemetry/ibus.c
341 timer_definition_unittest_EXPAND := yes
343 # SITL is a simulator with empty timerHardware and many hearders in target.c.
344 timer_definition_unittest_BLACKLIST := SITL
346 timer_definition_unittest_SRC = \
347 $(TARGET_DIR)/$(call get_base_target,$1)/target.c
349 timer_definition_unittest_DEFINES = \
350 TARGET=$1 \
351 BASE_TARGET=$(call get_base_target,$1)
353 timer_definition_unittest_INCLUDE_DIRS = \
354 $(TEST_DIR)/timer_definition_unittest.include \
355 $(TARGET_DIR)/$(call get_base_target,$1)
357 transponder_ir_unittest_SRC := \
358 $(USER_DIR)/drivers/transponder_ir_ilap.c \
359 $(USER_DIR)/drivers/transponder_ir_arcitimer.c
361 ws2811_unittest_SRC := \
362 $(USER_DIR)/drivers/light_ws2811strip.c
364 huffman_unittest_SRC := \
365 $(USER_DIR)/common/huffman.c \
366 $(USER_DIR)/common/huffman_table.c
368 huffman_unittest_DEFINES := \
369 USE_HUFFMAN=
371 rcdevice_unittest_SRC := \
372 $(USER_DIR)/common/crc.c \
373 $(USER_DIR)/common/bitarray.c \
374 $(USER_DIR)/fc/rc_modes.c \
375 $(USER_DIR)/io/rcdevice.c \
376 $(USER_DIR)/io/rcdevice_cam.c \
377 $(USER_DIR)/pg/pg.c \
379 pid_unittest_SRC := \
380 $(USER_DIR)/common/filter.c \
381 $(USER_DIR)/common/maths.c \
382 $(USER_DIR)/drivers/accgyro/gyro_sync.c \
383 $(USER_DIR)/fc/controlrate_profile.c \
384 $(USER_DIR)/fc/runtime_config.c \
385 $(USER_DIR)/flight/pid.c \
386 $(USER_DIR)/flight/pid_init.c \
387 $(USER_DIR)/pg/pg.c
389 pid_unittest_DEFINES := \
390 USE_ITERM_RELAX= \
391 USE_RC_SMOOTHING_FILTER= \
392 USE_ABSOLUTE_CONTROL= \
393 USE_LAUNCH_CONTROL= \
394 USE_FEEDFORWARD=
396 rcdevice_unittest_DEFINES := \
397 USE_RCDEVICE=
399 vtx_unittest_SRC := \
400 $(USER_DIR)/fc/core.c \
401 $(USER_DIR)/fc/dispatch.c \
402 $(USER_DIR)/fc/rc_controls.c \
403 $(USER_DIR)/fc/rc_modes.c \
404 $(USER_DIR)/fc/runtime_config.c \
405 $(USER_DIR)/drivers/vtx_common.c \
406 $(USER_DIR)/drivers/vtx_table.c \
407 $(USER_DIR)/io/vtx_control.c \
408 $(USER_DIR)/io/vtx.c \
409 $(USER_DIR)/common/bitarray.c
411 vtx_unittest_DEFINES := \
412 USE_VTX_COMMON= \
413 USE_VTX_CONTROL= \
414 USE_VTX_SMARTAUDIO=
416 rx_spi_spektrum_unittest_SRC := \
417 $(USER_DIR)/rx/cyrf6936_spektrum.c
419 rx_spi_spektrum_unittest_DEFINES := \
420 USE_RX_SPI= \
421 USE_RX_SPEKTRUM=
423 rx_spi_expresslrs_unittest_SRC := \
424 $(USER_DIR)/pg/rx_spi_expresslrs.c \
425 $(USER_DIR)/rx/expresslrs_common.c \
426 $(USER_DIR)/rx/expresslrs.c \
427 $(USER_DIR)/build/atomic.c \
429 rx_spi_expresslrs_unittest_DEFINES := \
430 USE_RX_SPI= \
431 USE_RX_EXPRESSLRS= \
432 USE_RX_SX1280= \
433 USE_RX_SX127X= \
435 rx_spi_expresslrs_telemetry_unittest_SRC := \
436 $(USER_DIR)/rx/crsf.c \
437 $(USER_DIR)/telemetry/crsf.c \
438 $(USER_DIR)/common/crc.c \
439 $(USER_DIR)/common/maths.c \
440 $(USER_DIR)/common/streambuf.c \
441 $(USER_DIR)/common/gps_conversion.c \
442 $(USER_DIR)/common/printf.c \
443 $(USER_DIR)/common/typeconversion.c \
444 $(USER_DIR)/rx/expresslrs_telemetry.c \
445 $(USER_DIR)/build/atomic.c \
446 $(USER_DIR)/telemetry/msp_shared.c \
448 rx_spi_expresslrs_telemetry_unittest_DEFINES := \
449 USE_RX_EXPRESSLRS= \
450 USE_GPS= \
451 USE_MSP_OVER_TELEMETRY= \
453 # Please tweak the following variable definitions as needed by your
454 # project, except GTEST_HEADERS, which you can use in your own targets
455 # but shouldn't modify.
457 # Points to the root of Google Test, relative to where this file is.
458 # Remember to tweak this if you move this file.
459 GTEST_DIR = ../../lib/test/gtest
461 # Use clang/clang++ by default
463 CC := clang-10
464 CXX := clang++-10
465 ifeq ($(shell which $(CC) 2>/dev/null),)
466 $(info Falling back to 'clang'.)
467 CC := clang
468 CXX := clang++
469 endif
471 #CC := gcc
472 #CXX := g++
474 # These flags are needed for clang 10 (linux / MacOS) to make test work:
475 # -Wno-c99-extensions
476 # -Wno-reorder
478 COMMON_FLAGS = \
479 -g \
480 -Wall \
481 -Wextra \
482 -Werror \
483 -Wno-error=unused-command-line-argument \
484 -ggdb3 \
485 -O0 \
486 -DUNIT_TEST \
487 -isystem $(GTEST_DIR)/inc \
488 -MMD -MP \
489 -Wno-c99-extensions \
490 -Wno-reorder
492 CC_VERSION = $(shell $(CC) -dumpversion)
493 CXX_VERSION = $(shell $(CXX) -dumpversion)
495 ifeq ($(shell $(CC) -v 2>&1 | grep -q "clang version" && echo "clang"),clang)
497 # Please revisit versions when new clang version arrive. Supported versions: { Linux / OSX: 7 - 13 }
498 # Travis reports CC_VERSION of 4.2.1
499 CC_VERSION_MAJOR := $(firstword $(subst ., ,$(CC_VERSION)))
500 CC_VERSION_CHECK_MIN := 7
501 CC_VERSION_CHECK_MAX := 13
503 # Added flags for clang 11 - 13 are not backwards compatible
504 ifeq ($(shell expr $(CC_VERSION_MAJOR) \> 10 \& $(CC_VERSION_MAJOR) \< 14), 1)
505 COMMON_FLAGS += \
506 -fcommon \
507 -Wno-void-pointer-to-int-cast
508 endif
510 ifeq ($(shell expr $(CC_VERSION_MAJOR) \< $(CC_VERSION_CHECK_MIN) \| $(CC_VERSION_MAJOR) \> $(CC_VERSION_CHECK_MAX)),1)
511 $(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).)
512 endif
514 COMMON_FLAGS += -fblocks
515 ifndef CYGWIN
516 ifneq ($(OSFAMILY), macosx)
517 LDFLAGS += -lBlocksRuntime
518 endif
519 endif
520 endif
522 $(info CC version: $(shell $(CC) --version))
523 $(info CXX version: $(shell $(CXX) --version))
525 USE_PTHREAD = YES
526 USE_COVERAGE = YES
527 ifeq ($(OSFAMILY), macosx)
528 USE_PTHREAD =
529 endif
530 ifdef CYGWIN
531 USE_PTHREAD =
532 USE_COVERAGE =
533 endif
535 ifdef USE_PTHREAD
536 COMMON_FLAGS += -pthread
537 endif
539 # Flags passed to the C compiler.
540 C_FLAGS = $(COMMON_FLAGS) \
541 -std=gnu99
543 # Flags passed to the C++ compiler.
544 CXX_FLAGS = $(COMMON_FLAGS) \
545 -std=gnu++11
547 # Compiler flags for coverage instrumentation
548 ifdef USE_COVERAGE
549 COVERAGE_FLAGS := --coverage
550 endif
552 C_FLAGS += $(COVERAGE_FLAGS)
553 CXX_FLAGS += $(COVERAGE_FLAGS)
555 C_FLAGS += -D_GNU_SOURCE
557 # Set up the parameter group linker flags according to OS
558 ifeq ($(OSFAMILY), macosx)
559 LDFLAGS += -Wl,-map,$(OBJECT_DIR)/$@.map
560 else
561 LDFLAGS += -Wl,-T,$(TEST_DIR)/pg.ld -Wl,-Map,$(OBJECT_DIR)/$@.map
562 endif
564 # Gather up all of the tests.
565 TEST_SRCS = $(sort $(wildcard $(TEST_DIR)/*.cc))
566 TEST_BASENAMES = $(TEST_SRCS:$(TEST_DIR)/%.cc=%)
567 TESTS_TARGET_SPECIFIC = $(foreach test,$(TEST_BASENAMES),$(if $($(test)_EXPAND),$(test)))
568 TESTS_TARGET_SPECIFIC_EXPANDED = $(foreach test,$(TESTS_TARGET_SPECIFIC),$(foreach \
569 target,$(filter-out $($(test)_BLACKLIST),$(VALID_TARGETS)),$(test).$(target)))
571 TESTS = $(foreach test,$(TEST_BASENAMES),$(if $($(test)_EXPAND),,$(test)))
572 TESTS_ALL = $(TESTS) $(TESTS_TARGET_SPECIFIC_EXPANDED)
573 TESTS_REPRESENTATIVE = $(TESTS) $(foreach test,$(TESTS_TARGET_SPECIFIC), \
574 $(test).$(word 1,$(filter-out $($(test)_BLACKLIST),$(VALID_TARGETS))))
576 # All Google Test headers. Usually you shouldn't change this
577 # definition.
578 GTEST_HEADERS = $(GTEST_DIR)/inc/gtest/*.h
580 ## V : Set verbosity level based on the V= parameter
581 ## V=0 Low
582 ## V=1 High
583 include ../../make/build_verbosity.mk
585 # House-keeping build targets.
587 ## test : Build and run the non target specific Unit Tests (default goal)
588 test: $(TESTS:%=test_%)
590 ## test-all : Build and run all Unit Tests
591 test-all: $(TESTS_ALL:%=test_%)
593 ## test-representative : Build and run a representative subset of the Unit Tests (i.e. run every expanded test only for the first target)
594 test-representative: $(TESTS_REPRESENTATIVE:%=test_%)
596 ## junittest : Build and run the Unit Tests, producing Junit XML result files."
597 junittest: EXEC_OPTS = "--gtest_output=xml:$<_results.xml"
598 junittest: $(TESTS:%=test_%)
602 ## help : print this help message and exit
603 ## what : print this help message and exit
604 ## usage : print this help message and exit
605 help what usage: Makefile
606 @echo ""
607 @echo "Makefile for Unit Tests"
608 @echo ""
609 @echo "Usage:"
610 @echo " make [goal] "
611 @echo ""
612 @echo "Valid goals are:"
613 @echo ""
614 @sed -n 's/^## //p' $<
615 @echo ""
616 @echo "Any of the Unit Test programs can be used as goals to build:"
617 @$(foreach test, $(TESTS), echo " $(OBJECT_DIR)/$(test)/$(test)";)
618 @echo ""
619 @echo "Any of the Unit Test programs (except for target specific unit tests) can be used as goals to build and run:"
620 @$(foreach test, $(TESTS), echo " test_$(test)";)
622 versions:
623 @echo "C compiler: $(CC): $(CC_VERSION)"
624 @echo "C++ compiler: $(CXX): $(CXX_VERSION)"
626 ## clean : Cleanup the UnitTest binaries.
627 clean :
628 rm -rf $(OBJECT_DIR)
631 # Builds gtest.a and gtest_main.a.
633 # Usually you shouldn't tweak such internal variables, indicated by a
634 # trailing _.
635 GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/inc/gtest/*.h $(GTEST_HEADERS)
637 # For simplicity and to avoid depending on Google Test's
638 # implementation details, the dependencies specified below are
639 # conservative and not optimized. This is fine as Google Test
640 # compiles fast and for ordinary users its source rarely changes.
641 $(OBJECT_DIR)/gtest-all.o : $(GTEST_SRCS_)
642 @echo "compiling $@" "$(STDOUT)"
643 @mkdir -p $(dir $@)
644 $(V1) $(CXX) $(CXX_FLAGS) -I$(GTEST_DIR) -Wno-missing-field-initializers -Wno-unused-const-variable -c \
645 $(GTEST_DIR)/src/gtest-all.cc -o $@
647 $(OBJECT_DIR)/gtest_main.o : $(GTEST_SRCS_)
648 @echo "compiling $@" "$(STDOUT)"
649 @mkdir -p $(dir $@)
650 $(V1) $(CXX) $(CXX_FLAGS) -I$(GTEST_DIR) -c \
651 $(GTEST_DIR)/src/gtest_main.cc -o $@
653 $(OBJECT_DIR)/gtest.a : $(OBJECT_DIR)/gtest-all.o
654 @echo "linking $@" "$(STDOUT)"
655 $(V1) $(AR) $(ARFLAGS) $@ $^
657 $(OBJECT_DIR)/gtest_main.a : $(OBJECT_DIR)/gtest-all.o $(OBJECT_DIR)/gtest_main.o
658 @echo "linking $@" "$(STDOUT)"
659 $(V1) $(AR) $(ARFLAGS) $@ $^
661 -include $(OBJECT_DIR)/gtest-all.d \
662 $(OBJECT_DIR)/gtest_main.d
665 # includes in test dir must override includes in user dir, unless the user
666 # specifies a list of endorsed directories in ${target}_INCLUDE_DIRS.
667 test_include_dirs = $1 $(TEST_DIR) $(USER_DIR)
668 test_cflags = $(addprefix -I,$(call test_include_dirs,$1))
671 # target name extractor
672 # param $1 = expanded test name in the form of test.target
673 target = $(1:$(basename $1).%=%)
675 # canned recipe for all test builds
677 # variable expansion rules of thumb (number of $'s):
678 # * parameters: one $, e.g. $1
679 # * statically accessed variables set elsewhere: one $, e.g. $(C_FLAGS)
680 # * dynamically accessed variables set elsewhere: one $, e.g. $($1_SRC)
681 # * make functions accessing only the above: one $, e.g. $(basename $1)
682 # * dynamically set and accessed variables: two $, e.g. $$($1_OBJS)
683 # * make functions accessing dynamically set variables: two $,
684 # e.g. $$(call test_cflags,$$($1_INCLUDE_DIRS))
686 # param $1 = plain test name for global tests, test.target for per-target tests
687 define test-specific-stuff
689 ifeq ($1,$(basename $1))
690 # standard global test
691 $1_OBJS = $(patsubst \
692 $(TEST_DIR)/%,$(OBJECT_DIR)/$1/%,$(patsubst \
693 $(USER_DIR)/%,$(OBJECT_DIR)/$1/%,$($1_SRC:=.o)))
694 else
695 # test executed for each target, $1 has the form of test.target
696 $1_SRC = $(addsuffix .o,$(call $(basename $1)_SRC,$(call target,$1)))
697 $1_OBJS = $$(patsubst \
698 $(TEST_DIR)/%,$(OBJECT_DIR)/$1/%,$$(patsubst \
699 $(USER_DIR)/%,$(OBJECT_DIR)/$1/%,$$(patsubst \
700 $(TARGET_DIR)/$(call get_base_target,$(call target,$1))/%,$(OBJECT_DIR)/$1/%,$$($1_SRC))))
701 $1_DEFINES = $(call $(basename $1)_DEFINES,$(call target,$1))
702 $1_INCLUDE_DIRS = $(call $(basename $1)_INCLUDE_DIRS,$(call target,$1))
703 endif
705 # $$(info $1 -v-v-------)
706 # $$(info $1_SRC: $$($1_SRC))
707 # $$(info $1_OBJS: $$($1_OBJS))
708 # $$(info $1 -^-^-------)
710 # include generated dependencies
711 -include $$($1_OBJS:.o=.d)
712 -include $(OBJECT_DIR)/$1/$(basename $1).d
714 $(OBJECT_DIR)/$1/%.c.o: $(USER_DIR)/%.c
715 @echo "compiling $$<" "$(STDOUT)"
716 $(V1) mkdir -p $$(dir $$@)
717 $(V1) $(CC) $(C_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
718 $$(foreach def,$$($1_DEFINES),-D $$(def)) \
719 -c $$< -o $$@
721 $(OBJECT_DIR)/$1/%.c.o: $(TEST_DIR)/%.c
722 @echo "compiling test c file: $$<" "$(STDOUT)"
723 $(V1) mkdir -p $$(dir $$@)
724 $(V1) $(CC) $(C_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
725 $$(foreach def,$$($1_DEFINES),-D $$(def)) \
726 -c $$< -o $$@
728 ifneq ($1,$(basename $1))
729 # per-target tests may compile files from the target directory
730 $(OBJECT_DIR)/$1/%.c.o: $(TARGET_DIR)/$(call get_base_target,$(call target,$1))/%.c
731 @echo "compiling target c file: $$<" "$(STDOUT)"
732 $(V1) mkdir -p $$(dir $$@)
733 $(V1) $(CC) $(C_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
734 $$(foreach def,$$($1_DEFINES),-D $$(def)) \
735 -c $$< -o $$@
736 endif
738 $(OBJECT_DIR)/$1/$(basename $1).o: $(TEST_DIR)/$(basename $1).cc
739 @echo "compiling $$<" "$(STDOUT)"
740 $(V1) mkdir -p $$(dir $$@)
741 $(V1) $(CXX) $(CXX_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
742 $$(foreach def,$$($1_DEFINES),-D $$(def)) \
743 -c $$< -o $$@
745 $(OBJECT_DIR)/$1/$(basename $1): $$($1_OBJS) \
746 $(OBJECT_DIR)/$1/$(basename $1).o \
747 $(OBJECT_DIR)/gtest_main.a
749 @echo "linking $$@" "$(STDOUT)"
750 $(V1) mkdir -p $(dir $$@)
751 $(V1) $(CXX) $(CXX_FLAGS) $(LDFLAGS) $$^ -o $$@
753 test_$1: $(OBJECT_DIR)/$1/$(basename $1)
754 $(V1) $$< $$(EXEC_OPTS) "$(STDOUT)" && echo "running $$@: PASS"
756 endef
759 ifeq ($(MAKECMDGOALS),test-all)
760 $(eval $(foreach test,$(TESTS_ALL),$(call test-specific-stuff,$(test))))
761 else
762 ifeq ($(MAKECMDGOALS),test-representative)
763 $(eval $(foreach test,$(TESTS_REPRESENTATIVE),$(call test-specific-stuff,$(test))))
764 else
765 $(eval $(foreach test,$(TESTS),$(call test-specific-stuff,$(test))))
766 endif
767 endif
769 $(foreach test,$(TESTS_ALL),$(if $($(basename $(test))_SRC),,$(error \
770 Test 'unit/$(basename $(test)).cc' has no '$(basename $(test))_SRC' variable defined)))
771 $(foreach var,$(filter-out TARGET_SRC,$(filter %_SRC,$(.VARIABLES))),$(if $(filter $(var:_SRC=)%,$(TESTS_ALL)),,$(error \
772 Variable '$(var)' has no 'unit/$(var:_SRC=).cc' test)))
775 target_list:
776 @echo ========== BASE TARGETS ==========
777 @echo $(BASE_TARGETS)
778 @echo ========== ALT TARGETS ==========
779 @echo $(ALT_TARGETS)
780 @echo ========== VALID_TARGETS ==========
781 @echo $(VALID_TARGETS)
782 @echo ========== BASE/ALT PAIRS ==========
783 @echo $(BASE_ALT_PAIRS)
784 @echo ========== ALT/BASE MAPPING ==========
785 @echo $(foreach target,$(ALT_TARGETS),$(target)\>$(call get_base_target,$(target)))
786 @echo ========== ALT/BASE FULL MAPPING ==========
787 @echo $(foreach target,$(VALID_TARGETS),$(target)\>$(call get_base_target,$(target)))