mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Some refactoring and reformatting (#1431)
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
// Variables related to CLI options
|
// Variables related to CLI options
|
||||||
extern bool isDmgMode;
|
extern bool isDmgMode;
|
||||||
extern char *linkerScriptName;
|
extern char const *linkerScriptName;
|
||||||
extern char const *mapFileName;
|
extern char const *mapFileName;
|
||||||
extern bool noSymInMap;
|
extern bool noSymInMap;
|
||||||
extern char const *symFileName;
|
extern char const *symFileName;
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ void FormatSpec::appendNumber(std::string &str, uint32_t value) const {
|
|||||||
uint32_t uval = value != (uint32_t)INT32_MIN ? labs((int32_t)value) : value;
|
uint32_t uval = value != (uint32_t)INT32_MIN ? labs((int32_t)value) : value;
|
||||||
snprintf(valueBuf, sizeof(valueBuf), "%" PRIu32, uval);
|
snprintf(valueBuf, sizeof(valueBuf), "%" PRIu32, uval);
|
||||||
} else {
|
} else {
|
||||||
char const *spec = useType == 'u' ? "%" PRIu32
|
char const *spec = useType == 'u' ? "%" PRIu32
|
||||||
: useType == 'X' ? "%" PRIX32
|
: useType == 'X' ? "%" PRIX32
|
||||||
: useType == 'x' ? "%" PRIx32
|
: useType == 'x' ? "%" PRIx32
|
||||||
: useType == 'o' ? "%" PRIo32
|
: useType == 'o' ? "%" PRIo32
|
||||||
|
|||||||
@@ -21,14 +21,13 @@
|
|||||||
#include "asm/symbol.hpp"
|
#include "asm/symbol.hpp"
|
||||||
#include "asm/warning.hpp"
|
#include "asm/warning.hpp"
|
||||||
|
|
||||||
FILE *dependFile = nullptr;
|
FILE *dependFile = nullptr; // -M
|
||||||
bool generatedMissingIncludes = false;
|
bool generatedMissingIncludes = false; // -MG
|
||||||
|
bool generatePhonyDeps = false; // -MP
|
||||||
|
std::string targetFileName; // -MQ, -MT
|
||||||
bool failedOnMissingInclude = false;
|
bool failedOnMissingInclude = false;
|
||||||
bool generatePhonyDeps = false;
|
bool verbose = false; // -v
|
||||||
std::string targetFileName;
|
bool warnings = true; // -w
|
||||||
|
|
||||||
bool verbose;
|
|
||||||
bool warnings; // True to enable warnings, false to disable them.
|
|
||||||
|
|
||||||
// Escapes Make-special chars from a string
|
// Escapes Make-special chars from a string
|
||||||
static std::string make_escape(std::string &str) {
|
static std::string make_escape(std::string &str) {
|
||||||
@@ -62,27 +61,27 @@ static int depType; // Variants of `-M`
|
|||||||
// This is because long opt matching, even to a single char, is prioritized
|
// This is because long opt matching, even to a single char, is prioritized
|
||||||
// over short opt matching
|
// over short opt matching
|
||||||
static option const longopts[] = {
|
static option const longopts[] = {
|
||||||
{"binary-digits", required_argument, nullptr, 'b'},
|
{"binary-digits", required_argument, nullptr, 'b'},
|
||||||
{"define", required_argument, nullptr, 'D'},
|
{"define", required_argument, nullptr, 'D'},
|
||||||
{"export-all", no_argument, nullptr, 'E'},
|
{"export-all", no_argument, nullptr, 'E'},
|
||||||
{"gfx-chars", required_argument, nullptr, 'g'},
|
{"gfx-chars", required_argument, nullptr, 'g'},
|
||||||
{"include", required_argument, nullptr, 'I'},
|
{"include", required_argument, nullptr, 'I'},
|
||||||
{"dependfile", required_argument, nullptr, 'M'},
|
{"dependfile", required_argument, nullptr, 'M'},
|
||||||
{"MG", no_argument, &depType, 'G'},
|
{"MG", no_argument, &depType, 'G'},
|
||||||
{"MP", no_argument, &depType, 'P'},
|
{"MP", no_argument, &depType, 'P'},
|
||||||
{"MT", required_argument, &depType, 'T'},
|
{"MT", required_argument, &depType, 'T'},
|
||||||
{"warning", required_argument, nullptr, 'W'},
|
{"warning", required_argument, nullptr, 'W'},
|
||||||
{"MQ", required_argument, &depType, 'Q'},
|
{"MQ", required_argument, &depType, 'Q'},
|
||||||
{"output", required_argument, nullptr, 'o'},
|
{"output", required_argument, nullptr, 'o'},
|
||||||
{"preinclude", required_argument, nullptr, 'P'},
|
{"preinclude", required_argument, nullptr, 'P'},
|
||||||
{"pad-value", required_argument, nullptr, 'p'},
|
{"pad-value", required_argument, nullptr, 'p'},
|
||||||
{"q-precision", required_argument, nullptr, 'Q'},
|
{"q-precision", required_argument, nullptr, 'Q'},
|
||||||
{"recursion-depth", required_argument, nullptr, 'r'},
|
{"recursion-depth", required_argument, nullptr, 'r'},
|
||||||
{"version", no_argument, nullptr, 'V'},
|
{"version", no_argument, nullptr, 'V'},
|
||||||
{"verbose", no_argument, nullptr, 'v'},
|
{"verbose", no_argument, nullptr, 'v'},
|
||||||
{"warning", required_argument, nullptr, 'W'},
|
{"warning", required_argument, nullptr, 'W'},
|
||||||
{"max-errors", required_argument, nullptr, 'X'},
|
{"max-errors", required_argument, nullptr, 'X'},
|
||||||
{nullptr, no_argument, nullptr, 0 }
|
{nullptr, no_argument, nullptr, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void printUsage() {
|
static void printUsage() {
|
||||||
@@ -124,8 +123,6 @@ int main(int argc, char *argv[]) {
|
|||||||
opt_G("0123");
|
opt_G("0123");
|
||||||
opt_P(0);
|
opt_P(0);
|
||||||
opt_Q(16);
|
opt_Q(16);
|
||||||
verbose = false;
|
|
||||||
warnings = true;
|
|
||||||
sym_SetExportAll(false);
|
sym_SetExportAll(false);
|
||||||
uint32_t maxDepth = DEFAULT_MAX_DEPTH;
|
uint32_t maxDepth = DEFAULT_MAX_DEPTH;
|
||||||
char const *dependFileName = nullptr;
|
char const *dependFileName = nullptr;
|
||||||
@@ -336,8 +333,7 @@ int main(int argc, char *argv[]) {
|
|||||||
if (failedOnMissingInclude)
|
if (failedOnMissingInclude)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// If no path specified, don't write file
|
out_WriteObject();
|
||||||
if (!objectName.empty())
|
|
||||||
out_WriteObject();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -304,6 +304,9 @@ static void writeFileStackNode(FileStackNode const &node, FILE *file) {
|
|||||||
|
|
||||||
// Write an object file
|
// Write an object file
|
||||||
void out_WriteObject() {
|
void out_WriteObject() {
|
||||||
|
if (objectName.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
FILE *file;
|
FILE *file;
|
||||||
if (objectName != "-") {
|
if (objectName != "-") {
|
||||||
file = fopen(objectName.c_str(), "wb");
|
file = fopen(objectName.c_str(), "wb");
|
||||||
|
|||||||
@@ -114,32 +114,32 @@ static char const *optstring = "-Aa:b:Cc:Dd:FfhL:mN:n:Oo:Pp:Qq:r:s:Tt:U:uVvx:Z";
|
|||||||
* over short opt matching
|
* over short opt matching
|
||||||
*/
|
*/
|
||||||
static option const longopts[] = {
|
static option const longopts[] = {
|
||||||
{"auto-attr-map", no_argument, nullptr, 'A' },
|
{"auto-attr-map", no_argument, nullptr, 'A'},
|
||||||
{"attr-map", required_argument, nullptr, 'a' },
|
{"attr-map", required_argument, nullptr, 'a'},
|
||||||
{"base-tiles", required_argument, nullptr, 'b' },
|
{"base-tiles", required_argument, nullptr, 'b'},
|
||||||
{"color-curve", no_argument, nullptr, 'C' },
|
{"color-curve", no_argument, nullptr, 'C'},
|
||||||
{"colors", required_argument, nullptr, 'c' },
|
{"colors", required_argument, nullptr, 'c'},
|
||||||
{"depth", required_argument, nullptr, 'd' },
|
{"depth", required_argument, nullptr, 'd'},
|
||||||
{"slice", required_argument, nullptr, 'L' },
|
{"slice", required_argument, nullptr, 'L'},
|
||||||
{"mirror-tiles", no_argument, nullptr, 'm' },
|
{"mirror-tiles", no_argument, nullptr, 'm'},
|
||||||
{"nb-tiles", required_argument, nullptr, 'N' },
|
{"nb-tiles", required_argument, nullptr, 'N'},
|
||||||
{"nb-palettes", required_argument, nullptr, 'n' },
|
{"nb-palettes", required_argument, nullptr, 'n'},
|
||||||
{"group-outputs", no_argument, nullptr, 'O' },
|
{"group-outputs", no_argument, nullptr, 'O'},
|
||||||
{"output", required_argument, nullptr, 'o' },
|
{"output", required_argument, nullptr, 'o'},
|
||||||
{"auto-palette", no_argument, nullptr, 'P' },
|
{"auto-palette", no_argument, nullptr, 'P'},
|
||||||
{"palette", required_argument, nullptr, 'p' },
|
{"palette", required_argument, nullptr, 'p'},
|
||||||
{"auto-palette-map", no_argument, nullptr, 'Q' },
|
{"auto-palette-map", no_argument, nullptr, 'Q'},
|
||||||
{"palette-map", required_argument, nullptr, 'q' },
|
{"palette-map", required_argument, nullptr, 'q'},
|
||||||
{"reverse", required_argument, nullptr, 'r' },
|
{"reverse", required_argument, nullptr, 'r'},
|
||||||
{"auto-tilemap", no_argument, nullptr, 'T' },
|
{"auto-tilemap", no_argument, nullptr, 'T'},
|
||||||
{"tilemap", required_argument, nullptr, 't' },
|
{"tilemap", required_argument, nullptr, 't'},
|
||||||
{"unit-size", required_argument, nullptr, 'U' },
|
{"unit-size", required_argument, nullptr, 'U'},
|
||||||
{"unique-tiles", no_argument, nullptr, 'u' },
|
{"unique-tiles", no_argument, nullptr, 'u'},
|
||||||
{"version", no_argument, nullptr, 'V' },
|
{"version", no_argument, nullptr, 'V'},
|
||||||
{"verbose", no_argument, nullptr, 'v' },
|
{"verbose", no_argument, nullptr, 'v'},
|
||||||
{"trim-end", required_argument, nullptr, 'x' },
|
{"trim-end", required_argument, nullptr, 'x'},
|
||||||
{"columns", no_argument, nullptr, 'Z' },
|
{"columns", no_argument, nullptr, 'Z'},
|
||||||
{nullptr, no_argument, nullptr, 0 }
|
{nullptr, no_argument, nullptr, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void printUsage() {
|
static void printUsage() {
|
||||||
|
|||||||
@@ -24,14 +24,14 @@
|
|||||||
#include "link/section.hpp"
|
#include "link/section.hpp"
|
||||||
#include "link/symbol.hpp"
|
#include "link/symbol.hpp"
|
||||||
|
|
||||||
bool isDmgMode; // -d
|
bool isDmgMode; // -d
|
||||||
char *linkerScriptName; // -l
|
char const *linkerScriptName; // -l
|
||||||
char const *mapFileName; // -m
|
char const *mapFileName; // -m
|
||||||
bool noSymInMap; // -M
|
bool noSymInMap; // -M
|
||||||
char const *symFileName; // -n
|
char const *symFileName; // -n
|
||||||
char const *overlayFileName; // -O
|
char const *overlayFileName; // -O
|
||||||
char const *outputFileName; // -o
|
char const *outputFileName; // -o
|
||||||
uint8_t padValue; // -p
|
uint8_t padValue; // -p
|
||||||
bool hasPadValue = false;
|
bool hasPadValue = false;
|
||||||
// Setting these three to 0 disables the functionality
|
// Setting these three to 0 disables the functionality
|
||||||
uint16_t scrambleROMX = 0; // -S
|
uint16_t scrambleROMX = 0; // -S
|
||||||
@@ -349,7 +349,7 @@ int main(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
if (linkerScriptName)
|
if (linkerScriptName)
|
||||||
warnx("Overriding linker script %s", musl_optarg);
|
warnx("Overriding linker script %s", linkerScriptName);
|
||||||
linkerScriptName = musl_optarg;
|
linkerScriptName = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
@@ -357,22 +357,22 @@ int main(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
if (mapFileName)
|
if (mapFileName)
|
||||||
warnx("Overriding map file %s", musl_optarg);
|
warnx("Overriding map file %s", mapFileName);
|
||||||
mapFileName = musl_optarg;
|
mapFileName = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
if (symFileName)
|
if (symFileName)
|
||||||
warnx("Overriding sym file %s", musl_optarg);
|
warnx("Overriding sym file %s", symFileName);
|
||||||
symFileName = musl_optarg;
|
symFileName = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'O':
|
case 'O':
|
||||||
if (overlayFileName)
|
if (overlayFileName)
|
||||||
warnx("Overriding overlay file %s", musl_optarg);
|
warnx("Overriding overlay file %s", overlayFileName);
|
||||||
overlayFileName = musl_optarg;
|
overlayFileName = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
if (outputFileName)
|
if (outputFileName)
|
||||||
warnx("Overriding output file %s", musl_optarg);
|
warnx("Overriding output file %s", outputFileName);
|
||||||
outputFileName = musl_optarg;
|
outputFileName = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'p': {
|
case 'p': {
|
||||||
|
|||||||
Reference in New Issue
Block a user