Skip to content

Commit 412c8f8

Browse files
committed
improved makefiles
1 parent 68b1ab2 commit 412c8f8

File tree

7 files changed

+103
-219
lines changed

7 files changed

+103
-219
lines changed

SW/progs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Makefile.progs

SW/progs/Makefile.progs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
BUILD ?= build-mega-atmega2560
2+
# MCU & nástroje
3+
MCU ?= atmega2560
4+
CC = avr-gcc
5+
OBJCOPY = avr-objcopy
6+
OBJDUMP = avr-objdump
7+
8+
LIB_PREFIX = ../../../libs
9+
Ilibs = -I$(LIB_PREFIX)
10+
11+
CFLAGS = -Os -mmcu=$(MCU) -std=gnu99 -Wall -ffreestanding -fno-exceptions -fno-unwind-tables $(Ilibs)
12+
# -nostartfiles Bez standardního vstupního kódu (crt0.o)
13+
# -ffreestanding Nepředpokládat přítomnost libc, vlastní prostředí
14+
# -fno-exceptions Zakáže C++ výjimky
15+
# -fno-unwind-tables Zakáže metadata pro stack trace (např. s výjimkami, laděním)
16+
ASFLAGS = -mmcu=$(MCU)
17+
LDFLAGS = -Wl,-Ttext=0
18+
19+
TARGET := $(notdir $(CURDIR))
20+
SRC ?= $(firstword $(wildcard $(TARGET).S $(TARGET).c ))
21+
22+
PORT ?= $(firstword $(wildcard /dev/ttyA-* /dev/ttyAr* /dev/ttyTot* /dev/ttyUSB* /dev/ttyACM* /dev/null) )
23+
24+
# ========== Automatická detekce knihoven ==========
25+
# Vyhledá řádky jako: ; LIBS: serial file
26+
27+
# LIB_LINES := $(shell grep -i '^; *LIBS:' $(SRC)|sed "s/; *LIBS://")
28+
# $(info $(foreach line,$(LIB_LINES),### $(line) ###))
29+
# LIBS := $(patsubst %,$(LIB_DIR)/$(BUILD)/%, $(LIB_LINES))
30+
# LIBS_DIRS := $(patsubst %,$(LIB_DIR)/%, $(LIB_LINES))
31+
# LIB_OBJS := $(addsuffix .o, $(LIBS))
32+
33+
34+
LIB_NAMES := $(shell grep -o '\s*LIBS:.*' $(SRC) | sed 's/.*\s*LIBS:\s*//' | tr ' ' '\n' | sort -u)
35+
LIB_OBJS := $(foreach lib,$(LIB_NAMES),$(LIB_PREFIX)/$(lib)/$(BUILD)/$(notdir $(lib)).o)
36+
37+
OBJS = $(BUILD)/$(TARGET).o $(LIB_OBJS)
38+
39+
# $(info $(LIB_LINES) ## $(LIBS) ## $(LIB_OBJS) )
40+
41+
# ========== Build pravidla ==========
42+
43+
all: $(BUILD)/$(TARGET).hex $(TARGET).dis | $(BUILD)/
44+
45+
%/:
46+
mkdir -p $@
47+
48+
$(BUILD)/$(TARGET).elf: $(OBJS) | $(BUILD)/
49+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
50+
define LIB_RULE_template
51+
$(LIB_PREFIX)/$(1)/$(BUILD)/$(notdir $(1)).o: $(LIB_PREFIX)/$(1)/*
52+
$(MAKE) -C $(LIB_PREFIX)/$(1) MCU=$(MCU) BUILD=$(BUILD) $(BUILD)/$(notdir $(1)).o
53+
endef
54+
55+
$(BUILD)/%.o: %.c | $(BUILD)/
56+
$(CC) $(CFLAGS) -c $< -o $@
57+
58+
$(BUILD)/%.o: %.S | $(BUILD)/
59+
$(CC) $(ASFLAGS) -c $< -o $@
60+
61+
$(foreach lib,$(LIB_NAMES),$(eval $(call LIB_RULE_template,$(lib))))
62+
63+
$(BUILD)/$(TARGET).hex: $(BUILD)/$(TARGET).elf
64+
$(OBJCOPY) -O ihex -R .eeprom $< $@
65+
66+
$(TARGET).dis: $(BUILD)/$(TARGET).elf Makefile
67+
$(OBJDUMP) --disassemble --source --line-numbers --demangle -z --section=.text --section=.data --section=.bss $< > $@
68+
69+
upload: $(BUILD)/$(TARGET).hex
70+
/usr/bin/avrdude -v -V -p $(MCU) -D -c wiring -b 115200 -P $(PORT) -U flash:w:$<:i
71+
72+
ispload: $(BUILD)/$(TARGET).hex
73+
/usr/bin/avrdude -v -p atmega2560 -c usbasp -b 115200 -e -U lock:w:0x3F:m -U efuse:w:0xFD:m -U hfuse:w:0xD9:m -U lfuse:w:0xFF:m
74+
/usr/bin/avrdude -v -p $(MCU) -D -c usbasp -b 115200 -U flash:w:$<:i
75+
76+
bootloader:
77+
/usr/bin/avrdude -v -p atmega2560 -c usbasp -b 115200 -e -U lock:w:0x3F:m -U efuse:w:0xFD:m -U hfuse:w:0xD8:m -U lfuse:w:0xFF:m
78+
/usr/bin/avrdude -v -p atmega2560 -c usbasp -b 115200 -U flash:w:/usr/share/arduino/hardware/arduino/avr/bootloaders//stk500v2/stk500boot_v2_mega2560.hex:i
79+
80+
81+
monitor:
82+
picocom -b 115200 --flow n --noreset --quiet $(PORT)
83+
84+
upload_monitor: upload monitor
85+
86+
clean:
87+
rm -f *.o *.elf *.hex *.dis
88+
rm -rf $(BUILD)

SW/progs/demo/blink_FK/Makefile

Lines changed: 0 additions & 82 deletions
This file was deleted.

SW/progs/demo/blink_FK/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Makefile.progs

SW/progs/demo/blink_all/Makefile

Lines changed: 0 additions & 82 deletions
This file was deleted.

SW/progs/demo/blink_all/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Makefile.progs

SW/progs/demo/serial_out/Makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ LIB_PREFIX = ../../../libs
99
Ilibs = -I$(LIB_PREFIX)
1010

1111
CFLAGS = -Os -mmcu=$(MCU) -std=gnu99 -Wall -nostartfiles $(Ilibs)
12+
#-nostartfiles Bez standardního vstupního kódu (crt0.o)
13+
#-ffreestanding Nepředpokládat přítomnost libc, vlastní prostředí
14+
#-fno-exceptions Zakáže C++ výjimky
15+
#-fno-unwind-tables Zakáže metadata pro stack trace (např. s výjimkami, laděním)
1216
ASFLAGS = -mmcu=$(MCU)
1317
LDFLAGS = -Wl,-Ttext=0
1418

15-
SRC ?= $(notdir $(CURDIR)).S
1619
TARGET := $(notdir $(CURDIR))
20+
SRC ?= $(firstword $(wildcard $(TARGET).S $(TARGET).c ))
21+
22+
PORT ?= $(firstword $(wildcard /dev/ttyA-* /dev/ttyAr* /dev/ttyTot* /dev/ttyUSB* /dev/ttyACM* /dev/null) )
1723

1824
# ========== Automatická detekce knihoven ==========
1925
# Vyhledá řádky jako: ; LIBS: serial file
@@ -25,7 +31,7 @@ TARGET := $(notdir $(CURDIR))
2531
# LIB_OBJS := $(addsuffix .o, $(LIBS))
2632

2733

28-
LIB_NAMES := $(shell grep -o '^;\s*LIBS:.*' $(SRC) | sed 's/^;\s*LIBS: //' | tr ' ' '\n' | sort -u)
34+
LIB_NAMES := $(shell grep -o '\s*LIBS:.*' $(SRC) | sed 's/.*\s*LIBS:\s*//' | tr ' ' '\n' | sort -u)
2935
LIB_OBJS := $(foreach lib,$(LIB_NAMES),$(LIB_PREFIX)/$(lib)/$(BUILD)/$(notdir $(lib)).o)
3036

3137
OBJS = $(BUILD)/$(TARGET).o $(LIB_OBJS)
@@ -61,7 +67,7 @@ $(TARGET).dis: $(BUILD)/$(TARGET).elf Makefile
6167
$(OBJDUMP) --disassemble --source --line-numbers --demangle -z --section=.text --section=.data --section=.bss $< > $@
6268

6369
upload: $(BUILD)/$(TARGET).hex
64-
/usr/bin/avrdude -v -V -p $(MCU) -D -c wiring -b 115200 -P /dev/ttyACM0 -U flash:w:$<:i
70+
/usr/bin/avrdude -v -V -p $(MCU) -D -c wiring -b 115200 -P $(PORT) -U flash:w:$<:i
6571

6672
ispload: $(BUILD)/$(TARGET).hex
6773
/usr/bin/avrdude -v -p atmega2560 -c usbasp -b 115200 -e -U lock:w:0x3F:m -U efuse:w:0xFD:m -U hfuse:w:0xD9:m -U lfuse:w:0xFF:m
@@ -73,7 +79,7 @@ bootloader:
7379

7480

7581
monitor:
76-
picocom -b 115200 --flow n --noreset --quiet /dev/ttyACM0
82+
picocom -b 115200 --flow n --noreset --quiet $(PORT)
7783

7884
upload_monitor: upload monitor
7985

SW/progs/test/usart0_echo_c_2/Makefile

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Makefile.progs

SW/progs/test/usart0_echo_c_2/usart0_echo_c_2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <avr/io.h>
22
#include <avr/interrupt.h>
33
#include "Serial/usart0/usart0.h"
4+
// LIBS: Serial/usart0
45

56

67
void setup(void) {

0 commit comments

Comments
 (0)