-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
80 lines (59 loc) · 2.02 KB
/
Makefile
File metadata and controls
80 lines (59 loc) · 2.02 KB
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
# get version info from git and compile into the program
# git tags have format vMAJOR.MINOR.RELEASE
# https://embeddedartistry.com/blog/2016/10/27/giving-you-build-a-version
version := $(subst -, ,$(shell git describe --long --dirty --tags))
COMMIT := $(strip $(word 3, $(version)))
COMMITS_PAST := $(strip $(word 2, $(version)))
DIRTY := $(strip $(word 4, $(version)))
ifneq ($(COMMITS_PAST), 0)
BUILD_INFO_COMMITS := "."$(COMMITS_PAST)
endif
ifneq ($(DIRTY),)
BUILD_INFO_DIRTY :="+"
endif
export BUILD_TAG :=$(strip $(word 1, $(version)))
export BUILD_INFO := $(COMMIT)$(BUILD_INFO_COMMITS)$(BUILD_INFO_DIRTY)
# define the C compiler to use
CPP = g++
# define any compile-time flags
CPPFLAGS = -Wall -g -std=c++17 -pthread
CPPFLAGS += -DVERSION_BUILD_DATE=\""$(shell date "+%F %T")"\" \
-DVERSION_BUILD_MACHINE=\""$(shell echo `whoami`@`hostname`)"\" \
-DVERSION_TAG=\"$(BUILD_TAG)\" \
-DVERSION_BUILD=\"$(BUILD_INFO)\"
# define any directories containing header files other than /usr/include
INCLUDES = -I./include -I/usr/include/libabbaurora
# define library paths in addition to /usr/lib
LFLAGS =
# define any libraries to link into executable:
LIBS = -lstdc++fs -lmosquitto -labbaurora
# define src and obj directories
SRC_DIR = src
# define build directory
OBJ_DIR = build
# define the C source files
SRCS = $(wildcard $(SRC_DIR)/*.cpp)
# define the C object files
OBJS = $(SRCS:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
# define the executable file
MAIN = solarmeter
###############
### targets ###
###############
.PHONY: build clean install
all: build $(MAIN)
build:
-@ mkdir -p $(OBJ_DIR)
$(MAIN): $(OBJS)
$(CPP) $(CPPFLAGS) $(INCLUDES) -o $(OBJ_DIR)/$(MAIN) $(OBJS) $(LFLAGS) $(LIBS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CPP) $(CPPFLAGS) $(INCLUDES) -c $< -o $@
clean:
-@ $(RM) $(OBJS) $(OBJ_DIR)/$(MAIN) *~
# define install directories
ifeq ($(PREFIX),)
PREFIX = /usr/local
endif
install: all
install -d $(DESTDIR)$(PREFIX)/bin/
install -m 755 $(OBJ_DIR)/$(MAIN) $(DESTDIR)$(PREFIX)/bin/