revision 1234:1b836bf92653
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 1234:1b836bf92653 |
parent | 1233:06923d1020de |
child | 1235:8da2f3dad9c0 |
author | nkeynes |
date | Fri Feb 24 17:31:18 2012 +1000 (11 years ago) |
Add some real option processing to genglsl and let it accept multiple glsl
input files (basically concatenate them together)
input files (basically concatenate them together)
![]() | src/Makefile.am | view | annotate | diff | log | |
![]() | src/Makefile.in | view | annotate | diff | log | |
![]() | src/tools/genglsl.c | view | annotate | diff | log |
1.1 --- a/src/Makefile.am Thu Feb 23 22:40:50 2012 +10001.2 +++ b/src/Makefile.am Fri Feb 24 17:31:18 2012 +10001.3 @@ -258,7 +258,7 @@1.4 $(GENDEC) $(srcdir)/sh4/sh4.def $(srcdir)/sh4/sh4stat.in -o $@1.5 pvr2/shaders.def: $(GENGLSL) pvr2/shaders.glsl1.6 $(mkdir_p) `dirname $@`1.7 - $(GENGLSL) $(srcdir)/pvr2/shaders.glsl $@1.8 + $(GENGLSL) $(srcdir)/pvr2/shaders.glsl -o $@1.9 pvr2/shaders.h: pvr2/shaders.def1.10 drivers/mac_keymap.h: dckeysyms.h drivers/mac_keymap.txt drivers/genkeymap.pl1.11 $(mkdir_p) `dirname $@`
2.1 --- a/src/Makefile.in Thu Feb 23 22:40:50 2012 +10002.2 +++ b/src/Makefile.in Fri Feb 24 17:31:18 2012 +10002.3 @@ -2720,7 +2720,7 @@2.4 $(GENDEC) $(srcdir)/sh4/sh4.def $(srcdir)/sh4/sh4stat.in -o $@2.5 pvr2/shaders.def: $(GENGLSL) pvr2/shaders.glsl2.6 $(mkdir_p) `dirname $@`2.7 - $(GENGLSL) $(srcdir)/pvr2/shaders.glsl $@2.8 + $(GENGLSL) $(srcdir)/pvr2/shaders.glsl -o $@2.9 pvr2/shaders.h: pvr2/shaders.def2.10 drivers/mac_keymap.h: dckeysyms.h drivers/mac_keymap.txt drivers/genkeymap.pl2.11 $(mkdir_p) `dirname $@`
3.1 --- a/src/tools/genglsl.c Thu Feb 23 22:40:50 2012 +10003.2 +++ b/src/tools/genglsl.c Fri Feb 24 17:31:18 2012 +10003.3 @@ -7,7 +7,7 @@3.4 * a C file with appropriate escaping, as well as program definitions3.5 * written as #program <name> = <shader1> <shader2> ... <shaderN>3.6 *3.7 - * Copyright (c) 2007-2010 Nathan Keynes.3.8 + * Copyright (c) 2007-2012 Nathan Keynes.3.9 *3.10 * This program is free software; you can redistribute it and/or modify3.11 * it under the terms of the GNU General Public License as published by3.12 @@ -26,6 +26,7 @@3.13 #include <stdio.h>3.14 #include <stdlib.h>3.15 #include <string.h>3.16 +#include <getopt.h>3.17 #include <glib/gstrfuncs.h>3.18 #include <glib/glist.h>3.20 @@ -144,7 +145,7 @@3.21 }3.24 -static struct glsldata *readInput( const char *filename )3.25 +static void readInput( const char *filename, glsldata_t result )3.26 {3.27 char buf[MAX_LINE];3.28 size_t current_size = 0, current_posn = 0;3.29 @@ -153,13 +154,17 @@3.30 FILE *f = fopen( filename, "ro" );3.31 if( f == NULL ) {3.32 fprintf( stderr, "Error: unable to open input file '%s': %s\n", filename, strerror(errno) );3.33 - exit(1);3.34 + exit(2);3.35 }3.37 shader_t shader = NULL;3.38 - glsldata_t result = g_malloc0(sizeof(struct glsldata));3.39 - assert( result != NULL );3.40 - result->filename = strdup(filename);3.41 + if( result->filename == NULL ) {3.42 + result->filename = g_strdup(filename);3.43 + } else {3.44 + const gchar *tmp = result->filename;3.45 + result->filename = g_strdup_printf("%s, %s", tmp, filename);3.46 + g_free((gchar *)tmp);3.47 + }3.49 while( fgets(buf, sizeof(buf), f) != NULL ) {3.50 if( strlen(buf) == 0 )3.51 @@ -220,8 +225,6 @@3.52 }3.54 fclose(f);3.55 - linkPrograms(result);3.56 - return result;3.57 }3.59 /**3.60 @@ -433,7 +436,7 @@3.61 fclose(f);3.62 }3.64 -const char *makeExtension(const char *basename, const char *ext)3.65 +static const char *makeExtension(const char *basename, const char *ext)3.66 {3.67 const char *oldext = strrchr(basename, '.');3.68 if( oldext == NULL ) {3.69 @@ -443,29 +446,65 @@3.70 }3.71 }3.73 +static char *option_list = "hi:o:";3.74 +static struct option long_option_list[] = {3.75 + { "help", no_argument, NULL, 'h' },3.76 + { "interface", required_argument, 'i' },3.77 + { "output", required_argument, NULL, 'o' },3.78 + { NULL, 0, 0, 0 } };3.79 +3.80 +static void usage() {3.81 + fprintf( stderr, "Usage: genglsl <glsl-source-list> [-o output.def] [-i output.h]\n");3.82 +}3.83 int main( int argc, char *argv[] )3.84 {3.85 - if( argc < 2 ) {3.86 - fprintf( stderr, "Usage: genglsl <glsl-source-file> [output.c [output.h]]\n");3.87 + const char *output_file = NULL;3.88 + const char *iface_file = NULL;3.89 + int opt;3.90 +3.91 + while( (opt = getopt_long( argc, argv, option_list, long_option_list, NULL )) != -1 ) {3.92 + switch( opt ) {3.93 + case 'h':3.94 + usage();3.95 + exit(0);3.96 + break;3.97 + case 'i':3.98 + if( iface_file != NULL ) {3.99 + fprintf( stderr, "Error: at most one interface file can be supplied\n" );3.100 + usage();3.101 + exit(1);3.102 + }3.103 + iface_file = optarg;3.104 + break;3.105 + case 'o':3.106 + if( output_file != NULL ) {3.107 + fprintf( stderr, "Error: at most one output file can be supplied\n" );3.108 + usage();3.109 + exit(1);3.110 + }3.111 + output_file = optarg;3.112 + }3.113 + }3.114 +3.115 + if( optind == argc ) {3.116 + usage();3.117 exit(1);3.118 }3.120 - glsldata_t data = readInput(argv[1]);3.121 -3.122 - const char *sourcefile, *ifacefile;3.123 - if( argc > 2 ) {3.124 - sourcefile = argv[2];3.125 - } else {3.126 - sourcefile = makeExtension(argv[1], ".def");3.127 + if( output_file == NULL ) {3.128 + output_file = makeExtension(argv[optind], ".def");3.129 + }3.130 + if( iface_file == NULL ) {3.131 + iface_file = makeExtension(output_file, ".h");3.132 }3.134 - if( argc > 3 ) {3.135 - ifacefile = argv[3];3.136 - } else {3.137 - ifacefile = makeExtension(sourcefile, ".h");3.138 + glsldata_t data = g_malloc0(sizeof(struct glsldata));3.139 + while( optind < argc ) {3.140 + readInput(argv[optind++], data);3.141 }3.142 + linkPrograms(data);3.144 - writeSource( sourcefile, data );3.145 - writeInterface( ifacefile, data );3.146 + writeSource( output_file, data );3.147 + writeInterface( iface_file, data );3.148 return 0;3.149 }
.