inspektors/common/Makefile
2018-01-21 13:54:20 +02:00

87 lines
2.1 KiB
Makefile

CC := avr-gcc
AR := avr-ar
SIZE := avr-size
OBJDUMP = avr-objdump
SRCDIR := src
BUILDDIR := build
INCDIR := include
LIBDIR := lib
LIB := libcommon
SRCEXT := c
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
INC := -I $(INCDIR)
# AR flags
ARFLAGS := rcs
MCU = atmega328p
## Language standard
CFLAGS += -std=gnu99
## Definitions
CFLAGS += -DF_CPU=16000000L -D__AVR__ -D__AVR_ATmega328P__
## Tuning
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
DEBUG_FORMAT = stabs
ifeq ($(BUILD),debug)
CFLAGS += -DDEBUG -g$(DEBUG_FORMAT)
CFLAGS += -Wall -Wextra -Wformat=2 -Wswitch-default \
-Wcast-align -Wpointer-arith -Wbad-function-cast \
-Wstrict-prototypes -Winline -Wundef -Wnested-externs \
-Wcast-qual -Wshadow -Wwrite-strings -Wconversion \
-Winit-self -Wstrict-aliasing -Wmissing-declarations \
-Wmissing-include-dirs -Wno-unused-parameter -Wuninitialized \
-Wold-style-definition -Wmissing-prototypes -Wunreachable-code \
-Wno-unused-but-set-variable -Wmaybe-uninitialized
CINCS += -I /usr/include/simavr
#
else
CFLAGS += -DNDEBUG -s -Os
endif
.PHONY: clean debug all
all: lib
lib: $(LIBDIR)/$(LIB).a
debug_header:
@echo "================================================="
@echo "Debug build initiated..."
@echo "--------"
debug: clean debug_header
$(MAKE) "BUILD=debug"
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@echo "================================================="
@echo "Building objects..."
@echo "--------"
@mkdir -p $(BUILDDIR)
@mkdir -p $(LIBDIR)
@mkdir -p $(INCDIR)
$(CC) $(CFLAGS) $(INC) -c -o $@ $<
.SECONDARY: $(OBJ)
%.a: $(OBJECTS)
@echo "================================================="
@echo "Building static library..."
@echo "--------"
$(AR) $(ARFLAGS) $(LIBDIR)/$(LIB).a $(OBJECTS)
clean:
@echo "================================================="
@echo "Cleaning up build files...";
@rm -rf $(BUILDDIR) $(LIBDIR)