Skip to content
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 ps2sdkinfo tool for version info #623

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SUBDIRS = \
bin2c \
ps2-irxgen \
ps2adpcm \
ps2sdkinfo \
romimg \
# gensymtab

Expand Down
56 changes: 56 additions & 0 deletions tools/ps2sdkinfo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.

TOOLS_INCS += -I$(TOOLS_OBJS_DIR)
TOOLS_CFLAGS += -std=c99 -D_DEFAULT_SOURCE=1
TOOLS_LDFLAGS +=

TOOLS_OBJS = main.o

PS2SDK_GIT_REMOTE_URL := $(shell git -C $(CURDIR) config --get remote.origin.url)
PS2SDK_GIT_HASH := $(shell git -C $(CURDIR) log -1 '--format=%H')
PS2SDK_GIT_TAG := $(shell git -C $(CURDIR) log -1 '--format=%(describe:tags,abbrev=0)')
PS2SDK_GIT_TIME := $(shell git -C $(CURDIR) log -1 '--format=%ct')
PS2SDK_GIT_TIME_ISO8601 := $(shell git -C $(CURDIR) log -1 '--format=%cd' --date="format:%Y-%m-%dT%H:%M:%S%z")
PS2SDK_GIT_TIME_RFC2822 := $(shell git -C $(CURDIR) log -1 '--format=%cd' --date="format:%a, %d %b %Y %H:%M:%S %z")

PS2SDK_BUILD_PATH := $(PS2SDKSRC)
PS2SDK_BUILD_USER := $(shell whoami)
PS2SDK_BUILD_MACHINE := $(shell hostname)
PS2SDK_BUILD_TIME := $(shell date +"%s")
PS2SDK_BUILD_TIME_ISO8601 := $(shell date -d'@'$(PS2SDK_BUILD_TIME) +"%Y-%m-%dT%H:%M:%S%z")
PS2SDK_BUILD_TIME_RFC2822 := $(shell date -d'@'$(PS2SDK_BUILD_TIME) +"%a, %d %b %Y %H:%M:%S %z")

include $(PS2SDKSRC)/Defs.make
include $(PS2SDKSRC)/tools/Rules.bin.make
include $(PS2SDKSRC)/tools/Rules.make
include $(PS2SDKSRC)/tools/Rules.release

$(TOOLS_OBJS_DIR)gitinfo.h:
$(MKDIR) -p $(TOOLS_OBJS_DIR) && \
printf '/* Git info for ps2sdk */\n' > $@ && \
printf '#ifndef %s\n#define %s "%s"\n#endif\n' PS2SDK_GIT_REMOTE_URL PS2SDK_GIT_REMOTE_URL "$(PS2SDK_GIT_REMOTE_URL)" >> $@ && \
printf '#ifndef %s\n#define %s "%s"\n#endif\n' PS2SDK_GIT_HASH PS2SDK_GIT_HASH "$(PS2SDK_GIT_HASH)" >> $@ && \
printf '#ifndef %s\n#define %s "%s"\n#endif\n' PS2SDK_GIT_TIME PS2SDK_GIT_TIME "$(PS2SDK_GIT_TIME)" >> $@ && \
printf '#ifndef %s\n#define %s "%s"\n#endif\n' PS2SDK_GIT_TIME_ISO8601 PS2SDK_GIT_TIME_ISO8601 "$(PS2SDK_GIT_TIME_ISO8601)" >> $@ && \
printf '#ifndef %s\n#define %s "%s"\n#endif\n' PS2SDK_GIT_TIME_RFC2822 PS2SDK_GIT_TIME_RFC2822 "$(PS2SDK_GIT_TIME_RFC2822)" >> $@ && \
printf '#ifndef %s\n#define %s "%s"\n#endif\n' PS2SDK_GIT_TAG PS2SDK_GIT_TAG "$(PS2SDK_GIT_TAG)" >> $@ && \
printf '/* Git info for ps2sdk end */\n' >> $@

