1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
RM=rm
MKDIR=mkdir
CC=gcc
STRIP=strip
OUTDIR?=build
OUTFILE="$(OUTDIR)/rtl_wmbus"
CPPFLAGS?=
CFLAGS?=
CFLAGS+=-Iinclude -std=gnu99
CFLAGS_WARNINGS?=-Wall -W -Waggregate-return -Wbad-function-cast -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment -Wno-float-equal -Winline -Wmain -Wmissing-noreturn -Wno-missing-prototypes -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wshadow -Wsign-compare -Wstrict-prototypes -Wswitch -Wunreachable-code -Wno-unused -Wuninitialized
LDFLAGS?=
LDLIBS?=-lm
SRC=rtl_wmbus.c
$(shell $(MKDIR) -p $(OUTDIR))
# Create a version number based on the latest git tag.
COMMIT_HASH?=$(shell git log --pretty=format:'%H' -n 1)
TAG?=$(shell git describe --tags --always)
BRANCH?=$(shell git rev-parse --abbrev-ref HEAD)
CHANGES?=$(shell git status -s | grep -v '?? ')
# Prefix with any development branch.
ifeq ($(BRANCH),master)
BRANCH:=
else
BRANCH:=$(BRANCH)_
endif
# The version is the git tag or tag-N-hash if there are N commits after the tag.
VERSION:=$(BRANCH)$(TAG)
ifneq ($(strip $(CHANGES)),)
# There are local non-committed changes! Add this to the version string as well!
VERSION:=$(VERSION) with local changes
COMMIT_HASH:=$(COMMIT_HASH) with local changes
endif
$(shell echo "#define VERSION \"$(VERSION)\"" > $(OUTDIR)/version.h.tmp)
$(shell echo "#define COMMIT \"$(COMMIT_HASH)\"" >> $(OUTDIR)/version.h.tmp)
PREV_VERSION=$(shell cat -n $(OUTDIR)/version.h 2> /dev/null)
CURR_VERSION=$(shell cat -n $(OUTDIR)/version.h.tmp 2>/dev/null)
ifneq ($(PREV_VERSION),$(CURR_VERSION))
$(shell mv $(OUTDIR)/version.h.tmp $(OUTDIR)/version.h)
else
$(shell rm $(OUTDIR)/version.h.tmp)
endif
$(info Building $(VERSION))
all: release
release:
$(CC) -DNDEBUG -O3 $(CPPFLAGS) $(CFLAGS) $(CFLAGS_WARNINGS) $(LDFLAGS) -o $(OUTFILE) $(SRC) $(LDLIBS)
debug:
$(CC) -DDEBUG -O0 -g3 -ggdb -p -pg $(CPPFLAGS) $(CFLAGS) $(CFLAGS_WARNINGS) $(LDFLAGS) -o $(OUTFILE) $(SRC) $(LDLIBS)
# Will build on Raspberry Pi 1 only
pi1:
$(CC) -DNDEBUG -O3 -march=armv6 -mtune=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp -ffast-math $(CPPFLAGS) $(CFLAGS) $(CFLAGS_WARNINGS) $(LDFLAGS) -o $(OUTFILE) $(SRC) $(LDLIBS)
rebuild: clean all
install:
@if [ ! -f $(OUTFILE) ] ; then echo "Cannot find the binary to install! You have to run just \"make\" first!" ; exit 1 ; fi
install -d $(DESTDIR)/usr/bin
install $(OUTFILE) $(DESTDIR)/usr/bin
clean:
$(RM) -rf "$(OUTDIR)"
|