5454 $(error Unsupported host OS for Makefile)
5555endif
5656
57+ # check if in a git repository
58+ ifeq ($(shell git rev-parse --is-inside-work-tree >/dev/null 2>/dev/null; echo $$? ) ,0)
59+ PACKAGE_VERSION := $(shell LC_ALL=C git --git-dir .git describe --tags --always --dirty)
60+ endif
61+
62+ # Get the current date and time in ISO 8601 format
63+ DATETIME := $(shell date +'% F % T UTC% z')
64+
65+ $(info Package version $(PACKAGE_VERSION))
66+ $(info Build date $(DATETIME))
67+
68+
5769RABBITIZER := tools/rabbitizer
5870RABBITIZER_LIB := $(RABBITIZER ) /build/librabbitizerpp.a
5971
@@ -110,9 +122,11 @@ LIBS := $(foreach lib,$(IDO_LIBS),$(BUILT_BIN)/$(lib))
110122
111123RECOMP_ELF := $(BUILD_BASE ) /recomp.elf
112124LIBC_IMPL := libc_impl
125+ VERSION_INFO := version_info
113126
114127TARGET_BINARIES := $(foreach binary,$(IDO_TC ) ,$(BUILT_BIN ) /$(binary ) )
115- O_FILES := $(foreach binary,$(IDO_TC ) ,$(BUILD_DIR ) /$(binary ) .o)
128+ # NCC is filtered out since it isn't an actual program, but a symlink to cc
129+ O_FILES := $(foreach binary,$(filter-out NCC, $(IDO_TC ) ) ,$(BUILD_DIR ) /$(binary ) .o)
116130C_FILES := $(O_FILES:.o=.c )
117131
118132# Automatic dependency files
@@ -138,6 +152,8 @@ ifeq ($(DETECTED_OS),linux)
138152$(RECOMP_ELF ) : LDFLAGS += -Wl,-export-dynamic
139153endif
140154
155+ CFLAGS += -DPACKAGE_VERSION="\"$(PACKAGE_VERSION ) \"" -DDATETIME="\"$(DATETIME ) \""
156+
141157% /$(LIBC_IMPL ) .o : WARNINGS += -Wno-unused-parameter -Wno-deprecated-declarations
142158% /$(LIBC_IMPL ) _53.o : WARNINGS += -Wno-unused-parameter -Wno-deprecated-declarations
143159
@@ -220,25 +236,26 @@ $(BUILT_BIN)/%: $(BUILD_DIR)/arm64-apple-macos11/% $(BUILD_DIR)/x86_64-apple-mac
220236
221237# ## Built programs ###
222238
223- $(BUILD_DIR ) /arm64-apple-macos11/% : $(BUILD_DIR ) /arm64-apple-macos11/% .o $(BUILD_DIR ) /arm64-apple-macos11/$(LIBC_IMPL ) .o | $(ERR_STRS )
239+ $(BUILD_DIR ) /arm64-apple-macos11/% : $(BUILD_DIR ) /arm64-apple-macos11/% .o $(BUILD_DIR ) /arm64-apple-macos11/$(LIBC_IMPL ) .o $( BUILD_DIR ) /arm64-apple-macos11/ $( VERSION_INFO ) .o | $(ERR_STRS )
224240 $(CC ) $(CSTD ) $(OPTFLAGS ) $(CFLAGS ) -target arm64-apple-macos11 -o $@ $^ $(LDFLAGS )
225241 $(STRIP ) $@
226242
227- $(BUILD_DIR ) /x86_64-apple-macos10.14/% : $(BUILD_DIR ) /x86_64-apple-macos10.14/% .o $(BUILD_DIR ) /x86_64-apple-macos10.14/$(LIBC_IMPL ) .o | $(ERR_STRS )
243+ $(BUILD_DIR ) /x86_64-apple-macos10.14/% : $(BUILD_DIR ) /x86_64-apple-macos10.14/% .o $(BUILD_DIR ) /x86_64-apple-macos10.14/$(LIBC_IMPL ) .o $( BUILD_DIR ) /x86_64-apple-macos10.14/ $( VERSION_INFO ) .o | $(ERR_STRS )
228244 $(CC ) $(CSTD ) $(OPTFLAGS ) $(CFLAGS ) -target x86_64-apple-macos10.14 -o $@ $^ $(LDFLAGS )
229245 $(STRIP ) $@
230246
247+ # NCC 7.1 is just a renamed cc
231248$(BUILD_BASE ) /7.1/arm64-apple-macos11/NCC : $(BUILD_BASE ) /7.1/arm64-apple-macos11/cc
232249 cp $^ $@
233250
234251$(BUILD_BASE ) /7.1/x86_64-apple-macos10.14/NCC : $(BUILD_BASE ) /7.1/x86_64-apple-macos10.14/cc
235252 cp $^ $@
236253
237- $(BUILD_DIR ) /arm64-apple-macos11/edgcpfe : $(BUILD_DIR ) /arm64-apple-macos11/edgcpfe.o $(BUILD_DIR ) /arm64-apple-macos11/$(LIBC_IMPL ) _53.o | $(ERR_STRS )
254+ $(BUILD_DIR ) /arm64-apple-macos11/edgcpfe : $(BUILD_DIR ) /arm64-apple-macos11/edgcpfe.o $(BUILD_DIR ) /arm64-apple-macos11/$(LIBC_IMPL ) _53.o $( BUILD_DIR ) /arm64-apple-macos11/ $( VERSION_INFO ) .o | $(ERR_STRS )
238255 $(CC ) $(CSTD ) $(OPTFLAGS ) $(CFLAGS ) -target arm64-apple-macos11 -o $@ $^ $(LDFLAGS )
239256 $(STRIP ) $@
240257
241- $(BUILD_DIR ) /x86_64-apple-macos10.14/edgcpfe : $(BUILD_DIR ) /x86_64-apple-macos10.14/edgcpfe.o $(BUILD_DIR ) /x86_64-apple-macos10.14/$(LIBC_IMPL ) _53.o | $(ERR_STRS )
258+ $(BUILD_DIR ) /x86_64-apple-macos10.14/edgcpfe : $(BUILD_DIR ) /x86_64-apple-macos10.14/edgcpfe.o $(BUILD_DIR ) /x86_64-apple-macos10.14/$(LIBC_IMPL ) _53.o $( BUILD_DIR ) /x86_64-apple-macos10.14/ $( VERSION_INFO ) .o | $(ERR_STRS )
242259 $(CC ) $(CSTD ) $(OPTFLAGS ) $(CFLAGS ) -target x86_64-apple-macos10.14 -o $@ $^ $(LDFLAGS )
243260 $(STRIP ) $@
244261
@@ -264,10 +281,17 @@ $(BUILD_DIR)/arm64-apple-macos11/$(LIBC_IMPL)_53.o: $(LIBC_IMPL).c
264281$(BUILD_DIR ) /x86_64-apple-macos10.14/$(LIBC_IMPL ) _53.o : $(LIBC_IMPL ) .c
265282 $(CC ) -c $(CSTD ) $(OPTFLAGS ) $(CFLAGS ) -DIDO53 $(WARNINGS ) -target x86_64-apple-macos10.14 -o $@ $<
266283
284+ # $(VERSION_INFO).o is set to depend on every other .o file to ensure the version information is always up to date
285+ $(BUILD_DIR ) /arm64-apple-macos11/$(VERSION_INFO ) .o : $(VERSION_INFO ) .c $(O_FILES ) $(BUILD_DIR ) /arm64-apple-macos11/$(LIBC_IMPL ) .o
286+ $(CC ) -c $(CSTD ) $(OPTFLAGS ) $(CFLAGS ) -D$(IDO_VERSION ) $(WARNINGS ) -target arm64-apple-macos11 -o $@ $<
287+
288+ $(BUILD_DIR ) /x86_64-apple-macos10.14/$(VERSION_INFO ) .o : $(VERSION_INFO ) .c $(O_FILES ) $(BUILD_DIR ) /x86_64-apple-macos10.14/$(LIBC_IMPL ) .o
289+ $(CC ) -c $(CSTD ) $(OPTFLAGS ) $(CFLAGS ) -D$(IDO_VERSION ) $(WARNINGS ) -target x86_64-apple-macos10.14 -o $@ $<
290+
267291else
268292# ## Built programs ###
269293
270- $(BUILT_BIN ) /% : $(BUILD_DIR ) /% .o $(BUILD_DIR ) /$(LIBC_IMPL ) .o | $(ERR_STRS )
294+ $(BUILT_BIN ) /% : $(BUILD_DIR ) /% .o $(BUILD_DIR ) /$(LIBC_IMPL ) .o $( BUILD_DIR ) / $( VERSION_INFO ) .o | $(ERR_STRS )
271295 $(CC ) $(CSTD ) $(OPTFLAGS ) $(CFLAGS ) -o $@ $^ $(LDFLAGS )
272296 $(STRIP ) $@
273297
@@ -276,7 +300,7 @@ $(BUILD_BASE)/7.1/out/NCC: $(BUILD_BASE)/7.1/out/cc
276300 cp $^ $@
277301
278302# edgcpfe 7.1 uses libc 5.3, so we need to hack a way to link a libc_impl file with the 5.3 stuff
279- $(BUILT_BIN ) /edgcpfe : $(BUILD_DIR ) /edgcpfe.o $(BUILD_DIR ) /$(LIBC_IMPL ) _53.o | $(ERR_STRS )
303+ $(BUILT_BIN ) /edgcpfe : $(BUILD_DIR ) /edgcpfe.o $(BUILD_DIR ) /$(LIBC_IMPL ) _53.o $( BUILD_DIR ) / $( VERSION_INFO ) .o | $(ERR_STRS )
280304 $(CC ) $(CSTD ) $(OPTFLAGS ) $(CFLAGS ) -o $@ $^ $(LDFLAGS )
281305 $(STRIP ) $@
282306
@@ -292,6 +316,10 @@ $(BUILD_DIR)/$(LIBC_IMPL).o: $(LIBC_IMPL).c
292316
293317$(BUILD_DIR ) /$(LIBC_IMPL ) _53.o : $(LIBC_IMPL ) .c
294318 $(CC ) -c $(CSTD ) $(OPTFLAGS ) $(CFLAGS ) -DIDO53 $(WARNINGS ) -o $@ $<
319+
320+ # $(VERSION_INFO).o is set to depend on every other .o file to ensure the version information is always up to date
321+ $(BUILD_DIR ) /$(VERSION_INFO ) .o : $(VERSION_INFO ) .c $(O_FILES ) $(BUILD_DIR ) /$(LIBC_IMPL ) .o $(BUILD_DIR ) /$(LIBC_IMPL ) _53.o
322+ $(CC ) -c $(CSTD ) $(OPTFLAGS ) $(CFLAGS ) -D$(IDO_VERSION ) $(WARNINGS ) -o $@ $<
295323endif
296324
297325# Remove built-in rules, to improve performance
0 commit comments