Skip to content

Commit 718e926

Browse files
committed
Build .release_info files containing the version string
By adding build-dependencies to all *_parse_options files whenever the contents of .release_info files differs from $(RELEASE_INFO), we ensure that binaries print the correct version strings.
1 parent 6416372 commit 718e926

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Release/*
2828
*.obj
2929
*.a
3030
*.lib
31+
.release_info
3132
src/ansi-c/arm_builtin_headers.inc
3233
src/ansi-c/clang_builtin_headers.inc
3334
src/ansi-c/cprover_builtin_headers.inc

src/common

+18-1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ OBJ += $(patsubst %.cc, %$(OBJEXT), $(filter %.cc, $(SRC)))
229229

230230
# get version from git
231231
GIT_INFO = $(shell git describe --tags --always --dirty || echo "n/a")
232+
GIT_INFO_FILE = .release_info
232233

233234
CBMC_VERSION_FILES += $(filter %_parse_options$(OBJEXT), $(OBJ))
234235

@@ -238,12 +239,28 @@ else
238239
$(CBMC_VERSION_FILES): CP_CXXFLAGS += -DCBMC_VERSION="\"$(CBMC_VERSION) ($(GIT_INFO))\""
239240
endif
240241

242+
# Use make >= 4.0's `file` function, if available - it should be faster than
243+
# `shell cat`
244+
ifeq ($(firstword $(subst ., , $(MAKE_VERSION))), 3)
245+
KNOWN_RELEASE_INFO = $(shell cat $(GIT_INFO_FILE) 2>/dev/null)
246+
else
247+
KNOWN_RELEASE_INFO = $(file < $(GIT_INFO_FILE))
248+
endif
249+
ifneq ($(GIT_INFO), $(KNOWN_RELEASE_INFO))
250+
$(CBMC_VERSION_FILES): $(GIT_INFO_FILE)
251+
252+
$(GIT_INFO_FILE):
253+
echo $(GIT_INFO) > $@
254+
255+
.PHONY: $(GIT_INFO_FILE)
256+
endif
257+
241258
clean:
242259
$(RM) $(patsubst %.cpp, %$(OBJEXT), $(filter %.cpp, $(SRC))) \
243260
$(patsubst %.cpp, %$(DEPEXT), $(filter %.cpp, $(SRC))) \
244261
$(patsubst %.cc, %$(OBJEXT), $(filter %.cc, $(SRC))) \
245262
$(patsubst %.cc, %$(DEPEXT), $(filter %.cc, $(SRC))) \
246-
$(CLEANFILES)
263+
$(CLEANFILES) $(GIT_INFO_FILE)
247264

248265
.PHONY: first_target clean all
249266
.PHONY: sources generated_files

0 commit comments

Comments
 (0)