| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- #
- # Makefile
- #
- # ---------- Base Defines ----------
- ROOTPATH := $(shell git rev-parse --show-toplevel)
- COMMANDLINE := $(shell ps -o args= $$PPID)
- # ---------- Base Includes ----------
- -include $(ROOTPATH)/Makefile.conf
- -include $(ROOTPATH)/Makefiles/Makefile.conf.base
- # ---------- Architectures ----------
- ARCHS := $(shell ls $(ROOTPATH)/Makefiles/Makefile.conf.* | grep -v base | sed 's/.*Makefile\.conf\.//g')
- ARCHS += any
- -include $(ROOTPATH)/Makefiles/Makefile.aliases
- ARCHS := $(filter-out any,$(ARCHS))
- ifeq ($(ARCH),)
- ifneq ($(DEFAULTARCH),)
- ARCH := $(DEFAULTARCH)
- else
- ARCH := x86_64
- endif
- endif
- -include $(ROOTPATH)/Makefiles/Makefile.conf.$(ARCH)
- ifeq (,$(findstring -S,$(COMMANDLINE)))
- ifneq ($(ARCH),)
- $(info ARCH: $(ARCH))
- endif
- endif
- # ---------- Defines ----------
- DATETIME := `date +'%y%m%d-%H%M'`
- MAKEFILEPATH := $(strip $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))))
- 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% doc% include% lib% Libraries% Makefiles%
- SUBDIRS := $(filter-out $(FILTER),$(SUBDIRS))
- SUBDIRARS = $(foreach dir,$(SUBDIRS),$(dir)/$(dir).a)
- SUBDIRS := $(foreach dir,$(SUBDIRS),$(dir)_DIRECTORY)
- 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)
- FILTER = Libraries%
- SOURCES := $(filter-out $(FILTER),$(SOURCES))
- REALOBJECTS := $(SOURCES:.cpp=.o.$(ARCH))
- DEPENDS = $(REALOBJECTS:.o.$(ARCH)=.d.$(ARCH))
- OBJECTS := Makefile.conf
- OBJECTS += $(REALOBJECTS)
- # ---------- Recursive Targets ----------
- Makefile.conf: ;
- $(LOCALOBJECTS): | $(SUBDIRS)
- $(OBJECTS): | $(SUBDIRS)
- artifacts: $(LOCALOBJECTS)
- .DEFAULT_GOAL := artifacts
- # ---------- Libraries ----------
- define build_target_library_arch
- @echo -n " [AR] $(1)\n"
- @$(PREFIX) $(AR) -crs $(1) $(2) $(POSTFIX)
- @mkdir -p $(ROOTPATH)/lib/$(ARCH)
- @mv $(1) $$(echo $(ROOTPATH)/lib/$(ARCH)/lib$(1) | sed 's/\.$(ARCH)//g')
- endef
- define add_target_library_arch
- LFLAGS += -L$(ROOTPATH)/lib/$(ARCH)
- CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/include
- $(1).$(ARCH): $$(OBJECTS)
- $$(call build_target_library_arch,$$@,$$(REALOBJECTS))
- endef
- define add_library
- -include $(ROOTPATH)/Libraries/$(1)/Makefile.dep
- LIBFILES += $(ROOTPATH)/Libraries/$(1)/lib/$(ARCH)/lib$(1).a
- LFLAGS += -L$(ROOTPATH)/Libraries/$(1)/lib/$(ARCH)
- CFLAGS += -I$(ROOTPATH)/Libraries/$(1)/include
- endef
- $(foreach library,$(LIBRARIES),$(eval $(call add_library,$(library))))
- # ---------- Targets ----------
- define build_target_arch
- $(eval $@_DATETIME := $(DATETIME))
- @echo -n " [LD] $(1)\n"
- @$(PREFIX) $(CC) -o $(1) $(2) $(LFLAGS) $(CFLAGS) $(POSTFIX)
- @if [ -d "$(DEBUGDIR)" ]; then \
- $(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; \
- fi
- 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
- define add_target_test_arch
- -include $(ROOTPATH)/Makefile.dep
- $(1).$(ARCH): $$(OBJECTS) $$(LIBFILES) Test/Test.o.$(ARCH)
- $$(call build_target_arch,$$@,$$(REALOBJECTS) $$(LIBFILES) Test/Test.o.$(ARCH))
- endef
- define add_target_arch
- $(1).$(ARCH): $$(OBJECTS) $$(LIBFILES) Application/$(strip $(1)).o.$(ARCH)
- $$(call build_target_arch,$$@,$$(REALOBJECTS) $$(LIBFILES) Application/$(strip $(1)).o.$(ARCH))
- endef
- define add_target
- ifeq ($(.DEFAULT_GOAL),artifacts)
- .DEFAULT_GOAL := $(1)
- endif
- ifneq (,$$(findstring .a,$(1)))
- $$(eval $$(call add_target_library_arch, $(1)))
- else
- ifeq ($(1),test)
- $$(eval $$(call add_target_test_arch, $(1)))
- else
- $$(eval $$(call add_target_arch, $(1)))
- endif
- endif
- $(1):
- $$(call build_target,$$@)
- endef
- $(foreach target,$(TARGETS),$(eval $(call add_target,$(target))))
- ifneq ($(MAKECMDGOALS),clean)
- -include $(LOCALDEPENDS)
- endif
- # ---------- Object Rules ----------
- %.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)
- # ---------- Recursive Rules ----------
- .PHONY: $(SUBDIRS)
- $(SUBDIRS):
- $(eval DIR := $(subst _DIRECTORY,,$@))
- @if [ -e "$(DIR)/Makefile" ]; then \
- depth=$(MAKELEVEL); \
- while [ $${depth} -gt 0 ] ; do \
- echo -n " "; \
- depth=`expr $$depth - 1`; \
- done; \
- true; \
- echo " <$(DIR)>"; \
- if ($(MAKE) -s -S -C $(DIR) artifacts $(ARCH)); then \
- :; \
- else \
- exit $$?; \
- fi; \
- depth=$(MAKELEVEL); \
- while [ $${depth} -gt 0 ] ; do \
- echo -n " "; \
- depth=`expr $$depth - 1`; \
- done; \
- true; \
- echo " </$(DIR)>"; \
- fi
- # ---------- Clean Rules ----------
- .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 \
- dir=$${dir%_DIRECTORY}; \
- if [ -e "$$dir/Makefile" ]; then \
- 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>"; \
- fi \
- done; \
- for target in $(TARGETS); do \
- rm -f $$target.$(ARCH); \
- done; \
- rm -f lib/$(ARCH)/*; \
- true; \
- fi
- @rm -f $(LOCALOBJECTS) $(LOCALDEPENDS) || 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 \
- dir=$${dir%_DIRECTORY}; \
- if [ -e "$$dir/Makefile" ]; then \
- 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>"; \
- fi \
- done; \
- for target in $(TARGETS); do \
- rm -f $$target.$(ARCH); \
- done; \
- true; \
- fi
- @rm -f $(LOCALDEPENDS) || true
- # ---------- Architecture Rules ----------
- .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
- # ---------- All Rule ----------
- .PHONY: all
- all: $(TARGETS)
|