Module/Makefile

69 lines
1.9 KiB
Makefile
Raw Permalink Normal View History

2024-01-16 16:14:54 +01:00
TARGET = stm32l4x2
PRJ = example
BLD = ./bld/
# clang 18, modules experimental
CC = clang
CXX = clang++
# arm-none-eabi- toolchain (+gcc)
LD = arm-none-eabi-ld
SIZE = arm-none-eabi-size
DUMP = arm-none-eabi-objdump
COPY = arm-none-eabi-objcopy
TGT = --target=thumbv7em-none-eabi -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
LDLIBS = -L/usr/lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m+fp/hard -L./$(TARGET) -Tscript.ld -lgcc
CFLAGS = -Wall $(TGT) -Oz -gdwarf-3 -I./$(TARGET) -ffunction-sections -fdata-sections -fno-exceptions
LFLAGS = -nostart-files --gc-sections -Map=example.map
MFLAGS = $(CFLAGS) -fmodules -fprebuilt-module-path=.
VFLAGS = -std=c++20 -fno-rtti
2024-01-18 11:42:56 +01:00
PFLAGS = c++-module $(TGT) -I./$(TARGET) -fprebuilt-module-path=. -fno-exceptions
2024-01-16 16:14:54 +01:00
VPATH = . ./$(TARGET)
# zdrojaky -> objekty
OBJS = STM32L4x2_startup.o system.o
2024-01-18 11:42:56 +01:00
MOBJS = morse.o io.o sys.o main.o
2024-01-16 16:14:54 +01:00
BOBJS = $(addprefix $(BLD),$(OBJS))
all: $(BLD) $(PRJ).elf
# ... atd.
# -include $(BLD)*.d
# linker
$(PRJ).elf: $(BOBJS) $(MOBJS)
2024-01-18 11:42:56 +01:00
-@echo [LLD $(TARGET)] $@
2024-01-16 16:14:54 +01:00
@$(LD) $(LFLAGS) -o $(PRJ).elf $(BOBJS) $(MOBJS) $(LDLIBS)
-@echo "size:"
@$(SIZE) $(PRJ).elf
-@echo "listing:"
$(DUMP) -d $(PRJ).elf > $(PRJ).lst
$(COPY) --strip-unneeded -O binary $(PRJ).elf $(PRJ).bin
-@echo "OK."
# preloz co je potreba
$(BLD)%.o: %.c
2024-01-18 11:42:56 +01:00
-@echo [CCC $(TARGET)] $@
2024-01-16 16:14:54 +01:00
@$(CC) -c $(CFLAGS) $< -o $@
$(BLD)%.o: %.cpp
-@echo [CXX $(TARGET)] $@
@$(CXX) $(VFLAGS) -c $(CFLAGS) $< -o $@
$(BLD):
mkdir $(BLD)
2024-01-19 13:04:24 +01:00
tabgen: tabgen.cpp
$(CXX) -Oz tabgen.cpp -o tabgen
table.cpp: tabgen
./tabgen
2024-01-16 16:14:54 +01:00
# MODULES #
2024-01-19 15:52:53 +01:00
main.o: main.cpp morse.pcm io.pcm
2024-01-19 13:04:24 +01:00
morse.o: morse.cpp table.cpp io.pcm sys.pcm
morse.pcm: morse.cpp table.cpp io.pcm sys.pcm
2024-01-16 16:14:54 +01:00
%.o: %.cpp
-@echo [CXM $(TARGET)] $@
@$(CXX) $(VFLAGS) -c $(MFLAGS) $< -o $@
%.pcm: %.cpp
-@echo [PRE $(TARGET)] $@
2024-01-18 11:42:56 +01:00
@$(CXX) $(VFLAGS) -x $(PFLAGS) $< --precompile -o $@
2024-01-16 16:14:54 +01:00
# vycisti
clean:
2024-01-19 13:04:24 +01:00
rm -f $(BLD)* *.o *.lst *.bin *.elf *.map *.pcm *~ table.cpp tabgen
2024-01-16 16:14:54 +01:00
.PHONY: all clean