wmbusmeters/Makefile

336 wiersze
11 KiB
Makefile
Czysty Zwykły widok Historia

2020-09-06 08:41:04 +00:00
# Copyright (C) 2017-2020 Fredrik Öhrström
#
# 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
STRIP_BINARY=$(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 '?? ')
TAG_COMMIT_HASH?=$(shell git show-ref --tags | grep $(TAG) | cut -f 1 -d ' ')
ifeq ($(BRANCH),master)
BRANCH:=
else
BRANCH:=$(BRANCH)_
endif
ifeq ($(COMMIT),$(TAG_COMMIT))
# Exactly on the tagged commit. The version is the tag!
VERSION:=$(BRANCH)$(TAG)
DEBVERSION:=$(BRANCH)$(TAG)
else
VERSION:=$(BRANCH)$(TAG)++
DEBVERSION:=$(BRANCH)$(TAG)++
endif
ifneq ($(strip $(CHANGES)),)
# There are changes, signify that with a +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
2019-04-15 19:00:53 +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)
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
CXXFLAGS ?= $(DEBUG_FLAGS) -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
METER_OBJS:=\
2017-08-09 10:00:11 +00:00
$(BUILD)/aes.o \
2020-01-28 15:15:11 +00:00
$(BUILD)/aescmac.o \
$(BUILD)/cmdline.o \
$(BUILD)/config.o \
2018-04-01 06:53:37 +00:00
$(BUILD)/dvparser.o \
$(BUILD)/meters.o \
2019-03-19 19:53:44 +00:00
$(BUILD)/meter_amiplus.o \
$(BUILD)/meter_apator08.o \
2020-02-06 12:14:46 +00:00
$(BUILD)/meter_apator162.o \
$(BUILD)/meter_cma12w.o \
2020-07-26 12:40:25 +00:00
$(BUILD)/meter_compact5.o \
2020-02-06 12:14:46 +00:00
$(BUILD)/meter_ebzwmbe.o \
$(BUILD)/meter_ehzp.o \
$(BUILD)/meter_esyswm.o \
2020-09-24 17:49:45 +00:00
$(BUILD)/meter_em24.o \
2020-11-14 09:48:49 +00:00
$(BUILD)/meter_emerlin868.o \
$(BUILD)/meter_ev200.o \
2021-01-26 21:22:59 +00:00
$(BUILD)/meter_evo868.o \
2020-02-06 12:14:46 +00:00
$(BUILD)/meter_eurisii.o \
2020-02-11 21:35:57 +00:00
$(BUILD)/meter_fhkvdataiii.o \
2021-01-06 18:48:56 +00:00
$(BUILD)/meter_fhkvdataiv.o \
2020-10-25 18:48:07 +00:00
$(BUILD)/meter_flowiq2200.o \
2020-02-06 12:14:46 +00:00
$(BUILD)/meter_hydrus.o \
$(BUILD)/meter_hydrocalm3.o \
2020-02-06 12:14:46 +00:00
$(BUILD)/meter_hydrodigit.o \
2020-05-26 20:18:37 +00:00
$(BUILD)/meter_iperl.o \
2020-02-06 12:14:46 +00:00
$(BUILD)/meter_izar.o \
2020-09-04 10:13:06 +00:00
$(BUILD)/meter_izar3.o \
$(BUILD)/meter_lansendw.o \
$(BUILD)/meter_lansensm.o \
2020-05-26 20:18:37 +00:00
$(BUILD)/meter_lansenth.o \
$(BUILD)/meter_lansenpu.o \
2020-02-06 12:14:46 +00:00
$(BUILD)/meter_mkradio3.o \
2020-11-22 19:40:03 +00:00
$(BUILD)/meter_mkradio4.o \
2020-05-26 20:18:37 +00:00
$(BUILD)/meter_multical21.o \
2020-02-06 12:14:46 +00:00
$(BUILD)/meter_multical302.o \
2020-08-18 16:20:30 +00:00
$(BUILD)/meter_multical403.o \
$(BUILD)/meter_multical603.o \
$(BUILD)/meter_multical803.o \
2020-02-06 12:14:46 +00:00
$(BUILD)/meter_omnipower.o \
$(BUILD)/meter_q400.o \
$(BUILD)/meter_qcaloric.o \
$(BUILD)/meter_rfmamb.o \
2020-04-01 15:21:11 +00:00
$(BUILD)/meter_rfmtx1.o \
2020-02-06 12:14:46 +00:00
$(BUILD)/meter_supercom587.o \
2020-10-31 14:16:14 +00:00
$(BUILD)/meter_sontex868.o \
$(BUILD)/meter_topaseskr.o \
2020-12-31 13:46:05 +00:00
$(BUILD)/meter_tsd2.o \
$(BUILD)/meter_ultrimis.o \
2020-02-06 12:14:46 +00:00
$(BUILD)/meter_vario451.o \
2020-07-08 19:16:26 +00:00
$(BUILD)/meter_waterstarm.o \
$(BUILD)/meter_whe46x.o \
2021-01-26 16:17:29 +00:00
$(BUILD)/meter_whe5x.o \
$(BUILD)/meter_sensostar.o \
2017-09-02 21:26:57 +00:00
$(BUILD)/printer.o \
$(BUILD)/rtlsdr.o \
2017-08-09 10:00:11 +00:00
$(BUILD)/serial.o \
$(BUILD)/shell.o \
2020-10-25 19:57:25 +00:00
$(BUILD)/sha256.o \
$(BUILD)/threads.o \
$(BUILD)/util.o \
2019-05-04 06:52:25 +00:00
$(BUILD)/units.o \
2017-08-09 10:00:11 +00:00
$(BUILD)/wmbus.o \
$(BUILD)/wmbus_amb8465.o \
2017-08-09 10:00:11 +00:00
$(BUILD)/wmbus_im871a.o \
2019-11-22 17:53:52 +00:00
$(BUILD)/wmbus_cul.o \
2019-02-25 21:03:20 +00:00
$(BUILD)/wmbus_rtlwmbus.o \
$(BUILD)/wmbus_rtl433.o \
$(BUILD)/wmbus_simulator.o \
2019-10-15 12:32:32 +00:00
$(BUILD)/wmbus_rawtty.o \
2020-09-26 11:52:24 +00:00
$(BUILD)/wmbus_rc1180.o \
$(BUILD)/wmbus_utils.o
2017-08-09 10:00:11 +00:00
2020-04-03 09:58:19 +00:00
all: $(BUILD)/wmbusmeters $(BUILD)/wmbusmeters-admin $(BUILD)/testinternals
@$(STRIP_BINARY)
2019-03-12 19:57:13 +00:00
@cp $(BUILD)/wmbusmeters $(BUILD)/wmbusmetersd
deb: wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb
2019-02-23 17:30:16 +00:00
install: $(BUILD)/wmbusmeters
@./install.sh $(BUILD)/wmbusmeters $(DESTDIR) $(EXTRA_INSTALL_OPTIONS)
2019-02-23 18:49:30 +00:00
uninstall:
@./uninstall.sh /
wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb:
2019-02-23 17:30:16 +00:00
@rm -rf $(BUILD)/debian/wmbusmeters
@mkdir -p $(BUILD)/debian/wmbusmeters/DEBIAN
@./install.sh $(BUILD)/wmbusmeters $(BUILD)/debian/wmbusmeters --no-adduser
@rm -f $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Package: wmbusmeters" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Version: $(DEBVERSION)" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Maintainer: Fredrik Öhrström" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Architecture: $(DEBARCH)" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Description: A tool to read wireless mbus telegrams from utility meters." >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@for x in preinst postinst prerm postrm ; do \
cp scripts/$$x $(BUILD)/debian/wmbusmeters/DEBIAN/ ; \
chmod 555 $(BUILD)/debian/wmbusmeters/DEBIAN/$$x ; \
done
@(cd $(BUILD)/debian; dpkg-deb --build wmbusmeters .)
@mv $(BUILD)/debian/wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb .
@echo Built package $@
@echo But the deb package is not yet working correctly! Work in progress.
2017-08-09 10:00:11 +00:00
snapcraft:
snapcraft --config snap/snapcraft.yaml
2020-05-25 18:31:22 +00:00
$(BUILD)/main.o: $(BUILD)/short_manual.h $(BUILD)/version.h
2019-10-24 19:06:33 +00:00
$(BUILD)/wmbusmeters: $(METER_OBJS) $(BUILD)/main.o $(BUILD)/short_manual.h
$(CXX) -o $(BUILD)/wmbusmeters $(METER_OBJS) $(BUILD)/main.o $(LDFLAGS) -lrtlsdr $(USBLIB) -lpthread
$(BUILD)/wmbusmeters-admin: $(METER_OBJS) $(BUILD)/admin.o $(BUILD)/ui.o $(BUILD)/short_manual.h
$(CXX) -o $(BUILD)/wmbusmeters-admin $(METER_OBJS) $(BUILD)/admin.o $(BUILD)/ui.o $(LDFLAGS) -lmenu -lform -lncurses -lrtlsdr $(USBLIB) -lpthread
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
$(BUILD)/testinternals: $(METER_OBJS) $(BUILD)/testinternals.o
$(CXX) -o $(BUILD)/testinternals $(METER_OBJS) $(BUILD)/testinternals.o $(LDFLAGS) -lrtlsdr $(USBLIB) -lpthread
2017-08-09 10:00:11 +00:00
2019-03-15 20:49:18 +00:00
$(BUILD)/fuzz: $(METER_OBJS) $(BUILD)/fuzz.o
$(CXX) -o $(BUILD)/fuzz $(METER_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
gcov:
$(GCOV) -o build_debug $(METER_OBJS)
mv *.gcov build_debug
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 '#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
2019-03-15 20:49:18 +00:00
build_fuzz:
@if [ "${AFLHOME}" = "" ]; then echo 'You must supply aflhome "make build_fuzz AFLHOME=/home/afl"'; exit 1; fi
$(MAKE) AFL_HARDEN=1 CXX=$(AFLHOME)/afl-g++ $(BUILD)/fuzz
2019-10-28 21:27:08 +00:00
$(MAKE) AFL_HARDEN=1 CXX=$(AFLHOME)/afl-g++ $(BUILD)/wmbusmeters
2019-03-15 20:49:18 +00:00
2019-10-28 21:27:08 +00:00
run_fuzz_difvifparser:
2019-03-15 20:49:18 +00:00
@if [ "${AFLHOME}" = "" ]; then echo 'You must supply aflhome "make run_fuzz AFLHOME=/home/afl"'; exit 1; fi
2019-10-28 21:27:08 +00:00
${AFLHOME}/afl-fuzz -i fuzz_testcases/difvifparser -o fuzz_findings/ build/fuzz
run_fuzz_telegrams:
@if [ "${AFLHOME}" = "" ]; then echo 'You must supply aflhome "make run_fuzz AFLHOME=/home/afl"'; exit 1; fi
${AFLHOME}/afl-fuzz -i fuzz_testcases/telegrams -o fuzz_findings/ build/wmbusmeters --listento=any stdin
# Include dependency information generated by gcc in a previous compile.
include $(wildcard $(patsubst %.o,%.d,$(METER_OBJS)))