diff options
Diffstat (limited to 'buildtools')
-rw-r--r-- | buildtools/Makefile | 12 | ||||
-rwxr-xr-x | buildtools/configure.pl | 48 | ||||
-rw-r--r-- | buildtools/genfontc.c | 199 | ||||
-rw-r--r-- | buildtools/libopt.c | 9 |
4 files changed, 257 insertions, 11 deletions
diff --git a/buildtools/Makefile b/buildtools/Makefile index 8671c066..0490865b 100644 --- a/buildtools/Makefile +++ b/buildtools/Makefile @@ -33,10 +33,20 @@ libopt.o: libopt.c typegen.o endiangen.o:%.o:%.c $(CC_FOR_BUILD) -c -o $@ $(CFLAGS_FOR_BUILD) $< +# genfontc is strange because it isn't really a build tool; it's a development +# tool. And it uses Netpbm. So we don't even build it by default and the +# developer who builds it explicitly may have to be careful. +genfontc.o:%.o:%.c importinc + $(CC_FOR_BUILD) -c -o $@ $(CFLAGS_FOR_BUILD) \ + $(NETPBM_INCLUDES) \ + $< +genfontc:%:%.o $(NETPBMLIB) + $(LD_FOR_BUILD) -o $@ $(LDFLAGS_FOR_BUILD) $< $(NETPBMLIB) + $(BUILDPROGS):%:%.o $(LD_FOR_BUILD) -o $@ $(LDFLAGS_FOR_BUILD) $< distclean clean: cleanlocal .PHONY: cleanlocal cleanlocal: - rm -f $(BUILDPROGS) + rm -f $(BUILDPROGS) genfontc diff --git a/buildtools/configure.pl b/buildtools/configure.pl index 9cafd019..5a7d8a33 100755 --- a/buildtools/configure.pl +++ b/buildtools/configure.pl @@ -1456,14 +1456,52 @@ sub gnuOptimizeOpt($) { +sub wnostrictoverflowWorks($) { + my ($gccCommandName) = @_; + + my ($cFile, $cFileName) = tempFile(".c"); + + print $cFile "int x;"; + + my $compileCommand = + "$gccCommandName -c -o /dev/null -Wno-strict-overflow $cFileName"; + print ("Doing test compile to see if -Wno-strict-overflow works: " + . "$compileCommand\n"); + my $rc = system($compileCommand); + + unlink($cFileName); + close($cFile); + + return ($rc == 0); +} + + + sub gnuCflags($) { my ($gccCommandName) = @_; - return("CFLAGS = " . gnuOptimizeOpt($gccCommandName) . " -ffast-math " . - " -pedantic -fno-common " . - "-Wall -Wno-uninitialized -Wmissing-declarations -Wimplicit " . - "-Wwrite-strings -Wmissing-prototypes -Wundef " . - "-Wno-unknown-pragmas\n"); + my $flags; + + $flags = gnuOptimizeOpt($gccCommandName) . " -ffast-math " . + " -pedantic -fno-common " . + "-Wall -Wno-uninitialized -Wmissing-declarations -Wimplicit " . + "-Wwrite-strings -Wmissing-prototypes -Wundef " . + "-Wno-unknown-pragmas "; + + if (wnostrictoverflowWorks($gccCommandName)) { + # The compiler generates some optimizations based on the assumption + # that you wouldn't code something that can arithmetically overflow, + # so adding a positive value to something can only make it bigger. + # E.g. if (x + y > x), where y is unsigned, is a no-op. The compiler + # optionally warns when it makes that assumption. Sometimes, the + # compiler is able to do that optimization because of inlining, so the + # code per se is not ridiculous, it just becomes superfluous in + # context. That means you can't code around the warning. Ergo, we + # must disable the warning. + + $flags .= '-Wno-strict-overflow'; + } + return("CFLAGS = $flags\n"); } diff --git a/buildtools/genfontc.c b/buildtools/genfontc.c new file mode 100644 index 00000000..ce6b8c9c --- /dev/null +++ b/buildtools/genfontc.c @@ -0,0 +1,199 @@ +#include "pm_c_util.h" +#include "mallocvar.h" +#include "shhopt.h" +#include "pm.h" +#include "pbmfont.h" + + + +struct CmdlineInfo { + /* All the information the user supplied in the command line, + in a form easy for the program to use. + */ + const char * font; + const char * builtin; + const char * header; + const char * varname; + unsigned int verbose; +}; + + + +static void +parseCommandLine(int argc, const char ** argv, + struct CmdlineInfo * const cmdlineP) { +/*---------------------------------------------------------------------------- + Note that the file spec array we return is stored in the storage that + was passed to us as the argv array. +-----------------------------------------------------------------------------*/ + optEntry * option_def; + /* Instructions to OptParseOptions3 on how to parse our options. + */ + optStruct3 opt; + + unsigned int fontSpec, builtinSpec, headerSpec, varnameSpec; + + unsigned int option_def_index; + + MALLOCARRAY_NOFAIL(option_def, 100); + + option_def_index = 0; /* incremented by OPTENTRY */ + OPTENT3(0, "font", OPT_STRING, &cmdlineP->font, &fontSpec, 0); + OPTENT3(0, "builtin", OPT_STRING, &cmdlineP->builtin, &builtinSpec, 0); + OPTENT3(0, "header", OPT_STRING, &cmdlineP->header, &headerSpec, 0); + OPTENT3(0, "varname", OPT_STRING, &cmdlineP->varname, &varnameSpec, 0); + OPTENT3(0, "verbose", OPT_FLAG, NULL, &cmdlineP->verbose, 0); + + opt.opt_table = option_def; + opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ + opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + + pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + /* Uses and sets argc, argv, and some of *cmdlineP and others. */ + + if (!fontSpec) + cmdlineP->font = NULL; + + if (!builtinSpec) + cmdlineP->builtin = NULL; + + if (!headerSpec) + cmdlineP->header = NULL; + + if (!varnameSpec) + cmdlineP->varname = NULL; +} + + + +static void +reportFont(struct font * const fontP) { + + unsigned int n; + unsigned int c; + + pm_message("FONT:"); + pm_message(" character dimensions: %uw x %uh", + fontP->maxwidth, fontP->maxheight); + pm_message(" Additional vert white space: %d pixels", fontP->y); + + for (c = 0, n = 0; c < ARRAY_SIZE(fontP->glyph); ++c) { + if (fontP->glyph[c]) + ++n; + } + + pm_message(" # characters: %u", n); +} + + + +static void +computeFont(const char * const fontName, + const char * const builtinName, + struct font ** const fontPP) { + + struct font * fontP; + + if (fontName) + fontP = pbm_loadfont(fontName); + else { + if (builtinName) + fontP = pbm_defaultfont(builtinName); + else + fontP = pbm_defaultfont("bdf"); + } + + *fontPP = fontP; +} + + + + +static void +dumpfont(struct font * const fontP, + const char * const header, + const char * const varname, + FILE * const ofP) { +/*---------------------------------------------------------------------------- + Dump out font as C source code. +-----------------------------------------------------------------------------*/ + unsigned int i; + unsigned int ng; + + for (i = 0, ng = 0; i < 256; ++i) { + if (fontP->glyph[i]) + ++ng; + } + + if (header != NULL) + printf("#include \"%s\"\n\n", header); + + printf("static struct glyph _g[%d] = {\n", ng); + + for (i = 0; i < 256; ++i) { + struct glyph * const glyphP = fontP->glyph[i]; + + if (glyphP) { + unsigned int j; + + printf(" { %d, %d, %d, %d, %d, \"", + glyphP->width, glyphP->height, + glyphP->x, glyphP->y, glyphP->xadd); + + for (j = 0; j < glyphP->width * glyphP->height; ++j) { + if (glyphP->bmap[j]) + printf("\\1"); + else + printf("\\0"); + } + --ng; + printf("\" }%s\n", ng ? "," : ""); + } + } + printf("};\n"); + + printf("struct font %s = { %d, %d, %d, %d, {\n", + (varname == NULL) ? "XXX_font" : varname, + fontP->maxwidth, fontP->maxheight, fontP->x, fontP->y); + + { + unsigned int i; + + for (i = 0; i < 256; ++i) { + if (fontP->glyph[i]) + printf(" _g + %d", ng++); + else + printf(" NULL"); + + if (i != 255) + printf(","); + + printf("\n"); + } + } + + printf(" }\n};\n"); +} + + + +int +main(int argc, const char *argv[]) { + + struct CmdlineInfo cmdline; + struct font * fontP; + + pm_proginit(&argc, argv); + + parseCommandLine(argc, argv, &cmdline); + + computeFont(cmdline.font, cmdline.builtin, &fontP); + + if (cmdline.verbose) + reportFont(fontP); + + dumpfont(fontP, cmdline.header, cmdline.varname, stdout); +} + + + diff --git a/buildtools/libopt.c b/buildtools/libopt.c index a0bf1cda..274e7c66 100644 --- a/buildtools/libopt.c +++ b/buildtools/libopt.c @@ -497,21 +497,20 @@ main(int argc, char **argv) { bool error; bool runtime; /* -runtime option has been seen */ - bool quiet; /* -quiet option has been seen */ int retval; unsigned int arg; /* Index into argv[] of argument we're processing */ char outputLine[1024]; strcpy(outputLine, ""); /* initial value */ runtime = FALSE; /* initial value */ - quiet = FALSE; /* initial value */ error = FALSE; /* no error yet */ + for (arg = 1; arg < argc && !error; arg++) { if (strcmp(argv[arg], "-runtime") == 0) runtime = TRUE; - else if (strcmp(argv[arg], "-quiet") == 0) - quiet = TRUE; - else { + else if (strcmp(argv[arg], "-quiet") == 0) { + /* Doesn't do anything today */ + } else { const char * options; processOneLibrary(argv[arg], runtime, explicit, &options, &error); |