Makefile
author Tero Marttila <terom@paivola.fi>
Sat, 05 Apr 2014 00:37:32 +0300
changeset 58 a445e08b63e0
parent 51 ec6271f0637b
child 62 2d68a76322cb
permissions -rw-r--r--
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
58
a445e08b63e0 hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents: 51
diff changeset
     1
PROG = hello-lkm
47
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
     2
51
ec6271f0637b make: fix build-deps, and avr-objdump -d build/src/hello.elf
Tero Marttila <terom@paivola.fi>
parents: 50
diff changeset
     3
ELF = build/src/$(PROG).elf
50
e4ac5a591dcd src/ layout
Tero Marttila <terom@paivola.fi>
parents: 48
diff changeset
     4
HEX = build/src/$(PROG).hex
e4ac5a591dcd src/ layout
Tero Marttila <terom@paivola.fi>
parents: 48
diff changeset
     5
e4ac5a591dcd src/ layout
Tero Marttila <terom@paivola.fi>
parents: 48
diff changeset
     6
all: $(HEX)
47
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
     7
48
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
     8
build:
50
e4ac5a591dcd src/ layout
Tero Marttila <terom@paivola.fi>
parents: 48
diff changeset
     9
	mkdir -p build/src
48
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    10
47
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    11
## Compiler
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    12
MCU = atmega328p
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    13
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    14
# CPU clock frequency
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    15
CPU = 16000000
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    16
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    17
CC = avr-gcc
48
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    18
CPPFLAGS = -DF_CPU=$(CPU)UL
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    19
CFLAGS = -g -mmcu=$(MCU) -Os
47
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    20
50
e4ac5a591dcd src/ layout
Tero Marttila <terom@paivola.fi>
parents: 48
diff changeset
    21
build/%.elf: %.c
48
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    22
	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $*.c
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    23
	$(CC) -MM $(CPPFLAGS) -MT $@ -MF build/$*.d $*.c
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    24
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    25
# existing .d files for rebuilding existing .o's
51
ec6271f0637b make: fix build-deps, and avr-objdump -d build/src/hello.elf
Tero Marttila <terom@paivola.fi>
parents: 50
diff changeset
    26
-include $(wildcard build/*/*.d)
47
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    27
50
e4ac5a591dcd src/ layout
Tero Marttila <terom@paivola.fi>
parents: 48
diff changeset
    28
build/%.hex: build/%.elf
47
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    29
	avr-objcopy -O ihex -R .eeprom $< $@
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    30
50
e4ac5a591dcd src/ layout
Tero Marttila <terom@paivola.fi>
parents: 48
diff changeset
    31
.PRECIOUS: build/%.elf
47
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    32
51
ec6271f0637b make: fix build-deps, and avr-objdump -d build/src/hello.elf
Tero Marttila <terom@paivola.fi>
parents: 50
diff changeset
    33
dump: $(ELF)
ec6271f0637b make: fix build-deps, and avr-objdump -d build/src/hello.elf
Tero Marttila <terom@paivola.fi>
parents: 50
diff changeset
    34
	avr-objdump -d $(ELF)
ec6271f0637b make: fix build-deps, and avr-objdump -d build/src/hello.elf
Tero Marttila <terom@paivola.fi>
parents: 50
diff changeset
    35
47
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    36
## Assembler
5
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
AS = avra
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
ASFLAGS = 
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
47
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    40
matrix.hex: spi.inc matrix.inc timer.inc delay.inc macros.inc font.inc font.def
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    41
led7seg.hex: spi.inc led7seg.inc adc.inc timer.inc delay.inc macros.inc
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    42
timer.hex: timer.inc macros.inc
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    43
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    44
%.hex: %.s
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    45
	$(AS) $(ASFLAGS) $<
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    46
	mv $<.hex $@
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    47
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    48
# fonts
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    49
font.inc: font.def
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    50
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    51
font.def: font.txt font-compile.py
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    52
	python font-compile.py $< $@ > /dev/null
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    53
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    54
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    55
## Flashing
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    56
# Arduino Duemilanove
5
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
AD_PART = m328p
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    58
AD_PROG = arduino
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    59
AD_BAUD = 57600
43
a0a003083d4c use /dev/arduino for avrdude
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    60
AD_PORT = /dev/arduino
5
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    61
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    62
AD = avrdude
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    63
ADFLAGS = -p $(AD_PART) -c $(AD_PROG) -b $(AD_BAUD) -P $(AD_PORT)
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
50
e4ac5a591dcd src/ layout
Tero Marttila <terom@paivola.fi>
parents: 48
diff changeset
    65
upload: $(HEX)
17
a7c668003a19 split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
    66
	$(AD) $(ADFLAGS) -U flash:w:$<
5
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
47
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    68
## Console
10
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    69
SERIAL_BAUD = 9600
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    70
SERIAL_FLOW = n
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    71
SERIAL_PARITY = n
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    72
SERIAL_BITS = 8
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    73
SERIAL_PORT = $(AD_PORT)
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    74
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    75
SERIAL_TERM = picocom
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    76
SERIAL_FLAGS = -b $(SERIAL_BAUD) -f $(SERIAL_FLOW) -p $(SERIAL_PARITY) -d $(SERIAL_BITS)
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    77
47
7f930a94ee1e bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents: 45
diff changeset
    78
console:
10
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    79
	$(SERIAL_TERM) $(SERIAL_FLAGS) $(SERIAL_PORT)
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    80