diff --git a/.gitignore b/.gitignore index dc11cce..169e0b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,14 @@ -*.o -*.d -*.a +*.o.* +*.d.* +*.a.* .*.swp .AppleDouble .debug .gdbinit gdb core-* -PresenceDetection -test +PresenceDetection* +!PresenceDetection.cc +test* +!test.cc fixPermissions.sh diff --git a/Application/Makefile.conf b/Application/Makefile.conf deleted file mode 120000 index 6d666f5..0000000 --- a/Application/Makefile.conf +++ /dev/null @@ -1 +0,0 @@ -../Makefile.conf \ No newline at end of file diff --git a/Bluetooth/Makefile.conf b/Bluetooth/Makefile.conf deleted file mode 120000 index 6d666f5..0000000 --- a/Bluetooth/Makefile.conf +++ /dev/null @@ -1 +0,0 @@ -../Makefile.conf \ No newline at end of file diff --git a/Libraries/JSON b/Libraries/JSON new file mode 120000 index 0000000..ee95d0c --- /dev/null +++ b/Libraries/JSON @@ -0,0 +1 @@ +../../Libraries/json/include \ No newline at end of file diff --git a/Makefile b/Makefile index fefbf8d..c33773c 100644 --- a/Makefile +++ b/Makefile @@ -2,29 +2,57 @@ # Makefile # -include Makefile.conf +ROOTPATH := /opt/build/PresenceDetection +COMMANDLINE := $(shell ps -o args= $$PPID) + +ARCHS := $(shell ls $(ROOTPATH)/Makefile.conf.* | grep -v base | sed 's/.*Makefile\.conf\.//g') +ARCH := $(filter $(ARCHS),$(MAKECMDGOALS)) + +ifeq ($(ARCH),) +ARCH := x86-64 +endif + +ifeq (,$(findstring -S,$(COMMANDLINE))) +$(info ARCH: $(ARCH)) +endif + +-include $(ROOTPATH)/Makefile.conf.$(ARCH) +-include $(ROOTPATH)/Makefile.conf.base PID := $(shell echo $$$$) PREFIX = nice -n 19 /usr/bin/time --format='%E (%U)' -o /dev/shm/t-$(PID) -POSTFIX = && cat /dev/shm/t-$(PID) | xargs -I "%" echo -en '\033[100D\033[60C$1' "%\n" && rm -f /dev/shm/t-$(PID) +POSTFIX = && cat /dev/shm/t-$(PID) | xargs -I "%" echo -en '\033[1A\033[100D\033[60C' "%\n" && rm -f /dev/shm/t-$(PID) -ARNAME = $(notdir $(CURDIR)).$(ARCH).a +ARNAME = $(notdir $(CURDIR)).a.$(ARCH) SUBDIRS := $(wildcard */.) SUBDIRS := $(foreach dir,$(SUBDIRS),$(subst /.,,$(dir))) +FILTER = crash% +SUBDIRS := $(filter-out $(FILTER),$(SUBDIRS)) FILTER = doc% SUBDIRS := $(filter-out $(FILTER),$(SUBDIRS)) +FILTER = Libraries% +SUBDIRS := $(filter-out $(FILTER),$(SUBDIRS)) SUBDIRARS = $(foreach dir,$(SUBDIRS),$(dir)/$(dir).a) LOCALSOURCES = $(wildcard *.cpp *.cc) -LOCALOBJECTS := $(LOCALSOURCES:.cpp=.$(ARCH).o) -LOCALOBJECTS := $(LOCALOBJECTS:.cc=.$(ARCH).o) -LOCALDEPENDS = $(LOCALOBJECTS:.o=.d) +LOCALOBJECTS := $(LOCALSOURCES:.cpp=.o.$(ARCH)) +LOCALOBJECTS := $(LOCALOBJECTS:.cc=.o.$(ARCH)) +LOCALDEPENDS = $(LOCALOBJECTS:.o.$(ARCH)=.d.$(ARCH)) SOURCES = $(wildcard *.cpp */*.cpp */*/*.cpp */*/*/*.cpp) -OBJECTS = $(SOURCES:.cpp=.$(ARCH).o) -DEPENDS = $(OBJECTS:.o=.d) +OBJECTS = $(SOURCES:.cpp=.o.$(ARCH)) +DEPENDS = $(OBJECTS:.o.$(ARCH)=.d.$(ARCH)) TARGETS = +define target + $(eval $@_DATETIME := $(DATETIME)) + @echo -n " [LD] $(1)\n" + @$(PREFIX) $(CC) -o $(1) $(2) $(LFLAGS) $(CFLAGS) $(POSTFIX) + @$(OBJCOPY) --only-keep-debug $(1) $(DEBUGDIR)/$(1)-$($@_DATETIME).debug + @$(STRIP) $(SFLAGS) $(1) + @$(OBJCOPY) --add-gnu-debuglink="$(DEBUGDIR)/$(1)-$($@_DATETIME).debug" $(1) + @chmod -x $(DEBUGDIR)/$(1)-$($@_DATETIME).debug +endef $(LOCALOBJECTS): | $(SUBDIRS) $(OBJECTS): | $(SUBDIRS) @@ -39,44 +67,44 @@ ifneq ($(MAKECMDGOALS),clean) -include $(LOCALDEPENDS) endif -%.$(ARCH).d: %.cpp +%.d.$(ARCH): %.cpp @depth=$(MAKELEVEL); \ while [ $${depth} -gt 0 ] ; do \ echo -n " "; \ depth=`expr $$depth - 1`; \ done; \ true - @echo -n " [MM] $@" - @$(PREFIX) $(CC) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ $(POSTFIX) + @echo -n " [MM] $@\n" + @$(PREFIX) $(CC) $(CFLAGS) $< -MM -MT $(@:.d.$(ARCH)=.o.$(ARCH)) >$@ $(POSTFIX) -%.$(ARCH).o: %.cpp +%.o.$(ARCH): %.cpp @depth=$(MAKELEVEL); \ while [ $${depth} -gt 0 ] ; do \ echo -n " "; \ depth=`expr $$depth - 1`; \ done; \ true - @echo -n " [CC] $@" + @echo -n " [CC] $@\n" @$(PREFIX) $(CC) -c $(CFLAGS) $< -o $@ $(POSTFIX) -%.$(ARCH).d: %.cc +%.d.$(ARCH): %.cc @depth=$(MAKELEVEL); \ while [ $${depth} -gt 0 ] ; do \ echo -n " "; \ depth=`expr $$depth - 1`; \ done; \ true - @echo -n " [MM] $@" - @$(PREFIX) $(CC) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ $(POSTFIX) + @echo -n " [MM] $@\n" + @$(PREFIX) $(CC) $(CFLAGS) $< -MM -MT $(@:.d.$(ARCH)=.o.$(ARCH)) >$@ $(POSTFIX) -%.$(ARCH).o: %.cc +%.o.$(ARCH): %.cc @depth=$(MAKELEVEL); \ while [ $${depth} -gt 0 ] ; do \ echo -n " "; \ depth=`expr $$depth - 1`; \ done; \ true - @echo -n " [CC] $@" + @echo -n " [CC] $@\n" @$(PREFIX) $(CC) -c $(CFLAGS) $< -o $@ $(POSTFIX) $(ARNAME): $(SUBDIRS) $(LOCALOBJECTS) @@ -86,7 +114,7 @@ $(ARNAME): $(SUBDIRS) $(LOCALOBJECTS) depth=`expr $$depth - 1`; \ done; \ true - @echo -n " [AR] $@" + @echo -n " [AR] $@\n" @$(PREFIX) $(AR) rcuT $@ $(LOCALOBJECTS) $(SUBDIRARS) $(POSTFIX) .PHONY: $(SUBDIRS) @@ -98,7 +126,7 @@ $(SUBDIRS): done; \ true @echo " <$@>" - @$(MAKE) -s -S -C $@ artifacts + @$(MAKE) -s -S -C $@ artifacts $(ARCH) @depth=$(MAKELEVEL); \ while [ $${depth} -gt 0 ] ; do \ echo -n " "; \ @@ -119,7 +147,7 @@ clean: depth=`expr $$depth - 1`; \ done; \ echo " <$$dir>"; \ - $(MAKE) -s -S -C $$dir $@; \ + $(MAKE) -s -S -C $$dir $@ $(ARCH); \ while [ $${depth} -gt 0 ] ; do \ echo -n " "; \ depth=`expr $$depth - 1`; \ @@ -128,3 +156,48 @@ clean: done; \ true @rm -f $(LOCALOBJECTS) $(LOCALDEPENDS) $(ARNAME) $(TARGETS) || true + +.PHONY: cleandeps +cleandeps: + @for dir in $(SUBDIRS); do \ + depth=$(MAKELEVEL); \ + while [ $${depth} -gt 0 ] ; do \ + echo -n " "; \ + depth=`expr $$depth - 1`; \ + done; \ + echo " <$$dir>"; \ + $(MAKE) -s -S -C $$dir $@ $(ARCH); \ + while [ $${depth} -gt 0 ] ; do \ + echo -n " "; \ + depth=`expr $$depth - 1`; \ + done; \ + echo " "; \ + done; \ + true + @rm -f $(LOCALDEPENDS) $(TARGETS) || true + +.PHONY: cleanall +cleanall: + @for dir in $(SUBDIRS); do \ + depth=$(MAKELEVEL); \ + while [ $${depth} -gt 0 ] ; do \ + echo -n " "; \ + depth=`expr $$depth - 1`; \ + done; \ + echo " <$$dir>"; \ + $(MAKE) -s -S -C $$dir $@ $(ARCH); \ + while [ $${depth} -gt 0 ] ; do \ + echo -n " "; \ + depth=`expr $$depth - 1`; \ + done; \ + echo " "; \ + done; \ + true + @rm -f *.d.* *.o.* + @rm -f $(ARNAME) $(TARGETS) || true + +.PHONY: $(ARCH) +$(ARCH): + @if [ "$(words $(MAKECMDGOALS))" = "1" ]; then \ + $(MAKE) -s -S $(.DEFAULT_GOAL) $(ARCH); \ + fi diff --git a/Makefile.conf b/Makefile.conf deleted file mode 120000 index 96d52a1..0000000 --- a/Makefile.conf +++ /dev/null @@ -1 +0,0 @@ -Makefile.conf.armv8 \ No newline at end of file diff --git a/Makefile.conf.armv6 b/Makefile.conf.armv6 index 6acde10..366e552 100644 --- a/Makefile.conf.armv6 +++ b/Makefile.conf.armv6 @@ -1,12 +1,9 @@ # -# Makefile.conf +# Makefile.conf.armv6 # ARCH := armv6 -CFLAGS := -g3 -O3 -fPIC -marm -march=armv6 -std=c++11 -CFLAGS += -Wall -Wextra -Wstrict-aliasing -fmax-errors=5 -Werror -Wunreachable-code -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wsign-promo -Wstrict-null-sentinel -Wswitch-default -Wno-unused -Wno-variadic-macros -Wno-parentheses -Wno-unused-parameter -fdiagnostics-show-option -# CFLAGS += -Wold-style-cast -Wundef -Wshadow -Wctor-dtor-privacy -Wredundant-decls -Wstrict-overflow=5 -Wcast-align -LFLAGS := -lpthread -lm -lboost_system -lboost_thread -lboost_program_options -lboost_date_time -lssl -lcrypto -lcurl -lz -ldl -lbluetooth +CFLAGS := -marm -march=armv6 AR := /opt/build/rpi-armv6/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ar CC := /opt/build/rpi-armv6/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ @@ -15,13 +12,3 @@ OBJCOPY := /opt/build/rpi-armv6/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-li CFLAGS += -I/opt/build/rpi-armv6/include LFLAGS += -L/opt/build/rpi-armv6/lib --sysroot /opt/build/rpi-armv6/tools/arm-bcm2708/arm-linux-gnueabihf/arm-linux-gnueabihf/sysroot -Wl,-rpath,/opt/build/rpi-armv6/lib - -CFLAGS += -fpermissive -CFLAGS += -I/opt/build/PresenceDetection - -CFLAGS += -ffunction-sections -fdata-sections -LFLAGS += -Wl,--gc-sections -SFLAGS := -s -R .comment -R .gnu.version --strip-unneeded - -DEBUGDIR := .debug -DATETIME := `date +'%y%m%d-%H%M'` diff --git a/Makefile.conf.armv8 b/Makefile.conf.armv8 index b62e2c5..9106c75 100644 --- a/Makefile.conf.armv8 +++ b/Makefile.conf.armv8 @@ -1,12 +1,9 @@ # -# Makefile.conf +# Makefile.conf.armv8 # ARCH := armv8 -CFLAGS := -g3 -O3 -fPIC -marm -march=armv8-a -std=c++11 -CFLAGS += -Wall -Wextra -Wstrict-aliasing -fmax-errors=5 -Werror -Wunreachable-code -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wsign-promo -Wstrict-null-sentinel -Wswitch-default -Wno-unused -Wno-variadic-macros -Wno-parentheses -Wno-unused-parameter -Wno-missing-field-initializers -fdiagnostics-show-option -# CFLAGS += -Wold-style-cast -Wundef -Wshadow -Wctor-dtor-privacy -Wredundant-decls -Wstrict-overflow=5 -Wcast-align -LFLAGS := -lpthread -lm -lboost_system -lboost_thread -lboost_program_options -lboost_date_time -lssl -lcrypto -lcurl -lz -ldl -lbluetooth +CFLAGS := -marm -march=armv8-a AR := /opt/build/rpi-armv8/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ar CC := /opt/build/rpi-armv8/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ @@ -15,13 +12,3 @@ OBJCOPY := /opt/build/rpi-armv8/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-li CFLAGS += -I/opt/build/rpi-armv8/include LFLAGS += -L/opt/build/rpi-armv8/lib --sysroot /opt/build/rpi-armv8/tools/arm-bcm2708/arm-linux-gnueabihf/arm-linux-gnueabihf/sysroot -Wl,-rpath,/opt/build/rpi-armv8/lib - -CFLAGS += -fpermissive -CFLAGS += -I/opt/build/PresenceDetection - -CFLAGS += -ffunction-sections -fdata-sections -LFLAGS += -Wl,--gc-sections -SFLAGS := -s -R .comment -R .gnu.version --strip-unneeded - -DEBUGDIR := .debug -DATETIME := `date +'%y%m%d-%H%M'` diff --git a/Makefile.conf.base b/Makefile.conf.base new file mode 100644 index 0000000..e4a679c --- /dev/null +++ b/Makefile.conf.base @@ -0,0 +1,18 @@ +# +# Makefile.conf.base +# + +CFLAGS += -g3 -O3 -fPIC -std=c++11 +CFLAGS += -Wall -Wextra -Wstrict-aliasing -fmax-errors=5 -Werror -Wunreachable-code -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wsign-promo -Wstrict-null-sentinel -Wswitch-default -Wno-unused -Wno-variadic-macros -Wno-parentheses -fdiagnostics-show-option +# CFLAGS += -Wold-style-cast -pedantic -Wcast-qual -Wundef -Wshadow -Wctor-dtor-privacy -Wredundant-decls -Wstrict-overflow=5 -Wcast-align +LFLAGS += -lpthread -lm -lboost_system -lboost_thread -lboost_program_options -lboost_date_time -lssl -lcrypto -lcurl -lz -ldl -lbluetooth + +CFLAGS += -fpermissive +CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/Libraries/JSON + +CFLAGS += -ffunction-sections -fdata-sections +LFLAGS += -Wl,--gc-sections +SFLAGS := -s -R .comment -R .gnu.version --strip-unneeded + +DEBUGDIR := .debug +DATETIME := `date +'%y%m%d-%H%M'` diff --git a/Makefile.conf.x86-64 b/Makefile.conf.x86-64 index 3dff520..8b6f107 100644 --- a/Makefile.conf.x86-64 +++ b/Makefile.conf.x86-64 @@ -1,24 +1,10 @@ # -# Makefile.conf.local +# Makefile.conf.x86-64 # ARCH := x86-64 -CFLAGS := -g3 -O3 -Wall -fPIC -std=c++11 -CFLAGS += -Wall -Wextra -Wstrict-aliasing -pedantic -fmax-errors=5 -Werror -Wunreachable-code -Wcast-qual -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wsign-promo -Wstrict-null-sentinel -Wswitch-default -Wno-unused -Wno-variadic-macros -Wno-parentheses -fdiagnostics-show-option -# CFLAGS += -Wold-style-cast -Wundef -Wshadow -Wctor-dtor-privacy -Wredundant-decls -Wstrict-overflow=5 -Wcast-align -LFLAGS := -lpthread -lm -lboost_system -lboost_thread -lboost_program_options -lboost_date_time -lssl -lcrypto -lcurl -lz -ldl -lbluetooth AR := ar CC := g++ STRIP := strip OBJCOPY := objcopy - -CFLAGS += -fpermissive -CFLAGS += -I/opt/build/PresenceDetection - -CFLAGS += -ffunction-sections -fdata-sections -LFLAGS += -Wl,--gc-sections -SFLAGS := -s -R .comment -R .gnu.version --strip-unneeded - -DEBUGDIR := .debug -DATETIME := `date +'%y%m%d-%H%M'` diff --git a/Makefile.target b/Makefile.target index 37eeb9c..f155990 100644 --- a/Makefile.target +++ b/Makefile.target @@ -2,19 +2,14 @@ # Makefile.target # -PresenceDetection: Application/PresenceDetection.$(ARCH).o $(OBJECTS) - $(eval $@_DATETIME := $(DATETIME)) - @echo [LD] $@ - @$(PREFIX) $(CC) -o $@ $^ $(LFLAGS) $(CFLAGS) $(POSTFIX) - @$(OBJCOPY) --only-keep-debug $@ $(DEBUGDIR)/$@-$($@_DATETIME).debug - @$(STRIP) $(SFLAGS) $@ - @$(OBJCOPY) --add-gnu-debuglink="$(DEBUGDIR)/$@-$($@_DATETIME).debug" $@ - @chmod -x $(DEBUGDIR)/$@-$($@_DATETIME).debug +PresenceDetection.$(ARCH): $(OBJECTS) Application/PresenceDetection.o.$(ARCH) + $(call target,$@,$^) -test: Application/Test.$(ARCH).o $(OBJECTS) - @echo [LD] $@ - @$(PREFIX) $(CC) -o $@ $^ $(LFLAGS) $(CFLAGS) $(POSTFIX) - @$(STRIP) $(SFLAGS) $@ +test.$(ARCH): $(OBJECTS) Application/Test.o.$(ARCH) + $(call target,$@,$^) + +PresenceDetection: PresenceDetection.$(ARCH) +test: test.$(ARCH) .DEFAULT_GOAL := PresenceDetection diff --git a/UniFi/Makefile.conf b/UniFi/Makefile.conf deleted file mode 120000 index 6d666f5..0000000 --- a/UniFi/Makefile.conf +++ /dev/null @@ -1 +0,0 @@ -../Makefile.conf \ No newline at end of file diff --git a/Util/JSON.h b/Util/JSON.h new file mode 100644 index 0000000..aa17f4c --- /dev/null +++ b/Util/JSON.h @@ -0,0 +1,16 @@ +#ifndef UTIL_JSON_H +#define UTIL_JSON_H + +#include "Libraries/JSON/nlohmann/json.hpp" + + +namespace PresenceDetection { +namespace Util { + +using namespace nlohmann; +typedef json JSON; + +} // namespace Util +} // namespace DomoticaServer + +#endif // UTIL_JSON_H diff --git a/Util/Makefile.conf b/Util/Makefile.conf deleted file mode 120000 index 6d666f5..0000000 --- a/Util/Makefile.conf +++ /dev/null @@ -1 +0,0 @@ -../Makefile.conf \ No newline at end of file