-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
101 lines (85 loc) · 2.94 KB
/
Makefile
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Standard Makefile for small projects
#
# Depends: clang-formater, doxygen, ctags
#
BIN=hotword
BINOBJ = hotword.o cmdargs.o audio.o timer.o net.o
# spdlog can include (bundled) fmt or have it external. In case of external (archlinux),
# SPDLOG_FMT_EXTERNAL must be defined and the fmt library linked additionally
CFLAGS=-pthread -DSPDLOG_FMT_EXTERNAL
CXXFLAGS=-pthread
# Note: -Wl,-rpath=/a/library/no/in/default/path : adds a path to the lib into binary
LDFLAGS=
LDLIBS=-lstdc++ -lspdlog -lfmt -lpthread -lasound -lsndfile
# external dependencies can be temporarily added to the ./external dir and used without install
# CFLAGS+=-I external/porcupine/include
# LDFLAGS=-L external/porcupine/lib/linux/x86_64/
# LDFLAGS+=-Wl,-rpath=/home/smokie/myDev/hotword/external/porcupine/lib/linux/x86_64
LDLIBS+=-lpv_porcupine
LDLIBS+=-lfvad
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
SRCDIR=src
OBJDIR=obj
DOCDIR=doc
# create pretty version tag (https://dev.to/eugenebabichenko/generating-pretty-version-strings-including-nightly-with-git-and-makefiles-48p3)
TAG_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1)
TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d")
VERSION := $(TAG:v%=%)
ifneq ($(COMMIT), $(TAG_COMMIT))
VERSION := $(VERSION)-next-$(COMMIT)-$(DATE)
endif
ifeq ($(VERSION),)
VERSION := $(COMMIT)-$(DATE)
endif
ifneq ($(shell git status --porcelain),)
VERSION := $(VERSION)-dirty
endif
CFLAGS+=-D VERSION=\""$(VERSION)"\"
all: $(BIN)
@echo "Creating '${VERSION}'"
# prefix object names with objectdir
_BINOBJ = $(patsubst %,$(OBJDIR)/%,$(BINOBJ))
# link all binobj to bin
$(BIN): $(_BINOBJ)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
# default rule for cpp file
# for a given objet, compile the sourcefile. Create objdir at first
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp | $(OBJDIR)
$(CC) -c $(INC) -o $@ $< $(CFLAGS)
$(OBJDIR):
mkdir -p $@
$(DOCDIR):
mkdir -p $@
documentation: $(DOCDIR)
doxygen
beautify:
clang-format -i -sytle=google ./src/*
# create compile_commands.json file by running 'bear' as a wrapper for make
# clean build required to catch all dependencies
compile_commands: clean
bear make
install: $(BIN)
ifneq (0, $(shell id -u))
@echo "Installation requires to be root !"
@exit 1
endif
mkdir -p $(DESTDIR)/usr/bin
install -Dm755 "$(BIN)" "$(DESTDIR)/usr/bin"
mkdir -p $(DESTDIR)/usr/share/hotword/res
install -m 644 res/beep_hi.wav $(DESTDIR)/usr/share/hotword/res/beep_hi.wav
install -m 644 res/beep_lo.wav $(DESTDIR)/usr/share/hotword/res/beep_lo.wav
install -m 644 res/beep_error.wav $(DESTDIR)/usr/share/hotword/res/beep_error.wav
install -m 644 res/respeaker.asoundrc $(DESTDIR)/usr/share/hotword/res/respeaker.asoundrc
.PHONY : tags clean beautify
tag:
ctags --recurse
clean:
rm -rf obj
rm -rf ${BIN}
rm -rf compile_commands.json
rm -rf *.plist
rm -rf .clangd
rm -rf tags