JDierkse před 6 roky
rodič
revize
05e4e7e631

+ 7 - 5
.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

+ 0 - 1
Application/Makefile.conf

@@ -1 +0,0 @@
-../Makefile.conf

+ 0 - 1
Bluetooth/Makefile.conf

@@ -1 +0,0 @@
-../Makefile.conf

+ 1 - 0
Libraries/JSON

@@ -0,0 +1 @@
+../../Libraries/json/include

+ 94 - 21
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 " </$$dir>"; \
+	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 " </$$dir>"; \
+	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

+ 0 - 1
Makefile.conf

@@ -1 +0,0 @@
-Makefile.conf.armv8

+ 2 - 15
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'`

+ 2 - 15
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'`

+ 18 - 0
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'`

+ 1 - 15
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'`

+ 7 - 12
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
 

+ 0 - 1
UniFi/Makefile.conf

@@ -1 +0,0 @@
-../Makefile.conf

+ 16 - 0
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

+ 0 - 1
Util/Makefile.conf

@@ -1 +0,0 @@
-../Makefile.conf