-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --version
flag
#61
Changes from all commits
0bb4e62
0b41326
d10f5b9
7adef00
b827107
3ba36d7
d8a62c8
a504bdf
a827acd
ed08bb7
7894496
c47487d
2af749f
3cdb5a6
3a1aa07
5f0e27c
3289a3e
4c5edcb
14650f6
c722d94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,18 @@ else | |
$(error Unsupported host OS for Makefile) | ||
endif | ||
|
||
# check if in a git repository | ||
ifeq ($(shell git rev-parse --is-inside-work-tree >/dev/null 2>/dev/null; echo $$?),0) | ||
PACKAGE_VERSION := $(shell LC_ALL=C git --git-dir .git describe --tags --always --dirty) | ||
endif | ||
|
||
# Get the current date and time in ISO 8601 format | ||
DATETIME := $(shell date +'%F %T UTC%z') | ||
|
||
$(info Package version $(PACKAGE_VERSION)) | ||
$(info Build date $(DATETIME)) | ||
|
||
|
||
RABBITIZER := tools/rabbitizer | ||
RABBITIZER_LIB := $(RABBITIZER)/build/librabbitizerpp.a | ||
|
||
|
@@ -110,9 +122,11 @@ LIBS := $(foreach lib,$(IDO_LIBS),$(BUILT_BIN)/$(lib)) | |
|
||
RECOMP_ELF := $(BUILD_BASE)/recomp.elf | ||
LIBC_IMPL := libc_impl | ||
VERSION_INFO := version_info | ||
|
||
TARGET_BINARIES := $(foreach binary,$(IDO_TC),$(BUILT_BIN)/$(binary)) | ||
O_FILES := $(foreach binary,$(IDO_TC),$(BUILD_DIR)/$(binary).o) | ||
# NCC is filtered out since it isn't an actual program, but a symlink to cc | ||
O_FILES := $(foreach binary,$(filter-out NCC, $(IDO_TC)),$(BUILD_DIR)/$(binary).o) | ||
C_FILES := $(O_FILES:.o=.c) | ||
|
||
# Automatic dependency files | ||
|
@@ -138,6 +152,8 @@ ifeq ($(DETECTED_OS),linux) | |
$(RECOMP_ELF): LDFLAGS += -Wl,-export-dynamic | ||
endif | ||
|
||
CFLAGS += -DPACKAGE_VERSION="\"$(PACKAGE_VERSION)\"" -DDATETIME="\"$(DATETIME)\"" | ||
|
||
%/$(LIBC_IMPL).o: WARNINGS += -Wno-unused-parameter -Wno-deprecated-declarations | ||
%/$(LIBC_IMPL)_53.o: WARNINGS += -Wno-unused-parameter -Wno-deprecated-declarations | ||
|
||
|
@@ -220,25 +236,26 @@ $(BUILT_BIN)/%: $(BUILD_DIR)/arm64-apple-macos11/% $(BUILD_DIR)/x86_64-apple-mac | |
|
||
### Built programs ### | ||
|
||
$(BUILD_DIR)/arm64-apple-macos11/%: $(BUILD_DIR)/arm64-apple-macos11/%.o $(BUILD_DIR)/arm64-apple-macos11/$(LIBC_IMPL).o | $(ERR_STRS) | ||
$(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) | ||
$(CC) $(CSTD) $(OPTFLAGS) $(CFLAGS) -target arm64-apple-macos11 -o $@ $^ $(LDFLAGS) | ||
$(STRIP) $@ | ||
|
||
$(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) | ||
$(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) | ||
$(CC) $(CSTD) $(OPTFLAGS) $(CFLAGS) -target x86_64-apple-macos10.14 -o $@ $^ $(LDFLAGS) | ||
$(STRIP) $@ | ||
|
||
# NCC 7.1 is just a renamed cc | ||
$(BUILD_BASE)/7.1/arm64-apple-macos11/NCC: $(BUILD_BASE)/7.1/arm64-apple-macos11/cc | ||
cp $^ $@ | ||
|
||
$(BUILD_BASE)/7.1/x86_64-apple-macos10.14/NCC: $(BUILD_BASE)/7.1/x86_64-apple-macos10.14/cc | ||
cp $^ $@ | ||
|
||
$(BUILD_DIR)/arm64-apple-macos11/edgcpfe: $(BUILD_DIR)/arm64-apple-macos11/edgcpfe.o $(BUILD_DIR)/arm64-apple-macos11/$(LIBC_IMPL)_53.o | $(ERR_STRS) | ||
$(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) | ||
$(CC) $(CSTD) $(OPTFLAGS) $(CFLAGS) -target arm64-apple-macos11 -o $@ $^ $(LDFLAGS) | ||
$(STRIP) $@ | ||
|
||
$(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) | ||
$(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) | ||
$(CC) $(CSTD) $(OPTFLAGS) $(CFLAGS) -target x86_64-apple-macos10.14 -o $@ $^ $(LDFLAGS) | ||
$(STRIP) $@ | ||
|
||
|
@@ -264,10 +281,17 @@ $(BUILD_DIR)/arm64-apple-macos11/$(LIBC_IMPL)_53.o: $(LIBC_IMPL).c | |
$(BUILD_DIR)/x86_64-apple-macos10.14/$(LIBC_IMPL)_53.o: $(LIBC_IMPL).c | ||
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -DIDO53 $(WARNINGS) -target x86_64-apple-macos10.14 -o $@ $< | ||
|
||
# $(VERSION_INFO).o is set to depend on every other .o file to ensure the version information is always up to date | ||
$(BUILD_DIR)/arm64-apple-macos11/$(VERSION_INFO).o: $(VERSION_INFO).c $(O_FILES) $(BUILD_DIR)/arm64-apple-macos11/$(LIBC_IMPL).o | ||
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -D$(IDO_VERSION) $(WARNINGS) -target arm64-apple-macos11 -o $@ $< | ||
|
||
$(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 | ||
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -D$(IDO_VERSION) $(WARNINGS) -target x86_64-apple-macos10.14 -o $@ $< | ||
Comment on lines
+285
to
+289
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These shouldn't need to depend on other .o files There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Elliptic's intention here was to force a rebuild for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, right! Makes sense, worth a comment maybe |
||
|
||
else | ||
### Built programs ### | ||
|
||
$(BUILT_BIN)/%: $(BUILD_DIR)/%.o $(BUILD_DIR)/$(LIBC_IMPL).o | $(ERR_STRS) | ||
$(BUILT_BIN)/%: $(BUILD_DIR)/%.o $(BUILD_DIR)/$(LIBC_IMPL).o $(BUILD_DIR)/$(VERSION_INFO).o | $(ERR_STRS) | ||
$(CC) $(CSTD) $(OPTFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS) | ||
$(STRIP) $@ | ||
|
||
|
@@ -276,7 +300,7 @@ $(BUILD_BASE)/7.1/out/NCC: $(BUILD_BASE)/7.1/out/cc | |
cp $^ $@ | ||
|
||
# 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 | ||
$(BUILT_BIN)/edgcpfe: $(BUILD_DIR)/edgcpfe.o $(BUILD_DIR)/$(LIBC_IMPL)_53.o | $(ERR_STRS) | ||
$(BUILT_BIN)/edgcpfe: $(BUILD_DIR)/edgcpfe.o $(BUILD_DIR)/$(LIBC_IMPL)_53.o $(BUILD_DIR)/$(VERSION_INFO).o | $(ERR_STRS) | ||
$(CC) $(CSTD) $(OPTFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS) | ||
$(STRIP) $@ | ||
|
||
|
@@ -292,6 +316,10 @@ $(BUILD_DIR)/$(LIBC_IMPL).o: $(LIBC_IMPL).c | |
|
||
$(BUILD_DIR)/$(LIBC_IMPL)_53.o: $(LIBC_IMPL).c | ||
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -DIDO53 $(WARNINGS) -o $@ $< | ||
|
||
# $(VERSION_INFO).o is set to depend on every other .o file to ensure the version information is always up to date | ||
$(BUILD_DIR)/$(VERSION_INFO).o: $(VERSION_INFO).c $(O_FILES) $(BUILD_DIR)/$(LIBC_IMPL).o $(BUILD_DIR)/$(LIBC_IMPL)_53.o | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similarly |
||
$(CC) -c $(CSTD) $(OPTFLAGS) $(CFLAGS) -D$(IDO_VERSION) $(WARNINGS) -o $@ $< | ||
endif | ||
|
||
# Remove built-in rules, to improve performance | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Function that prints version info. This file should be compiled with the following defined: | ||
* - PACKAGE_VERSION, e.g. with `-DPACKAGE_VERSION="\"$(LC_ALL=C git --git-dir .git describe --tags --dirty)\""` | ||
* - DATETIME, e.g. with `-DDATETIME="\"$(date +'%F %T UTC%z')\""` | ||
* | ||
* The code in this file is mostly taken from | ||
* - CPython: https://github.com/python/cpython/, licensed under the PSF, available here: https://docs.python.org/3/license.html | ||
* - The Ocarina of Time practice rom, gz: https://github.com/glankk/gz/ | ||
*/ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <libgen.h> | ||
|
||
#if defined(IDO53) | ||
#define IDO_VERSION "IDO 5.3" | ||
#elif defined(IDO71) | ||
#define IDO_VERSION "IDO 7.1" | ||
#else | ||
#define IDO_VERSION "" | ||
#endif | ||
|
||
#ifndef COMPILER | ||
|
||
// Note the __clang__ conditional has to come before the __GNUC__ one because | ||
// clang pretends to be GCC. | ||
#if defined(__clang__) | ||
#define COMPILER "Clang " __clang_version__ | ||
#elif defined(__GNUC__) | ||
#define COMPILER "GCC " __VERSION__ | ||
// Generic fallbacks. | ||
#elif defined(__cplusplus) | ||
#define COMPILER "C++" | ||
#else | ||
#define COMPILER "C" | ||
#endif | ||
|
||
#endif /* !COMPILER */ | ||
|
||
/* git */ | ||
#ifndef PACKAGE_VERSION | ||
#define PACKAGE_VERSION "Unknown version" | ||
#endif | ||
|
||
/* Date and time */ | ||
#ifndef DATETIME | ||
#define DATETIME "Unknown date" | ||
#endif | ||
|
||
extern char* progname; | ||
|
||
void print_version_info(void) { | ||
char* buf = malloc(strlen(progname) + 1); | ||
strcpy(buf, progname); | ||
char* name = basename(buf); | ||
|
||
printf("%s `%s` static recompilation, Decompals version\n", IDO_VERSION, name); | ||
printf("Source: https://github.com/decompals/ido-static-recomp\n"); | ||
printf("Version: %s\n", PACKAGE_VERSION); | ||
printf("Build date: %s\n", DATETIME); | ||
printf("Compiler: %s\n", COMPILER); | ||
|
||
free(buf); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happened to these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
version_info.o
depends on every other .o file to be built first, but we weren't creatingNCC.c/NCC.o
files because this file is just a renamedcc
binary. Because of this make couldn't build theversion_info.o
file, so how NCC is handled, instead of copying and renaming acc
program, it copies thecc.c
program and builds that insteadThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, ok. Seems a bit wasteful to compile cc.c multiple times, maybe the .o can be copied instead. Or NCC can be filtered out from O_FILES.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding an empty rule for
NCC.o
still complains because the other rule already set the dependency ofNCC.o
onNCC.c
I'll try to filter it out from O_FILES