Cleanup and Categorize Makefile

This commit is contained in:
2020-08-20 12:36:41 +02:00
parent 58be4141e4
commit fa91e7dd7a
+42 -12
View File
@@ -1,11 +1,14 @@
#
# Makefile # Makefile
# #
DATETIME := `date +'%y%m%d-%H%M'` # ---------- Base Defines ----------
MAKEFILEPATH := $(strip $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))))
ROOTPATH := $(shell git rev-parse --show-toplevel) ROOTPATH := $(shell git rev-parse --show-toplevel)
COMMANDLINE := $(shell ps -o args= $$PPID) COMMANDLINE := $(shell ps -o args= $$PPID)
# ---------- Architectures ----------
ARCHS := $(shell ls $(ROOTPATH)/Makefiles/Makefile.conf.* | grep -v base | sed 's/.*Makefile\.conf\.//g') ARCHS := $(shell ls $(ROOTPATH)/Makefiles/Makefile.conf.* | grep -v base | sed 's/.*Makefile\.conf\.//g')
ARCHS += any ARCHS += any
@@ -19,9 +22,10 @@ $(info ARCH: $(ARCH))
endif endif
endif endif
-include $(ROOTPATH)/Makefiles/Makefile.conf.$(ARCH) # ---------- Defines ----------
-include $(ROOTPATH)/Makefiles/Makefile.conf.base
-include $(ROOTPATH)/Makefile.conf DATETIME := `date +'%y%m%d-%H%M'`
MAKEFILEPATH := $(strip $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))))
PID := $(shell echo $$$$) PID := $(shell echo $$$$)
PREFIX = nice -n 19 /usr/bin/time --format='%E (%U)' -o /dev/shm/t-$(PID) PREFIX = nice -n 19 /usr/bin/time --format='%E (%U)' -o /dev/shm/t-$(PID)
@@ -46,6 +50,23 @@ OBJECTS = $(SOURCES:.cpp=.o.$(ARCH))
DEPENDS = $(OBJECTS:.o.$(ARCH)=.d.$(ARCH)) DEPENDS = $(OBJECTS:.o.$(ARCH)=.d.$(ARCH))
TARGETS = TARGETS =
# ---------- Recursive Targets ----------
$(LOCALOBJECTS): | $(SUBDIRS)
$(OBJECTS): | $(SUBDIRS)
artifacts: $(LOCALOBJECTS)
.DEFAULT_GOAL := artifacts
# ---------- Includes ----------
-include $(ROOTPATH)/Makefiles/Makefile.conf.$(ARCH)
-include $(ROOTPATH)/Makefiles/Makefile.conf.base
-include $(ROOTPATH)/Makefile.conf
# ---------- Libraries ----------
define build_target_library_arch define build_target_library_arch
$(eval $@_DATETIME := $(DATETIME)) $(eval $@_DATETIME := $(DATETIME))
@echo -n " [AR] $(1)\n" @echo -n " [AR] $(1)\n"
@@ -54,6 +75,9 @@ define build_target_library_arch
@mv $(1) $$(echo $(ROOTPATH)/lib/$(ARCH)/lib$(1) | sed 's/\.$(ARCH)//g') @mv $(1) $$(echo $(ROOTPATH)/lib/$(ARCH)/lib$(1) | sed 's/\.$(ARCH)//g')
endef endef
# ---------- Targets ----------
define build_target_arch define build_target_arch
$(eval $@_DATETIME := $(DATETIME)) $(eval $@_DATETIME := $(DATETIME))
@echo -n " [LD] $(1)\n" @echo -n " [LD] $(1)\n"
@@ -78,12 +102,7 @@ define build_target
fi fi
endef endef
$(LOCALOBJECTS): | $(SUBDIRS)
$(OBJECTS): | $(SUBDIRS)
artifacts: $(LOCALOBJECTS)
.DEFAULT_GOAL := artifacts
-include Makefile.target -include Makefile.target
@@ -91,6 +110,8 @@ ifneq ($(MAKECMDGOALS),clean)
-include $(LOCALDEPENDS) -include $(LOCALDEPENDS)
endif endif
# ---------- Object Rules ----------
%.d.$(ARCH): %.cpp %.d.$(ARCH): %.cpp
@if [ "$(ARCH)" != "any" ]; then \ @if [ "$(ARCH)" != "any" ]; then \
depth=$(MAKELEVEL); \ depth=$(MAKELEVEL); \
@@ -145,6 +166,8 @@ $(ARNAME): $(SUBDIRS) $(LOCALOBJECTS)
@echo -n " [AR] $@\n" @echo -n " [AR] $@\n"
@$(PREFIX) $(AR) rcuT $@ $(LOCALOBJECTS) $(SUBDIRARS) $(POSTFIX) @$(PREFIX) $(AR) rcuT $@ $(LOCALOBJECTS) $(SUBDIRARS) $(POSTFIX)
# ---------- Recursive Rules ----------
.PHONY: $(SUBDIRS) .PHONY: $(SUBDIRS)
$(SUBDIRS): $(SUBDIRS):
@if [ -e "$@/Makefile" ]; then \ @if [ -e "$@/Makefile" ]; then \
@@ -169,8 +192,7 @@ $(SUBDIRS):
echo " </$@>"; \ echo " </$@>"; \
fi fi
.PHONY: all # ---------- Clean Rules ----------
all: $(TARGETS)
.PHONY: clean .PHONY: clean
clean: clean:
@@ -237,6 +259,8 @@ cleandeps:
fi fi
@rm -f $(LOCALDEPENDS) || true @rm -f $(LOCALDEPENDS) || true
# ---------- Architecture Rules ----------
.PHONY: $(ARCH) .PHONY: $(ARCH)
$(ARCH): $(ARCH):
@if [ "$(words $(MAKECMDGOALS))" = "0" ]; then \ @if [ "$(words $(MAKECMDGOALS))" = "0" ]; then \
@@ -250,3 +274,9 @@ $(ARCH):
$(MAKE) -s -S $(.DEFAULT_GOAL) $(ARCH); \ $(MAKE) -s -S $(.DEFAULT_GOAL) $(ARCH); \
fi \ fi \
fi fi
# ---------- All Rule ----------
.PHONY: all
all: $(TARGETS)