synth/arm/makefile

111 lines
3.0 KiB
Makefile
Raw Normal View History

2022-05-08 06:00:22 +00:00
CC = arm-none-eabi-gcc
2022-05-17 03:26:37 +00:00
LD = arm-none-eabi-g++
2022-05-08 06:00:22 +00:00
CXX = arm-none-eabi-g++
OBJCOPY = arm-none-eabi-objcopy
linker_script = bootloader.ld
2022-06-19 07:57:04 +00:00
includes =
2022-05-09 03:55:58 +00:00
sources =
2022-05-08 06:00:22 +00:00
2022-05-17 03:28:24 +00:00
CFLAGS = -march=armv6-m -g -ffunction-sections -fdata-sections -Os -Werror -Wall -flto
CXXFLAGS = $(CFLAGS) -std=c++20 -fno-exceptions -fcoroutines
CPPFLAGS = -MD -MP
2022-05-09 03:55:58 +00:00
LDFLAGS = -march=armv6-m \
-g --specs=nano.specs --specs=nosys.specs \
2022-05-17 03:28:24 +00:00
-Wl,--gc-sections -Os \
-Wl,--print-memory-usage -flto
2022-05-08 06:00:22 +00:00
2022-05-17 03:56:25 +00:00
includes += -Ihal/cmsis
2022-05-09 03:55:58 +00:00
sources += hal/lib/common/xil_assert.c
includes += -Ihal/lib/common
2022-05-17 03:56:25 +00:00
sources += hal/uart/xuartlite.c hal/uart/xuartlite_stats.c hal/uart/xuartlite_intr.c
2022-05-09 03:55:58 +00:00
includes += -Ihal/uart
2022-05-17 17:17:56 +00:00
bootloader_objects = bootloader.o vector_table.o $(sources:.c=.o)
2022-05-17 03:56:25 +00:00
app_objects = app_init.o crash.o main.o uart.o stdlib.o async.o trace.o $(sources:.c=.o)
2022-05-09 03:55:58 +00:00
2022-05-17 03:28:24 +00:00
CPPFLAGS += $(includes)
2022-05-09 03:55:58 +00:00
2024-05-07 21:02:14 +00:00
.PHONY: app
app: app.bin ## Build the main app
.PHONY: bootloader ## Build the bootloader
bootloader: bootloader.elf
2022-05-08 06:00:22 +00:00
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
2022-05-17 03:28:24 +00:00
bootloader.elf: $(bootloader_objects) bootloader.ld
$(LD) -Wl,-Tbootloader.ld $(LDFLAGS) -o $@ $(bootloader_objects)
2022-05-17 03:28:24 +00:00
app.elf: $(app_objects) app.ld
$(LD) -Wl,-Tapp.ld $(LDFLAGS) -o $@ $(app_objects)
2022-05-08 06:00:22 +00:00
2022-05-17 03:56:25 +00:00
deps = $(app_objects:.o=.d) $(bootloader_objects:.o=.d)
2022-05-08 06:00:22 +00:00
HOSTCXX = clang++
2022-06-19 07:41:17 +00:00
HOSTLDFLAGS = -lgmock -lgtest -lgtest_main -L/usr/local/opt/llvm/lib -L/usr/local/lib
HOSTCFLAGS = -std=c++20 -g\
-I/usr/local/opt/llvm/include \
-I/usr/local/include \
-I/usr/local/include \
-MP -MD
2022-05-17 03:56:25 +00:00
2022-06-19 07:41:17 +00:00
TSAN_CFLAGS = $(HOSTCFLAGS) -fsanitize=thread
ASAN_CFLAGS = $(HOSTCFLAGS) -fsanitize=address -fsanitize=leak
tests = ring_buffer_test.run async_test_asan.run async_test_tsan.run uart_test_tsan.run
2022-05-17 03:56:25 +00:00
2024-05-07 21:02:14 +00:00
.PHONY: test
test: $(tests) ## Run tests
2022-05-17 03:56:25 +00:00
test/async_test_asan: async_test.cc async.host.o lock.host.o
test/async_test_tsan: async_test.cc async.host.o lock.host.o
test/ring_buffer_test: ring_buffer_test.cc lock.host.o
test/uart_test_tsan: uart_test.cc fake_uart.host.o async.host.o lock.host.o
%.run: test/%
TSAN_OPTIONS='suppressions=tsan.suppressions' ASAN_OPTIONS=detect_leaks=1 ./$<
2022-06-19 07:41:17 +00:00
%.host.o: %.cc
$(HOSTCXX) $(HOSTCFLAGS) -c -o $@ $<
test/%_test: | mktest
$(HOSTCXX) $(HOSTCFLAGS) -o $@ $^ $(HOSTLDFLAGS)
test/%_asan: | mktest
$(HOSTCXX) $(ASAN_CFLAGS) -o $@ $^ $(HOSTLDFLAGS)
test/%_tsan: | mktest
$(HOSTCXX) $(TSAN_CFLAGS) -o $@ $^ $(HOSTLDFLAGS)
2022-06-19 07:41:17 +00:00
2024-05-07 21:02:14 +00:00
.PHONY: mktest
mktest:
2022-06-19 07:41:17 +00:00
mkdir -p test
2023-06-04 03:41:16 +00:00
test_deps = async.host.d lock.host.d fake_uart.host.d
2022-05-17 03:56:25 +00:00
2024-05-07 21:02:14 +00:00
.PHONY: dev-image
dev-image:
docker build -t arm-dev -f dev.dockerfile .
2022-06-19 07:57:04 +00:00
2024-05-07 21:02:14 +00:00
.PHONY: dev
dev: dev-image ## Run a dev container
docker run -it --rm -v $(CURDIR):/workspace -w /workspace arm-dev
.PHONY: clean
clean: ## Remove generated files
2022-06-19 07:57:04 +00:00
rm -rf *.elf *.bin $(app_objects) $(bootloader_objects) $(deps)
rm -rf test/ *.dSYM $(test_deps) *.o
2022-06-19 07:57:04 +00:00
2024-05-07 21:02:14 +00:00
.PHONY: help
help: ## Show this help
@echo Noteworthy targets:
@egrep '^[a-zA-Z_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help
#-include $(deps)
#-include $(test_deps)