wmbusmeters/Makefile

368 wiersze
13 KiB
Makefile
Czysty Zwykły widok Historia

# Copyright (C) 2017-2022 Fredrik Öhrström (gpl-3.0-or-later)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2017-08-09 10:00:11 +00:00
# To compile for Raspberry PI ARM:
# make HOST=arm
#
# To build with debug information:
# make DEBUG=true
# make DEBUG=true HOST=arm
DESTDIR?=/
2019-04-15 19:00:53 +00:00
ifeq "$(HOST)" "arm"
2020-04-21 16:07:46 +00:00
CXX?=arm-linux-gnueabihf-g++
STRIP?=arm-linux-gnueabihf-strip
2019-04-15 19:00:53 +00:00
BUILD=build_arm
2020-04-21 16:44:19 +00:00
DEBARCH=armhf
2019-04-15 19:00:53 +00:00
else
2020-04-21 16:07:46 +00:00
CXX?=g++
STRIP?=strip
2019-04-15 19:00:53 +00:00
#--strip-unneeded --remove-section=.comment --remove-section=.note
BUILD=build
2020-04-21 16:44:19 +00:00
DEBARCH=amd64
2019-04-15 19:00:53 +00:00
endif
ifeq "$(DEBUG)" "true"
2020-01-17 15:13:02 +00:00
DEBUG_FLAGS=-O0 -ggdb -fsanitize=address -fno-omit-frame-pointer -fprofile-arcs -ftest-coverage
2019-04-15 19:00:53 +00:00
STRIP_BINARY=
BUILD:=$(BUILD)_debug
ifneq '' '$(findstring clang++,$(CXX))'
2020-04-21 16:44:19 +00:00
DEBUG_LDFLAGS=-fsanitize=address --coverage
GCOV?=llvm-cov gcov
else
DEBUG_LDFLAGS=-lasan -lgcov --coverage
GCOV?=gcov
2020-04-21 16:07:46 +00:00
endif
2019-04-15 19:00:53 +00:00
else
DEBUG_FLAGS=-Os -g
STRIP_BINARY=cp $(BUILD)/wmbusmeters $(BUILD)/wmbusmeters.g; $(STRIP) $(BUILD)/wmbusmeters
2020-01-17 15:13:02 +00:00
GCOV=To_run_gcov_add_DEBUG=true
2019-04-15 19:00:53 +00:00
endif
$(shell mkdir -p $(BUILD))
COMMIT_HASH?=$(shell git log --pretty=format:'%H' -n 1)
TAG?=$(shell git describe --tags)
BRANCH?=$(shell git rev-parse --abbrev-ref HEAD)
CHANGES?=$(shell git status -s | grep -v '?? ')
ifeq ($(BRANCH),master)
BRANCH:=
else
BRANCH:=$(BRANCH)_
endif
2021-04-13 18:56:42 +00:00
VERSION:=$(BRANCH)$(TAG)
DEBVERSION:=$(BRANCH)$(TAG)
ifneq ($(strip $(CHANGES)),)
2021-04-13 18:56:42 +00:00
# There are local un-committed changes.
VERSION:=$(VERSION) with local changes
2019-04-15 19:00:53 +00:00
COMMIT_HASH:=$(COMMIT_HASH) with local changes
DEBVERSION:=$(DEBVERSION)l
endif
2019-04-15 19:00:53 +00:00
$(shell echo "#define VERSION \"$(VERSION)\"" > $(BUILD)/version.h.tmp)
$(shell echo "#define COMMIT \"$(COMMIT_HASH)\"" >> $(BUILD)/version.h.tmp)
2017-08-09 10:00:11 +00:00
2022-01-08 13:10:05 +00:00
PREV_VERSION:=$(shell cat -n $(BUILD)/version.h 2> /dev/null)
CURR_VERSION:=$(shell cat -n $(BUILD)/version.h.tmp 2>/dev/null)
2019-04-15 19:00:53 +00:00
ifneq ($(PREV_VERSION),$(CURR_VERSION))
$(shell mv $(BUILD)/version.h.tmp $(BUILD)/version.h)
2017-08-09 10:00:11 +00:00
else
2019-04-15 19:00:53 +00:00
$(shell rm $(BUILD)/version.h.tmp)
2017-08-09 10:00:11 +00:00
endif
2019-04-15 19:00:53 +00:00
$(info Building $(VERSION))
2017-08-09 10:00:11 +00:00
FUZZFLAGS ?= -DFUZZING=false
CXXFLAGS ?= $(DEBUG_FLAGS) $(FUZZFLAGS) -fPIC -std=c++11 -Wall -Werror=format-security
CXXFLAGS += -I$(BUILD)
LDFLAGS ?= $(DEBUG_LDFLAGS)
2017-08-09 10:00:11 +00:00
USBLIB = -lusb-1.0
ifeq ($(shell uname -s),FreeBSD)
CXXFLAGS += -I/usr/local/include
LDFLAGS += -L/usr/local/lib
USBLIB = -lusb
endif
2019-02-23 12:53:52 +00:00
$(BUILD)/%.o: src/%.cc $(wildcard src/%.h)
2020-01-28 18:09:39 +00:00
$(CXX) $(CXXFLAGS) $< -c -E > $@.src
$(CXX) $(CXXFLAGS) $< -MMD -c -o $@
2017-08-09 10:00:11 +00:00
2022-01-08 13:10:05 +00:00
PROG_OBJS:=\
2017-08-09 10:00:11 +00:00
$(BUILD)/aes.o \
2020-01-28 15:15:11 +00:00
$(BUILD)/aescmac.o \
2021-03-09 21:00:11 +00:00
$(BUILD)/bus.o \
$(BUILD)/cmdline.o \
$(BUILD)/config.o \
2018-04-01 06:53:37 +00:00
$(BUILD)/dvparser.o \
2021-02-13 14:18:59 +00:00
$(BUILD)/mbus_rawtty.o \
$(BUILD)/meters.o \
$(BUILD)/manufacturer_specificities.o \
$(BUILD)/printer.o \
$(BUILD)/rtlsdr.o \
$(BUILD)/serial.o \
$(BUILD)/shell.o \
$(BUILD)/sha256.o \
$(BUILD)/threads.o \
2022-01-08 13:10:05 +00:00
$(BUILD)/translatebits.o \
$(BUILD)/util.o \
$(BUILD)/units.o \
$(BUILD)/wmbus.o \
$(BUILD)/wmbus_amb8465.o \
$(BUILD)/wmbus_im871a.o \
$(BUILD)/wmbus_cul.o \
$(BUILD)/wmbus_rtlwmbus.o \
$(BUILD)/wmbus_rtl433.o \
$(BUILD)/wmbus_simulator.o \
$(BUILD)/wmbus_rawtty.o \
$(BUILD)/wmbus_rc1180.o \
$(BUILD)/wmbus_utils.o \
$(BUILD)/lora_iu880b.o \
# If you run: "make DRIVER=minomess" then only driver_minomess.cc will be compiled into wmbusmeters.
# The old style drivers meter_xyz.cc must always be compiled in, but eventually they will be gone.
2022-01-13 08:51:08 +00:00
ifeq ($(DRIVER),)
DRIVER_OBJS:=$(wildcard src/meter_*.cc) $(wildcard src/driver_*.cc)
2022-01-13 08:51:08 +00:00
else
$(info Building a single driver $(DRIVER))
DRIVER_OBJS:=src/driver_auto.cc src/driver_unknown.cc $(wildcard src/meter_*.cc) src/driver_$(DRIVER).cc
2022-01-13 08:51:08 +00:00
endif
2022-01-08 13:10:05 +00:00
DRIVER_OBJS:=$(patsubst src/%.cc,$(BUILD)/%.o,$(DRIVER_OBJS))
all: $(BUILD)/wmbusmeters $(BUILD)/wmbusmetersd $(BUILD)/wmbusmeters.g $(BUILD)/wmbusmeters-admin $(BUILD)/testinternals
deb: wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb
2019-02-23 17:30:16 +00:00
2021-06-29 14:54:12 +00:00
check_deb:
lintian --no-tag-display-limit wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb
2021-12-25 13:19:27 +00:00
clean_deb:
rm -f wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb
# Check docs verifies that all options in the source have been mentioned in the README and in the man page.
# Also any option not in the source but mentioned in the docs is warned for as well.
2021-06-26 10:24:30 +00:00
check_docs:
@rm -f /tmp/options_in_*
2021-06-26 10:24:30 +00:00
@cat src/cmdline.cc | grep -o -- '--[a-z][a-z]*' | sort | uniq | grep -v internaltesting > /tmp/options_in_code
@cat wmbusmeters.1 | grep -o -- '--[a-z][a-z]*' | sort | uniq | grep -v internaltesting > /tmp/options_in_man
@cat README.md | grep -o -- '--[a-z][a-z]*' | sort | uniq | grep -v internaltesting > /tmp/options_in_readme
2021-06-26 10:28:17 +00:00
@./build/wmbusmeters --help | grep -o -- '--[a-z][a-z]*' | sort | uniq | grep -v internaltesting > /tmp/options_in_binary
2021-06-29 14:54:12 +00:00
@diff /tmp/options_in_code /tmp/options_in_man || echo CODE_VS_MAN
@diff /tmp/options_in_code /tmp/options_in_readme || echo CODE_VS_README
@diff /tmp/options_in_code /tmp/options_in_binary || echo CODE_VS_BINARY
2021-06-26 10:28:17 +00:00
@echo "OK docs"
2021-06-26 10:24:30 +00:00
install: $(BUILD)/wmbusmeters check_docs
@./install.sh $(BUILD)/wmbusmeters $(DESTDIR) $(EXTRA_INSTALL_OPTIONS)
2019-02-23 18:49:30 +00:00
uninstall:
@./uninstall.sh /
wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb:
2021-06-26 15:49:21 +00:00
@./deb/create_deb.sh $(BUILD) $@ $(DEBVERSION) $(DEBARCH)
2017-08-09 10:00:11 +00:00
snapcraft:
2021-03-06 14:44:38 +00:00
snapcraft
$(BUILD)/main.o: $(BUILD)/short_manual.h $(BUILD)/version.h $(BUILD)/authors.h
$(BUILD)/authors.h:
./scripts/generate_authors.sh $(BUILD)/authors.h
2019-10-24 19:06:33 +00:00
# Build binary with debug information. ~15M size binary.
2022-01-08 13:10:05 +00:00
$(BUILD)/wmbusmeters.g: $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/main.o $(BUILD)/short_manual.h
$(CXX) -o $(BUILD)/wmbusmeters.g $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/main.o $(LDFLAGS) -lrtlsdr $(USBLIB) -lpthread
# Production build will have debug information stripped. ~1.5M size binary.
# DEBUG=true builds, which has address sanitizer code, will always keep the debug information.
$(BUILD)/wmbusmeters: $(BUILD)/wmbusmeters.g
cp $(BUILD)/wmbusmeters.g $(BUILD)/wmbusmeters
$(STRIP_BINARY)
$(BUILD)/wmbusmetersd: $(BUILD)/wmbusmeters
cp $(BUILD)/wmbusmeters $(BUILD)/wmbusmetersd
ifeq ($(shell uname -s),Darwin)
$(BUILD)/wmbusmeters-admin:
touch $(BUILD)/wmbusmeters-admin
else
2022-01-08 13:10:05 +00:00
$(BUILD)/wmbusmeters-admin: $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/admin.o $(BUILD)/ui.o $(BUILD)/short_manual.h
$(CXX) -o $(BUILD)/wmbusmeters-admin.g $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/admin.o $(BUILD)/ui.o $(LDFLAGS) -lmenu -lform -lncurses -lrtlsdr $(USBLIB) -lpthread
endif
2020-04-03 09:58:19 +00:00
2019-10-24 19:06:33 +00:00
$(BUILD)/short_manual.h: README.md
echo 'R"MANUAL(' > $(BUILD)/short_manual.h
sed -n '/wmbusmeters version/,/```/p' README.md \
2020-05-26 20:18:37 +00:00
| grep -v 'wmbusmeters version' \
| grep -v '```' >> $(BUILD)/short_manual.h
2019-10-24 19:06:33 +00:00
echo ')MANUAL";' >> $(BUILD)/short_manual.h
2022-01-08 13:10:05 +00:00
$(BUILD)/testinternals: $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/testinternals.o
$(CXX) -o $(BUILD)/testinternals $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/testinternals.o $(LDFLAGS) -lrtlsdr $(USBLIB) -lpthread
2017-08-09 10:00:11 +00:00
2022-01-08 13:10:05 +00:00
$(BUILD)/fuzz: $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/fuzz.o
$(CXX) -o $(BUILD)/fuzz $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/fuzz.o $(LDFLAGS) -lrtlsdr -lpthread
2019-03-15 20:49:18 +00:00
2017-08-09 10:00:11 +00:00
clean:
2019-01-04 21:27:51 +00:00
rm -rf build/* build_arm/* build_debug/* build_arm_debug/* *~
2017-09-02 21:26:57 +00:00
2020-01-17 15:13:02 +00:00
clean_cc:
find . -name "*.gcov" -delete
find . -name "*.gcda" -delete
2021-08-19 10:54:04 +00:00
# This generates annotated source files ending in .gcov
# inside the build_debug where non-executed source lines are marked #####
2020-01-17 15:13:02 +00:00
gcov:
2021-08-19 10:54:04 +00:00
@if [ "$(DEBUG)" = "" ]; then echo "You have to run \"make gcov DEBUG=true\""; exit 1; fi
2022-01-08 13:10:05 +00:00
$(GCOV) -o build_debug $(PROG_OBJS) $(DRIVER_OBJS)
2020-01-17 15:13:02 +00:00
mv *.gcov build_debug
2021-08-19 10:54:04 +00:00
lcov:
@if [ "$(DEBUG)" = "" ]; then echo "You have to run \"make lcov DEBUG=true\""; exit 1; fi
lcov --directory . -c --no-external --output-file build_debug/lcov.info
(cd build_debug; genhtml lcov.info)
xdg-open build_debug/src/index.html
2020-09-18 19:48:47 +00:00
test:
2019-11-03 21:00:18 +00:00
@./test.sh build/wmbusmeters
2020-09-18 19:48:47 +00:00
testd:
2019-11-03 21:00:18 +00:00
@./test.sh build_debug/wmbusmeters
2019-03-05 17:38:54 +00:00
2017-09-02 21:26:57 +00:00
update_manufacturers:
iconv -f utf-8 -t ascii//TRANSLIT -c DLMS_Flagids.csv -o tmp.flags
cat tmp.flags | grep -v ^# | cut -f 1 > list.flags
cat tmp.flags | grep -v ^# | cut -f 2 > names.flags
cat tmp.flags | grep -v ^# | cut -f 3 > countries.flags
cat countries.flags | sort -u | grep -v '^$$' > uniquec.flags
cat names.flags | tr -d "'" | tr -c 'a-zA-Z0-9\n' ' ' | tr -s ' ' | sed 's/^ //g' | sed 's/ $$//g' > ansi.flags
cat ansi.flags | sed 's/\(^.......[^0123456789]*\)[0123456789]\+.*/\1/g' > cleaned.flags
cat cleaned.flags | sed -e "$$(sed 's:.*:s/&//Ig:' uniquec.flags)" > cleanedc.flags
cat cleanedc.flags | sed \
-e 's/ ab\( \|$$\)/ /Ig' \
-e 's/ ag\( \|$$\)/ /Ig' \
-e 's/ a \?s\( \|$$\)/ /Ig' \
-e 's/ co\( \|$$\)/ /Ig' \
-e 's/ b \?v\( \|$$\)/ /Ig' \
-e 's/ bvba\( \|$$\)/ /Ig' \
-e 's/ corp\( \|$$\)/ /Ig' \
-e 's/ d \?o \?o\( \|$$\)/ /g' \
-e 's/ d \?d\( \|$$\)/ /g' \
-e 's/ gmbh//Ig' \
-e 's/ gbr//Ig' \
-e 's/ inc\( \|$$\)/ /Ig' \
-e 's/ kg\( \|$$\)/ /Ig' \
-e 's/ llc/ /Ig' \
-e 's/ ltd//Ig' \
-e 's/ limited//Ig' \
-e 's/ nv\( \|$$\)/ /Ig' \
-e 's/ oy//Ig' \
-e 's/ ood\( \|$$\)/ /Ig' \
-e 's/ooo\( \|$$\)/ /Ig' \
-e 's/ pvt\( \|$$\)/ /Ig' \
-e 's/ pte\( \|$$\)/ /Ig' \
-e 's/ pty\( \|$$\)/ /Ig' \
-e 's/ plc\( \|$$\)/ /Ig' \
-e 's/ private\( \|$$\)/ /Ig' \
-e 's/ s \?a\( \|$$\)/ /Ig' \
-e 's/ sarl\( \|$$\)/ /Ig' \
-e 's/ sagl\( \|$$\)/ /Ig' \
-e 's/ s c ul//Ig' \
-e 's/ s \?l\( \|$$\)/ /Ig' \
-e 's/ s \?p \?a\( \|$$\)/ /Ig' \
-e 's/ sp j\( \|$$\)/ /Ig' \
-e 's/ sp z o o//Ig' \
-e 's/ s r o//Ig' \
-e 's/ s \?r \?l//Ig' \
-e 's/ ug\( \|$$\)/ /Ig' \
> trimmed.flags
cat trimmed.flags | tr -s ' ' | sed 's/^ //g' | sed 's/ $$//g' > done.flags
paste -d '|,' list.flags done.flags countries.flags | sed 's/,/, /g' | sed 's/ |/|/g' > manufacturers.txt
echo "// Copyright (C) $(date +%Y) Fredrik Öhrström (CC0)" > m.h
echo '#ifndef MANUFACTURERS_H' >> m.h
echo '#define MANUFACTURERS_H' >> m.h
2017-09-02 21:26:57 +00:00
echo '#define MANFCODE(a,b,c) ((a-64)*1024+(b-64)*32+(c-64))' >> m.h
echo "#define LIST_OF_MANUFACTURERS \\" >> m.h
cat manufacturers.txt | sed -e "s/\(.\)\(.\)\(.\).\(.*\)/X(\1\2\3,MANFCODE('\1','\2','\3'),\"\4\")\\\\/g" | sed 's/, ")/")/' >> m.h
2017-09-02 21:26:57 +00:00
echo >> m.h
cat manufacturers.txt | sed -e "s/\(.\)\(.\)\(.\).*/#define MANUFACTURER_\1\2\3 MANFCODE('\1','\2','\3')/g" >> m.h
2017-09-02 21:26:57 +00:00
echo >> m.h
echo '#endif' >> m.h
mv m.h src/manufacturers.h
2019-11-03 15:31:30 +00:00
rm *.flags manufacturers.txt
GCC_MAJOR_VERSION:=$(shell gcc --version | head -n 1 | sed 's/.* \([0-9]\)\.[0-9]\.[0-9]$$/\1/')
AFL_HOME:=AFLplusplus
$(AFL_HOME)/src/afl-cc.c:
mkdir -p AFLplusplus
if ! dpkg -s gcc-$(GCC_MAJOR_VERSION)-plugin-dev 2>/dev/null >/dev/null ; then echo "Please run: sudo apt install gcc-$(GCC_MAJOR_VERSION)-plugin-dev"; exit 1; fi
git clone https://github.com/AFLplusplus/AFLplusplus.git
afl_prepared: AFLplusplus/src/afl-cc.c
(cd AFLplusplus; make)
touch afl_prepared
build_fuzz: afl_prepared
$(MAKE) AFL_HARDEN=1 CXX=$(AFL_HOME)/afl-g++-fast FUZZFLAGS=-DFUZZING=true $(BUILD)/fuzz
$(MAKE) AFL_HARDEN=1 CXX=$(AFL_HOME)/afl-g++-fast FUZZFLAGS=-DFUZZING=true $(BUILD)/wmbusmeters
2019-03-15 20:49:18 +00:00
2019-10-28 21:27:08 +00:00
run_fuzz_difvifparser:
${AFL_HOME}/afl-fuzz -i fuzz_testcases/difvifparser -o fuzz_findings_difvifparser/ build/fuzz
2019-10-28 21:27:08 +00:00
run_fuzz_telegrams: extract_fuzz_telegram_seeds
${AFL_HOME}/afl-fuzz -i fuzz_testcases/telegrams -o fuzz_findings_telegrams/ build/wmbusmeters --listento=any stdin
extract_fuzz_telegram_seeds:
@cat simulations/simulation_* | grep "^telegram=" | tr -d '|' | sed 's/^telegram=//' > $(BUILD)/seeds
@mkdir -p fuzz_testcases/telegrams
@rm -f fuzz_testcases/telegrams/seed_*
@SEED=1; while read -r line; do echo "$${line}" | xxd -r -p - > "fuzz_testcases/telegrams/seed_$${SEED}"; SEED=$$((SEED + 1)); done < $(BUILD)/seeds; echo "Extracted $${SEED} seeds from simulations."
relay: utils/relay.c
gcc -g utils/relay.c -o relay -O0 -ggdb -fsanitize=address -fno-omit-frame-pointer -fprofile-arcs -ftest-coverage
2022-01-25 08:58:37 +00:00
# Bump major number
release_major:
@./scripts/release.sh major
# Bump minor number
release_minor:
@./scripts/release.sh minor
# Bump patch number
release_patch:
@./scripts/release.sh patch
# Bump release candidate number, ie a bug in the previous RC was found!
release_rc:
@./scripts/release.sh rc
deploy:
@./scripts/deploy.sh
list_copyrights:
./scripts/check_copyrights.sh
# Include dependency information generated by gcc in a previous compile.
2022-01-08 13:10:05 +00:00
include $(wildcard $(patsubst %.o,%.d,$(PROG_OBJS) $(DRIVER_OBJS)))