aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 1259ef0c7550db1b8c60d7cfc1eac63f72a1fdf1 (plain)
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
.POSIX:

default: all

SHELL		:= /bin/sh

SRCS_DIR	= src/
INCS_DIR	= inc/
OBJS_DIR	= obj/
TRGT_DIR	= bin/

SRCS_NAME	= main.cpp
SRCS_NAME	+= jo_lowbat.cpp

SRCS		= $(addprefix ${SRCS_DIR}, ${SRCS_NAME})

INCS		= jo_lowbat.hpp

OBJS		= $(patsubst ${SRCS_DIR}%.cpp,${OBJS_DIR}%.o,${SRCS})

DEBUG		+= Og -ggdb
DEBUG		= -ggdb
FSANITIZE	= -fsanitize=address

CXX			= g++

OPTIMIZE	= -O2
OPTIMIZE	+= -pipe

CXXFLAGS		= -Wall
CXXFLAGS	 	+= -Wextra
CXXFLAGS	 	+= -Werror
#CXXFLAGS		+= ${OPTIMIZE}
CXXFLAGS		+= ${DEBUG}
#CXXFLAGS		+= ${FSANITIZE}

NAME		= lowbat

MKDIR		= mkdir -p
RM			= rm -rf

OS			= $(shell uname -s)
ifeq ($(OS), Darwin)
	PREFIX	= /usr/local
else
	PREFIX	= /usr
endif
MANPREFIX	= $(PREFIX)/share/man


${OBJS_DIR}%.o:		${SRCS_DIR}%.cpp ${INCS_DIR}${INCS}
	@${MKDIR} ${OBJS_DIR}
	${CXX} ${CXXFLAGS} -I${INCS_DIR} -c -o $@ $<

${NAME}:			${OBJS}
	@${MKDIR} ${TRGT_DIR}
	${CXX} ${CXXFLAGS} -o ${TRGT_DIR}${NAME} ${OBJS}

all:				${NAME}

clean:
	${RM} ${OBJS_DIR}

fclean:				clean
	${RM} ${TRGT_DIR}

re:					fclean all

install:			all
	mkdir -p $(DESTDIR)$(PREFIX)/bin
	cp -f bin/lowbat $(DESTDIR)$(PREFIX)/bin/
	chmod 755 $(DESTDIR)$(PREFIX)/bin/lowbat
	mkdir -p $(DESTDIR)$(MANPREFIX)/man1
	cp -f man/lowbat.1 $(DESTDIR)$(MANPREFIX)/man1/lowbat.1

uninstall:
	rm -f $(DESTDIR)$(PREFIX)/bin/lowbat
	rm -f $(DESTDIR)$(MANPREFIX)/man1/lowbat.1

.PHONY: all lowbat clean fclean re install uninstall