Merge pull request #188 from version-string

Add command to print version string

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
This commit is contained in:
Antonio Niño Díaz
2017-07-22 14:10:10 +01:00
13 changed files with 142 additions and 39 deletions

View File

@@ -15,13 +15,15 @@ PNGCFLAGS := `${PKG_CONFIG} --static --cflags libpng`
PNGLDFLAGS := `${PKG_CONFIG} --static --libs-only-L libpng` PNGLDFLAGS := `${PKG_CONFIG} --static --libs-only-L libpng`
PNGLDLIBS := `${PKG_CONFIG} --static --libs-only-l libpng` PNGLDLIBS := `${PKG_CONFIG} --static --libs-only-l libpng`
VERSION_STRING := `git describe --tags --dirty --always 2>/dev/null`
WARNFLAGS := -Wall -Werror WARNFLAGS := -Wall -Werror
# Overridable CFLAGS # Overridable CFLAGS
CFLAGS := -g CFLAGS := -g
# Non-overridable CFLAGS # Non-overridable CFLAGS
REALCFLAGS := ${CFLAGS} ${WARNFLAGS} -std=c99 -D_POSIX_C_SOURCE=200809L \ REALCFLAGS := ${CFLAGS} ${WARNFLAGS} -std=c99 -D_POSIX_C_SOURCE=200809L \
-Iinclude -Iinclude -DBUILD_VERSION_STRING=\"${VERSION_STRING}\"
YFLAGS := YFLAGS :=
LFLAGS := --nounistd LFLAGS := --nounistd
@@ -49,7 +51,9 @@ rgbasm_obj := \
src/extern/err.o \ src/extern/err.o \
src/extern/reallocarray.o \ src/extern/reallocarray.o \
src/extern/strlcpy.o \ src/extern/strlcpy.o \
src/extern/strlcat.o src/extern/strlcat.o \
src/extern/version.o
src/asm/asmy.h: src/asm/asmy.c src/asm/asmy.h: src/asm/asmy.c
src/asm/locallex.o src/asm/globlex.o src/asm/lexer.o: src/asm/asmy.h src/asm/locallex.o src/asm/globlex.o src/asm/lexer.o: src/asm/asmy.h
@@ -66,20 +70,23 @@ rgblink_obj := \
src/link/parser.o \ src/link/parser.o \
src/link/script.o \ src/link/script.o \
src/link/symbol.o \ src/link/symbol.o \
src/extern/err.o src/extern/err.o \
src/extern/version.o
src/link/parser.h: src/link/parser.c src/link/parser.h: src/link/parser.c
src/link/lexer.o: src/link/parser.h src/link/lexer.o: src/link/parser.h
rgbfix_obj := \ rgbfix_obj := \
src/fix/main.o \ src/fix/main.o \
src/extern/err.o src/extern/err.o \
src/extern/version.o
rgbgfx_obj := \ rgbgfx_obj := \
src/gfx/gb.o \ src/gfx/gb.o \
src/gfx/main.o \ src/gfx/main.o \
src/gfx/makepng.o \ src/gfx/makepng.o \
src/extern/err.o src/extern/err.o \
src/extern/version.o
rgbasm: ${rgbasm_obj} rgbasm: ${rgbasm_obj}
$Q${CC} ${REALCFLAGS} -o $@ ${rgbasm_obj} -lm $Q${CC} ${REALCFLAGS} -o $@ ${rgbasm_obj} -lm

21
include/extern/version.h vendored Normal file
View File