$(TOOLS_OBJS_DIR)buildinfo.h:
$(MKDIR) -p $(TOOLS_OBJS_DIR) && \
printf '/* Build info for ps2sdk */\n' > $@ && \
printf '#ifndef %s\n#define %s "%s"\n#endif\n' PS2SDK_BUILD_PATH PS2SDK_BUILD_PATH "$(PS2SDK_BUILD_PATH)" >> $@ && \
printf '#ifndef %s\n#define %s "%s"\n#endif\n' PS2SDK_BUILD_USER PS2SDK_BUILD_USER "$(PS2SDK_BUILD_USER)" >> $@ && \
printf '#ifndef %s\n#define %s "%s"\n#endif\n' PS2SDK_BUILD_MACHINE PS2SDK_BUILD_MACHINE "$(PS2SDK_BUILD_MACHINE)" >> $@ && \
printf '#ifndef %s\n#define %s "%s"\n#endif\n' PS2SDK_BUILD_TIME PS2SDK_BUILD_TIME "$(PS2SDK_BUILD_TIME)" >> $@ && \
printf '#ifndef %s\n#define %s "%s"\n#endif\n' PS2SDK_BUILD_TIME_ISO8601 PS2SDK_BUILD_TIME_ISO8601 "$(PS2SDK_BUILD_TIME_ISO8601)" >> $@ && \
printf '#ifndef %s\n#define %s "%s"\n#endif\n' PS2SDK_BUILD_TIME_RFC2822 PS2SDK_BUILD_TIME_RFC2822 "$(PS2SDK_BUILD_TIME_RFC2822)" >> $@ && \
printf '/* Build info for ps2sdk end */\n' >> $@

$(TOOLS_OBJS_DIR)main.o: $(TOOLS_OBJS_DIR)gitinfo.h $(TOOLS_OBJS_DIR)buildinfo.h
73 changes: 73 additions & 0 deletions tools/ps2sdkinfo/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.
*/

#include <stdio.h>
#include <string.h>
#include "gitinfo.h"
#include "buildinfo.h"

typedef struct info_item_
{
const char *key;
const char *value;
} info_item_t;

static info_item_t info_items[] =
{
{"PS2SDK_GIT_REMOTE_URL", PS2SDK_GIT_REMOTE_URL},
{"PS2SDK_GIT_HASH", PS2SDK_GIT_HASH},
{"PS2SDK_GIT_TIME", PS2SDK_GIT_TIME},
{"PS2SDK_GIT_TIME_ISO8601", PS2SDK_GIT_TIME_ISO8601},
{"PS2SDK_GIT_TIME_RFC2822", PS2SDK_GIT_TIME_RFC2822},
{"PS2SDK_GIT_TAG", PS2SDK_GIT_TAG},
{"PS2SDK_BUILD_PATH", PS2SDK_BUILD_PATH},
{"PS2SDK_BUILD_USER", PS2SDK_BUILD_USER},
{"PS2SDK_BUILD_MACHINE", PS2SDK_BUILD_MACHINE},
{"PS2SDK_BUILD_TIME", PS2SDK_BUILD_TIME},
{"PS2SDK_BUILD_TIME_ISO8601", PS2SDK_BUILD_TIME_ISO8601},
{"PS2SDK_BUILD_TIME_RFC2822", PS2SDK_BUILD_TIME_RFC2822},
{NULL, NULL},
};

int main(int argc, char *argv[])
{
int retval;
retval = 0;
if (argc <= 1)
{
for (int i = 0; info_items[i].key != NULL; i += 1)
{
printf("%s=%s\n", info_items[i].key, info_items[i].value);
}
return retval;
}

for (int i = 1; i < argc; i += 1)
{
int found;
found = 0;
for (int j = 0; info_items[j].key != NULL; j += 1)
{
if (strcmp(info_items[j].key, argv[i]) == 0)
{
printf("%s\n", info_items[j].value);
found = 1;
break;
}
}
if (found == 0)
{
printf("%s\n", "NOTFOUND");
retval = 1;
}
}

return retval;
}