Skip to content

Commit aeeb859

Browse files
committed
Allow certain makefile args be overridable
Modifications to makefile to allow MCU, F_CPU and BOOTLOADER_ADDRESS variables be overridable by command-line arguments.
1 parent 2f03aae commit aeeb859

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

Makefile

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Author: Peter Fleury
44
# File: $Id: Makefile,v 1.7 2015/08/15 09:10:38 peter Exp $
55
#
6-
# Adjust MCU, F_CPU and BOOTLOADER_ADDRESS below to your AVR target
6+
# Adjust MCU, F_CPU and BOOTLOADER_ADDRESS below to your AVR target
77
#----------------------------------------------------------------------------
88
# usage:
99
#
@@ -13,22 +13,22 @@
1313
# Please customize the avrdude settings below first!
1414
#
1515
# make filename.s = Just compile filename.c into the assembler code only.
16-
# make filename.i = Create a preprocessed source file
16+
# make filename.i = Create a preprocessed source file
1717
#
1818
# To rebuild project do "make clean" then "make"
1919
#----------------------------------------------------------------------------
2020

2121

2222
# MCU name
23-
MCU = atmega8
23+
MCU ?= atmega8
2424

2525

2626
# Processor frequency.
27-
# This will define a symbol, F_CPU, in all source code files equal to the
28-
# processor frequency. You can then use this symbol in your source code to
27+
# This will define a symbol, F_CPU, in all source code files equal to the
28+
# processor frequency. You can then use this symbol in your source code to
2929
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
3030
# automatically to create a 32-bit value in your source code.
31-
F_CPU = 7372800
31+
F_CPU ?= 7372800
3232

3333

3434
# Target file name (without extension).
@@ -40,7 +40,7 @@ TARGET = stk500boot
4040
# BOOTLOADER_ADDRESS = 2 * ( (AVR-Flash size in words) - (boot-size in words) )
4141
# e.g. for ATmega8 and 512 words boot size: 2 * ( 4096 - 512 ) or 2 * ( 0x1000 - 0x200 ) = 0x1C00
4242
# for ATmega32 and 512 words boot size: 2 * ( 16384 - 512 ) or 2 * ( 0x4000 - 0x200 ) = 0x7C00
43-
BOOTLOADER_ADDRESS = 0x1C00
43+
BOOTLOADER_ADDRESS ?= 0x1C00
4444

4545

4646
# List C source files here. (C dependencies are automatically generated.)
@@ -68,7 +68,7 @@ EXTRAINCDIRS =
6868
# (unlike VPATH= which is a search path for all prerequisites, not just source files)
6969

7070

71-
# Optimization level, can be [0, 1, 2, 3, s].
71+
# Optimization level, can be [0, 1, 2, 3, s].
7272
# 0 = turn off optimization. s = optimize for size.
7373
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
7474
OPT = s
@@ -99,7 +99,7 @@ CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
9999
CFLAGS += -Wall -Wstrict-prototypes
100100
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
101101
CFLAGS += -save-temps
102-
CFLAGS += -fno-move-loop-invariants -fno-tree-scev-cprop -fno-inline-small-functions -fno-jump-tables
102+
CFLAGS += -fno-move-loop-invariants -fno-tree-scev-cprop -fno-inline-small-functions -fno-jump-tables
103103

104104

105105
#---------------- Assembler Options ----------------
@@ -116,7 +116,7 @@ PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
116116
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
117117

118118
# If this is left blank, then it will use the Standard printf version.
119-
PRINTF_LIB =
119+
PRINTF_LIB =
120120
#PRINTF_LIB = $(PRINTF_LIB_MIN)
121121
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
122122

@@ -128,7 +128,7 @@ SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
128128
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
129129

130130
# If this is left blank, then it will use the Standard scanf version.
131-
SCANF_LIB =
131+
SCANF_LIB =
132132
#SCANF_LIB = $(SCANF_LIB_MIN)
133133
#SCANF_LIB = $(SCANF_LIB_FLOAT)
134134

