+glaze.pc
lib32
lib64
libglaze.so*
-LIBGLAZE_VERSION_MAJOR = 0
-LIBGLAZE_VERSION_MINOR = 0
-LIBGLAZE_VERSION_RELEASE = 0
+all:
+
+# Get settings from the output of configure by running it to generate
+# Makefile.config if it doesn't exist yet.
+
+# If Makefile.config doesn't exist, then srcdir won't be
+# set. Conditionally set it (assuming a plain srcdir build) so that
+# the rule to generate Makefile.config can actually work.
+srcdir ?= .
+
+include Makefile.config
+Makefile.config: $(srcdir)/configure
+ifeq ($(configure_options),)
+ @echo ""
+ @echo "Note: Calling ./configure with no command-line arguments. This is often fine,"
+ @echo " but if you want to specify any arguments (such as an alternate prefix"
+ @echo " into which to install), call ./configure explicitly and then make again."
+ @echo " See \"./configure --help\" for more details."
+ @echo ""
+endif
+ $(srcdir)/configure $(configure_options)
LIBGLAZE_LINKER_NAME = libglaze.so
-LIBGLAZE_SONAME = $(LIBGLAZE_LINKER_NAME).$(LIBGLAZE_VERSION_MAJOR)
-LIBGLAZE_LIBNAME = $(LIBGLAZE_SONAME).$(LIBGLAZE_VERSION_MINOR).$(LIBGLAZE_VERSION_RELEASE)
+LIBGLAZE_SONAME = $(LIBGLAZE_LINKER_NAME).$(MAJOR)
+LIBGLAZE_LIBNAME = $(LIBGLAZE_SONAME).$(MINOR).$(RELEASE)
-TARGETS = lib64/libGL.so.1 lib32/libGL.so.1
+TARGETS = $(LIBGLAZE_LIBNAME) lib64/libGL.so.1 lib32/libGL.so.1
all: $(TARGETS)
install -m0644 lib64/libGL.so.1 $(DESTDIR)$(LIBDIR)/glaze/lib64
mkdir -p $(DESTDIR)$(LIBDIR)/glaze/lib32
install -m0644 lib32/libGL.so.1 $(DESTDIR)$(LIBDIR)/glaze/lib32
+ install -m0644 $(LIBGLAZE_LIBNAME) $(DESTDIR)$(LIBDIR)
+ ln -sf $(LIBGLAZE_LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBGLAZE_SONAME)
+ ln -sf $(LIBGLAZE_LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBGLAZE_LINKER_NAME)
+ mkdir -p $(DESTDIR)$(LIBDIR)/pkgconfig
+ install glaze.pc $(DESTDIR)$(LIBDIR)/pkgconfig
+ mkdir -p $(DESTDIR)$(INCLUDEDIR)/glaze
+ install -m0644 glaze.h $(DESTDIR)$(INCLUDEDIR)/glaze
clean:
rm -f $(TARGETS)
-
-# Get settings from the output of configure by running it to generate
-# Makefile.config if it doesn't exist yet.
-
-# If Makefile.config doesn't exist, then srcdir won't be
-# set. Conditionally set it (assuming a plain srcdir build) so that
-# the rule to generate Makefile.config can actually work.
-srcdir ?= .
-
-include Makefile.config
-Makefile.config: $(srcdir)/configure
-ifeq ($(configure_options),)
- @echo ""
- @echo "Note: Calling ./configure with no command-line arguments. This is often fine,"
- @echo " but if you want to specify any arguments (such as an alternate prefix"
- @echo " into which to install), call ./configure explicitly and then make again."
- @echo " See \"./configure --help\" for more details."
- @echo ""
-endif
- $(srcdir)/configure $(configure_options)
PROJECT=glaze
PROJECT_BLURB="a shiny way to wrap OpenGL"
+MAJOR=0
+MINOR=0
+RELEASE=0
+VERSION=${MAJOR}.${MINOR}.${RELEASE}
+
srcdir=$(dirname "$0")
# For a non-srcdir configure invocation (such as ../configure), create
LDFLAGS = ${LDFLAGS}
# Flags to enable warnings when using the C compiler
-WARN_CFLAGS=${WARN_CFLAGS}
+WARN_CFLAGS = ${WARN_CFLAGS}
# The prefix to which ${PROJECT} should be installed
PREFIX = ${PREFIX}
# The directory to which executables should be installed
-BINDIR = ${BINDIR:=\$(PREFIX)/bin}
+BINDIR = ${BINDIR:-\$(PREFIX)/bin}
# The directory to which libraries should be installed
-LIBDIR = ${LIBDIR:=\$(PREFIX)/lib}
+LIBDIR = ${LIBDIR:-\$(PREFIX)/lib}
# The directory to which headers should be installed
-INCLUDEDIR = ${INCLUDEDIR:=\$(PREFIX)/include}
+INCLUDEDIR = ${INCLUDEDIR:-\$(PREFIX)/include}
# Whether compiler can create 32 or 64-bit binaries
COMPILER_SUPPORTS_32 = ${have_m32}
COMPILER_SUPPORTS_64 = ${have_m64}
+# Version information for glaze library
+MAJOR = ${MAJOR}
+MINOR = ${MINOR}
+RELEASE = ${RELEASE}
+VERSION = ${VERSION}
+
+EOF
+
+# construct the glaze.pc file
+cat > glaze.pc <<EOF
+prefix=${PREFIX}
+exec_prefix=\${prefix}
+libdir=${LIBDIR:-\${exec_prefix\}/lib}
+includedir=${INCLUDEDIR:-\${prefix\}/include}
+
+Name: ${PROJECT}
+Description: ${PROJECT_BLURB}
+Version: ${VERSION}
+
+Libs: -L\${libdir} -lglaze
+Cflags: -I\${includedir}/glaze
EOF
--- /dev/null
+/* 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.
+ */
+
+#define _GNU_SOURCE
+#include <dlfcn.h>
+
+#include "glaze.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+void *
+glaze_lookup (char *function)
+{
+ static void *libgl_handle = NULL;
+ void *ret;
+
+ if (libgl_handle == NULL) {
+ const char *path;
+
+ path = getenv ("GLAZE_LIBGL");
+ if (path == NULL) {
+ fprintf (stderr, "GLAZE_LIBGL unset. "
+ "Please set to path of libGL.so under glaze.\n"
+ );
+ exit (1);
+ }
+
+ libgl_handle = dlopen (path, RTLD_LAZY | RTLD_GLOBAL);
+ if (libgl_handle == NULL) {
+ fprintf (stderr, "Error: Failed to dlopen %s\n", path);
+ exit (1);
+ }
+ }
+
+ ret = dlsym (libgl_handle, function);
+
+ if (ret == NULL) {
+ fprintf (stderr, "Error: glaze_lookup failed to dlsym %s\n",
+ function);
+ exit (1);
+ }
+
+ return ret;
+}
--- /dev/null
+/* 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.
+ */
+
+#ifndef GLAZE_H
+#define GLAZE_H
+
+/* Perform dynamic lookup of 'function' within the library specified
+ * by the GLAZE_LIBGL environment variable.
+ */
+void *
+glaze_lookup (char *function);
+
+/* A helper macro for glaze-using wrappers to defer an operation to
+ * the "real" underlying OpenGL function.
+ *
+ * The underlying function to be called will be obtained by calling
+ * glaze_lookup. This lookup will be cached in a local variable
+ * (defined by this macro) named real_<function>.
+ *
+ * NOTE: This macro can only be used a single time within any
+ * function, (due to the locally-defined variable). If this is
+ * inadequate, callers can instead call glaze_lookup manually.
+ */
+#define GLAZE_DEFER(function,...) do { \
+ static typeof(&function) real_ ## function; \
+ if (! real_ ## function) \
+ real_ ## function = glaze_lookup (#function); \
+ real_ ## function(__VA_ARGS__); \
+} while (0);
+
+/* As GLAZE_DEFER, but also set 'ret' to the value returned by the
+ * underlying "real" function. */
+#define GLAZE_DEFER_WITH_RETURN(ret, function,...) do { \
+ static typeof(&function) real_ ## function; \
+ if (! real_ ## function) \
+ real_ ## function = glaze_lookup (#function); \
+ (ret) = real_ ## function(__VA_ARGS__); \
+} while (0);
+
+#endif /* GLAZE_H */