Files
bacnet_stack/ports/atmega168/Makefile
T
Kari Argillander 0177c59f4a Use pre-commit and editorconfig (#753)
* Add editorconfig and pre-commit config

Editorconfig is widly used and supported file. It says basic things how
files should be formatted.

pre-commit is tool which can automatically check some basic checks like
code formatting everytime someone makes commit. This can also be used in
CI to run these things. Then it is very easy to do same things locally
as in CI. This also makes easy to select clang-format version so
everyone is using same one.

* clang-format: Ignore folders where are external code

We should not format external code. Add clang-format files to exclude
those. We should move external code always to example external/ folder
so we can exclude those more easily.

* clang-format: Remove custom zephyr/.clang-gormat

This clang-format file where introduces before our root clang-format. It
does not make sense anymore as we have root clang-format. Removing this
will unifie formatting in whole repo.

* clang-format: Add couple new rules

Add couple new formatting rules.

Always align const to left side. We did have only one place where it was
right side so this make sense as it is already rule for us.

I choose also insertbraces becuase when I run this I notice that we have
lot of multiline code without braces. So very error prone places. This
will take error possibility away. Repo also always use braces even with
single line statments so this does not matter much.

* ci: Add pre-commit validation

Validate pre-commit in CI.

* format: Convert spaces to tabs in Makefiles

Makefile normally use tabs. We enforce that with editorconfig. Fix
couple places where spaces where still in use.

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
2024-08-28 17:04:00 -05:00

196 lines
4.7 KiB
Makefile

###############################################################################
# Makefile for BACnet
###############################################################################
## General Flags
MCU = atmega328
AVRDUDE_MCU = m328
TARGET = bacnet
## Tools
CC = avr-gcc
AR = avr-ar
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
AVRDUDE = avrdude
LINT = splint
# programmer id--check the avrdude for complete list
# # of available opts. These should include stk500,
# # avr910, avrisp, bsd, pony and more. Set this to
# # one of the valid "-c PROGRAMMER-ID" values
# # described in the avrdude info page.
# #
AVRDUDE_PROGRAMMERID = avrispmkII
#
# # port--serial or parallel port to which your
# # hardware programmer is attached
# #
AVRDUDE_PORT = /dev/ttyUSB0
# Source locations
BACNET_SRC = ../../src
BACNET_CORE = $(BACNET_SRC)/bacnet
BACNET_BASIC = $(BACNET_CORE)/basic
# local files for this project
CSRC = main.c \
timer.c \
stack.c \
rs485.c \
dlmstp.c \
apdu.c \
h_rp.c \
device.c \
av.c \
bv.c \
h_whois.c \
h_wp.c
# common demo files needed
BASICSRC = $(BACNET_BASIC)/tsm/tsm.c \
$(BACNET_BASIC)/npdu/h_npdu.c \
$(BACNET_BASIC)/sys/bigend.c \
$(BACNET_BASIC)/sys/debug.c \
$(BACNET_BASIC)/service/s_iam.c \
$(BACNET_BASIC)/service/h_noserv.c
# core BACnet stack files
CORESRC = \
$(BACNET_CORE)/datalink/crc.c \
$(BACNET_CORE)/npdu.c \
$(BACNET_CORE)/bacdcode.c \
$(BACNET_CORE)/bacint.c \
$(BACNET_CORE)/bacreal.c \
$(BACNET_CORE)/bacstr.c \
$(BACNET_CORE)/iam.c \
$(BACNET_CORE)/rp.c \
$(BACNET_CORE)/wp.c \
$(BACNET_CORE)/whois.c \
$(BACNET_CORE)/bacaddr.c \
$(BACNET_CORE)/abort.c \
$(BACNET_CORE)/reject.c \
$(BACNET_CORE)/bacerror.c \
$(BACNET_CORE)/bacapp.c
## Include Directories
INCLUDES = -I. -I$(BACNET_SRC) -I$(BACNET_CORE)
# Source to Object conversion
COBJ = $(CSRC:.c=.o)
BASICOBJ = $(BASICSRC:.c=.o)
COREOBJ = $(CORESRC:.c=.o)
LIBRARY = lib$(TARGET).a
## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
OPTIMIZE_FLAGS = -mcall-prologues
#OPTIMIZE_FLAGS += -finline-functions
OPTIMIZE_FLAGS += -finline-functions-called-once
#OPTIMIZATION = -O0
#OPTIMIZATION = -Os
OPTIMIZATION = -Os $(OPTIMIZE_FLAGS)
#OPTIMIZATION = -O3 $(OPTIMIZE_FLAGS)
## Compile options common for all C compilation units.
BFLAGS = -DBACDL_MSTP
BFLAGS += -DMAX_APDU=50
BFLAGS += -DBIG_ENDIAN=0
BFLAGS += -DMAX_TSM_TRANSACTIONS=0
#BFLAGS += -DCRC_USE_TABLE
BFLAGS += -DBACAPP_REAL
BFLAGS += -DBACAPP_OBJECT_ID
BFLAGS += -DBACAPP_UNSIGNED
BFLAGS += -DBACAPP_ENUMERATED
BFLAGS += -DBACAPP_CHARACTER_STRING
BFLAGS += -DWRITE_PROPERTY
BFLAGS += -DMAX_ANALOG_VALUES=10
BFLAGS += -DMAX_BINARY_VALUES=10
ifeq (${LEGACY},true)
# disable deprecated function warnings for legacy builds
BFLAGS += -DBACNET_STACK_DEPRECATED_DISABLE
endif
CFLAGS = $(COMMON)
# dead code removal
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += -Wall -gdwarf-2 $(BFLAGS) $(OPTIMIZATION) -fsigned-char
CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d
# silence some warnings
CFLAGS += -Wno-switch
## Assembly specific flags
ASMFLAGS = $(COMMON)
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
## Linker flags
LDFLAGS = $(COMMON)
#dead code removal
#LDFLAGS += -Wl,-nostartfiles,-nostdlib
LDFLAGS += -Wl,--gc-sections,-static
LDFLAGS += -Wl,-Map=$(TARGET).map,-L.,-l$(TARGET)
#LDFLAGS += -Wl,-Map=$(TARGET).map
## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom
HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
## Objects that must be built in order to link
OBJECTS = $(COBJ) $(BASICOBJ)
#OBJECTS = $(COBJ)
## Build
TARGET_ELF=$(TARGET).elf
all: $(LIBRARY) $(TARGET_ELF) $(TARGET).hex $(TARGET).eep $(TARGET).lst \
size Makefile
##Link
$(TARGET_ELF): $(OBJECTS) $(LIBRARY)
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
%.hex: $(TARGET_ELF)
$(OBJCOPY) -O ihex $(HEX_FLASH_FLAGS) $< $@
%.eep: $(TARGET_ELF)
-$(OBJCOPY) $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
%.lst: $(TARGET_ELF)
$(OBJDUMP) -h -S $< > $@
lib: $(LIBRARY)
$(LIBRARY): $(COREOBJ) Makefile
$(AR) rcs $@ $(COREOBJ)
$(OBJDUMP) --syms $@ > $(LIBRARY:.a=.lst)
.c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $*.c -o $@
size: ${TARGET_ELF}
@echo
@${SIZE} ${TARGET_ELF}
lint:
$(LINT) $(BFLAGS) $(CSRC)
install: $(TARGET_ELF)
$(AVRDUDE) -c $(AVRDUDE_PROGRAMMERID) \
-p $(AVRDUDE_MCU) -P $(AVRDUDE_PORT) -e \
-U flash:w:$(TARGET).hex
## Clean target
.PHONY: clean
clean:
-rm -rf $(OBJECTS) $(TARGET_ELF) dep/*
-rm -rf $(LIBRARY) $(COREOBJ) $(LIBRARY:.a=.lst)
-rm -rf $(TARGET).hex $(TARGET).eep $(TARGET).lst $(TARGET).map
## Other dependencies
-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)