Skip to content

Commit

Permalink
make Makefile-{SIM,AVR,common} more generic
Browse files Browse the repository at this point in the history
Allow stock makefile variables to be overridden by 'make' caller
so the user's 'Makefile' can be authoritative.

See Makefile-example for usage.
  • Loading branch information
phord authored and Traumflug committed Mar 4, 2014
1 parent 21e5343 commit 11d7227
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
24 changes: 13 additions & 11 deletions Makefile-AVR
Expand Up @@ -40,17 +40,17 @@
# #
##############################################################################

# MCU_TARGET = atmega168
# MCU_TARGET = atmega328p
MCU_TARGET = atmega644p
# MCU_TARGET = atmega1280
# MCU_TARGET = atmega2560
# MCU_TARGET = at90usb1287
# MCU_TARGET = atmega32u4
# MCU_TARGET ?= atmega168
# MCU_TARGET ?= atmega328p
MCU_TARGET ?= atmega644p
# MCU_TARGET ?= atmega1280
# MCU_TARGET ?= atmega2560
# MCU_TARGET ?= at90usb1287
# MCU_TARGET ?= atmega32u4

# CPU clock rate
F_CPU = 16000000L
# F_CPU = 8000000L
F_CPU ?= 16000000L
# F_CPU ?= 8000000L

##############################################################################
# #
Expand Down Expand Up @@ -79,9 +79,10 @@ TOOLCHAIN = avr-
# -P <port> Serial port the electronics is connected to.
# -C <config file> Optional, default is /etc/avrdude.conf.

UPLOADER = avrdude
UPLOADER ?= avrdude
# UPLOADER = <path-to-arduino-folder>/hardware/tools/avrdude

ifndef UPLOADER_FLAGS
UPLOADER_FLAGS = -c stk500v2
# UPLOADER_FLAGS += -b 19200
# UPLOADER_FLAGS += -b 57600
Expand All @@ -91,6 +92,7 @@ UPLOADER_FLAGS += -p $(MCU_TARGET)
# UPLOADER_FLAGS += -P /dev/ttyACM0
UPLOADER_FLAGS += -P /dev/ttyUSB0
# UPLOADER_FLAGS += -C <path-to-arduino-folder>/hardware/tools/avrdude.conf
endif


##############################################################################
Expand All @@ -108,7 +110,7 @@ TARGET = $(PROGRAM).hex
# to keep this working and can take a shortcut:
SOURCES = $(wildcard *.c)

CFLAGS = -DF_CPU=$(F_CPU)
CFLAGS += -DF_CPU=$(F_CPU)
CFLAGS += -mmcu=$(MCU_TARGET)
CFLAGS += -g
CFLAGS += -Wall
Expand Down
2 changes: 1 addition & 1 deletion Makefile-SIM
Expand Up @@ -44,7 +44,7 @@ SIM_SOURCES = $(subst $(SIM_PATH)/,,$(wildcard $(SIM_PATH)/*.c))
SOURCES := $(filter-out $(subst _sim.c,.c,$(SIM_SOURCES)),$(SOURCES)) $(SIM_SOURCES)

OBJ = $(patsubst %.c,$(BUILDDIR)/%.sim.o,$(SOURCES))
CFLAGS = -g -Wall -Wstrict-prototypes -Wno-format -Os $(DEFS) -std=gnu99
CFLAGS += -g -Wall -Wstrict-prototypes -Wno-format -Os $(DEFS) -std=gnu99
CFLAGS += -funsigned-char -funsigned-bitfields -fshort-enums -I.. -I.
CFLAGS += -DSIMULATOR

Expand Down
36 changes: 36 additions & 0 deletions Makefile-example
@@ -0,0 +1,36 @@
################################################################################
#
## Example Makefile
#
# For convenience, copy this file to "Makefile" and customize it to fit your
# needs.
#
# Then you can type 'make avr' or simply 'make' to build for your printer.
#
################################################################################
.PHONY: sim avr clean all default

# Override variables in the stock makefiles
export F_CPU = 20000000L
export MCU_TARGET = atmega644p

default: avr

all: sim avr

# Build the simulator
sim:
@echo "----[ Simulator ]----"
@make -sf Makefile-SIM

# Build Teacup for an Atmel processor
avr:
@echo "----[ $(MCU_TARGET) ]----"
@make -sf Makefile-AVR

clean:
@echo "----[ Clean ]----"
@make -sf Makefile-SIM clean
@make -sf Makefile-AVR clean
# Add any more cleanup steps you want here. Example,
# rm -f *.png

0 comments on commit 11d7227

Please sign in to comment.