+ /* Set GLAZE_WRAPPER to absolute path of wrapper library */
+ if (wrapper == NULL || *wrapper == '\0') {
+ fprintf (stderr, "Error: glaze_execute called with empty wrapper library.\n");
+ return;
+ }
+
+ wrapper = resolve_wrapper_path (ctx, wrapper);
+
+ setenv ("GLAZE_WRAPPER", wrapper, 1);
+
+ /* Ensure GLAZE_LIBGL is set. If not, set GLAZE_LIBGL_32_AUTO
+ * and GLAZE_LIBGL_64_AUTO
+ *
+ * Note that we must do this before setting LD_LIBRARY_PATH,
+ * since after that, of course we would find Glaze's wrapper
+ * libGL.so.1. */
+ if (getenv ("GLAZE_LIBGL") == NULL) {
+ char *libgl_path;
+
+ libgl_path = read_process_output_one_line ("glaze-find-libgl-32");
+ if (libgl_path) {
+ setenv ("GLAZE_LIBGL_32_AUTO", libgl_path, 1);
+ free (libgl_path);
+ }
+
+ libgl_path = read_process_output_one_line ("glaze-find-libgl-64");
+ if (libgl_path) {
+ setenv ("GLAZE_LIBGL_64_AUTO", libgl_path, 1);
+ free (libgl_path);
+ }
+ }
+
+ /* Set LD_LIBRARY_PATH to include glaze's own libGL.so */
+ const char *glaze_libgl_dir, *ld_library_path;
+
+ glaze_libgl_dir = find_glaze_libgl_dir ();
+
+ ld_library_path = getenv ("LD_LIBRARY_PATH");
+
+ if (ld_library_path == NULL)
+ ld_library_path = glaze_libgl_dir;
+ else
+ ld_library_path = talloc_asprintf (ctx, "%s:%s",
+ glaze_libgl_dir,
+ ld_library_path);
+
+ setenv ("LD_LIBRARY_PATH", ld_library_path, 1);
+
+ talloc_free (ctx);
+
+ /* Execute program */
+ execvp (argv[0], argv);
+
+ /* If execvp returns, something went wrong. */
+ fprintf (stderr, "Error: Failed to exec:");
+ for (i = 0; i < argc; i++)
+ fprintf (stderr, " %s", argv[i]);
+ fprintf (stderr, "\n");
+
+ return;
+}
+
+void
+glaze_set_first_gl_call_callback (const char *function_name)
+{
+ setenv ("GLAZE_FIRST_GL_CALL_CALLBACK", function_name, 1);
+}