Files
PresenceDetection/Makefile
T
2019-04-18 20:51:50 +02:00

235 lines
5.6 KiB
Makefile

#
# Makefile
#
ROOTPATH := /opt/build/PresenceDetection
COMMANDLINE := $(shell ps -o args= $$PPID)
ARCHS := $(shell ls $(ROOTPATH)/Makefile.conf.* | grep -v base | sed 's/.*Makefile\.conf\.//g')
ARCHS += any
ARCH := $(filter $(ARCHS),$(MAKECMDGOALS))
MAKECMDGOALS := $(filter-out $(ARCH),$(MAKECMDGOALS))
ARCHS := $(filter-out any,$(ARCHS))
ifeq ($(ARCH),)
ARCH := x86-64
endif
ifeq (,$(findstring -S,$(COMMANDLINE)))
ifneq ($(ARCH),)
$(info ARCH: $(ARCH))
endif
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[1A\033[100D\033[60C' "%\n" && rm -f /dev/shm/t-$(PID)
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=.o.$(ARCH))
LOCALOBJECTS := $(LOCALOBJECTS:.cc=.o.$(ARCH))
LOCALDEPENDS = $(LOCALOBJECTS:.o.$(ARCH)=.d.$(ARCH))
SOURCES = $(wildcard *.cpp */*.cpp */*/*.cpp */*/*/*.cpp)
OBJECTS = $(SOURCES:.cpp=.o.$(ARCH))
DEPENDS = $(OBJECTS:.o.$(ARCH)=.d.$(ARCH))
TARGETS =
define build_target_arch
$(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
define build_target
@if [ "$(ARCH)" = "any" ]; then \
for arch in $(ARCHS); do \
echo "ARCH: $$arch"; \
$(MAKE) -s -S $(1) $$arch; \
done; \
true; \
else \
$(MAKE) -s -S $(1).$(ARCH) $(ARCH); \
fi
endef
$(LOCALOBJECTS): | $(SUBDIRS)
$(OBJECTS): | $(SUBDIRS)
artifacts: $(LOCALOBJECTS)
.DEFAULT_GOAL := artifacts
-include Makefile.target
ifneq ($(MAKECMDGOALS),clean)
-include $(LOCALDEPENDS)
endif
%.d.$(ARCH): %.cpp
@if [ "$(ARCH)" != "any" ]; then \
depth=$(MAKELEVEL); \
while [ $${depth} -gt 0 ] ; do \
echo -n " "; \
depth=`expr $$depth - 1`; \
done; \
true; \
echo -n " [MM] $@\n"; \
$(PREFIX) $(CC) $(CFLAGS) $< -MM -MT $(@:.d.$(ARCH)=.o.$(ARCH)) >$@ $(POSTFIX); \
fi
%.o.$(ARCH): %.cpp
@depth=$(MAKELEVEL); \
while [ $${depth} -gt 0 ] ; do \
echo -n " "; \
depth=`expr $$depth - 1`; \
done; \
true
@echo -n " [CC] $@\n"
@$(PREFIX) $(CC) -c $(CFLAGS) $< -o $@ $(POSTFIX)
%.d.$(ARCH): %.cc
@if [ "$(ARCH)" != "any" ]; then \
depth=$(MAKELEVEL); \
while [ $${depth} -gt 0 ] ; do \
echo -n " "; \
depth=`expr $$depth - 1`; \
done; \
true; \
echo -n " [MM] $@\n"; \
$(PREFIX) $(CC) $(CFLAGS) $< -MM -MT $(@:.d.$(ARCH)=.o.$(ARCH)) >$@ $(POSTFIX); \
fi
%.o.$(ARCH): %.cc
@depth=$(MAKELEVEL); \
while [ $${depth} -gt 0 ] ; do \
echo -n " "; \
depth=`expr $$depth - 1`; \
done; \
true
@echo -n " [CC] $@\n"
@$(PREFIX) $(CC) -c $(CFLAGS) $< -o $@ $(POSTFIX)
$(ARNAME): $(SUBDIRS) $(LOCALOBJECTS)
@depth=$(MAKELEVEL); \
while [ $${depth} -gt 0 ] ; do \
echo -n " "; \
depth=`expr $$depth - 1`; \
done; \
true
@echo -n " [AR] $@\n"
@$(PREFIX) $(AR) rcuT $@ $(LOCALOBJECTS) $(SUBDIRARS) $(POSTFIX)
.PHONY: $(SUBDIRS)
$(SUBDIRS):
@depth=$(MAKELEVEL); \
while [ $${depth} -gt 0 ] ; do \
echo -n " "; \
depth=`expr $$depth - 1`; \
done; \
true
@echo " <$@>"
@$(MAKE) -s -S -C $@ artifacts $(ARCH)
@depth=$(MAKELEVEL); \
while [ $${depth} -gt 0 ] ; do \
echo -n " "; \
depth=`expr $$depth - 1`; \
done; \
true
@echo " </$@>"
.PHONY: all
all: $(TARGETS)
.PHONY: clean
clean:
@if [ "$(ARCH)" = "any" ]; then \
for arch in $(ARCHS); do \
echo "ARCH: $$arch"; \
$(MAKE) -s -S $(MAKECMDGOALS) $$arch; \
done; \
true; \
else \
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; \
for target in $(TARGETS); do \
rm -f $$target.$(ARCH); \
done; \
true; \
fi
@rm -f $(LOCALOBJECTS) $(LOCALDEPENDS) $(ARNAME) || true
.PHONY: cleandeps
cleandeps:
@if [ "$(ARCH)" = "any" ]; then \
for arch in $(ARCHS); do \
echo "ARCH: $$arch"; \
$(MAKE) -s -S $(MAKECMDGOALS) $$arch; \
done; \
true; \
else \
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; \
for target in $(TARGETS); do \
rm -f $$target.$(ARCH); \
done; \
true; \
fi
@rm -f $(LOCALDEPENDS) || true
.PHONY: $(ARCH)
$(ARCH):
@if [ "$(words $(MAKECMDGOALS))" = "0" ]; then \
if [ "$(ARCH)" = "any" ]; then \
for arch in $(ARCHS); do \
echo "ARCH: $$arch"; \
$(MAKE) -s -S $(.DEFAULT_GOAL) $$arch; \
done; \
true; \
else \
$(MAKE) -s -S $(.DEFAULT_GOAL) $(ARCH); \
fi \
fi