Skip to content
Snippets Groups Projects
Commit 7191df84 authored by Graziano Scalamera's avatar Graziano Scalamera
Browse files

Support install in Makefile

parent 0e65f6d7
No related branches found
No related tags found
No related merge requests found
# Main Makefile for BACnet-stack applications, tests, and sample ports
# Export the variables defined here to all subprocesses
# (see http://www.gnu.org/software/automake/manual/make/Special-Targets.html)
.EXPORT_ALL_VARIABLES:
# all: demos router-ipv6 ${DEMO_LINUX}
.PHONY: all
all: apps
.PHONY: bsd
bsd:
$(MAKE) BACNET_PORT=bsd -s -C apps all
.PHONY: win32
win32:
$(MAKE) BACNET_PORT=win32 -s -C apps all
.PHONY: mingw32
mingw32:
i686-w64-mingw32-gcc --version
ORIGINAL_CC=$(CC) ; \
ORIGINAL_LD=$(LD) ; \
export CC=i686-w64-mingw32-gcc ; \
export LD=i686-w64-mingw32-ld ; \
$(MAKE) BACNET_PORT=win32 -s -C apps all ; \
export CC=$(ORIGINAL_CC) ; \
export LD=$(ORIGINAL_LD)
.PHONY: mstpwin32
mstpwin32:
$(MAKE) BACDL=mstp BACNET_PORT=win32 -s -C apps all
.PHONY: mstp
mstp:
$(MAKE) BACDL=mstp -s -C apps all
.PHONY: bip6-win32
bip6-win32:
$(MAKE) BACDL=bip6 BACNET_PORT=win32 -s -C apps all
.PHONY: bip6
bip6:
$(MAKE) BACDL=bip6 -s -C apps all
TARGET = bacnet
#
# release numbers for libraries
#
LIBVERSION = 1
LIBRELEASE = 3
LIBSUBRELEASE = 8
########################################################################################################
#
# prefix detination for installation
#
ifeq ($(PREFIX),)
PREFIX := /usr
endif
#
# support for shared libray versioning
#
LFLAGS_SONAME = -Wl,-soname,
SHLDFLAGS = -shared
BASELIBNAME = lib$(TARGET)
SHLIB_SUFFIX = so
#
# file name for libraries
#
# LIBRARY = $(BASELIBNAME).a
DT_SONAME = $(BASELIBNAME).$(SHLIB_SUFFIX).$(LIBVERSION)
DT_SHLIB = $(BASELIBNAME).$(SHLIB_SUFFIX).$(LIBVERSION).$(LIBRELEASE).$(LIBSUBRELEASE)
SHLIB = $(BASELIBNAME).$(SHLIB_SUFFIX)
# Passing parameters via command line or from Makefile export to this one
BACNET_DEFINES ?=
# BACnet Library
BACNET_LIB_DIR = $(realpath ./lib)
BACNET_LIB_NAME = bacnet
BACNET_LIB_TARGET = $(BACNET_LIB_DIR)/lib$(BACNET_LIB_NAME).a
BACNET_LIB ?= -L$(BACNET_LIB_DIR) -l$(BACNET_LIB_NAME)
# choose a datalink to build the example applications
# Use BACDL=mstp or BACDL=bip and BBMD=server when invoking make
ifeq (${BACDL_DEFINE},)
ifeq (${BACDL},ethernet)
BACDL_DEFINE=-DBACDL_ETHERNET=1
endif
ifeq (${BACDL},arcnet)
BACDL_DEFINE=-DBACDL_ARCNET=1
endif
ifeq (${BACDL},mstp)
BACDL_DEFINE=-DBACDL_MSTP=1
endif
ifeq (${BACDL},bip)
BACDL_DEFINE=-DBACDL_BIP=1
endif
ifeq (${BACDL},bip6)
BACDL_DEFINE=-DBACDL_BIP6=1
endif
ifeq (${BACDL},none)
BACDL_DEFINE=-DBACDL_NONE=1
endif
ifeq (${BACDL},bip-mstp)
BACDL_DEFINE=-DBACDL_ROUTER=1
endif
ifeq (${BACDL},bip-bip6)
BACDL_DEFINE=-DBACDL_ROUTER=1
endif
ifeq (${BACDL},all)
BACDL_DEFINE=-DBACDL_ALL=1
endif
ifeq (${BACDL},)
BACDL_DEFINE ?= -DBACDL_BIP=1
BBMD_DEFINE ?= -DBBMD_ENABLED=1 -DBBMD_CLIENT_ENABLED
endif
.PHONY: bip
bip:
$(MAKE) BACDL=bip -s -C apps all
ifeq (${BBMD},none)
BBMD_DEFINE = -DBBMD_ENABLED=0
endif
ifeq (${BBMD},server)
BBMD_DEFINE = -DBBMD_ENABLED=1
endif
ifeq (${BBMD},client)
BBMD_DEFINE = -DBBMD_ENABLED=0 -DBBMD_CLIENT_ENABLED
endif
ifeq (${BBMD},full)
BBMD_DEFINE = -DBBMD_ENABLED=1 -DBBMD_CLIENT_ENABLED
endif
.PHONY: bip-client
bip-client:
$(MAKE) BACDL=bip BBMD=client -s -C apps all
endif
.PHONY: ethernet
ethernet:
$(MAKE) BACDL=ethernet -s -C apps all
# Define WEAK_FUNC for unsupported or specific compilers
BACNET_DEFINES += $(BACDL_DEFINE)
BACNET_DEFINES += $(BBMD_DEFINE)
BACNET_DEFINES += -DWEAK_FUNC=
BACNET_DEFINES += $(MAKE_DEFINE)
# Choose a BACnet Ports Directory for the example applications target OS
ifeq (${BACNET_PORT},)
ifeq ($(OS),Windows_NT)
BACNET_PORT = win32
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
BACNET_PORT = linux
endif
ifeq ($(UNAME_S),Darwin)
BACNET_PORT = bsd
endif
ifeq ($(UNAME_S),FreeBSD)
BACNET_PORT = bsd
endif
ifeq ($(UNAME_S),OpenBSD)
BACNET_PORT = bsd
endif
endif
endif
.PHONY: apps
apps:
$(MAKE) -s -C apps all
# linux, win32, bsd
BACNET_PORT ?= linux
.PHONY: lib
lib:
$(MAKE) -s -C apps $@
# build in uci integration - use UCI=1 when invoking make
ifeq (${UCI},1)
BACNET_DEFINES += -DBAC_UCI
UCI_LIB_DIR ?= /usr/local/lib
BACNET_LIB += -L$(UCI_LIB_DIR) -luci
endif
# OS specific builds
ifeq (${BACNET_PORT},linux)
PFLAGS = -pthread
TARGET_EXT =
SYSTEM_LIB=-lc,-lgcc,-lrt,-lm
endif
ifeq (${BACNET_PORT},bsd)
PFLAGS = -pthread
TARGET_EXT =
SYSTEM_LIB=-lc,-lm
CSTANDARD = -std=c99
endif
ifeq (${BACNET_PORT},win32)
# winget install --id=MSYS2.MSYS2 -e
# pacman -Syu mingw-w64-i686-toolchain
# add alias make=mingw32-make.exe to .bashrc
TARGET_EXT = .exe
SYSTEM_LIB=-lws2_32,-lgcc,-lm,-liphlpapi,-lwinmm
BACNET_DEFINES += -D_NO_OLDNAMES
endif
CMAKE_BUILD_DIR=build
.PHONY: cmake
cmake:
[ -d $(CMAKE_BUILD_DIR) ] || mkdir -p $(CMAKE_BUILD_DIR)
[ -d $(CMAKE_BUILD_DIR) ] && cd $(CMAKE_BUILD_DIR) && cmake .. -DBUILD_SHARED_LIBS=ON && cmake --build . --clean-first
.PHONY: cmake-win32
cmake-win32:
mkdir -p $(CMAKE_BUILD_DIR)
cd $(CMAKE_BUILD_DIR) && cmake ../ -DBACNET_STACK_BUILD_APPS=ON && cmake --build ./ --clean-first
cp $(CMAKE_BUILD_DIR)/Debug/*.exe ./bin/.
# source file locations
BACNET_PORT_DIR = $(realpath ./ports/$(BACNET_PORT))
BACNET_SRC_DIR = $(realpath ./src)
#
# List of the public include files
#
INC_FILES = $(BACNET_PORT_DIR)/bacport.h $(BACNET_PORT_DIR)/rs485.h $(BACNET_PORT_DIR)/dlmstp_linux.h
INC_BACNET_DIRS := $(shell find src/bacnet -type d)
# Compiler flag to set the C Standard level.
# c89 - "ANSI" C - ISO C90
# gnu89 - c89 plus GNU extensions
# c90 - "ANSI" C - ISO C90
# gnu90 - C90 with GNU extensions
# c99 - ISO C99 standard
# gnu99 - C99 plus GNU extensions
# c11 - C11
# gnu11 - C11 plus GNU extensions
# c17 - C11 with corrections
# note: default is compiled as ANSI C for widest compiler compatibilty
# note: code that requires newer language features must use __STDC_VERSION__
CSTANDARD ?= -std=gnu89
#build for release (default) or debug
OPTIMIZATION ?= -Os
DEBUGGING ?=
# enable all relevant warnings that find bugs
WARNING_ALL := -Wall -Wextra -pedantic
WARNING_ALL += -Wfloat-equal -Wconversion
WARNING_ALL += -Wredundant-decls -Wswitch-default
WARNING_ALL += -Wunused-variable
# don't warn about conversion, sign, compares, long long and attributes
# since they are common in embedded
WARNING_ALL += -Wno-sign-conversion -Wno-conversion -Wno-sign-compare
WARNING_ALL += -Wno-long-long -Wno-attributes
# don't warn about implicit fallthrough since it's common in network protocols
WARNING_ALL += -Wno-implicit-fallthrough
#WARNING_ALL += -Werror
WARNINGS ?= $(WARNING_ALL)
# dead code removal
ifeq (${BUILD},debug)
OPTIMIZATION = -O0
DEBUGGING = -g -DDEBUG_ENABLED=1
ifeq (${BACDL_DEFINE},-DBACDL_BIP=1)
BACNET_DEFINES += -DBIP_DEBUG
endif
endif
.PHONY: abort
abort:
$(MAKE) -s -C apps $@
ifeq (${LEGACY},true)
# disable deprecated function warnings for legacy builds
BACNET_DEFINES += -DBACNET_STACK_DEPRECATED_DISABLE
endif
.PHONY: ack-alarm
ack-alarm:
$(MAKE) -s -C apps $@
BACNET_DEFINES += -DPRINT_ENABLED=1
BACNET_DEFINES += -DBACAPP_ALL
BACNET_DEFINES += -DBACFILE
BACNET_DEFINES += -DINTRINSIC_REPORTING
BACNET_DEFINES += -DBACNET_TIME_MASTER
BACNET_DEFINES += -DBACNET_PROPERTY_LISTS=1
BACNET_DEFINES += -DBACNET_PROPERTY_ARRAY_LISTS=1
BACNET_DEFINES += -DBACNET_PROTOCOL_REVISION=24
# put all the flags together
INCLUDES = -I$(BACNET_SRC_DIR) -I$(BACNET_PORT_DIR)
CFLAGS += $(WARNINGS) $(DEBUGGING) $(OPTIMIZATION) $(BACNET_DEFINES) $(INCLUDES)
CFLAGS += $(CSTANDARD) -fPIC
ifneq (${BACNET_LIB},)
LFLAGS += $(BACNET_LIB)
endif
# BACnet library depends on system flags.
# System flags must go after BACnet library flags.
LFLAGS += -Wl,$(SYSTEM_LIB)
# GCC dead code removal
CFLAGS += -ffunction-sections -fdata-sections
ifeq ($(shell uname -s),Darwin)
LFLAGS += -Wl,-dead_strip
else
LFLAGS += -Wl,--gc-sections
endif
# Debug linker commands
# LFLAGS += -Wl,-v
.PHONY: add-list-element
add-list-element:
$(MAKE) -s -C apps $@
.EXPORT_ALL_VARIABLES:
.PHONY: apdu
apdu:
$(MAKE) -s -C apps $@
SUBDIRS = lib readprop writeprop readfile writefile reinit server dcc \
whohas whois iam ucov scov timesync epics readpropm readrange \
writepropm uptransfer getevent uevent abort error event ack-alarm \
server-client add-list-element remove-list-element create-object \
delete-object server-discover apdu
ifeq (${BACDL_DEFINE},-DBACDL_BIP=1)
SUBDIRS += whoisrouter iamrouter initrouter whatisnetnum netnumis
ifneq (${BBMD},none)
SUBDIRS += readbdt readfdt writebdt
endif
endif
.PHONY: blinkt
blinkt:
$(MAKE) -s -C apps $@
ifeq (${BACNET_PORT},linux)
ifneq (${OSTYPE},cygwin)
SUBDIRS += mstpcap mstpcrc
endif
endif
.PHONY: create-object
create-object:
$(MAKE) -s -C apps $@
ifeq (${BACNET_PORT},win32)
SUBDIRS += mstpcap mstpcrc
endif
.PHONY: dcc
dcc:
$(MAKE) -s -C apps $@
ifeq (${BACNET_PORT},bsd)
SUBDIRS += mstpcap mstpcrc
endif
.PHONY: delete-object
delete-object:
$(MAKE) -s -C apps $@
#####
# Define target-specific fuzzing flags
#####
.PHONY: epics
epics:
$(MAKE) -s -C apps $@
# AFL
fuzz-afl: CC=afl-gcc
fuzz-afl: FUZZ_FLAGS=-DFUZZING=1
fuzz-afl: LFLAGS += $(FUZZ_FLAGS)
fuzz-afl: CFLAGS += $(FUZZ_FLAGS)
fuzz-afl: export AFL_USE_ASAN=1
.PHONY: error
error:
$(MAKE) -s -C apps $@
# LIBFUZZER
fuzz-libfuzzer: CC=clang
fuzz-libfuzzer: FUZZ_FLAGS=-DFUZZING=1 -fsanitize=fuzzer,address -g3 -Og -fno-optimize-sibling-calls -fno-omit-frame-pointer
fuzz-libfuzzer: LFLAGS += $(FUZZ_FLAGS)
fuzz-libfuzzer: CFLAGS += $(FUZZ_FLAGS)
.PHONY: event
event:
$(MAKE) -s -C apps $@
#####
# Fuzz setup end
#####
.PHONY: iam
iam:
$(MAKE) -s -C apps $@
.PHONY: all clean
TARGETS = all clean
.PHONY: getevent
getevent:
$(MAKE) -s -C apps $@
.PHONY: gateway
gateway:
$(MAKE) -s -B -C apps $@
.PHONY: lib
lib: lib/Makefile Makefile $(BACNET_LIB_TARGET)
.PHONY: gateway-win32
gateway-win32:
$(MAKE) BACNET_PORT=win32 -s -B -C apps gateway
$(BACNET_LIB_TARGET):
$(MAKE) -B -C lib
.PHONY: piface
piface:
$(MAKE) CSTANDARD="-std=gnu11" LEGACY=true -s -C apps $@
clean:
$(MAKE) -C lib clean
.PHONY: readbdt
readbdt:
$(MAKE) -s -C apps $@
.PHONY: readfdt
readfdt:
$(MAKE) -s -C apps $@
.PHONY: readprop
readprop:
$(MAKE) -s -C apps $@
.PHONY: readpropm
readpropm:
$(MAKE) -s -C apps $@
.PHONY: remove-list-element
remove-list-element:
$(MAKE) -s -C apps $@
.PHONY: writebdt
writebdt:
$(MAKE) -s -C apps $@
.PHONY: whatisnetnum
whatisnetnum:
$(MAKE) -s -C apps $@
.PHONY: netnumis
netnumis:
$(MAKE) -s -C apps $@
.PHONY: server
server:
$(MAKE) -s -C apps $@
define newline
.PHONY: server-client
server-client:
$(MAKE) LEGACY=true -s -C apps $@
.PHONY: server-discover
server-discover:
$(MAKE) LEGACY=true -s -C apps $@
endef
.PHONY: mstpcap
mstpcap:
$(MAKE) -s -C apps $@
install: all lib
# cp -f $(OutputFile) $(LibInstall)
install -d $(PREFIX)/lib
ln -sfrn $(PREFIX)/lib/$(DT_SONAME) $(PREFIX)/lib/$(SHLIB)
ln -sfrn $(PREFIX)/lib/$(DT_SHLIB) $(PREFIX)/lib/$(DT_SONAME)
cp $(BACNET_LIB_DIR)/$(DT_SHLIB) $(PREFIX)/lib/$(DT_SHLIB)
cp $(BACNET_LIB_TARGET) $(PREFIX)/lib/lib$(BACNET_LIB_NAME).a
install -D -m 644 $(INC_FILES) -t $(PREFIX)/include
$(foreach dir,$(INC_BACNET_DIRS),$(if $(strip $(wildcard $(dir)/*.h)),install -D -m 644 $(wildcard $(dir)/*.h) -t $(PREFIX)/include/$(patsubst src/%,./%,$(dir)) $(newline),))
.PHONY: mstpcrc
mstpcrc:
$(MAKE) -s -C apps $@
.PHONY: uevent
uevent:
$(MAKE) -s -C apps $@
.PHONY: whois
whois:
$(MAKE) -s -C apps $@
.PHONY: writepropm
writepropm:
$(MAKE) -s -C apps $@
.PHONY: router
router:
$(MAKE) -s -C apps $@
.PHONY: router-ipv6
router-ipv6:
$(MAKE) -s -B BACDL=bip-bip6 -C apps $@
.PHONY: router-ipv6-win32
router-ipv6-win32:
$(MAKE) BACNET_PORT=win32 -s -B BACDL=bip-bip6 -C apps router-ipv6
.PHONY: router-ipv6-clean
router-ipv6-clean:
$(MAKE) -C apps $@
.PHONY: router-mstp
router-mstp:
$(MAKE) -s -B BACDL=bip-mstp -C apps $@
.PHONY: router-mstp-win32
router-mstp-win32:
$(MAKE) BACNET_PORT=win32 -s -B BACDL=bip-mstp -C apps router-mstp
.PHONY: router-mstp-clean
router-mstp-clean:
$(MAKE) -C apps $@
.PHONY: fuzz-libfuzzer
fuzz-libfuzzer:
$(MAKE) -s -C apps $@
.PHONY: fuzz-afl
fuzz-afl:
$(MAKE) -s -C apps $@
# Add "ports" to the build, if desired
.PHONY: ports
ports: atmega168 bdk-atxx4-mstp at91sam7s stm32f10x stm32f4xx
@echo "Built the ARM7 and AVR ports"
.PHONY: ports-clean
ports-clean: atmega168-clean bdk-atxx4-mstp-clean at91sam7s-clean \
stm32f10x-clean stm32f4xx-clean xplained-clean
.PHONY: atmega168
atmega168: ports/atmega168/Makefile
$(MAKE) -s -C ports/atmega168 clean all
.PHONY: atmega168-clean
atmega168-clean: ports/atmega168/Makefile
$(MAKE) -s -C ports/atmega168 clean
.PHONY: bdk-atxx4-mstp
bdk-atxx4-mstp: ports/bdk-atxx4-mstp/Makefile
$(MAKE) -s -C ports/bdk-atxx4-mstp clean all
.PHONY: bdk-atxx4-mstp-clean
bdk-atxx4-mstp-clean: ports/bdk-atxx4-mstp/Makefile
$(MAKE) -s -C ports/bdk-atxx4-mstp clean
.PHONY: at91sam7s
at91sam7s: ports/at91sam7s/Makefile
$(MAKE) -s -C ports/at91sam7s clean all
.PHONY: at91sam7s-clean
at91sam7s-clean: ports/at91sam7s/Makefile
$(MAKE) -s -C ports/at91sam7s clean
AT91SAM7S_CMAKE_BUILD_DIR=ports/at91sam7s/build
.PHONY: at91sam7s-cmake
at91sam7s-cmake:
[ -d $(AT91SAM7S_CMAKE_BUILD_DIR) ] || mkdir -p $(AT91SAM7S_CMAKE_BUILD_DIR)
[ -d $(AT91SAM7S_CMAKE_BUILD_DIR) ] && cd $(AT91SAM7S_CMAKE_BUILD_DIR) && \
cmake ../ && cmake --build . --clean-first
.PHONY: stm32f10x
stm32f10x: ports/stm32f10x/Makefile
$(MAKE) -s -C ports/stm32f10x clean all
.PHONY: stm32f10x-clean
stm32f10x-clean: ports/stm32f10x/Makefile
$(MAKE) -s -C ports/stm32f10x clean
.PHONY: stm32f4xx
stm32f4xx: ports/stm32f4xx/Makefile
$(MAKE) -s -C ports/stm32f4xx clean all
.PHONY: stm32f4xx-clean
stm32f4xx-clean: ports/stm32f4xx/Makefile
$(MAKE) -s -C ports/stm32f4xx clean
STM32F4XX_CMAKE_BUILD_DIR=ports/stm32f4xx/build
.PHONY: stm32f4xx-cmake
stm32f4xx-cmake:
[ -d $(STM32F4XX_CMAKE_BUILD_DIR) ] || mkdir -p $(STM32F4XX_CMAKE_BUILD_DIR)
[ -d $(STM32F4XX_CMAKE_BUILD_DIR) ] && cd $(STM32F4XX_CMAKE_BUILD_DIR) && \
cmake ../ && cmake --build . --clean-first
.PHONY: xplained
xplained: ports/xplained/Makefile
$(MAKE) -s -C ports/xplained clean all
.PHONY: xplained-clean
xplained-clean: ports/xplained/Makefile
$(MAKE) -s -C ports/xplained clean
.PHONY: mstpsnap
mstpsnap: ports/linux/mstpsnap.mak
$(MAKE) -s -C ports/linux -f mstpsnap.mak clean all
.PHONY: lwip
lwip: ports/lwip/Makefile
$(MAKE) -s -C ports/lwip clean all
.PHONY: pretty
pretty:
find ./src -iname *.h -o -iname *.c -exec \
clang-format -i -style=file -fallback-style=none {} \;
find ./apps -iname *.h -o -iname *.c -exec \
clang-format -i -style=file -fallback-style=none {} \;
.PHONY: pretty-apps
pretty-apps:
find ./apps -iname *.h -o -iname *.c -exec \
clang-format -i -style=file -fallback-style=none {} \;
.PHONY: pretty-ports
pretty-ports:
find ./ports -maxdepth 2 -type f -iname *.h -o -iname *.c -exec \
clang-format -i -style=file -fallback-style=none {} \;
.PHONY: pretty-test
pretty-test:
find ./test/bacnet -type f -iname *.h -o -iname *.c -exec \
clang-format -i -style=file -fallback-style=none {} \;
CLANG_TIDY_OPTIONS = -fix-errors -checks="readability-braces-around-statements"
CLANG_TIDY_OPTIONS += -- -Isrc -Iports/linux
.PHONY: tidy
tidy:
find ./src -iname *.h -o -iname *.c -exec clang-tidy {} $(CLANG_TIDY_OPTIONS) \;
find ./apps -iname *.c -exec clang-tidy {} $(CLANG_TIDY_OPTIONS) \;
.PHONY: scan-build
scan-build:
scan-build --status-bugs -analyze-headers make -j2 LEGACY=true server
SPLINT_OPTIONS := -weak +posixlib +quiet \
-D__signed__=signed -D__gnuc_va_list=va_list \
-Isrc -Iports/linux \
+matchanyintegral +ignoresigns -unrecog -preproc \
+error-stream-stderr +warning-stream-stderr -warnposix \
-bufferoverflowhigh
SPLINT_FIND_OPTIONS := ./src -path ./src/bacnet/basic/ucix -prune -o -name "*.c"
.PHONY: splint
splint:
find $(SPLINT_FIND_OPTIONS) -exec splint $(SPLINT_OPTIONS) {} \;
CPPCHECK_OPTIONS = --enable=warning,portability
CPPCHECK_OPTIONS += --template=gcc
CPPCHECK_OPTIONS += --inline-suppr
CPPCHECK_OPTIONS += --suppress=selfAssignment
CPPCHECK_OPTIONS += --suppress=integerOverflow
CPPCHECK_OPTIONS += -DBACNET_STACK_DEPRECATED
#CPPCHECK_OPTIONS += -I./src
#CPPCHECK_OPTIONS += --enable=information --check-config
CPPCHECK_OPTIONS += --error-exitcode=1
.PHONY: cppcheck
cppcheck:
cppcheck $(CPPCHECK_OPTIONS) --quiet --force ./src/
.PHONY: flawfinder
flawfinder:
flawfinder --minlevel 5 --error-level=5 ./src/
IGNORE_WORDS = ba,statics
CODESPELL_OPTIONS = --write-changes --interactive 3 --enable-colors
CODESPELL_OPTIONS += --ignore-words-list $(IGNORE_WORDS)
.PHONY: codespell
codespell:
codespell $(CODESPELL_OPTIONS) ./src
SPELL_OPTIONS = --enable-colors --ignore-words-list $(IGNORE_WORDS)
.PHONY: spell
spell:
codespell $(SPELL_OPTIONS) ./src
# McCabe's Cyclomatic Complexity Scores
# sudo apt install pmccable
COMPLEXITY_SRC = \
$(wildcard ./src/bacnet/*.c) \
$(wildcard ./src/bacnet/basic/*.c) \
$(wildcard ./src/bacnet/basic/binding/*.c) \
$(wildcard ./src/bacnet/basic/service/*.c) \
$(wildcard ./src/bacnet/basic/sys/*.c) \
./src/bacnet/basic/npdu/h_npdu.c \
./src/bacnet/basic/npdu/s_router.c \
./src/bacnet/basic/tsm/tsm.c
.PHONY: pmccabe
pmccabe:
pmccabe $(COMPLEXITY_SRC) | awk '{print $$2,$$6,$$7}' | sort -nr | head -20
# sudo apt install complexity
# 0-9 Easily maintained code.
# 10-19 Maintained with little trouble.
# 20-29 Maintained with some effort.
# 30-39 Difficult to maintain code.
# 40-49 Hard to maintain code.
# 50-99 Unmaintainable code.
# 100-199 Crazy making difficult code.
# 200+ I only wish I were kidding.
.PHONY: complexity
complexity:
complexity $(COMPLEXITY_SRC)
# sudo apt install sloccount
.PHONY: sloccount
sloccount:
sloccount .
.PHONY: clean
clean: ports-clean
$(MAKE) -s -C src clean
$(MAKE) -s -C apps clean
$(MAKE) -s -C apps/router clean
$(MAKE) -s -C apps/router-ipv6 clean
$(MAKE) -s -C apps/router-mstp clean
$(MAKE) -s -C apps/gateway clean
$(MAKE) -s -C apps/fuzz-afl clean
$(MAKE) -s -C apps/fuzz-libfuzzer clean
$(MAKE) -s -C ports/lwip clean
$(MAKE) -s -C test clean
rm -rf ./build
.PHONY: test
test:
$(MAKE) -s -C test clean
$(MAKE) -s -j -C test all
.PHONY: retest
retest:
$(MAKE) -s -j -C test retest
# Zephyr unit testing with twister
# expects zephyr to be installed in ../zephyr in Workspace
# expects ZEPHYR_BASE to be set. E.g. source ../zephyr/zephyr-env.sh
# see https://docs.zephyrproject.org/latest/getting_started/index.html
TWISTER_RESULTS=../twister-out.unit_testing
.PHONY: twister
twister:
ifndef ZEPHYR_BASE
$(error ZEPHYR_BASE is undefined)
endif
$(ZEPHYR_BASE)/scripts/twister -O $(TWISTER_RESULTS) -p unit_testing -T zephyr/tests
.PHONY: twister-clean
twister-clean:
-rm -rf $(TWISTER_RESULTS)
# BACnet Stack library
# Build all the non-OS or port specific code
BACNET_LIB_NAME ?= bacnet
BACNET_LIB_DIR ?= $(realpath .)
BACNET_LIB_TARGET ?= $(BACNET_LIB_DIR)/lib$(BACNET_LIB_NAME).a
BACNET_SRC_DIR ?= $(realpath ../src)
BACNET_PORT_DIR ?= $(realpath ../ports/linux)
BACNET_DEFINES ?=
#build for release (default) or debug
OPTIMIZATION ?= -Os
DEBUGGING ?=
# enable all relevant warnings that find bugs
WARNING_ALL := -Wall -Wextra -Wfloat-equal -Wconversion
WARNING_ALL += -Wredundant-decls -Wswitch-default -pedantic
# don't warn about conversion, sign, compares, long long and attributes
# since they are common in embedded
WARNING_ALL += -Wno-sign-conversion -Wno-conversion -Wno-sign-compare
WARNING_ALL += -Wno-long-long -Wno-attributes
# don't warn about implicit fallthrough since it's common in network protocols
WARNING_ALL += -Wno-implicit-fallthrough
#WARNING_ALL += -Werror
WARNINGS ?= $(WARNING_ALL)
# dead code removal
ifeq (${BUILD},debug)
OPTIMIZATION = -O0
DEBUGGING = -g -DDEBUG_ENABLED=1
endif
# put all the flags together
INCLUDES = -I$(BACNET_SRC_DIR)
CFLAGS += $(WARNINGS) $(DEBUGGING) $(OPTIMIZATION) $(BACNET_DEFINES) $(INCLUDES)
CFLAGS += -ffunction-sections -fdata-sections
APPS_ENVIRONMENT_SRC = \
$(BACNET_SRC_DIR)/bacnet/datalink/dlenv.c
PORT_ARCNET_SRC = \
$(BACNET_PORT_DIR)/arcnet.c
PORT_MSTP_SRC = \
$(BACNET_PORT_DIR)/rs485.c \
$(BACNET_PORT_DIR)/dlmstp.c \
$(BACNET_SRC_DIR)/bacnet/datalink/cobs.c \
$(BACNET_SRC_DIR)/bacnet/datalink/mstp.c \
$(BACNET_SRC_DIR)/bacnet/datalink/mstptext.c \
$(BACNET_SRC_DIR)/bacnet/datalink/crc.c
PORT_ETHERNET_SRC = \
$(BACNET_PORT_DIR)/ethernet.c
PORT_BIP_SRC = \
$(BACNET_PORT_DIR)/bip-init.c \
$(BACNET_SRC_DIR)/bacnet/datalink/bvlc.c \
$(BACNET_SRC_DIR)/bacnet/basic/bbmd/h_bbmd.c
PORT_BIP6_SRC = \
$(BACNET_PORT_DIR)/bip6.c \
$(BACNET_SRC_DIR)/bacnet/basic/bbmd6/h_bbmd6.c \
$(BACNET_SRC_DIR)/bacnet/basic/bbmd6/vmac.c \
$(BACNET_SRC_DIR)/bacnet/datalink/bvlc6.c
PORT_ALL_SRC = \
$(BACNET_SRC_DIR)/bacnet/datalink/datalink.c \
$(PORT_ARCNET_SRC) \
$(PORT_MSTP_SRC) \
$(PORT_ETHERNET_SRC) \
$(PORT_BIP_SRC) \
$(PORT_BIP6_SRC)
PORT_NONE_SRC = \
$(BACNET_SRC_DIR)/bacnet/datalink/datalink.c
ifeq (${BACDL_DEFINE},-DBACDL_BIP=1)
BACNET_PORT_SRC = ${PORT_BIP_SRC} ${APPS_ENVIRONMENT_SRC}
endif
ifeq (${BACDL_DEFINE},-DBACDL_BIP6=1)
BACNET_PORT_SRC = ${PORT_BIP6_SRC} ${APPS_ENVIRONMENT_SRC}
endif
ifeq (${BACDL_DEFINE},-DBACDL_MSTP=1)
BACNET_PORT_SRC = ${PORT_MSTP_SRC} ${APPS_ENVIRONMENT_SRC}
endif
ifeq (${BACDL_DEFINE},-DBACDL_ARCNET=1)
BACNET_PORT_SRC = ${PORT_ARCNET_SRC} ${APPS_ENVIRONMENT_SRC}
endif
ifeq (${BACDL_DEFINE},-DBACDL_ETHERNET=1)
BACNET_PORT_SRC = ${PORT_ETHERNET_SRC} ${APPS_ENVIRONMENT_SRC}
endif
ifeq (${BACDL_DEFINE},-DBACDL_NONE=1)
BACNET_PORT_SRC = ${PORT_NONE_SRC}
endif
ifeq (${BACDL_DEFINE},-DBACDL_ALL=1)
BACNET_PORT_SRC = ${PORT_ALL_SRC}
endif
ifeq (${BACDL},bip-mstp)
BACNET_PORT_SRC = ${PORT_BIP_SRC} ${PORT_MSTP_SRC}
endif
ifeq (${BACDL},bip-bip6)
BACNET_PORT_SRC = ${PORT_BIP_SRC} ${PORT_BIP6_SRC}
endif
ifneq (${BACDL_DEFINE},)
CFLAGS += ${BACDL_DEFINE}
endif
BACNET_PORT_SRC += \
$(BACNET_PORT_DIR)/mstimer-init.c \
$(BACNET_PORT_DIR)/datetime-init.c
BACNET_SRC ?= \
$(wildcard $(BACNET_SRC_DIR)/bacnet/*.c) \
BACNET_BASIC_SRC ?= \
$(wildcard $(BACNET_SRC_DIR)/bacnet/basic/*.c) \
$(wildcard $(BACNET_SRC_DIR)/bacnet/basic/binding/*.c) \
$(wildcard $(BACNET_SRC_DIR)/bacnet/basic/service/*.c) \
$(wildcard $(BACNET_SRC_DIR)/bacnet/basic/sys/*.c) \
$(BACNET_SRC_DIR)/bacnet/basic/npdu/h_npdu.c \
$(BACNET_SRC_DIR)/bacnet/basic/npdu/s_router.c \
$(BACNET_SRC_DIR)/bacnet/basic/tsm/tsm.c
# build in uci integration - use UCI=1 when invoking make
ifeq (${UCI},1)
BACNET_BASIC_SRC += \
$(wildcard $(BACNET_SRC_DIR)/bacnet/basic/ucix/*.c)
endif
SRCS := $(BACNET_SRC) $(BACNET_BASIC_SRC) $(BACNET_PORT_SRC)
OBJS = ${SRCS:.c=.o}
all: $(BACNET_LIB_TARGET)
lib: $(BACNET_LIB_TARGET)
$(BACNET_LIB_TARGET): $(OBJS) Makefile
$(CC) $(C_FLAGS) $(OBJS) $(LD_FLAGS) $(SHLDFLAGS) $(LFLAGS_SONAME)$(DT_SONAME) -o $(DT_SHLIB)
ln -sf $(DT_SHLIB) $(DT_SONAME)
ln -sf $(DT_SONAME) $(SHLIB)
${AR} rcs $@ $(OBJS)
.c.o:
${CC} -c ${CFLAGS} $*.c -o $@
depend:
rm -f .depend
${CC} -MM ${CFLAGS} *.c >> .depend
clean:
rm -rf core $(OBJS) $(BACNET_LIB_TARGET)
rm -rf $(SHLIB)*
include: .depend
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment