mirror of https://github.com/PrimeDecomp/prime.git
Improve metroidbuildinfo, use file instead of string passed from command line
Former-commit-id: cca1bc81f5
This commit is contained in:
parent
698badd39d
commit
096c8a89b7
2
Makefile
2
Makefile
|
@ -94,6 +94,7 @@ endif
|
||||||
CC = $(WINE) tools/mwcc_compiler/$(MWCC_VERSION)/mwcceppc.exe
|
CC = $(WINE) tools/mwcc_compiler/$(MWCC_VERSION)/mwcceppc.exe
|
||||||
LD := $(WINE) tools/mwcc_compiler/$(MWLD_VERSION)/mwldeppc.exe
|
LD := $(WINE) tools/mwcc_compiler/$(MWLD_VERSION)/mwldeppc.exe
|
||||||
ELF2DOL := tools/elf2dol
|
ELF2DOL := tools/elf2dol
|
||||||
|
METROIDBUILDINFO := tools/metroidbuildinfo
|
||||||
|
|
||||||
TRANSFORM_DEP := tools/transform-dep.py
|
TRANSFORM_DEP := tools/transform-dep.py
|
||||||
FRANK := tools/franklite.py
|
FRANK := tools/franklite.py
|
||||||
|
@ -163,6 +164,7 @@ $(LDSCRIPT): ldscript.lcf
|
||||||
|
|
||||||
$(DOL): $(ELF) | tools
|
$(DOL): $(ELF) | tools
|
||||||
$(QUIET) $(ELF2DOL) $< $@
|
$(QUIET) $(ELF2DOL) $< $@
|
||||||
|
$(METROIDBUILDINFO) $@ buildstrings/$(NAME).$(VERSION).build
|
||||||
$(QUIET) $(SHA1SUM) -c sha1/$(NAME).$(VERSION).sha1
|
$(QUIET) $(SHA1SUM) -c sha1/$(NAME).$(VERSION).sha1
|
||||||
ifneq ($(findstring -map,$(LDFLAGS)),)
|
ifneq ($(findstring -map,$(LDFLAGS)),)
|
||||||
$(QUIET) $(PYTHON) tools/calcprogress.py $(DOL) $(MAP)
|
$(QUIET) $(PYTHON) tools/calcprogress.py $(DOL) $(MAP)
|
||||||
|
|
|
@ -127,6 +127,7 @@ MetroidBuildInfo:
|
||||||
.ascii "!#$MetroidBuildInfo!#$"
|
.ascii "!#$MetroidBuildInfo!#$"
|
||||||
.global BuildString
|
.global BuildString
|
||||||
BuildString:
|
BuildString:
|
||||||
|
#.asciz "PAD_PAD_PAD_PAD_PAD_PAD_PAD_PAD_PAD"
|
||||||
.if version == 2
|
.if version == 2
|
||||||
.asciz "Build v1.097 12/19/2002 16:03:43"
|
.asciz "Build v1.097 12/19/2002 16:03:43"
|
||||||
.asciz "AD"
|
.asciz "AD"
|
||||||
|
|
|
@ -3,10 +3,13 @@ CFLAGS := -O3 -Wall -s
|
||||||
|
|
||||||
default: all
|
default: all
|
||||||
|
|
||||||
all: elf2dol
|
all: elf2dol metroidbuildinfo
|
||||||
|
|
||||||
elf2dol: elf2dol.c
|
elf2dol: elf2dol.c
|
||||||
$(CC) $(CFLAGS) -o $@ $^
|
$(CC) $(CFLAGS) -o $@ $^
|
||||||
|
|
||||||
|
metroidbuildinfo: metroidbuildinfo.c
|
||||||
|
$(CC) $(CFLAGS) -o $@ $^
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) elf2dol
|
$(RM) elf2dol metroidbuildinfo
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define VERSION_MAX_LEN 35
|
#define VERSION_MAX_LEN (size_t)(35)
|
||||||
#define METROID_BUILD_INFO_TAG "!#$MetroidBuildInfo!#$"
|
#define METROID_BUILD_INFO_TAG "!#$MetroidBuildInfo!#$"
|
||||||
|
|
||||||
void* memmem(const void* l, size_t l_len, const void* s, size_t s_len) {
|
void* memmem(const void* l, size_t l_len, const void* s, size_t s_len) {
|
||||||
|
@ -44,7 +44,7 @@ int main(int argc, const char* argv[]) {
|
||||||
|
|
||||||
);
|
);
|
||||||
fprintf(stdout, "Usage:\n"
|
fprintf(stdout, "Usage:\n"
|
||||||
"\tmetroidbuildinfo <binary> <version-string>\n");
|
"\tmetroidbuildinfo <binary> <build_file>\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,13 +55,22 @@ int main(int argc, const char* argv[]) {
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Verify string length, if the string is too long hard error */
|
char build_string[36] = {0};
|
||||||
if (strlen(argv[2]) > VERSION_MAX_LEN) {
|
FILE* build = fopen(argv[2], "rb");
|
||||||
fprintf(stderr, "Version string '%s'\ntoo long, got %i, expected %i\n", argv[2], ver_len,
|
|
||||||
VERSION_MAX_LEN);
|
if (!build) {
|
||||||
|
fprintf(stderr, "Unable to open '%s'\nPlease ensure the file exists!\n", argv[2]);
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
/* Lets include the null terminator */
|
size_t read_len = fread(build_string, 1, 35, build);
|
||||||
|
fclose(build);
|
||||||
|
|
||||||
|
if (read_len <= 0) {
|
||||||
|
fprintf(stderr, "Empty file %s specified for build version!\n", argv[2]);
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
|
||||||
|
build_string[strcspn(build_string, "\n")] = '\0';
|
||||||
|
|
||||||
/* Get source length */
|
/* Get source length */
|
||||||
fseek(source, 0, SEEK_END);
|
fseek(source, 0, SEEK_END);
|
||||||
|
@ -70,7 +79,7 @@ int main(int argc, const char* argv[]) {
|
||||||
void* source_buf = malloc(source_len);
|
void* source_buf = malloc(source_len);
|
||||||
if (source_buf == NULL) {
|
if (source_buf == NULL) {
|
||||||
fprintf(stderr, "Unable to allocate buffer of size %zubytes!\n", source_len);
|
fprintf(stderr, "Unable to allocate buffer of size %zubytes!\n", source_len);
|
||||||
return -4;
|
return -5;
|
||||||
}
|
}
|
||||||
fread(source_buf, 1, source_len, source);
|
fread(source_buf, 1, source_len, source);
|
||||||
fclose(source);
|
fclose(source);
|
||||||
|
@ -84,7 +93,7 @@ int main(int argc, const char* argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lets actually copy over the build string */
|
/* Lets actually copy over the build string */
|
||||||
strcpy(ptr + strlen(METROID_BUILD_INFO_TAG), argv[2]);
|
strcpy(ptr + strlen(METROID_BUILD_INFO_TAG), build_string);
|
||||||
|
|
||||||
/* Now attempt to open the target file */
|
/* Now attempt to open the target file */
|
||||||
FILE* target = fopen(argv[1], "wb");
|
FILE* target = fopen(argv[1], "wb");
|
||||||
|
@ -101,5 +110,5 @@ int main(int argc, const char* argv[]) {
|
||||||
/* Don't leak */
|
/* Don't leak */
|
||||||
free(source_buf);
|
free(source_buf);
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue