-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
83 lines (63 loc) · 2.86 KB
/
Copy pathMakefile
File metadata and controls
83 lines (63 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
CC ?= cc
RM ?= rm -f
INSTALL ?= install
PREFIX ?= /usr/local
CFLAGS += -Wall -std=c99 -pedantic
.PHONY: all check test install format readme_update clean help
all: example
# ---- Desktop build & output ----------------------------------------------
example: example.c adc_linmap.h linmap.h
$(CC) $(CFLAGS) $(LDFLAGS) -o example example.c
output/:
mkdir output
output/example.md: example output/
./example | tee ./output/example.md
# ---- AVR build & simulation ----------------------------------------------
example-avr.elf: example-avr.c adc_linmap.h linmap.h simavr_cmd.h
avr-gcc -mmcu=atmega328p -Os -std=c99 -DF_CPU=16000000UL \
-Wl,-u,vfprintf -lprintf_flt -lm -o example-avr.elf example-avr.c
output/example-avr.md: example-avr.elf output/
@bash -c 'simavr -m atmega328p -f 16000000 --no-color ./example-avr.elf 2>&1 >/dev/null \
| sed -r "s/\x1B\[[0-9;]*[mK]//g" | sed -r "s/\.\.$$//" | tee ./output/example-avr.md; \
exit $${PIPESTATUS[0]}'
# Run AVR unit tests and print PASS/FAIL summary; simavr exit code signals result
test: example-avr.elf
@echo "Running AVR unit tests under simavr..."
@bash -c 'simavr -m atmega328p -f 16000000 --no-color ./example-avr.elf 2>&1 >/dev/null \
| sed -r "s/\x1B\[[0-9;]*[mK]//g" | sed -r "s/\.\.$$//" \
| grep -E "^(PASS|FAIL|##)"; \
exit $${PIPESTATUS[0]}'
# Build everything and run tests (use this before pushing)
check: example output/example.md example-avr.elf output/example-avr.md test
# ---- Installation --------------------------------------------------------
install: linmap.h adc_linmap.h
$(INSTALL) -d $(DESTDIR)$(PREFIX)/include
$(INSTALL) -m 644 linmap.h adc_linmap.h $(DESTDIR)$(PREFIX)/include
# ---- Maintenance ---------------------------------------------------------
# Regenerate the generated section of README.md from current build output
readme_update: output/example.md output/example-avr.md
jq -r '.version' clib.json \
| xargs -I{} sed -i \
's|<versionBadge>.*</versionBadge>|<versionBadge></versionBadge>|' \
README.md
sed -i '/<!--- GENERATED CONTENT BELOW --->/q' README.md
cat output/example.md >> README.md
cat output/example-avr.md >> README.md
# Auto-format all C sources and headers (requires clang-format)
format:
clang-format -i *.c *.h
clean:
$(RM) example example-avr.elf
$(RM) -r output/
help:
@echo "Targets:"
@echo " all Build desktop example (default)"
@echo " check Full build + AVR unit tests"
@echo " test Run AVR unit tests under simavr"
@echo " install Install headers to PREFIX (default: /usr/local)"
@echo " readme_update Regenerate README from current output"
@echo " format clang-format all .c/.h files"
@echo " clean Remove build artifacts and output/"
@echo ""
@echo "Variables:"
@echo " PREFIX=$(PREFIX) CC=$(CC)"