mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 12:47:08 +00:00
Don't recompile misc.cpp on every run
alternative to https://github.com/official-stockfish/Stockfish/pull/6660 closes https://github.com/official-stockfish/Stockfish/pull/6662 No functional change
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
**/*.o
|
**/*.o
|
||||||
**/*.s
|
**/*.s
|
||||||
src/.depend
|
src/.depend
|
||||||
|
.build_sha.txt
|
||||||
|
.build_date.txt
|
||||||
|
|
||||||
# Built binary
|
# Built binary
|
||||||
src/stockfish*
|
src/stockfish*
|
||||||
|
|||||||
+34
-15
@@ -833,19 +833,28 @@ ifeq ($(pext),yes)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.8.1 Try to include git commit sha for versioning
|
### 3.8.1 Try to include git info for versioning and avoid recompiles if nothing changes
|
||||||
GIT_SHA := $(shell git rev-parse HEAD 2>/dev/null | cut -c 1-8)
|
BUILD_SHA_FILE := .build_sha.txt
|
||||||
ifneq ($(GIT_SHA), )
|
BUILD_DATE_FILE := .build_date.txt
|
||||||
CXXFLAGS += -DGIT_SHA=$(GIT_SHA)
|
GIT_SHA := $(shell git rev-parse HEAD 2>/dev/null | cut -c 1-8 || true)
|
||||||
|
GIT_DATE := $(shell git show -s --date=format:%Y%m%d --format=%cd HEAD 2>/dev/null || true)
|
||||||
|
COMPILER_DATE := $(shell date +%Y%m%d 2>/dev/null)
|
||||||
|
|
||||||
|
BUILD_DATE := $(if $(GIT_DATE),$(GIT_DATE),$(COMPILER_DATE))
|
||||||
|
|
||||||
|
define cache_file_contents
|
||||||
|
$(shell \
|
||||||
|
if [ ! -f "$(1)" ] || [ "$$(cat "$(1)" 2>/dev/null)" != "$(2)" ]; then \
|
||||||
|
printf '%s\n' "$(2)" > "$(1)"; \
|
||||||
|
fi)
|
||||||
|
endef
|
||||||
|
|
||||||
|
ifneq ($(filter $(MAKECMDGOALS),help strip install clean net objclean profileclean format config-sanity),$(MAKECMDGOALS))
|
||||||
|
_ := $(call cache_file_contents,$(BUILD_SHA_FILE),$(GIT_SHA))
|
||||||
|
_ := $(call cache_file_contents,$(BUILD_DATE_FILE),$(BUILD_DATE))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### 3.8.2 Try to include git commit date for versioning
|
### 3.8.2 Try to include architecture
|
||||||
GIT_DATE := $(shell git show -s --date=format:'%Y%m%d' --format=%cd HEAD 2>/dev/null)
|
|
||||||
ifneq ($(GIT_DATE), )
|
|
||||||
CXXFLAGS += -DGIT_DATE=$(GIT_DATE)
|
|
||||||
endif
|
|
||||||
|
|
||||||
### 3.8.3 Try to include architecture
|
|
||||||
ifneq ($(ARCH), )
|
ifneq ($(ARCH), )
|
||||||
CXXFLAGS += -DARCH=$(ARCH)
|
CXXFLAGS += -DARCH=$(ARCH)
|
||||||
endif
|
endif
|
||||||
@@ -1035,7 +1044,7 @@ clean: objclean profileclean
|
|||||||
|
|
||||||
# clean binaries and objects
|
# clean binaries and objects
|
||||||
objclean:
|
objclean:
|
||||||
@rm -f stockfish stockfish.exe *.o ./syzygy/*.o ./nnue/*.o ./nnue/features/*.o
|
@rm -f stockfish stockfish.exe *.o ./syzygy/*.o ./nnue/*.o ./nnue/features/*.o $(BUILD_SHA_FILE) $(BUILD_DATE_FILE)
|
||||||
|
|
||||||
# clean auxiliary profiling files
|
# clean auxiliary profiling files
|
||||||
profileclean:
|
profileclean:
|
||||||
@@ -1131,9 +1140,19 @@ config-sanity: net
|
|||||||
$(EXE): $(OBJS)
|
$(EXE): $(OBJS)
|
||||||
+$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
+$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
||||||
|
|
||||||
# Force recompilation to ensure version info is up-to-date
|
%.o: %.cpp
|
||||||
misc.o: FORCE
|
$(strip $(CXX) $(CPPFLAGS) $(CXXFLAGS)) -c -o $@ $<
|
||||||
FORCE:
|
|
||||||
|
# Cache git metadata when available, otherwise cache the compiler date.
|
||||||
|
misc.o: misc.cpp $(BUILD_SHA_FILE) $(BUILD_DATE_FILE)
|
||||||
|
@sha="$$(cat $(BUILD_SHA_FILE))"; \
|
||||||
|
set -- $(CXX) $(CPPFLAGS) $(CXXFLAGS); \
|
||||||
|
test -n "$$sha" && set -- "$$@" -DGIT_SHA=$$sha; \
|
||||||
|
test -n "$(GIT_DATE)" && set -- "$$@" -DGIT_DATE=$(GIT_DATE); \
|
||||||
|
set -- "$$@" -c $< -o $@; \
|
||||||
|
printf '%s ' "$$@"; \
|
||||||
|
printf '\n'; \
|
||||||
|
"$$@"
|
||||||
|
|
||||||
clang-profile-make:
|
clang-profile-make:
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
|
|||||||
Reference in New Issue
Block a user