From acd14c47b39d0fd15f0b7b212b70606e394b2d0b Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 23 Sep 2013 08:13:22 -0700 Subject: [PATCH] Add a simple helper program, glaze This program allows for a user of glaze to simply execute: glaze --wrapper=mywrapper.so which is a fair bit easier than setting all of LD_LIBRARY_PATH, GLAZE_LIBGL, and GLAZE_WRAPPER to achieve the same result. --- .gitignore | 1 + Makefile | 9 ++++++ glaze.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 glaze.c diff --git a/.gitignore b/.gitignore index 9f7c755..96bf551 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ config.h +glaze glaze.pc glaze-32.pc glaze-find-libgl-32 diff --git a/Makefile b/Makefile index 5ab342a..d881b38 100644 --- 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 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 +#include +#include +#include + +#include + +static void +usage (void) +{ + printf ("Usage: glaze --wrapper= [program args...]\n" + "\n" + "Execute with 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; +} -- 2.43.0