diff --git a/Makefile b/Makefile index e7ed16240..529c4a17f 100644 --- a/Makefile +++ b/Makefile @@ -130,6 +130,27 @@ CXXFLAGS += $(WARNING_FLAGS) -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT) -Woverl LDFLAGS += $(PLATFORM_LDFLAGS) +date := $(shell date +%F) +git_sha := $(shell git describe HEAD 2>/dev/null) +gen_build_version = \ + printf '%s\n' \ + '\#include "build_version.h"' \ + 'const char* rocksdb_build_git_sha = \ + "rocksdb_build_git_sha:$(git_sha)";' \ + 'const char* rocksdb_build_git_date = \ + "rocksdb_build_git_date:$(date)";' \ + 'const char* rocksdb_build_compile_date = __DATE__;' + +# Record the version of the source that we are compiling. +# We keep a record of the git revision in this file. It is then built +# as a regular source file as part of the compilation process. +# One can run "strings executable_filename | grep _build_" to find +# the version of the source that we used to build the executable file. +util/build_version.cc: + $(AM_V_GEN)$(gen_build_version) > $@.tmp + $(AM_V_at)if test -f $@; then \ + cmp -s $@.tmp $@ && : || mv -f $@.tmp $@; else mv -f $@.tmp $@; fi + LIBOBJECTS = $(SOURCES:.cc=.o) MOCKOBJECTS = $(MOCK_SOURCES:.cc=.o) @@ -751,7 +772,7 @@ endif @$(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) \ -MM -MT'$@' -MT'$(<:.cc=.o)' "$<" -o '$@' -DEPFILES = $(filter-out util/build_version.d,$(SOURCES:.cc=.d)) +DEPFILES = $(SOURCES:.cc=.d) depend: $(DEPFILES) diff --git a/build_tools/build_detect_platform b/build_tools/build_detect_platform index 9c8bd7d2a..80f50610a 100755 --- a/build_tools/build_detect_platform +++ b/build_tools/build_detect_platform @@ -79,7 +79,7 @@ if test -z "$CLANG_SCAN_BUILD"; then CLANG_SCAN_BUILD=scan-build fi -if test -z "$CLANG_ANALYZER"; then +if test -z "$CLANG_ANALYZER"; then CLANG_ANALYZER=$(which clang++) fi @@ -165,11 +165,7 @@ esac JAVA_LDFLAGS="$PLATFORM_LDFLAGS" -if test -z "$DO_NOT_RUN_BUILD_DETECT_VERSION"; then - "$PWD/build_tools/build_detect_version" -fi - -# We want to make a list of all cc files within util, db and table +# We want to make a list of all cc files in $DIRS, # except for the test and benchmark files. By default, find will output a list # of all files matching either rule, so we need to append -print to make the # prune take effect. @@ -183,6 +179,12 @@ PORTABLE_FILES=`cd "$ROCKSDB_ROOT"; find $DIRS $PRUNE_TEST -o $PRUNE_BENCH -o $P MOCK_SOURCES=`cd "$ROCKSDB_ROOT"; find $DIRS -name '*mock*.cc' -print | grep -v "test" | sort | tr "\n" " "` set +f # re-enable globbing +# If the generated util/build_version.cc is not on the list, add it: +case $PORTABLE_FILES in + *util/build_version.cc*) ;; + *) PORTABLE_FILES="$PORTABLE_FILES util/build_version.cc" ;; +esac + # The sources consist of the portable files, plus the platform-specific port # file. echo "SOURCES=$PORTABLE_FILES $GENERIC_PORT_FILES $PORT_FILES" >> "$OUTPUT" diff --git a/build_tools/build_detect_version b/build_tools/build_detect_version deleted file mode 100755 index f7d711f0d..000000000 --- a/build_tools/build_detect_version +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh -# -# Record the version of the source that we are compiling. -# We keep a record of the git revision in util/version.cc. This source file -# is then built as a regular source file as part of the compilation process. -# One can run "strings executable_filename | grep _build_" to find the version of -# the source that we used to build the executable file. - -OUTFILE="$PWD/util/build_version.cc" - -GIT_SHA="" -if command -v git >/dev/null 2>&1; then - GIT_SHA=$(git rev-parse HEAD 2>/dev/null) -fi - -cat > "${OUTFILE}" <