]> git.tdb.fi Git - gldbg.git/commitdiff
Rewrite the Makefile to have proper dependencies and stuff
authorMikko Rasa <tdb@tdb.fi>
Fri, 11 Jun 2010 12:35:56 +0000 (12:35 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 11 Jun 2010 12:35:56 +0000 (12:35 +0000)
Alter #includes for generated files so they work better with the new Makefile
Fix a constness problem in gl.tm
Split glwrap.c to better facilitate porting to gles2

Makefile
gl.tm
source/enums.c
source/functions.h
source/gldecoder.c
source/gldecoder.h
source/glprint.c
source/glwrap.c
source/glwrap.h [new file with mode: 0644]
source/glwrap_funcs.c [new file with mode: 0644]

index c4dedb2484142439f6f193c85223c73e6e651bc8..294618646c0f3f46133aab054430a25955758cf8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,46 +1,99 @@
 # $Id$
 
-CFLAGS = -Igensrc -ggdb -Wall -Wextra
-CXXFLAGS = -Igensrc -ggdb -Wall -Wextra
+CPPFLAGS := -I.
+CFLAGS := -ggdb -Wall -Wextra
+CXXFLAGS := $(CFLAGS)
 
-PACKAGES_gldbg = mspcore mspstrings mspio mspfs
-CXXFLAGS_gldbg = $(shell pkg-config --cflags $(PACKAGES_gldbg))
-LIBS_gldbg = $(shell pkg-config --libs $(PACKAGES_gldbg)) -lreadline
+PACKAGES_gldbg := mspcore mspstrings mspio mspfs
+
+SOURCES_libgldbg := source/gldecoder.c \
+       source/glprint.c \
+       source/enums.c \
+       source/arraysize.c \
+       source/tmpalloc.c
+SOURCES_glwrap := source/glwrap.c \
+       source/glwrap_funcs.c \
+       source/arraysize.c
+SOURCES_gldump := source/gldump.c
+SOURCES_gldbg := source/gldbg.cpp \
+       source/commandinterpreter.cpp \
+       source/tracer.cpp \
+       source/process.cpp \
+       source/glstate.cpp \
+       source/texturestate.cpp \
+       source/bufferstate.cpp \
+       source/profiler.cpp \
+       source/arraystate.cpp
+TEMPLATES := source/functions.enum.t \
+       source/gldecoder.funcs.t \
+       source/gldecoder.struct.t \
+       source/glprint.funcs.t \
+       source/glwrap.funcs.t
+
+objs = $(patsubst source/%.cpp,temp/%.o,$(patsubst source/%.c,temp/%.o,$(1)))
+deps = $(patsubst source/%.cpp,temp/%.d,$(patsubst source/%.c,temp/%.d,$(1)))
+gen = $(patsubst source/%.t,gensrc/%,$(1))
+
+GENSOURCES := $(call gen,$(TEMPLATES))
+SOURCES_all := $(sort $(SOURCES_libgldbg) $(SOURCES_glwrap) $(SOURCES_gldump) $(SOURCES_gldbg))
+
+OBJECTS_libgldbg := $(call objs,$(SOURCES_libgldbg))
+OBJECTS_glwrap := $(call objs,$(SOURCES_glwrap))
+OBJECTS_gldump := $(call objs,$(SOURCES_gldump))
+OBJECTS_gldbg := $(call objs,$(SOURCES_gldbg))
+
+OBJECTS_all := $(call objs,$(SOURCES_all))
+DEPS_all := $(call deps,$(SOURCES_all))
+
+$(OBJECTS_gldbg): CXXFLAGS += $(shell pkg-config --cflags $(PACKAGES_gldbg))
+gldbg: LIBS += $(shell pkg-config --libs $(PACKAGES_gldbg)) -lreadline
+gldump gldbg: LIBS += ./libgldbg.a
 
 all: glwrap.so gldump gldbg
 
-glwrap.so: source/glwrap.o source/arraysize.o
+glwrap.so: $(OBJECTS_glwrap)
        $(CC) -shared -o $@ $^ $(LIBS) $(LDFLAGS)
 
-gldump: source/gldecoder.o source/gldump.o source/glprint.o source/enums.o source/arraysize.o source/tmpalloc.o
+gldump: $(OBJECTS_gldump) libgldbg.a
        $(CC) -o $@ $^ $(LIBS) $(LDFLAGS)
 
-gldbg: source/gldbg.o source/gldecoder.o source/glprint.o source/commandinterpreter.o source/tracer.o source/process.o source/enums.o source/arraysize.o source/tmpalloc.o source/glstate.o source/texturestate.o source/bufferstate.o source/profiler.o source/arraystate.o
-       $(CXX) -o $@ $^ $(LIBS_gldbg) $(LIBS) $(LDFLAGS)
-
-source/glwrap.o: source/functions.h gensrc/functions.enum gensrc/glwrap.funcs
-source/gldecoder.o: source/functions.h gensrc/gldecoder.struct gensrc/gldecoder.funcs gensrc/gldecoder.funcs
-source/gldump.o: source/gldecoder.h gensrc/gldecoder.struct source/glprint.h
-source/glprint.o: source/arraysize.h gensrc/glprint.funcs gensrc/gldecoder.struct
-source/enums.o: gensrc/enums.table
-source/gldbg.o: source/gldbg.h source/gldecoder.h source/tracer.h source/commandinterpreter.h source/glstate.h source/profiler.h
-source/tracer.o: source/gldecoder.h source/glprint.h
-source/commandinterpreter.o: source/gldbg.h source/glstate.h
-source/process.o: source/process.h
-source/glstate.o: source/glstate.h source/gldecoder.h source/texturestate.h source/bufferstate.h
-source/texturestate.o: source/texturestate.h
-source/bufferstate.o: source/arraystate.h source/bufferstate.h source/enums.h
-source/arraystate.o: source/arraystate.h source/bufferstate.h
-
-%.o: %.cpp
-       $(CXX) -c $(CXXFLAGS) $(CXXFLAGS_gldbg) -o $@ $<
+gldbg: $(OBJECTS_gldbg) libgldbg.a
+       $(CXX) -o $@ $^ $(LIBS) $(LDFLAGS)
+
+libgldbg.a: $(OBJECTS_libgldbg)
+       $(AR) rc $@ $^
+
+temp/%.o: source/%.c temp/.created
+       $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
+
+temp/%.o: source/%.cpp temp/.created
+       $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
+
+temp/.created:
+       mkdir -p temp
+       touch $@
 
 gensrc/%: source/%.t gensrc/.created genwrap.py gl.files gl.tm gl.io gl.spec glx.files glx.tm glx.io glx.spec glxext.spec
        python ./genwrap.py $< gl.files glx.files >$@
 
-gensrc/enums.table: enum.spec genenum.py
+gensrc/enums.table: gensrc/.created enum.spec genenum.py
        python ./genenum.py enum.spec >$@
 
 gensrc/.created:
        mkdir -p gensrc
        touch $@
+
+-include $(DEPS_all)
+
+temp/%.d: source/%.c temp/.created
+       $(CC) $(CPPFLAGS) -MM -MF $@ -MT $(patsubst source/%.c,temp/%.o,$<) -MG $<
+
+temp/%.d: source/%.cpp temp/.created
+       $(CXX) $(CPPFLAGS) -MM -MF $@ -MT $(patsubst source/%.cpp,temp/%.o,$<) -MG $<
+
+.PHONY: clean
+clean:
+       $(RM) $(DEPS_all)
+       $(RM) $(OBJECTS_all)
+       $(RM) gensrc/enums.table $(GENSOURCES)
+       $(RM) glwrap.so libgldbg.a gldump gldbg
diff --git a/gl.tm b/gl.tm
index bc05d5fc08b8a90d7c13a985c462d4444fa7e4d8..cab85509a4a0a9b432d3c72eab8ea7bb01df5391 100644 (file)
--- a/gl.tm
+++ b/gl.tm
@@ -10,7 +10,8 @@ BlendingFactorDest,*,*,                   GLenum,*,*
 BlendingFactorSrc,*,*,             GLenum,*,*
 Boolean,*,*,                       GLboolean,*,*
 BooleanPointer,*,*,                GLboolean*,*,*
-Char,*,array,                      GLchar *,*,value
+Char,in,array,                     const GLchar *,*,value
+Char,out,array,                            GLchar *,*,value
 CharPointer,*,*,                   GLchar*,*,*
 CheckedFloat32,*,*,                GLfloat,*,*
 CheckedInt32,*,*,                  GLint,*,*
index d3572b8a0d185e8aad5eb9d4c910bff23fe9747d..b3e43af9b57ab6ba10c3ccf99ff66e6aedafb6fa 100644 (file)
@@ -18,7 +18,7 @@ typedef struct sEnumInfo
        const char *name;
 } EnumInfo;
 
