]> git.notmuchmail.org Git - glaze/commitdiff
Add a simple helper program, glaze
authorCarl Worth <cworth@cworth.org>
Mon, 23 Sep 2013 15:13:22 +0000 (08:13 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 23 Sep 2013 15:13:22 +0000 (08:13 -0700)
This program allows for a user of glaze to simply execute:

glaze --wrapper=mywrapper.so <program> <args>

which is a fair bit easier than setting all of LD_LIBRARY_PATH,
GLAZE_LIBGL, and GLAZE_WRAPPER to achieve the same result.

.gitignore
Makefile
glaze.c [new file with mode: 0644]

index 9f7c7555201e69f92e40c4e8baa8fc114fd2d9f6..96bf5515c013a8367d41e2246ca6be025008441d 100644 (file)
@@ -1,4 +1,5 @@
 config.h
+glaze
 glaze.pc
 glaze-32.pc
 glaze-find-libgl-32
index 5ab342a8cebb55c0b1a70871ff14306b03859588..d881b38df1901deb9b8ee54fc64c7654dcd993af 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,8 @@ LIBGLAZE_32_LINKER_NAME = libglaze-32.so
 LIBGLAZE_32_SONAME = $(LIBGLAZE_32_LINKER_NAME).$(MAJOR)
 LIBGLAZE_32_LIBNAME = $(LIBGLAZE_32_SONAME).$(MINOR).$(RELEASE)
 
+TARGETS = glaze
+
 ifeq ($(COMPILER_SUPPORTS_32),Yes)
 TARGETS += $(LIBGLAZE_32_LIBNAME)
 TARGETS += $(LIB32_DIR)/libGL.so.1
@@ -44,12 +46,18 @@ all: $(TARGETS)
 
 GLAZE_CFLAGS = $(CFLAGS) $(WARN_CFLAGS)
 
+glaze: glaze.c $(LIBGLAZE_LINKER_NAME)
+       $(CC) $(GLAZE_CFLAGS) -I. -L. -o $@ $< -ldl -lglaze
+
 $(LIBGLAZE_32_LIBNAME): libglaze.c
        $(CC) $(GLAZE_CFLAGS) -m32 -fPIC -shared -Wl,-Bsymbolic,-soname=$(LIBGLAZE_SONAME) -ldl -ltalloc -o $@ $<
 
 $(LIBGLAZE_LIBNAME): libglaze.c
        $(CC) $(GLAZE_CFLAGS) -m64 -fPIC -shared -Wl,-Bsymbolic,-soname=$(LIBGLAZE_SONAME) -ldl -ltalloc -o $@ $<
 
+$(LIBGLAZE_LINKER_NAME): $(LIBGLAZE_LIBNAME)
+       ln -sf $(LIBGLAZE_LIBNAME) $@
+
 $(LIB64_DIR)/libGL.so.1: glaze-gl.c
        mkdir -p $(LIB64_DIR)
        $(CC) $(GLAZE_CFLAGS) -DGLAZE_BITS=64 -m64 -fPIC -shared -Wl,-Bsymbolic -o $@ $<
@@ -70,6 +78,7 @@ install: all
        install -m0644 glaze.h $(DESTDIR)$(INCLUDEDIR)/glaze
        mkdir -p $(DESTDIR)$(BINDIR)
        mkdir -p $(DESTDIR)$(LIBDIR)/pkgconfig
+       install -m0755 glaze $(DESTDIR)$(BINDIR)
 ifeq ($(COMPILER_SUPPORTS_32),Yes)
        mkdir -p $(DESTDIR)$(LIBDIR)/glaze/$(LIB32_DIR)
        install -m0644 $(LIB32_DIR)/libGL.so.1 $(DESTDIR)$(LIBDIR)/glaze/$(LIB32_DIR)
diff --git a/glaze.c b/glaze.c
new file mode 100644 (file)
index 0000000..9a3e055
--- /dev/null
+++ b/glaze.c
@@ -0,0 +1,84 @@
+/* Copyright © 2013, Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <limits.h>
+
+#include <glaze.h>
+
+static void
+usage (void)
+{
+       printf ("Usage: glaze --wrapper=<wrapper> <program> [program args...]\n"
+               "\n"
+               "Execute <program> with <wrapper> providing alternate OpenGL functions.\n");
+}
+
+enum {
+       WRAPPER_OPT = CHAR_MAX + 1
+};
+
+int
+main (int argc, char *argv[])
+{
+       const char *wrapper = NULL;
+       int opt;
+
+       const char *short_options="h";
+       const struct option long_options[] = {
+               {"help", no_argument, 0, 'h'},
+               {"wrapper", required_argument, 0, WRAPPER_OPT},
+               {0, 0, 0, 0}
+       };
+
+       while (1)
+       {
+               opt = getopt_long (argc, argv, short_options, long_options, NULL);
+               if (opt == -1)
+                       break;
+
+               switch (opt) {
+               case 'h':
+                       usage ();
+                       return 0;
+               case WRAPPER_OPT:
+                       wrapper = optarg;
+                       break;
+               default:
+                       fprintf (stderr, "Internal error: "
+                                "unexpected getopt value: %d\n", opt);
+                       exit (1);
+               }
+       }
+
+       if (optind >= argc) {
+               fprintf (stderr, "Error: No program name provided, "
+                        "see (glaze --help)\n");
+               exit (1);
+       }
+
+       glaze_execute (argc - optind, &argv[optind], wrapper);
+
+       /* If glaze_execute returns then something went wrong. */
+       return 1;
+}