SHELL:=/bin/bash SRCDIR:= define NEW_LINE endef export NEW_LINE CXXFLAGS:= -pipe -std=c++14 $(CXX_OTHER_FLAGS) -c -fPIC SOURCES:= $(shell find $(SOURCES_BASE_DIR)/$(SRCDIR) -maxdepth 1 -type f -name "*.cpp") DEPENDENCIES:= $(patsubst $(SOURCES_BASE_DIR)/$(SRCDIR)%.cpp, $(OBJECTS_BASE_DIR)/$(SRCDIR)%.d, $(SOURCES)) OBJECTS:= $(patsubst %.d, %.o, $(DEPENDENCIES)) SOURCES_DIRS:= $(shell find $(SOURCES_BASE_DIR)/$(SRCDIR) -maxdepth 1 -mindepth 1 -type d) OBJECTS_DIRS:= $(patsubst $(SOURCES_BASE_DIR)/$(SRCDIR)%, %/, $(SOURCES_DIRS)) OBJECTS_DIRS_MAKEFILES:= $(patsubst %, %makefile, $(OBJECTS_DIRS)) .PHONY: all .PRECIOUS: $(DEPENDECIES) $(OBJECTS_DIRS_MAKEFILES) all: $(OBJECTS_DIRS) $(OBJECTS) %.d: makefile @echo "\ $(shell sha1sum <<< "$@" | sed "s/ -//g") = \$$(shell (\$$(CXX) -MM \$$(CXXFLAGS) $(patsubst $(OBJECTS_BASE_DIR)/$(SRCDIR)%.d,$(SOURCES_BASE_DIR)/$(SRCDIR)%.cpp, $@) 2>/dev/null || echo \"$(patsubst $(OBJECTS_BASE_DIR)/$(SRCDIR)%.d,$(SOURCES_BASE_DIR)/$(SRCDIR)%.cpp, $@) FORCE\") | sed \"s/.*://g;s/\\\\\\\\//g\")$${NEW_LINE}\ $(patsubst %.d,%.o, $@): \$$($(shell sha1sum <<< "$@" | sed "s/ -//g")) makefile$${NEW_LINE}\ \$$(CXX) \$$(CXXFLAGS) \$$< -o $(patsubst %.d,%.o, $@)$${NEW_LINE}\ " > $@ %/makefile: makefile mkdir -p $(dir $@) cp makefile $@ %/: FORCE | %/makefile @accesstime=`stat -c %Y $@` && \ $(MAKE) -C $@ SRCDIR=$(SRCDIR)$(notdir $(patsubst %/, %, $@))/ OBJECTS_BASE_DIR=$(OBJECTS_BASE_DIR) SOURCES_BASE_DIR=$(SOURCES_BASE_DIR) CXX_OTHER_FLAGS="$(CXX_OTHER_FLAGS)" && \ accesstime2=`stat -c %Y $@` && \ if [ $$accesstime -ne $$accesstime2 ]; then \ touch .; \ fi FORCE: -include $(DEPENDENCIES)