added new makefile

pull/1/head
Ondřej Hruška 9 years ago
parent 3d946abdfd
commit d3dce4ffa7
  1. 84
      Makefile
  2. 9
      README.md

@ -1,60 +1,98 @@
## === CPU settings === ###################################
# Makefile for MightyPork/avr-lib #
# Revision 3 #
###################################
## ===== CPU settings =====
# CPU type # CPU type
MCU = atmega328p MCU = atmega328p
# CPU frequency # CPU frequency
F_CPU = 16000000 F_CPU = 16000000
# Fuses # Fuses
LFUSE = 0xFF LFUSE = 0xFF
HFUSE = 0xDE HFUSE = 0xDE
EFUSE = 0x05 EFUSE = 0x05
OPTIMIZE = s
## ===== Source files =====
## === Source files ===
# Main C file # Main C file
MAIN = main.c MAIN = main.c
# Extra C files in this folder
LOCAL_SOURCE =
# Library directory (with C files) # Library directory (with C and H files)
EXTRA_SOURCE_DIR = lib/ LIB_DIR = lib/
# C files in the library directory # C files in the library directory
EXTRA_SOURCE_FILES = uart.c LIB_C_FILES = uart.c iopins.c stream.c adc.c dht11.c sonar.c onewire.c spi.c sd.c fat16.c
# Extra Files that need config file:
#LIB_C_FILES += lcd.c
#LIB_C_FILES += color.c wsrgb.c
#LIB_C_FILES += debouce.c
LIB_H_FILES = adc.h calc.h dht11.h fat16.h fat16_internal.h iopins.h nsdelay.h onewire.h sd.h sonar.h spi.h stream.h uart.h
LIB_H_FILES += lcd.h color.h wsrgb.h debounce.h
## ===== Programmer =====
## === Programmer ===
PROGRAMMER_TYPE = arduino PROGRAMMER_TYPE = arduino
PROGRAMMER_ARGS = -b 57600 -P /dev/ttyUSB0 PROGRAMMER_ARGS = -b 57600 -P /dev/ttyUSB0
## === C flags === ## ===== C flags =====
CFLAGS = -std=gnu99 -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -I. -I$(EXTRA_SOURCE_DIR) CFLAGS = -std=gnu99 -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -I. -I$(LIB_DIR)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums CFLAGS += -funsigned-char
CFLAGS += -Wall -Wno-main -Wno-strict-prototypes -Wno-comment CFLAGS += -funsigned-bitfields
CFLAGS += -g2 -Wextra -Wfatal-errors -Wno-unused-but-set-variable CFLAGS += -fpack-struct
CFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--relax CFLAGS += -fshort-enums
# CFLAGS += -lm ## Math CFLAGS += -finline-functions
# CFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf CFLAGS += -ffunction-sections
# CFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf CFLAGS += -fdata-sections
CFLAGS_BUILD = $(CFLAGS) -Os CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -Wno-main
CFLAGS += -Wno-comment
CFLAGS += -Wno-unused-but-set-variable
CFLAGS += -Wfatal-errors
CFLAGS += -Wl,--gc-sections
CFLAGS += -Wl,--relax
CFLAGS += -Wl,--relax
#CFLAGS += -lm ## Math
#CFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## Floating-point printf
#CFLAGS += -Wl,-u,vfprintf -lprintf_min ## Smaller printf
CFLAGS_BUILD = $(CFLAGS) -O$(OPTIMIZE)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
## Defined programs / locations ## Defined programs / locations
CC = avr-gcc CC = avr-gcc
OBJCOPY = avr-objcopy OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump OBJDUMP = avr-objdump
AVRSIZE = avr-size AVRSIZE = avr-size
AVRDUDE = avrdude AVRDUDE = avrdude
UART_TERM = gtkterm -p /dev/ttyUSB0
## === File lists === ## === File lists ===
TARGET = $(strip $(basename $(MAIN))) TARGET = $(strip $(basename $(MAIN)))
SRC1 = $(TARGET).c SRC1 = $(TARGET).c
SRC = $(SRC1) SRC = $(SRC1)
EXTRA_SOURCE = $(addprefix $(EXTRA_SOURCE_DIR), $(EXTRA_SOURCE_FILES)) EXTRA_SOURCE = $(addprefix $(LIB_DIR), $(LIB_C_FILES))
LIB_H_FILES_FILES = $(addprefix $(LIB_DIR), $(LIB_H_FILES))
SRC += $(EXTRA_SOURCE) SRC += $(EXTRA_SOURCE)
SRC += $(LOCAL_SOURCE)
HEADERS = $(SRC:.c=.h) HEADERS = $(SRC:.c=.h)
OBJ = $(SRC:.c=.o) OBJ = $(SRC:.c=.o)
@ -67,7 +105,7 @@ pre: $(TARGET).pre
%.hex: %.elf %.hex: %.elf
$(OBJCOPY) -R .eeprom -O ihex $< $@ $(OBJCOPY) -R .eeprom -O ihex $< $@
%.elf: $(SRC) %.elf: $(SRC) $(LIB_H_FILES_FILES) Makefile
$(CC) $(CFLAGS_BUILD) $(SRC) --output $@ $(CC) $(CFLAGS_BUILD) $(SRC) --output $@
%.pre: $(SRC1) %.pre: $(SRC1)
@ -122,6 +160,10 @@ flashe: $(TARGET).eeprom
shell: shell:
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt
fser: all flash ser
ser:
$(UART_TERM)
# === fuses === # === fuses ===

@ -10,6 +10,15 @@ and smaller.
Pull requests to add new modules are welcome, please go ahead! Pull requests to add new modules are welcome, please go ahead!
## Makefile
You can use the provided Makefile to boild your project with this library.
A project typically consists of one `main.c` file, and some `*_config.c` files where the
library headers request it (those define eg. IO pin mapping).
Adjust the Makefile to yoru needs!
## License ## License
The library is provided under MIT license, see the LICENSE file for more info. The library is provided under MIT license, see the LICENSE file for more info.

Loading…
Cancel
Save