aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile69
1 files changed, 69 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..17ffdf6
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,69 @@
+# if $CXX is not set, guess default `cc'. It has to be in system
+CXX ?= c++
+# compile options
+CXXFLAGS += -std=c++17
+# link options
+LDFLAGS ?= -lrt
+
+# INSTALL binary
+INSTALL ?= install
+
+# install path is: $(DESTDIR)$(PREFIX)/$(BINDIR)/system-stats
+DESTDIR ?=
+BINARY ?= system-stats
+PREFIX ?= /usr/local
+BINDIR ?= $(PREFIX)/bin
+LIBDIR ?= $(PREFIX)/lib
+SYSCONFDIR ?= $(PREFIX)/etc
+DATADIR ?= $(PREFIX)/share
+
+IS_CLANG = $(shell $(CXX) -v 2>&1 | grep -q clang && echo true)
+
+ifeq ($(IS_CLANG),true)
+ CXXFLAGS += -Wno-gnu-zero-variadic-macro-arguments
+ CXXFLAGS += -Wno-empty-translation-unit
+endif
+
+# Echo function
+<< := @echo
+ifneq ($(shell eval 'echo -e'),-e)
+ << += -e
+endif
+
+<<sources>> := $(wildcard src/system-stats/*.cpp)
+<<objects>> := $(<<sources>>:src/%.cpp=obj/%.o)
+
+all: system-stats
+
+obj/%.o: src/%.cpp
+ $(<<) " CXX\t" $(<:src/%=%)
+ @mkdir -p $(shell dirname $(@))
+ @$(CXX) -c $(<) -o $(@) $(CXXFLAGS)
+
+system-stats: $(<<objects>>)
+ $(<<) "LINK\t" "system-stats$(^:obj/%=\\n\\t + %)"
+ @$(CXX) $(^) -o $(@) $(LDFLAGS)
+
+install: system-stats
+ $(INSTALL) -Dm0755 system-stats -s "$(DESTDIR)$(LIBDIR)/system-stats/system-stats"
+ install -Dm0755 src/bin/watcher "$(DESTDIR)$(BINDIR)/watcher"
+ install -Dm0755 data/scripts/sync-stats "$(DESTDIR)$(LIBDIR)/system-stats/sync-stats"
+ install -Dm0644 data/scripts/common "$(DESTDIR)$(LIBDIR)/system-stats/common"
+ install -Dm0755 data/scripts/sync-logs "$(DESTDIR)$(LIBDIR)/system-stats/sync-logs"
+ install -Dm0644 data/shopno-os-log.desktop "$(DESTDIR)$(SYSCONFDIR)/xdg/autostart/shopno-os-log.desktop"
+ install -dm0755 "$(DESTDIR)$(DATADIR)/Watcher/"
+ install -Dm0644 -t "$(DESTDIR)$(DATADIR)/Watcher/" src/Watcher/*
+
+uninstall:
+ @$(RM) -rfv \
+ "$(DESTDIR)$(BINDIR)/watcher" \
+ "$(DESTDIR)$(LIBDIR)/system-stats" \
+ "$(DESTDIR)$(BINDIR)/watcher" \
+ "$(DESTDIR)$(DATADIR)/Watcher" \
+ "$(DESTDIR)$(SYSCONFDIR)/xdg/autostart/shopno-os-log.desktop"
+
+clean:
+ $(<<) " RM\t" "system-stats$(<<objects>>:obj/%=\\n\\t + %)"
+ @$(RM) -f $(<<objects>>) system-stats
+
+.PHONY: all clean install uninstall test