Makefile
author Tero Marttila <terom@paivola.fi>
Thu, 03 Apr 2014 18:49:02 +0300
changeset 48 50dc2f4d90fd
parent 47 7f930a94ee1e
child 50 e4ac5a591dcd
permissions -rw-r--r--
Makefile: .d build deps
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
     1
PROG = hello
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
# console
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
     3
# dmx
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
     4
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
     5
all: $(PROG).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
     6
48
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
     7
build:
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
     8
	mkdir -p build/
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
     9
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
    10
## 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
    11
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
    12
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
# 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
    14
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
    15
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
CC = avr-gcc
48
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    17
CPPFLAGS = -DF_CPU=$(CPU)UL
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    18
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
    19
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
%.elf: %.c
48
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    21
	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $*.c
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    22
	$(CC) -MM $(CPPFLAGS) -MT $@ -MF build/$*.d $*.c
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    23
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    24
# existing .d files for rebuilding existing .o's
50dc2f4d90fd Makefile: .d build deps
Tero Marttila <terom@paivola.fi>
parents: 47
diff changeset
    25
-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
    26
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
%.hex: %.elf
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
    28
	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
    29
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
.PRECIOUS: %.elf
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
    31
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
## Assembler
5
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
AS = avra
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
ASFLAGS = 
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
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
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
    37
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
    38
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
    39
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
%.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
    41
	$(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
    42
	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
    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
# 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
    45
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
    46
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
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
    48
	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
    49
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
## 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
    52
# Arduino Duemilanove
5
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    53
AD_PART = m328p
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    54
AD_PROG = arduino
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    55
AD_BAUD = 57600
43
a0a003083d4c use /dev/arduino for avrdude
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    56
AD_PORT = /dev/arduino
5
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    58
AD = avrdude
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    59
ADFLAGS = -p $(AD_PART) -c $(AD_PROG) -b $(AD_BAUD) -P $(AD_PORT)
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    60
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
    61
upload: $(PROG).hex
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
    62
	$(AD) $(ADFLAGS) -U flash:w:$<
5
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    63
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
    64
## Console
10
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    65
SERIAL_BAUD = 9600
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    66
SERIAL_FLOW = n
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    67
SERIAL_PARITY = n
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    68
SERIAL_BITS = 8
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    69
SERIAL_PORT = $(AD_PORT)
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    70
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    71
SERIAL_TERM = picocom
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    72
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
    73
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
    74
console:
10
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    75
	$(SERIAL_TERM) $(SERIAL_FLAGS) $(SERIAL_PORT)
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    76