Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / test / Makefile
bloba2c105ed995761fb9221472a8c2432395ba3ba6e
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 rx_spi_expresslrs_unittest_SRC := \
422 $(USER_DIR)/pg/rx_spi_expresslrs.c \
423 $(USER_DIR)/rx/expresslrs_common.c \
424 $(USER_DIR)/rx/expresslrs.c \
426 rx_spi_expresslrs_unittest_DEFINES := \
427 USE_RX_SPI= \
428 USE_RX_EXPRESSLRS= \
429 USE_RX_SX1280= \
430 USE_RX_SX127X= \
432 rx_spi_expresslrs_telemetry_unittest_SRC := \
433 $(USER_DIR)/rx/crsf.c \
434 $(USER_DIR)/telemetry/crsf.c \
435 $(USER_DIR)/common/crc.c \
436 $(USER_DIR)/common/maths.c \
437 $(USER_DIR)/common/streambuf.c \
438 $(USER_DIR)/common/gps_conversion.c \
439 $(USER_DIR)/common/printf.c \
440 $(USER_DIR)/common/typeconversion.c \
441 $(USER_DIR)/rx/expresslrs_telemetry.c \
442 $(USER_DIR)/build/atomic.c \
443 $(USER_DIR)/telemetry/msp_shared.c \
445 rx_spi_expresslrs_telemetry_unittest_DEFINES := \
446 USE_RX_EXPRESSLRS= \
447 USE_GPS= \
448 USE_MSP_OVER_TELEMETRY= \
450 # Please tweak the following variable definitions as needed by your
451 # project, except GTEST_HEADERS, which you can use in your own targets
452 # but shouldn't modify.
454 # Points to the root of Google Test, relative to where this file is.
455 # Remember to tweak this if you move this file.
456 GTEST_DIR = ../../lib/test/gtest
458 # Use clang/clang++ by default
460 CC := clang-10
461 CXX := clang++-10
462 ifeq ($(shell which $(CC) 2>/dev/null),)
463 $(info Falling back to 'clang'.)
464 CC := clang
465 CXX := clang++
466 endif
468 #CC := gcc
469 #CXX := g++
471 # These flags are needed for clang 10 (linux / MacOS) to make test work:
472 # -Wno-c99-extensions
473 # -Wno-reorder
475 COMMON_FLAGS = \
476 -g \
477 -Wall \
478 -Wextra \
479 -Werror \
480 -Wno-error=unused-command-line-argument \
481 -ggdb3 \
482 -O0 \
483 -DUNIT_TEST \
484 -isystem $(GTEST_DIR)/inc \
485 -MMD -MP \
486 -Wno-c99-extensions \
487 -Wno-reorder
489 CC_VERSION = $(shell $(CC) -dumpversion)
490 CXX_VERSION = $(shell $(CXX) -dumpversion)
492 ifeq ($(shell $(CC) -v 2>&1 | grep -q "clang version" && echo "clang"),clang)
494 # Please revisit versions when new clang version arrive. Supported versions: { Linux / OSX: 7 - 13 }
495 # Travis reports CC_VERSION of 4.2.1
496 CC_VERSION_MAJOR := $(firstword $(subst ., ,$(CC_VERSION)))
497 CC_VERSION_CHECK_MIN := 7
498 CC_VERSION_CHECK_MAX := 13
500 # Added flags for clang 11 - 13 are not backwards compatible
501 ifeq ($(shell expr $(CC_VERSION_MAJOR) \> 10 \& $(CC_VERSION_MAJOR) \< 14), 1)
502 COMMON_FLAGS += \
503 -fcommon \
504 -Wno-void-pointer-to-int-cast
505 endif
507 ifeq ($(shell expr $(CC_VERSION_MAJOR) \< $(CC_VERSION_CHECK_MIN) \| $(CC_VERSION_MAJOR) \> $(CC_VERSION_CHECK_MAX)),1)
508 $(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).)
509 endif
511 COMMON_FLAGS += -fblocks
512 ifndef CYGWIN
513 ifneq ($(OSFAMILY), macosx)
514 LDFLAGS += -lBlocksRuntime
515 endif
516 endif
517 endif
519 $(info CC version: $(shell $(CC) --version))
520 $(info CXX version: $(shell $(CXX) --version))
522 USE_PTHREAD = YES
523 USE_COVERAGE = YES
524 ifeq ($(OSFAMILY), macosx)
525 USE_PTHREAD =
526 endif
527 ifdef CYGWIN
528 USE_PTHREAD =
529 USE_COVERAGE =
530 endif
532 ifdef USE_PTHREAD
533 COMMON_FLAGS += -pthread
534 endif
536 # Flags passed to the C compiler.
537 C_FLAGS = $(COMMON_FLAGS) \
538 -std=gnu99
540 # Flags passed to the C++ compiler.
541 CXX_FLAGS = $(COMMON_FLAGS) \
542 -std=gnu++11
544 # Compiler flags for coverage instrumentation
545 ifdef USE_COVERAGE
546 COVERAGE_FLAGS := --coverage
547 endif
549 C_FLAGS += $(COVERAGE_FLAGS)
550 CXX_FLAGS += $(COVERAGE_FLAGS)
552 C_FLAGS += -D_GNU_SOURCE
554 # Set up the parameter group linker flags according to OS
555 ifeq ($(OSFAMILY), macosx)
556 LDFLAGS += -Wl,-map,$(OBJECT_DIR)/$@.map
557 else
558 LDFLAGS += -Wl,-T,$(TEST_DIR)/pg.ld -Wl,-Map,$(OBJECT_DIR)/$@.map
559 endif
561 # Gather up all of the tests.
562 TEST_SRCS = $(sort $(wildcard $(TEST_DIR)/*.cc))
563 TEST_BASENAMES = $(TEST_SRCS:$(TEST_DIR)/%.cc=%)
564 TESTS_TARGET_SPECIFIC = $(foreach test,$(TEST_BASENAMES),$(if $($(test)_EXPAND),$(test)))
565 TESTS_TARGET_SPECIFIC_EXPANDED = $(foreach test,$(TESTS_TARGET_SPECIFIC),$(foreach \
566 target,$(filter-out $($(test)_BLACKLIST),$(VALID_TARGETS)),$(test).$(target)))
568 TESTS = $(foreach test,$(TEST_BASENAMES),$(if $($(test)_EXPAND),,$(test)))
569 TESTS_ALL = $(TESTS) $(TESTS_TARGET_SPECIFIC_EXPANDED)
570 TESTS_REPRESENTATIVE = $(TESTS) $(foreach test,$(TESTS_TARGET_SPECIFIC), \
571 $(test).$(word 1,$(filter-out $($(test)_BLACKLIST),$(VALID_TARGETS))))
573 # All Google Test headers. Usually you shouldn't change this
574 # definition.
575 GTEST_HEADERS = $(GTEST_DIR)/inc/gtest/*.h
577 ## V : Set verbosity level based on the V= parameter
578 ## V=0 Low
579 ## V=1 High
580 include ../../make/build_verbosity.mk
582 # House-keeping build targets.
584 ## test : Build and run the non target specific Unit Tests (default goal)
585 test: $(TESTS:%=test_%)
587 ## test-all : Build and run all Unit Tests
588 test-all: $(TESTS_ALL:%=test_%)
590 ## test-representative : Build and run a representative subset of the Unit Tests (i.e. run every expanded test only for the first target)
591 test-representative: $(TESTS_REPRESENTATIVE:%=test_%)
593 ## junittest : Build and run the Unit Tests, producing Junit XML result files."
594 junittest: EXEC_OPTS = "--gtest_output=xml:$<_results.xml"
595 junittest: $(TESTS:%=test_%)
599 ## help : print this help message and exit
600 ## what : print this help message and exit
601 ## usage : print this help message and exit
602 help what usage: Makefile
603 @echo ""
604 @echo "Makefile for Unit Tests"
605 @echo ""
606 @echo "Usage:"
607 @echo " make [goal] "
608 @echo ""
609 @echo "Valid goals are:"
610 @echo ""
611 @sed -n 's/^## //p' $<
612 @echo ""
613 @echo "Any of the Unit Test programs can be used as goals to build:"
614 @$(foreach test, $(TESTS), echo " $(OBJECT_DIR)/$(test)/$(test)";)
615 @echo ""
616 @echo "Any of the Unit Test programs (except for target specific unit tests) can be used as goals to build and run:"
617 @$(foreach test, $(TESTS), echo " test_$(test)";)
619 versions:
620 @echo "C compiler: $(CC): $(CC_VERSION)"
621 @echo "C++ compiler: $(CXX): $(CXX_VERSION)"
623 ## clean : Cleanup the UnitTest binaries.
624 clean :
625 rm -rf $(OBJECT_DIR)
628 # Builds gtest.a and gtest_main.a.
630 # Usually you shouldn't tweak such internal variables, indicated by a
631 # trailing _.
632 GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/inc/gtest/*.h $(GTEST_HEADERS)
634 # For simplicity and to avoid depending on Google Test's
635 # implementation details, the dependencies specified below are
636 # conservative and not optimized. This is fine as Google Test
637 # compiles fast and for ordinary users its source rarely changes.
638 $(OBJECT_DIR)/gtest-all.o : $(GTEST_SRCS_)
639 @echo "compiling $@" "$(STDOUT)"
640 @mkdir -p $(dir $@)
641 $(V1) $(CXX) $(CXX_FLAGS) -I$(GTEST_DIR) -Wno-missing-field-initializers -Wno-unused-const-variable -c \
642 $(GTEST_DIR)/src/gtest-all.cc -o $@
644 $(OBJECT_DIR)/gtest_main.o : $(GTEST_SRCS_)
645 @echo "compiling $@" "$(STDOUT)"
646 @mkdir -p $(dir $@)
647 $(V1) $(CXX) $(CXX_FLAGS) -I$(GTEST_DIR) -c \
648 $(GTEST_DIR)/src/gtest_main.cc -o $@
650 $(OBJECT_DIR)/gtest.a : $(OBJECT_DIR)/gtest-all.o
651 @echo "linking $@" "$(STDOUT)"
652 $(V1) $(AR) $(ARFLAGS) $@ $^
654 $(OBJECT_DIR)/gtest_main.a : $(OBJECT_DIR)/gtest-all.o $(OBJECT_DIR)/gtest_main.o
655 @echo "linking $@" "$(STDOUT)"
656 $(V1) $(AR) $(ARFLAGS) $@ $^
658 -include $(OBJECT_DIR)/gtest-all.d \
659 $(OBJECT_DIR)/gtest_main.d
662 # includes in test dir must override includes in user dir, unless the user
663 # specifies a list of endorsed directories in ${target}_INCLUDE_DIRS.
664 test_include_dirs = $1 $(TEST_DIR) $(USER_DIR)
665 test_cflags = $(addprefix -I,$(call test_include_dirs,$1))
668 # target name extractor
669 # param $1 = expanded test name in the form of test.target
670 target = $(1:$(basename $1).%=%)
672 # canned recipe for all test builds
674 # variable expansion rules of thumb (number of $'s):
675 # * parameters: one $, e.g. $1
676 # * statically accessed variables set elsewhere: one $, e.g. $(C_FLAGS)
677 # * dynamically accessed variables set elsewhere: one $, e.g. $($1_SRC)
678 # * make functions accessing only the above: one $, e.g. $(basename $1)
679 # * dynamically set and accessed variables: two $, e.g. $$($1_OBJS)
680 # * make functions accessing dynamically set variables: two $,
681 # e.g. $$(call test_cflags,$$($1_INCLUDE_DIRS))
683 # param $1 = plain test name for global tests, test.target for per-target tests
684 define test-specific-stuff
686 ifeq ($1,$(basename $1))
687 # standard global test
688 $1_OBJS = $(patsubst \
689 $(TEST_DIR)/%,$(OBJECT_DIR)/$1/%,$(patsubst \
690 $(USER_DIR)/%,$(OBJECT_DIR)/$1/%,$($1_SRC:=.o)))
691 else
692 # test executed for each target, $1 has the form of test.target
693 $1_SRC = $(addsuffix .o,$(call $(basename $1)_SRC,$(call target,$1)))
694 $1_OBJS = $$(patsubst \
695 $(TEST_DIR)/%,$(OBJECT_DIR)/$1/%,$$(patsubst \
696 $(USER_DIR)/%,$(OBJECT_DIR)/$1/%,$$(patsubst \
697 $(TARGET_DIR)/$(call get_base_target,$(call target,$1))/%,$(OBJECT_DIR)/$1/%,$$($1_SRC))))
698 $1_DEFINES = $(call $(basename $1)_DEFINES,$(call target,$1))
699 $1_INCLUDE_DIRS = $(call $(basename $1)_INCLUDE_DIRS,$(call target,$1))
700 endif
702 # $$(info $1 -v-v-------)
703 # $$(info $1_SRC: $$($1_SRC))
704 # $$(info $1_OBJS: $$($1_OBJS))
705 # $$(info $1 -^-^-------)
707 # include generated dependencies
708 -include $$($1_OBJS:.o=.d)
709 -include $(OBJECT_DIR)/$1/$(basename $1).d
711 $(OBJECT_DIR)/$1/%.c.o: $(USER_DIR)/%.c
712 @echo "compiling $$<" "$(STDOUT)"
713 $(V1) mkdir -p $$(dir $$@)
714 $(V1) $(CC) $(C_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
715 $$(foreach def,$$($1_DEFINES),-D $$(def)) \
716 -c $$< -o $$@
718 $(OBJECT_DIR)/$1/%.c.o: $(TEST_DIR)/%.c
719 @echo "compiling test c file: $$<" "$(STDOUT)"
720 $(V1) mkdir -p $$(dir $$@)
721 $(V1) $(CC) $(C_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
722 $$(foreach def,$$($1_DEFINES),-D $$(def)) \
723 -c $$< -o $$@
725 ifneq ($1,$(basename $1))
726 # per-target tests may compile files from the target directory
727 $(OBJECT_DIR)/$1/%.c.o: $(TARGET_DIR)/$(call get_base_target,$(call target,$1))/%.c
728 @echo "compiling target c file: $$<" "$(STDOUT)"
729 $(V1) mkdir -p $$(dir $$@)
730 $(V1) $(CC) $(C_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
731 $$(foreach def,$$($1_DEFINES),-D $$(def)) \
732 -c $$< -o $$@
733 endif
735 $(OBJECT_DIR)/$1/$(basename $1).o: $(TEST_DIR)/$(basename $1).cc
736 @echo "compiling $$<" "$(STDOUT)"
737 $(V1) mkdir -p $$(dir $$@)
738 $(V1) $(CXX) $(CXX_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
739 $$(foreach def,$$($1_DEFINES),-D $$(def)) \
740 -c $$< -o $$@
742 $(OBJECT_DIR)/$1/$(basename $1): $$($1_OBJS) \
743 $(OBJECT_DIR)/$1/$(basename $1).o \
744 $(OBJECT_DIR)/gtest_main.a
746 @echo "linking $$@" "$(STDOUT)"
747 $(V1) mkdir -p $(dir $$@)
748 $(V1) $(CXX) $(CXX_FLAGS) $(LDFLAGS) $$^ -o $$@
750 test_$1: $(OBJECT_DIR)/$1/$(basename $1)
751 $(V1) $$< $$(EXEC_OPTS) "$(STDOUT)" && echo "running $$@: PASS"
753 endef
756 ifeq ($(MAKECMDGOALS),test-all)
757 $(eval $(foreach test,$(TESTS_ALL),$(call test-specific-stuff,$(test))))
758 else
759 ifeq ($(MAKECMDGOALS),test-representative)
760 $(eval $(foreach test,$(TESTS_REPRESENTATIVE),$(call test-specific-stuff,$(test))))
761 else
762 $(eval $(foreach test,$(TESTS),$(call test-specific-stuff,$(test))))
763 endif
764 endif
766 $(foreach test,$(TESTS_ALL),$(if $($(basename $(test))_SRC),,$(error \
767 Test 'unit/$(basename $(test)).cc' has no '$(basename $(test))_SRC' variable defined)))
768 $(foreach var,$(filter-out TARGET_SRC,$(filter %_SRC,$(.VARIABLES))),$(if $(filter $(var:_SRC=)%,$(TESTS_ALL)),,$(error \
769 Variable '$(var)' has no 'unit/$(var:_SRC=).cc' test)))
772 target_list:
773 @echo ========== BASE TARGETS ==========
774 @echo $(BASE_TARGETS)
775 @echo ========== ALT TARGETS ==========
776 @echo $(ALT_TARGETS)
777 @echo ========== VALID_TARGETS ==========
778 @echo $(VALID_TARGETS)
779 @echo ========== BASE/ALT PAIRS ==========
780 @echo $(BASE_ALT_PAIRS)
781 @echo ========== ALT/BASE MAPPING ==========
782 @echo $(foreach target,$(ALT_TARGETS),$(target)\>$(call get_base_target,$(target)))
783 @echo ========== ALT/BASE FULL MAPPING ==========
784 @echo $(foreach target,$(VALID_TARGETS),$(target)\>$(call get_base_target,$(target)))