-#include "enums.table"
+#include "gensrc/enums.table"
 
 const char *describe_enum(GLenum value, const char *categ)
 {
index 0f5d96d91b94073ff89e67ae5ff8925c4f765d7c..caa99e9217f4ded977e16b696fb431a8530c1348 100644 (file)
@@ -8,6 +8,6 @@ Distributed under the GPL
 #ifndef FUNCTIONS_H_
 #define FUNCTIONS_H_
 
-#include "functions.enum"
+#include "gensrc/functions.enum"
 
 #endif
index 8d0f15a1287f57b555bdd6ca18b1269f72f1aa9d..f61e327aa92a9217a589ebb8f7174680f8125a7c 100644 (file)
@@ -141,7 +141,7 @@ static unsigned read_string_array(string **v, const char *data)
        return pos;
 }
 
-#include "gldecoder.funcs"
+#include "gensrc/gldecoder.funcs"
 
 static int decode_gldError(GlDecoder *dec, const char *data)
 {
index 9eb7d89c83906127399c53cf0b721c23e5895e05..b13bc215fa90262f4a19ba9dccbcabf246b5145d 100644 (file)
@@ -15,7 +15,7 @@ Distributed under the GPL
 extern "C" {
 #endif
 
-#include "gldecoder.struct"
+#include "gensrc/gldecoder.struct"
 
 GlDecoder *gldecoder_new(void *, void (*)(void *));
 void gldecoder_delete(GlDecoder *);
index 0081953d8b088de4998ecc8c62b5c6e8d91d499c..8dacdb338b1834765dcb25554835cea5fb31343e 100644 (file)
@@ -129,7 +129,7 @@ static const char *print_data(const void *data, unsigned size)
        }
 }
 