@@ -0,0 +1,21 @@
/*
* Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#define PACKAGE_VERSION_MAJOR (0)
#define PACKAGE_VERSION_MINOR (3)
#define PACKAGE_VERSION_PATCH (2)
const char * get_package_version_string(void);

View File

@@ -12,6 +12,7 @@
#include "asm/main.h" #include "asm/main.h"
#include "extern/err.h" #include "extern/err.h"
#include "extern/reallocarray.h" #include "extern/reallocarray.h"
#include "extern/version.h"
int yyparse(void); int yyparse(void);
void setuplex(void); void setuplex(void);
@@ -278,7 +279,7 @@ static void
usage(void) usage(void)
{ {
printf( printf(
"Usage: rgbasm [-hvE] [-b chars] [-Dname[=value]] [-g chars] [-i path]\n" "Usage: rgbasm [-EhVvw] [-b chars] [-Dname[=value]] [-g chars] [-i path]\n"
" [-M dependfile] [-o outfile] [-p pad_value] file.asm\n"); " [-M dependfile] [-o outfile] [-p pad_value] file.asm\n");
exit(1); exit(1);
} }
@@ -324,7 +325,7 @@ main(int argc, char *argv[])
newopt = CurrentOptions; newopt = CurrentOptions;
while ((ch = getopt(argc, argv, "b:D:g:hi:M:o:p:vEw")) != -1) { while ((ch = getopt(argc, argv, "b:D:g:hi:M:o:p:EVvw")) != -1) {
switch (ch) { switch (ch) {
case 'b': case 'b':
if (strlen(optarg) == 2) { if (strlen(optarg) == 2) {
@@ -338,6 +339,9 @@ main(int argc, char *argv[])
case 'D': case 'D':
opt_AddDefine(optarg); opt_AddDefine(optarg);
break; break;
case 'E':
newopt.exportall = true;
break;
case 'g': case 'g':
if (strlen(optarg) == 4) { if (strlen(optarg) == 4) {
newopt.gbgfx[0] = optarg[1]; newopt.gbgfx[0] = optarg[1];
@@ -373,17 +377,18 @@ main(int argc, char *argv[])
"between 0 and 0xFF"); "between 0 and 0xFF");
} }
break; break;
case 'V':
printf("rgbasm %s\n", get_package_version_string());
exit(0);
case 'v': case 'v':
newopt.verbose = true; newopt.verbose = true;
break; break;
case 'E':
newopt.exportall = true;
break;
case 'w': case 'w':
newopt.warnings = false; newopt.warnings = false;
break; break;
default: default:
usage(); usage();
/* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;

View File

@@ -20,7 +20,7 @@
.Nd Game Boy assembler .Nd Game Boy assembler
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm rgbasm .Nm rgbasm
.Op Fl Ehvw .Op Fl EhVvw
.Op Fl b Ar chars .Op Fl b Ar chars
.Op Fl D Ar name Ns Op = Ns Ar value .Op Fl D Ar name Ns Op = Ns Ar value
.Op Fl g Ar chars .Op Fl g Ar chars
@@ -72,6 +72,8 @@ Write an object file to the given filename.
.It Fl p Ar pad_value .It Fl p Ar pad_value
When padding an image, pad with this value. When padding an image, pad with this value.
The default is 0x00. The default is 0x00.
.It Fl V
Print the version of the program and exit.
.It Fl v .It Fl v
Be verbose. Be verbose.
.It Fl w .It Fl w

View File

@@ -549,6 +549,9 @@ The following symbols are defined by the assembler:
.It Ic EQU Ta Ic __UTC_HOUR__ Ta Ta Current hour, 0-23 .It Ic EQU Ta Ic __UTC_HOUR__ Ta Ta Current hour, 0-23
.It Ic EQU Ta Ic __UTC_MINUTE__ Ta Ta Current minute, 0-59 .It Ic EQU Ta Ic __UTC_MINUTE__ Ta Ta Current minute, 0-59
.It Ic EQU Ta Ic __UTC_SECOND__ Ta Ta Current second, 0-59 .It Ic EQU Ta Ic __UTC_SECOND__ Ta Ta Current second, 0-59
.It Ic EQU Ta Ic __RGBDS_MAJOR__ Ta Ta Major version number of RGBDS.
.It Ic EQU Ta Ic __RGBDS_MINOR__ Ta Ta Minor version number of RGBDS.
.It Ic EQU Ta Ic __RGBDS_PATCH__ Ta Ta Patch version number of RGBDS.
.El .El
.Pp .Pp
.Sh DEFINING DATA .Sh DEFINING DATA
@@ -1012,6 +1015,15 @@ machine.
.It Sx __ISO_8601_UTC__ .It Sx __ISO_8601_UTC__
.It Sx __LINE__ .It Sx __LINE__
.It Sx __TIME__ .It Sx __TIME__
.It Sx __RGBDS_MAJOR__
.It Sx __RGBDS_MINOR__
.It Sx __RGBDS_PATCH__
.It Sx __UTC_YEAR__
.It Sx __UTC_MONTH__
.It Sx __UTC_DAY__
.It Sx __UTC_HOUR__
.It Sx __UTC_MINUTE__
.It Sx __UTC_SECOND__
.It Sx _NARG .It Sx _NARG
.It Sx _PI .It Sx _PI
.It Sx _RS .It Sx _RS

View File

@@ -13,6 +13,7 @@
#include "asm/mymath.h" #include "asm/mymath.h"
#include "asm/output.h" #include "asm/output.h"
#include "extern/err.h" #include "extern/err.h"
#include "extern/version.h"
struct sSymbol *tHashedSymbols[HASHSIZE]; struct sSymbol *tHashedSymbols[HASHSIZE];
struct sSymbol *pScope = NULL; struct sSymbol *pScope = NULL;
@@ -848,6 +849,9 @@ sym_PrepPass2(void)
sym_AddString("__UTC_HOUR__", SavedHOUR); sym_AddString("__UTC_HOUR__", SavedHOUR);
sym_AddString("__UTC_MINUTE__", SavedMINUTE); sym_AddString("__UTC_MINUTE__", SavedMINUTE);
sym_AddString("__UTC_SECOND__", SavedSECOND); sym_AddString("__UTC_SECOND__", SavedSECOND);
sym_AddEqu("__RGBDS_MAJOR__", PACKAGE_VERSION_MAJOR);
sym_AddEqu("__RGBDS_MINOR__", PACKAGE_VERSION_MINOR);
sym_AddEqu("__RGBDS_PATCH__", PACKAGE_VERSION_PATCH);
sym_AddSet("_RS", 0); sym_AddSet("_RS", 0);
sym_AddEqu("_NARG", 0); sym_AddEqu("_NARG", 0);

34
src/extern/version.c vendored Normal file
View File

@@ -0,0 +1,34 @@
/*
* Copyright (C) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <string.h>
#include "extern/version.h"
const char * get_package_version_string(void)
{
static char s[50];
/* The following conditional should be simplified by the compiler. */
if (strlen(BUILD_VERSION_STRING) == 0) {
snprintf(s, sizeof(s), "v%d.%d.%d", PACKAGE_VERSION_MAJOR,
PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCH);
return s;
} else {
return BUILD_VERSION_STRING;
}
}