@@ -163,15 +163,16 @@ LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
163163
#--------------- bootloader linker Options -------
164164
# BOOTLOADER_ADDRESS (=Start of Boot Loader section
165165
# in bytes - not words) is defined above.
166-
LDFLAGS += -Wl,--section-start=.text=$(BOOTLOADER_ADDRESS) -nostartfiles -nodefaultlibs
166+
LDFLAGS += -Wl,--section-start=.text=$(BOOTLOADER_ADDRESS) -nostartfiles
167+
# LDFLAGS += -Wl,--section-start=.text=$(BOOTLOADER_ADDRESS) -nostartfiles -nodefaultlibs
167168

168169

169170
#---------------- Programming Options (avrdude) ----------------
170171

171172
# Programming hardware: Type: avrdude -c ? to get a full listing.
172173
AVRDUDE_PROGRAMMER = usbasp
173174

174-
# usb, com1 = serial port, lpt1 = parallel port
175+
# usb, com1 = serial port, lpt1 = parallel port
175176
AVRDUDE_PORT = USB
176177

177178
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
@@ -187,7 +188,7 @@ AVRDUDE_NO_SAFEMODE = -u
187188
# Note that this counter needs to be initialized first using -Yn,
188189
#AVRDUDE_ERASE_COUNTER = -y
189190

190-
# Increase verbosity level.
191+
# Increase verbosity level.
191192
#AVRDUDE_VERBOSE = -v -v
192193

193194
# Adjust programming speed of USBasp
@@ -199,11 +200,11 @@ AVRDUDE_NO_SAFEMODE = -u
199200
# -B 125 8 khz
200201
# -B 62 16khz
201202
# -B 31 32khz * the cutoff for bit banged isp
202-
# -B 10 93.75 khz
203+
# -B 10 93.75 khz
203204
# -B 5 187.5 khz
204205
# -B 2 375 khz
205206
# -B 1 750 khz
206-
# -B .5 1.5mhz
207+
# -B .5 1.5mhz
207208
AVRDUDE_SPEED = -B .5
208209

209210
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
@@ -248,7 +249,7 @@ MSG_CLEANING = Cleaning project:
248249
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
249250

250251
# Define all listing files.
251-
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
252+
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
252253

253254

254255
# Compiler flags to generate dependency files.
@@ -266,7 +267,7 @@ all: gccversion $(TARGET).elf $(TARGET).hex $(TARGET).eep $(TARGET).lss $(TARGET
266267

267268

268269
# Display compiler version information.
269-
gccversion :
270+
gccversion :
270271
@echo $(OBJ1)
271272
@$(CC) --version
272273

@@ -278,7 +279,7 @@ gccversion :
278279

279280
%.eep: %.elf
280281
@echo $(MSG_EEPROM) $@
281-
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
282+
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
282283

283284
# Create extended listing file from ELF output file.
284285
%.lss: %.elf
@@ -295,7 +296,7 @@ gccversion :
295296
.PRECIOUS : $(OBJ)
296297
%.elf: $(OBJ)
297298
@echo $(MSG_LINKING) $@
298-
$(CC) -mmcu=$(MCU) $(LDFLAGS) $^ --output $(@F)
299+
$(CC) -mmcu=$(MCU) $(LDFLAGS) $^ --output $(@F)
299300

300301
# Compile: create object files from C source files.
301302
%.o : %.c
@@ -313,15 +314,15 @@ gccversion :
313314

314315
# Create preprocessed source for use in sending a bug report.
315316
%.i : %.c
316-
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $(@F)
317+
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $(@F)
317318

318319

319320
# Display size of file.
320321
size: ${TARGET}.elf
321322
@avr-size -C --mcu=${MCU} ${TARGET}.elf
322323

323324

324-
# Program the device.
325+
# Program the device.
325326
program: $(TARGET).hex $(TARGET).eep
326327
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
327328

@@ -333,7 +334,7 @@ clean:
333334

334335

335336
# Include the dependency files.
336-
#-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
337+
#-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
337338
-include $(shell mkdir .dep 2>NUL) $(wildcard .dep/*)
338339

339340

0 commit comments

Comments
 (0)