-#include "glprint.funcs"
+#include "gensrc/glprint.funcs"
 
 static void print_gldError(void *user_data, GLenum code)
 {
index 68351143d31aca0567dca79c1d7051a885ced85c..52c6552e1f5c0c007939e62f07a31e233ba8e587 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of gldbg
-Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2009-2010  Mikko Rasa, Mikkosoft Productions
 Distributed under the GPL
 */
 
@@ -10,38 +10,78 @@ Distributed under the GPL
 #include <string.h>
 #include <dlfcn.h>
 #include <sys/uio.h>
-#include <X11/Xlib.h>
-#include <GL/gl.h>
-#include <GL/glx.h>
-#include "arraysize.h"
-#include "functions.h"
 
-static inline void *glsym(const char *sym)
+#define INTERNAL __attribute__((visibility("internal")))
+
+INTERNAL inline const char *get_lib_names(void)
+{
+       const char *env = getenv("GLWRAP_LIBS");
+       if(env)
+               return env;
+       return "libGL.so";
+}
+
+INTERNAL inline void *glsym(const char *name)
 {
-       static void *libgl = NULL;
-       if(!libgl)
+       static void **gl_libs = NULL;
+       unsigned i;
+
+       if(!gl_libs)
        {
-               const char *libgl_name = getenv("GLWRAP_LIBGL");
-               if(!libgl_name)
-                       libgl_name = "libGL.so";
-               libgl = dlopen(libgl_name, RTLD_NOW);
-               if(!libgl)
+               char *lib_names = strdup(get_lib_names());
+               unsigned n_libs = 1;
+               unsigned j;
+
+               for(i=0; lib_names[i]; ++i)
+                       if(lib_names[i]==':')
+                               ++n_libs;
+
+               gl_libs = (void **)malloc((n_libs+1)*sizeof(void *));
+               i = 0;
+               n_libs = 0;
+               for(j=0;; ++j)
                {
-                       fprintf(stderr, "Could not open %s: %s\n", libgl_name, dlerror());
-                       abort();
+                       if(lib_names[j]==':' || lib_names[j]==0)
+                       {
+                               int at_end = (lib_names[j]==0);
+                               lib_names[j] = 0;
+
+                               gl_libs[n_libs] = dlopen(lib_names+i, RTLD_NOW);
+                               if(!gl_libs[n_libs])
+                               {
+                                       fprintf(stderr, "Could not open %s: %s\n", lib_names+i, dlerror());
+                                       abort();
+                               }
+
+                               i = j+1;
+                               ++n_libs;
+
+                               if(at_end)
+                                       break;
+                       }
                }
+
+               gl_libs[n_libs] = 0;
+               free(lib_names);
        }
 
-       return dlsym(libgl, sym);
+       for(i=0; gl_libs[i]; ++i)
+       {
+               void *sym = dlsym(gl_libs[i], name);
+               if(sym)
+                       return sym;
+       }
+
+       return NULL;
 }
 
-static char *buffer = 0;
-static char *write_pos;
-static struct iovec *iovecs = 0;
-static struct iovec *cur_vec;
-static unsigned length;
+INTERNAL char *buffer = 0;
+INTERNAL char *write_pos;
+INTERNAL struct iovec *iovecs = 0;
+INTERNAL struct iovec *cur_vec;
+INTERNAL unsigned length;
 
-static inline void next_vec()
+INTERNAL inline void next_vec(void)
 {
        if(write_pos!=cur_vec->iov_base)
        {
@@ -52,54 +92,54 @@ static inline void next_vec()
        }
 }
 
-static inline void write_bytes(const char *ptr, unsigned size)
+INTERNAL inline void write_bytes(const char *ptr, unsigned size)
 {
        unsigned i;
        for(i=0; i<size; ++i)
                *write_pos++ = *ptr++;
 }
 
-static inline void write_char(char v)
+INTERNAL inline void write_char(char v)
 {
        *write_pos++ = v;
 }
 
-static inline void write_short(short v)
+INTERNAL inline void write_short(short v)
 {
        write_bytes((char *)&v, sizeof(short));
 }
 
-static inline void write_int(int v)
+INTERNAL inline void write_int(int v)
 {
        write_bytes((char *)&v, sizeof(int));
 }
 
-static inline void write_long(long v)
+INTERNAL inline void write_long(long v)
 {
        write_bytes((char *)&v, sizeof(long));
 }
 
-static inline void write_long_long(long long v)
+INTERNAL inline void write_long_long(long long v)
 {
        write_bytes((char *)&v, sizeof(long long));
 }
 
-static inline void write_float(float v)
+INTERNAL inline void write_float(float v)
 {
        write_bytes((char *)&v, sizeof(float));
 }
 
-static inline void write_double(double v)
+INTERNAL inline void write_double(double v)
 {
        write_bytes((char *)&v, sizeof(double));
 }
 
-static inline void write_pointer(const void *p)
+INTERNAL inline void write_pointer(const void *p)
 {
        write_bytes((char *)&p, sizeof(void *));
 }
 
-static inline void write_data(const void *data, unsigned size)
+INTERNAL inline void write_data(const void *data, unsigned size)
 {
        if(data)
        {
@@ -115,12 +155,12 @@ static inline void write_data(const void *data, unsigned size)
                write_int(0);
 }
 
-static inline void write_string(const char *s)
+INTERNAL inline void write_string(const char *s)
 {
        write_data(s, strlen(s)+1);
 }
 
-static inline void write_string_array(const char **sa, unsigned size)
+INTERNAL inline void write_string_array(const char **sa, unsigned size)
 {
        unsigned i;
        size /= sizeof(const char *);
@@ -129,7 +169,7 @@ static inline void write_string_array(const char **sa, unsigned size)
                write_string(sa[i]);
 }
 
-static inline void begin_packet(int func)
+INTERNAL inline void begin_packet(int func)
 {
        if(!buffer)
                buffer = (char *)malloc(1024);
@@ -143,7 +183,7 @@ static inline void begin_packet(int func)
        write_short(func);
 }
 
-static inline void send_packet()
+INTERNAL inline void send_packet(void)
 {
        static int fd = -1;
        if(fd<0)
@@ -159,102 +199,3 @@ static inline void send_packet()
        write_int(length);
        writev(fd, iovecs, cur_vec-iovecs);
 }
-
-int in_begin_block = 0;
-GLenum cur_error = GL_NO_ERROR;
-
-static void check_error()
-{
-       GLenum (*orig_glGetError)() = 0;
-       GLenum code;
-
-       if(in_begin_block)
-               return;
-
-       if(!orig_glGetError)
-               orig_glGetError = glsym("glGetError");
-
-       code = orig_glGetError();
-       if(code!=GL_NO_ERROR)
-       {
-               begin_packet(FUNC_GLDERROR);
-               write_int(code);
-               send_packet();
-
-               if(cur_error==GL_NO_ERROR)
-                       cur_error = code;
-       }
-}
-
-void APIENTRY glBegin(GLenum mode)
-{
-       static void (*orig)(GLenum);
-       if(!orig)
-               orig = glsym("glBegin");
-       orig(mode);
-
-       begin_packet(FUNC_GLBEGIN);
-       write_int(mode);
-       send_packet();
-
-       in_begin_block = 1;
-}
-
-void APIENTRY glEnd()
-{
-       static void (*orig)();
-       if(!orig)
-               orig = glsym("glEnd");
-       orig();
-
-       begin_packet(FUNC_GLEND);
-       send_packet();
-
-       in_begin_block = 0;
-       check_error();
-}
-
-GLenum APIENTRY glGetError()
-{
-       GLenum ret = GL_NO_ERROR;
-
-       if(in_begin_block)
-       {
-               if(cur_error==GL_NO_ERROR)
-                       cur_error = GL_INVALID_OPERATION;
-       }
-       else
-       {
-               ret = cur_error;
-               cur_error = GL_NO_ERROR;
-       }
-
-       begin_packet(FUNC_GLGETERROR);
-       write_int(ret);
-       send_packet();
-
-       return ret;
-}
-
-void (*glXGetProcAddress(const GLubyte *procname))(void)
-{
-       void *handle = 0;
-       void (*ret)() = 0;
-
-       if(glsym((const char *)procname))
-       {
-               handle = dlopen(NULL, RTLD_LAZY);
-               ret = dlsym(handle, (const char *)procname);
-       }
-
-       begin_packet(FUNC_GLXGETPROCADDRESS);
-       write_pointer(ret);
-       write_string((const char *)procname);
-       send_packet();
-
-       return ret;
-}
-
-void (*glXGetProcAddressARB(const GLubyte *))(void) __attribute__((alias("glXGetProcAddress")));
-
-#include "glwrap.funcs"
diff --git a/source/glwrap.h b/source/glwrap.h
new file mode 100644 (file)
index 0000000..047f9c4
--- /dev/null
@@ -0,0 +1,26 @@
+/* $Id$
+
+This file is part of gldbg
+Copyright © 2010  Mikko Rasa, Mikkosoft Productions
+Distributed under the GPL
+*/
+
+#ifndef GLWRAP_H_
+#define GLWRAP_H_
+
+void *glsym(const char *);
+void write_char(char);
+void write_short(short);
+void write_int(int);
+void write_long(long);
+void write_long_long(long long);
+void write_float(float);
+void write_double(double);
+void write_pointer(const void *);
+void write_data(const void *, unsigned);
+void write_string(const char *);
+void write_string_array(const char **, unsigned);
+void begin_packet(int);
+void send_packet(void);
+
+#endif
diff --git a/source/glwrap_funcs.c b/source/glwrap_funcs.c
new file mode 100644 (file)
index 0000000..e7676f6
--- /dev/null
@@ -0,0 +1,113 @@
+/* $Id$
+
+This file is part of gldbg
+Copyright © 2010  Mikko Rasa, Mikkosoft Productions
+Distributed under the GPL
+*/
+
+#include <dlfcn.h>
+#include <X11/Xlib.h>
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include "arraysize.h"
+#include "functions.h"
+#include "glwrap.h"
+
+int in_begin_block = 0;
+GLenum cur_error = GL_NO_ERROR;
+
+static void check_error()
+{
+       GLenum (*orig_glGetError)() = 0;
+       GLenum code;
+
+       if(in_begin_block)
+               return;
+
+       if(!orig_glGetError)
+               orig_glGetError = glsym("glGetError");
+
+       code = orig_glGetError();
+       if(code!=GL_NO_ERROR)
+       {
+               begin_packet(FUNC_GLDERROR);
+               write_int(code);
+               send_packet();
+
+               if(cur_error==GL_NO_ERROR)
+                       cur_error = code;
+       }
+}
+
+void APIENTRY glBegin(GLenum mode)
+{
+       static void (*orig)(GLenum);
+       if(!orig)
+               orig = glsym("glBegin");
+       orig(mode);
+
+       begin_packet(FUNC_GLBEGIN);
+       write_int(mode);
+       send_packet();
+
+       in_begin_block = 1;
+}
+
+void APIENTRY glEnd()
+{
+       static void (*orig)();
+       if(!orig)
+               orig = glsym("glEnd");
+       orig();
+
+       begin_packet(FUNC_GLEND);
+       send_packet();
+
+       in_begin_block = 0;
+       check_error();
+}
+
+GLenum APIENTRY glGetError()
+{
+       GLenum ret = GL_NO_ERROR;
+
+       if(in_begin_block)
+       {
+               if(cur_error==GL_NO_ERROR)
+                       cur_error = GL_INVALID_OPERATION;
+       }
+       else
+       {
+               ret = cur_error;
+               cur_error = GL_NO_ERROR;
+       }
+
+       begin_packet(FUNC_GLGETERROR);
+       write_int(ret);
+       send_packet();
+
+       return ret;
+}
+
+void (*glXGetProcAddress(const GLubyte *procname))(void)
+{
+       void *handle = 0;
+       void (*ret)() = 0;
+
+       if(glsym((const char *)procname))
+       {
+               handle = dlopen(NULL, RTLD_LAZY);
+               ret = dlsym(handle, (const char *)procname);
+       }
+
+       begin_packet(FUNC_GLXGETPROCADDRESS);
+       write_pointer(ret);
+       write_string((const char *)procname);
+       send_packet();
+
+       return ret;
+}
+
+void (*glXGetProcAddressARB(const GLubyte *))(void) __attribute__((alias("glXGetProcAddress")));
+
+#include "gensrc/glwrap.funcs"