View File

@@ -22,12 +22,13 @@
#include <unistd.h> #include <unistd.h>
#include "extern/err.h" #include "extern/err.h"
#include "extern/version.h"
static void static void
usage(void) usage(void)
{ {
printf( printf(
"usage: rgbfix [-Ccjsv] [-i game_id] [-k licensee_str] [-l licensee_id]\n" "usage: rgbfix [-CcjsVv] [-i game_id] [-k licensee_str] [-l licensee_id]\n"
" [-m mbc_type] [-n rom_version] [-p pad_value] [-r ram_size]\n" " [-m mbc_type] [-n rom_version] [-p pad_value] [-r ram_size]\n"
" [-t title_str] file\n"); " [-t title_str] file\n");
exit(1); exit(1);
@@ -69,7 +70,7 @@ main(int argc, char *argv[])
int version; /* mask ROM version number */ int version; /* mask ROM version number */
int padvalue; /* to pad the rom with if it changes size */ int padvalue; /* to pad the rom with if it changes size */
while ((ch = getopt(argc, argv, "Cci:jk:l:m:n:p:sr:t:v")) != -1) { while ((ch = getopt(argc, argv, "Cci:jk:l:m:n:p:sr:t:Vv")) != -1) {
switch (ch) { switch (ch) {
case 'C': case 'C':
coloronly = true; coloronly = true;
@@ -177,6 +178,9 @@ main(int argc, char *argv[])
title = optarg; title = optarg;
break; break;
case 'V':
printf("rgbfix %s\n", get_package_version_string());
exit(0);
case 'v': case 'v':
validate = true; validate = true;
break; break;

View File

@@ -20,7 +20,7 @@
.Nd Game Boy checksum fixer .Nd Game Boy checksum fixer
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm rgbfix .Nm rgbfix
.Op Fl Ccjsv .Op Fl CcjsVv
.Op Fl i Ar game_id .Op Fl i Ar game_id
.Op Fl k Ar licensee_str .Op Fl k Ar licensee_str
.Op Fl l Ar licensee_id .Op Fl l Ar licensee_id
@@ -108,6 +108,8 @@ or
.Pc . .Pc .
If both this and the game ID are set, the game ID will overwrite the If both this and the game ID are set, the game ID will overwrite the
overlapping portion of the title. overlapping portion of the title.
.It Fl V
Print the version of the program and exit.
.It Fl v .It Fl v
Validate the header and fix checksums: the Nintendo character area Validate the header and fix checksums: the Nintendo character area
.Pq Ad 0x104 Ns \(en Ns Ad 0x133 , .Pq Ad 0x104 Ns \(en Ns Ad 0x133 ,

View File

@@ -14,17 +14,19 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <getopt.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "extern/version.h"
#include "gfx/main.h" #include "gfx/main.h"
static void static void
usage(void) usage(void)
{ {
printf( printf(
"usage: rgbgfx [-DFfhPTuv] [-d #] [-o outfile] [-p palfile] [-t mapfile]\n" "usage: rgbgfx [-DFfhPTuVv] [-d #] [-o outfile] [-p palfile] [-t mapfile]\n"
"[-x #] infile\n"); " [-x #] infile\n");
exit(1); exit(1);
} }
@@ -49,27 +51,30 @@ main(int argc, char *argv[])
depth = 2; depth = 2;
while((ch = getopt(argc, argv, "DvFfd:hx:Tt:uPp:o:")) != -1) { while((ch = getopt(argc, argv, "Dd:Ffho:Tt:uPp:Vvx:")) != -1) {
switch(ch) { switch(ch) {
case 'D': case 'D':
opts.debug = true; opts.debug = true;
break; break;
case 'v': case 'd':
opts.verbose = true; depth = strtoul(optarg, NULL, 0);
break; break;
case 'F': case 'F':
opts.hardfix = true; opts.hardfix = true;
case 'f': case 'f':
opts.fix = true; opts.fix = true;
break; break;
case 'd':
depth = strtoul(optarg, NULL, 0);
break;
case 'h': case 'h':
opts.horizontal = true; opts.horizontal = true;
break; break;
case 'x': case 'o':
opts.trim = strtoul(optarg, NULL, 0); opts.outfile = optarg;
break;
case 'P':
opts.palout = true;
break;
case 'p':
opts.palfile = optarg;
break; break;
case 'T': case 'T':
opts.mapout = true; opts.mapout = true;
@@ -80,17 +85,18 @@ main(int argc, char *argv[])
case 'u': case 'u':
opts.unique = true; opts.unique = true;
break; break;
case 'P': case 'V':
opts.palout = true; printf("rgbgfx %s\n", get_package_version_string());
exit(0);
case 'v':
opts.verbose = true;
break; break;
case 'p': case 'x':
opts.palfile = optarg; opts.trim = strtoul(optarg, NULL, 0);
break;
case 'o':
opts.outfile = optarg;
break; break;
default: default:
usage(); usage();
/* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;

View File

@@ -20,7 +20,7 @@
.Nd Game Boy graphics converter .Nd Game Boy graphics converter
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm rgbgfx .Nm rgbgfx
.Op Fl DfFhPTv .Op Fl DfFhPTVv
.Op Fl o Ar outfile .Op Fl o Ar outfile
.Op Fl d Ar depth .Op Fl d Ar depth
.Op Fl p Ar palfile .Op Fl p Ar palfile
@@ -70,6 +70,8 @@ removing the file extension, and appending
.Pa .tilemap . .Pa .tilemap .
.It Fl u .It Fl u
Truncate repeated tiles. Useful with tilemaps. Truncate repeated tiles. Useful with tilemaps.
.It Fl V
Print the version of the program and exit.
.It Fl v .It Fl v
Verbose. Verbose.
Print errors when the command line parameters and the parameters in Print errors when the command line parameters and the parameters in

View File

@@ -4,6 +4,7 @@
#include <unistd.h> #include <unistd.h>
#include "extern/err.h" #include "extern/err.h"
#include "extern/version.h"
#include "link/object.h" #include "link/object.h"
#include "link/output.h" #include "link/output.h"
#include "link/assign.h" #include "link/assign.h"
@@ -33,7 +34,7 @@ static void
usage(void) usage(void)
{ {
printf( printf(
"usage: rgblink [-twd] [-l linkerscript] [-m mapfile] [-n symfile] [-O overlay]\n" "usage: rgblink [-dtVw] [-l linkerscript] [-m mapfile] [-n symfile] [-O overlay]\n"
" [-o outfile] [-p pad_value] [-s symbol] file [...]\n"); " [-o outfile] [-p pad_value] [-s symbol] file [...]\n");
exit(1); exit(1);
} }
@@ -52,7 +53,7 @@ main(int argc, char *argv[])
if (argc == 1) if (argc == 1)
usage(); usage();
while ((ch = getopt(argc, argv, "l:m:n:o:O:p:s:twd")) != -1) { while ((ch = getopt(argc, argv, "dl:m:n:O:o:p:s:tVw")) != -1) {
switch (ch) { switch (ch) {
case 'l': case 'l':
SetLinkerscriptName(optarg); SetLinkerscriptName(optarg);
@@ -98,7 +99,7 @@ main(int argc, char *argv[])
* This option implies OPT_CONTWRAM. * This option implies OPT_CONTWRAM.
*/ */
options |= OPT_DMG_MODE; options |= OPT_DMG_MODE;
/* fallthrough */ /* FALLTHROUGH */
case 'w': case 'w':
/* Set to set WRAM as a single continuous block as on /* Set to set WRAM as a single continuous block as on
* DMG. All WRAM sections must be WRAM0 as bankable WRAM * DMG. All WRAM sections must be WRAM0 as bankable WRAM
@@ -106,6 +107,9 @@ main(int argc, char *argv[])
* will raise an error. */ * will raise an error. */
options |= OPT_CONTWRAM; options |= OPT_CONTWRAM;
break; break;
case 'V':
printf("rgblink %s\n", get_package_version_string());
exit(0);
default: default:
usage(); usage();
/* NOTREACHED */ /* NOTREACHED */

View File

@@ -20,9 +20,7 @@
.Nd Game Boy linker .Nd Game Boy linker
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm rgblink .Nm rgblink
.Op Fl t .Op Fl dtVw
.Op Fl w
.Op Fl d
.Op Fl m Ar mapfile .Op Fl m Ar mapfile
.Op Fl n Ar symfile .Op Fl n Ar symfile
.Op Fl O Ar overlayfile .Op Fl O Ar overlayfile
@@ -95,6 +93,8 @@ have to be consistent.
See See
.Xr rgblink 5 .Xr rgblink 5
for more information about its format. for more information about its format.
.It Fl V
Print the version of the program and exit.
.El .El
.Sh EXAMPLES .Sh EXAMPLES
All you need for a basic ROM is an object file, which can be made into a ROM All you need for a basic ROM is an object file, which can be made into a ROM